Skip to content

Respect optional fields in select options #895

@chrisvxd

Description

@chrisvxd

Puck does not allow optional values in select fields.

Steps to reproduce

Add an optional value with a select field

Code example

type Props = {
  MyComponent: {
    fruit?: 'apple' | 'banana' // Make optional with `?`
  }
}

const conf: Config<Props> = {
  components: {
    MyComponent: {
      fields: {
        fruit: {
          type: "select",
          options: [
            { label: '', value: undefined }, // Should work because `fruit` is optional
            { label: 'Apple', value: 'apple' },
            { label: 'Banana', value: 'banana' },
          ]
        }
      }
    }
  }
}

What happened

TS complains that undefined is not a valid value for fruit

What I expected to happen

TS would not complain because fruit is optional in the Props type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions