firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

Refactor: Make `defineString` generic for better type-safety

Open keeganpotgieter opened this issue 5 months ago • 0 comments

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 avatar May 20 '25 01:05 keeganpotgieter