Allow readonly parameters to storybook knobs

Since these functions don't modify their parameters, they may be
readonly. Non-breaking change as mutable arrays are still allowed as
well.
This commit is contained in:
Andrew MacLeay
2018-08-02 16:33:31 -04:00
parent 48ebc7e7c7
commit 4ee926dbad
2 changed files with 11 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/storybooks/storybook
// Definitions by: Joscha Feth <https://github.com/joscha>
// Martynas Kadisa <https://github.com/martynaskadisa>
// A.MacLeay <https://github.com/amacleay>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
@@ -49,11 +50,11 @@ export function object<T>(name: string, value: T, groupId?: string): T;
export type SelectValue = string | number;
export function select<T extends string>(name: string, options: { [s: string]: string }, value: T, groupId?: string): T;
export function select<T extends number>(name: string, options: { [s: number]: string }, value: T, groupId?: string): T;
export function select<T extends SelectValue>(name: string, options: T[], value: T, groupId?: string): T;
export function select<T extends SelectValue>(name: string, options: ReadonlyArray<T>, value: T, groupId?: string): T;
export function date(name: string, value?: Date, groupId?: string): Date;
export function array<T>(name: string, value: T[], separator?: string, groupId?: string): T[];
export function array<T>(name: string, value: ReadonlyArray<T>, separator?: string, groupId?: string): T[];
export function button(name: string, handler: () => any, groupId?: string): void;

View File

@@ -90,6 +90,14 @@ stories.add('dynamic knobs', () => {
);
});
const readonlyOptionsArray: ReadonlyArray<string> = ['hi'];
select('With readonly array', readonlyOptionsArray, readonlyOptionsArray[0]);
const genericArray = array('With regular array', ['hi', 'there']);
const userInputArray = array('With readonly array', readonlyOptionsArray);
userInputArray.push('Make sure that the output is still mutable although the input need not be!');
// groups
const groupId = 'GROUP-ID1';