mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-12 19:59:02 +08:00
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:
5
types/storybook__addon-knobs/index.d.ts
vendored
5
types/storybook__addon-knobs/index.d.ts
vendored
@@ -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;
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user