Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export FormState type #180

Open
crazyursus92 opened this issue Dec 15, 2022 · 0 comments
Open

Export FormState type #180

crazyursus92 opened this issue Dec 15, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@crazyursus92
Copy link

crazyursus92 commented Dec 15, 2022

I am developing base form components in my project and I want to reuse type to provide form state to component. For example
I have a component called "ControlWrapper" which resposible for display label and validation error and I want to be full type safety, so I want to resuse FormState type from lib. Now I need to copy FromState from lib to my own type file and it is affect runtime typescript perfomance and maintainability

<script lang="ts">
  import get from "lodash/get";
  import type { DotNestedKeys, FormState } from "./types";

  type T = $$Generic<Record<string, any>>;
  type $$Props = {
    formState: FormState<T>;
    className?: string;
    label?: string;
    name: DotNestedKeys<T>;
  };

  let {
    formState: { errors },
    className,
    label,
    name,
  } = $$props as $$Props;

  $: error = get($errors, name);
</script>

<div class="form-control w-full max-w-xs {className}">
  {#if label}
    <label class="label">
      <span class="label-text">{label}</span>
    </label>
  {/if}
  <slot />
  {#if error}
    <label class="label">
      <span class="label-text-alt">{error}</span>
    </label>
  {/if}
</div>

Problem to solve

Any developer can build his own full type sefety component base on this type

Intended users

Developer

Proposal

export FromState type from lib

@crazyursus92 crazyursus92 added the enhancement New feature or request label Dec 15, 2022
crazyursus92 added a commit to crazyursus92/svelte-forms-lib that referenced this issue Dec 15, 2022
crazyursus92 added a commit to crazyursus92/svelte-forms-lib that referenced this issue Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant