Skip to content

Allow to cast a field to a specific type (e.g. when working with dynamic schemas where the actual type can not be inferred) #67

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestnext versionThis is planned for the next major version

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions