Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate addon-options to typescript #6428

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not dist/index.d.ts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this package has multiple files with exports - I then use public_api.d.ts as entry point and export everything from one file

"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/**/*"
]
}