Skip to content

Commit

Permalink
Merge pull request #6428 from storybooks/ts-migration/addon-options
Browse files Browse the repository at this point in the history
Migrate addon-options to typescript
  • Loading branch information
ndelangen authored Apr 5, 2019
2 parents a0af6ec + 0e1478e commit 05610b9
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions addons/options/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"license": "MIT",
"main": "dist/index.js",
"types": "dist/public_api.d.ts",
"scripts": {
"prepare": "node ../../scripts/prepare.js"
},
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions addons/options/src/index.js → addons/options/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.');
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -61,7 +61,7 @@ export const withOptions = makeDecorator({
...inputOptions,
...parameters,
},
});
} as any);
}, 'withOptions is deprecated, use addParameters({ options: {} }) instead'),
});

Expand Down
2 changes: 2 additions & 0 deletions addons/options/src/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { ADDON_ID } from './constants';
export { setOptions, withOptions } from './index';
File renamed without changes.
1 change: 1 addition & 0 deletions addons/options/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare var module: any;
9 changes: 9 additions & 0 deletions addons/options/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src"
},
"include": [
"src/**/*"
]
}

0 comments on commit 05610b9

Please sign in to comment.