From 5e38f192a33ea962847c0780d121736009d74281 Mon Sep 17 00:00:00 2001 From: Emilio Martinez Date: Mon, 8 Jul 2019 04:21:01 -0700 Subject: [PATCH] App-html: apply types within storybook/html --- app/html/src/client/preview/index.ts | 16 ++++++++++++++-- app/html/src/client/preview/render.ts | 17 +++++++++++++++-- app/html/src/server/framework-preset-html.ts | 5 ++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/html/src/client/preview/index.ts b/app/html/src/client/preview/index.ts index c1ac22948c0a..b85e13e84a71 100644 --- a/app/html/src/client/preview/index.ts +++ b/app/html/src/client/preview/index.ts @@ -3,6 +3,17 @@ import { start } from '@storybook/core/client'; import './globals'; import render from './render'; +export type StoriesOfArgs = [string, typeof module]; + +export type LoadFnArgs = [RequireContext, typeof module, string]; + +export interface RequireContext { + keys(): string[]; + (id: string): any; + (id: string): T; + resolve(id: string): string; +} + const { load: coreLoad, clientApi, configApi, forceReRender } = start(render); export const { @@ -15,8 +26,9 @@ export const { } = clientApi; const framework = 'html'; -export const storiesOf = (...args) => clientApi.storiesOf(...args).addParameters({ framework }); -export const load = (...args) => coreLoad(...args, framework); +export const storiesOf = (...args: StoriesOfArgs) => + clientApi.storiesOf(...args).addParameters({ framework }); +export const load = (...args: LoadFnArgs) => coreLoad(...args, framework); export const { configure } = configApi; export { forceReRender }; diff --git a/app/html/src/client/preview/render.ts b/app/html/src/client/preview/render.ts index ff955aca414b..3d0b571d4830 100644 --- a/app/html/src/client/preview/render.ts +++ b/app/html/src/client/preview/render.ts @@ -1,17 +1,30 @@ import { document, Node } from 'global'; import { stripIndents } from 'common-tags'; +export interface ShowErrorArgs { + title: string; + description: string; +} + +export interface RenderMainArgs { + storyFn: () => string | Node | undefined; + selectedKind: string; + selectedStory: string; + showMain: () => void; + showError: (args: ShowErrorArgs) => void; + forceRender: boolean; +} + const rootElement = document.getElementById('root'); export default function renderMain({ - parameters = {}, storyFn, selectedKind, selectedStory, showMain, showError, forceRender, -}) { +}: RenderMainArgs) { const element = storyFn(); showMain(); diff --git a/app/html/src/server/framework-preset-html.ts b/app/html/src/server/framework-preset-html.ts index 1abdd1c33862..a3b4185d0a1a 100644 --- a/app/html/src/server/framework-preset-html.ts +++ b/app/html/src/server/framework-preset-html.ts @@ -1,4 +1,7 @@ -export function webpack(config) { +// eslint-disable-next-line import/no-extraneous-dependencies +import { Configuration } from 'webpack'; + +export function webpack(config: Configuration) { return { ...config, module: {