Skip to content

Commit

Permalink
refactor(cli): improve typing of window
Browse files Browse the repository at this point in the history
In order to be able to extend types in global scope with an `import` at the top of the file we have to create a new dedicated file (and can not use already existing typings.d.ts).
For details, see https://stackoverflow.com/questions/30960386/how-to-extend-the-window-typescript-interface/30961346#30961346
  • Loading branch information
gaetanmaisse committed May 17, 2020
1 parent ffa1522 commit 5860974
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cli/src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const read = async (url: string) => {
const data = JSON.parse(
await page.evaluate(async () => {
// eslint-disable-next-line no-undef
const d = (window as any).__STORYBOOK_STORY_STORE__.extract();
const d = window.__STORYBOOK_STORY_STORE__.extract();

const result = Object.entries(d).reduce(
(acc, [k, v]: [string, any]) => ({
Expand Down
7 changes: 7 additions & 0 deletions lib/cli/src/window.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { StoryStore } from '@storybook/client-api';

declare global {
interface Window {
__STORYBOOK_STORY_STORE__: StoryStore;
}
}

0 comments on commit 5860974

Please sign in to comment.