mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
storyboook addon knobs select: correct types for an array (#38316)
* Update select types * add test * fix tests
This commit is contained in:
parent
31913491d8
commit
72c07c7005
7
types/storybook__addon-knobs/index.d.ts
vendored
7
types/storybook__addon-knobs/index.d.ts
vendored
@ -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'],
|
||||
|
||||
@ -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' }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user