From 8ca3486ccb8c192e8ce8b073dc2c4ab33d8da60b Mon Sep 17 00:00:00 2001 From: Xingchen Hong Date: Tue, 2 Apr 2019 00:19:33 -0700 Subject: [PATCH 1/2] Fix return type of @storybook/addon-knobs/radios `radios` picks value from property values of `options` or default value `value`. So return type should be consistent with them. --- types/storybook__addon-knobs/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/storybook__addon-knobs/index.d.ts b/types/storybook__addon-knobs/index.d.ts index dd512af5d0..b2fe8f8261 100644 --- a/types/storybook__addon-knobs/index.d.ts +++ b/types/storybook__addon-knobs/index.d.ts @@ -49,7 +49,7 @@ export function color(name: string, value: string, groupId?: string): string; export function object(name: string, value: T, groupId?: string): T; -export function radios(name: string, options: { [s: string]: T }, value?: T, groupId?: string): string; +export function radios(name: string, options: { [s: string]: T }, value?: T, groupId?: string): T; export function select(name: string, options: { [s: string]: T }, value: T, groupId?: string): T; export function select< From 89bc63855e1adbf12d73bd1bc7918e6f3556748b Mon Sep 17 00:00:00 2001 From: Xingchen Hong Date: Tue, 2 Apr 2019 00:37:53 -0700 Subject: [PATCH 2/2] Add test case for `radios` with `number` values If the property values of the options are numbers, the return type should also be numbers. Also adds type to the test case where the property values are strings. --- types/storybook__addon-knobs/storybook__addon-knobs-tests.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/storybook__addon-knobs/storybook__addon-knobs-tests.tsx b/types/storybook__addon-knobs/storybook__addon-knobs-tests.tsx index 0e95a757ba..821d4677fc 100644 --- a/types/storybook__addon-knobs/storybook__addon-knobs-tests.tsx +++ b/types/storybook__addon-knobs/storybook__addon-knobs-tests.tsx @@ -35,7 +35,8 @@ stories.add('with all knobs', () => { const selectedColor = color('Color', 'black'); const favoriteNumber = number('Favorite Number', 42); const comfortTemp = number('Comfort Temp', 72, { range: true, min: 60, max: 90, step: 1 }); - const radioStation = radios('Favorite Radio Station', { 1100: "1100", 2200: "2200", 3300: "3300" }); + const radioStation: string = radios('Favorite Radio Station', { 1100: "1100", 2200: "2200", 3300: "3300" }); + const luckyNumber: number = radios('Lucky Number', { 3: 3, 7: 7, 23: 23 }); const textDecoration = select('Decoration', { None: 'none', Underline: 'underline', @@ -77,6 +78,7 @@ stories.add('with all knobs', () => {

My favorite number is {favoriteNumber}.

My most comfortable room temperature is {comfortTemp} degrees Fahrenheit.

My favorite radio station is: {radioStation}

+

My lucky number is {luckyNumber}.

); });