In typescript how can I get an array of string options?
export type KeyboardType = 'default' | 'email-address' | 'numeric' | 'phone-pad' | 'number-pad' | 'decimal-pad';
const keyboardTypes = x; // ['default', 'email-address', 'numeric', 'phone-pad', 'number-pad', 'decimal-pad']
>Solution :
You can’t, since types only exist at compile/transpile time.
You can do the opposite, however, where you have an array of values keyboardTypes (make sure to add as const) and then define the type KeyboardType as the values of that array.
const keyboardTypes = ['default', 'email-address', 'numeric', 'phone-pad', 'number-pad', 'decimal-pad'] as const;
export type KeyboardType = typeof keyboardTypes[number];
// ^? 'default' | 'email-address' | 'numeric' | 'phone-pad' | 'number-pad' | 'decimal-pad'