From 140d0dc3e477b99a4bd1e1b6452560bfd702f35f Mon Sep 17 00:00:00 2001 From: Andrew MacLeay Date: Mon, 28 Jan 2019 15:24:13 -0500 Subject: [PATCH] @storybook/addon-notes: support global decorator Support the global decorator usage supplied in [the README](https://github.com/storybooks/storybook/blob/9f30442098e5350f5ba4872887cf9d1a03146e74/addons/ondevice-notes/README.md#getting-started) --- types/storybook__addon-notes/index.d.ts | 4 ++++ .../storybook__addon-notes/storybook__addon-notes-tests.tsx | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/types/storybook__addon-notes/index.d.ts b/types/storybook__addon-notes/index.d.ts index b669ce0a9c..096da8fa34 100644 --- a/types/storybook__addon-notes/index.d.ts +++ b/types/storybook__addon-notes/index.d.ts @@ -17,5 +17,9 @@ export type WithNotesOptions = string | { markdownOptions?: MarkedOptions; }; +// It would be preferable to infer the argument types, but that requires TS v 3.1 +// export function withNotes(...args: StoryDecorator extends (...a: infer A) => any ? A : never): ReturnType; +export function withNotes(story: RenderFunction, context: { kind: string, story: string }): ReturnType; +// Less-preferred but still supported: export function withNotes(options?: WithNotesOptions): StoryDecorator; export function withMarkdownNotes(markdown: string, options?: MarkedOptions): StoryDecorator; diff --git a/types/storybook__addon-notes/storybook__addon-notes-tests.tsx b/types/storybook__addon-notes/storybook__addon-notes-tests.tsx index ebf24ce227..edfe0daf14 100644 --- a/types/storybook__addon-notes/storybook__addon-notes-tests.tsx +++ b/types/storybook__addon-notes/storybook__addon-notes-tests.tsx @@ -1,8 +1,11 @@ import * as React from 'react'; -import { storiesOf } from '@storybook/react'; +import { addDecorator, storiesOf } from '@storybook/react'; import { withNotes, withMarkdownNotes, } from '@storybook/addon-notes'; +// New, preferred global registration: +addDecorator(withNotes); + const SIMPLE_MARKDOWN = ` ## Markdown for component