From 16d81a789790cc86345629712444eb26623d4196 Mon Sep 17 00:00:00 2001 From: Andrew MacLeay Date: Mon, 28 Jan 2019 14:32:27 -0500 Subject: [PATCH] Allow withInfo to be used as top-level story decorator This allows the syntax [suggested by the README](https://github.com/storybooks/storybook/blob/dc38ae87bb1ef80ccd48b1695009e36632cbe5ee/addons/info/README.md#basic-usage) --- types/storybook__addon-info/index.d.ts | 6 +++++- types/storybook__addon-info/storybook__addon-info-tests.tsx | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/types/storybook__addon-info/index.d.ts b/types/storybook__addon-info/index.d.ts index 111f7dc54d..a6c463f5d9 100644 --- a/types/storybook__addon-info/index.d.ts +++ b/types/storybook__addon-info/index.d.ts @@ -6,7 +6,7 @@ // TypeScript Version: 2.8 import * as React from 'react'; -import { RenderFunction } from '@storybook/react'; +import { RenderFunction, StoryDecorator } from '@storybook/react'; export interface WrapStoryProps { storyFn?: RenderFunction; @@ -29,6 +29,10 @@ export interface Options { maxPropStringLength?: number; } +// TODO: it would be better to use type inference for the parameters +// type DecoratorParams = StoryDecorator extends (...a: infer A) => any ? A: never; +export function withInfo(story: RenderFunction, context: { kind: string, story: string }): ReturnType; +// Legacy, but supported export function withInfo(textOrOptions?: string | Options): (storyFn: RenderFunction) => (context?: object) => React.ReactElement; export function setDefaults(newDefaults: Options): Options; diff --git a/types/storybook__addon-info/storybook__addon-info-tests.tsx b/types/storybook__addon-info/storybook__addon-info-tests.tsx index 46fd799314..505780bf7e 100644 --- a/types/storybook__addon-info/storybook__addon-info-tests.tsx +++ b/types/storybook__addon-info/storybook__addon-info-tests.tsx @@ -1,11 +1,13 @@ /// import * as React from 'react'; -import { storiesOf } from '@storybook/react'; +import { addDecorator, storiesOf } from '@storybook/react'; import { setDefaults, withInfo } from '@storybook/addon-info'; const { Component } = React; +addDecorator(withInfo); + setDefaults({ inline: false, propTables: false