storyboook addon knobs select: correct types for an array (#38316)

* Update select types

* add test

* fix tests
This commit is contained in:
Andrew Lisowski 2019-09-16 15:05:24 -07:00 committed by Orta
parent 31913491d8
commit 72c07c7005
2 changed files with 14 additions and 1 deletions

View File

@ -52,7 +52,12 @@ export function object<T>(name: string, value: T, groupId?: string): T;
export function radios<T>(name: string, options: { [s: string]: T }, value?: T, groupId?: string): T;
export function select<T>(name: string, options: { [s: string]: T }, value: T, groupId?: string): T;
export function select<T>(
name: string,
options: { [s: string]: T } | ReadonlyArray<T>,
value: T,
groupId?: string,
): T;
export function select<
T extends Exclude<
React.OptionHTMLAttributes<HTMLOptionElement>['value'],

View File

@ -108,6 +108,14 @@ const stringLiteralArray: StringLiteralType[] = ['Apple', 'Banana', 'Grapes'];
// type of value returned from `select` must be `StringLiteralType`.
const _: StringLiteralType = select('With string literal array', stringLiteralArray, stringLiteralArray[0]);
type StringLiteralTypeUndefined = StringLiteralType | undefined;
const _Undefined: StringLiteralTypeUndefined = select(
'With string literal array',
stringLiteralArray,
undefined,
);
const optionsObject = {
Apple: { taste: 'sweet', color: 'red' },
Lemon: { taste: 'sour', color: 'yellow' }