Skip to content

Conversation

keeganpotgieter
Copy link

@keeganpotgieter keeganpotgieter commented May 20, 2025

Description

The defineString function does not narrow the type when adding input.select.options. This means we have to typecast in certain situations, even though we know what the types should be.

Code sample

const environmentParam = params.defineString("ENVIRONMENT", {
      default: "production", // This will now error out if it does not match one of the options
      input: {
        select: {
          options: [
            { label: "Production", value: "production" },
            { label: "Staging", value: "staging" },
            { label: "Development", value: "development" },
          ],
        },
      },
});

const environment = environmentParam.value();
// ^? "production" | "staging" | "development"

Limitations

  • If defaultValue is provided with no options the value is still wide, rather than loose autocomplete

@keeganpotgieter keeganpotgieter force-pushed the refactor/make-defineString-type-safe branch from c4788a9 to 5e88ed1 Compare June 17, 2025 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant