diff --git a/addons/options/package.json b/addons/options/package.json index 1e0945382065..3ddaad44e35f 100644 --- a/addons/options/package.json +++ b/addons/options/package.json @@ -17,6 +17,7 @@ }, "license": "MIT", "main": "dist/index.js", + "types": "dist/public_api.d.ts", "scripts": { "prepare": "node ../../scripts/prepare.js" }, diff --git a/addons/options/src/constants.js b/addons/options/src/constants.ts similarity index 100% rename from addons/options/src/constants.js rename to addons/options/src/constants.ts diff --git a/addons/options/src/index.js b/addons/options/src/index.ts similarity index 92% rename from addons/options/src/index.js rename to addons/options/src/index.ts index 311a82081dcf..acfaf60bdc98 100644 --- a/addons/options/src/index.js +++ b/addons/options/src/index.ts @@ -3,7 +3,7 @@ import addons, { makeDecorator } from '@storybook/addons'; import EVENTS from './constants'; -function emitOptions(options) { +function emitOptions(options: any) { const channel = addons.getChannel(); if (!channel) { throw new Error( @@ -21,7 +21,7 @@ function emitOptions(options) { // setOptions function will send Storybook UI options when the channel is // ready. If called before, options will be cached until it can be sent. let globalOptions = {}; -export const setOptions = deprecate(options => { +export const setOptions = deprecate((options: any) => { globalOptions = options; emitOptions(options); }, '`setOptions(options)` is deprecated. Please use the `withOptions(options)` decorator globally.'); @@ -32,7 +32,7 @@ export const withOptions = makeDecorator({ skipIfNoParametersOrOptions: false, wrapper: deprecate((getStory, context, { options: inputOptions, parameters }) => { // do not send hierachy related options over the channel - const { hierarchySeparator, hierarchyRootSeparator, ...change } = { + const { hierarchySeparator, hierarchyRootSeparator, ...change }: any = { ...globalOptions, ...inputOptions, ...parameters, @@ -48,7 +48,7 @@ export const withOptions = makeDecorator({ // MUTATION ! // eslint-disable-next-line no-param-reassign - context.options = { + (context as any).options = { ...globalOptions, ...inputOptions, ...parameters, @@ -61,7 +61,7 @@ export const withOptions = makeDecorator({ ...inputOptions, ...parameters, }, - }); + } as any); }, 'withOptions is deprecated, use addParameters({ options: {} }) instead'), }); diff --git a/addons/options/src/public_api.ts b/addons/options/src/public_api.ts new file mode 100644 index 000000000000..c327fdba2b68 --- /dev/null +++ b/addons/options/src/public_api.ts @@ -0,0 +1,2 @@ +export { ADDON_ID } from './constants'; +export { setOptions, withOptions } from './index'; diff --git a/addons/options/src/register.js b/addons/options/src/register.ts similarity index 100% rename from addons/options/src/register.js rename to addons/options/src/register.ts diff --git a/addons/options/src/typings.d.ts b/addons/options/src/typings.d.ts new file mode 100644 index 000000000000..6ed0217569a0 --- /dev/null +++ b/addons/options/src/typings.d.ts @@ -0,0 +1 @@ +declare var module: any; diff --git a/addons/options/tsconfig.json b/addons/options/tsconfig.json new file mode 100644 index 000000000000..266f855ff1a3 --- /dev/null +++ b/addons/options/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src" + }, + "include": [ + "src/**/*" + ] +}