Skip to content

Feature Request: CustomFieldStore helper type #67

@katywings

Description

@katywings

Is

If the schema is generated during runtime, you currently do not have a built-in way to help the editor infer the correct types.

Correct: the schema is inside the code, so the editor has no issues to infer the types:
Image

Wrong: the schema was generated, so the editor infers a Strudel of all possible types:
Image

Should

There should be ways, or atleast one way to get the correct field props for the particular situations. E.g. maybe a builtin CustomFieldStore helper type that returns the proper FieldStore type for the specified schema:

const numberSchema = v.number();

type CustomFieldStore<T extends v.GenericSchema> = FieldStore<
  v.ObjectSchema<{ s: T }, undefined>,
  ['s']
>;

<Show when={dbField.type === 'number'}>
  <Field of={loginForm()} path={[dbField.name]}>
    {(field_) => {
      const field = field_ as CustomFieldStore<typeof numberSchema>;
      type V = typeof field.input;

      return (
        <TextInput
          {...field.props}
          input={field.input}
          errors={field.errors}
          type="number"
          label={label()}
          required
        />
      );
    }}
  </Field>
</Show>

Result:
Image

Extras

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions