From 22f17cf61d5d5c4d2c4e346e3d8792f6fe247d2c Mon Sep 17 00:00:00 2001 From: Prannay Budhraja Date: Wed, 9 Aug 2017 18:39:58 -0700 Subject: [PATCH] select knob options object keys are strings or numbers only * select knob uses the keys of the "options" object as the selected values, and doesn't support arbitrary types as values. * It only supports arbitrary types for the select->option->child. These are the values in options object. * The value of the select knob or the selected option however, is still either a string or number. Also, since typescript object key signature can only be either "string" or "number" (but not string | number) we need to specify both types explicitly. options : { [s: string | number]: T } does not work. --- types/storybook__addon-knobs/index.d.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/types/storybook__addon-knobs/index.d.ts b/types/storybook__addon-knobs/index.d.ts index 3e422640c8..11fbfb9cd5 100644 --- a/types/storybook__addon-knobs/index.d.ts +++ b/types/storybook__addon-knobs/index.d.ts @@ -36,8 +36,10 @@ export function color(name: string, value: string): string; export function object(name: string, value: T): T; -export function select(name: string, options: { [s: string]: T }, value: string): T; -export function select(name: string, options: string[], value: string): string; +export function select(name: string, options: { [s: string]: T }, value: string): string; +export function select(name: string, options: { [s: number]: T }, value: number): number; +type SelectValue = string | number; +export function select(name: string, options: T[], value: T): T; export function date(name: string, value?: Date): Date;