Skip to content

Commit

Permalink
remove all ts-ignore in vue, tighten typings
Browse files Browse the repository at this point in the history
Less any, more explicit types and type checks
Turned on noImplicitReturns, strict, explicit-function-return-type (vue)
  • Loading branch information
Andy Brenneke committed Jul 15, 2020
1 parent 5bc86c2 commit a985e88
Show file tree
Hide file tree
Showing 39 changed files with 270 additions and 160 deletions.
10 changes: 6 additions & 4 deletions app/angular/src/client/preview/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable prefer-destructuring */
import { start } from '@storybook/core/client';
import client from '@storybook/core/client';
import { ClientStoryApi, Loadable } from '@storybook/addons';

import './globals';
Expand All @@ -18,7 +18,7 @@ interface ClientApi extends ClientStoryApi<StoryFnAngularReturnType> {
load: (...args: any[]) => void;
}

const api = start(render);
const api = client.start(render);

export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({
Expand All @@ -27,8 +27,10 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
};

export const configure: ClientApi['configure'] = (...args) => api.configure(framework, ...args);
export const addDecorator: ClientApi['addDecorator'] = api.clientApi.addDecorator;
export const addParameters: ClientApi['addParameters'] = api.clientApi.addParameters;
export const addDecorator: ClientApi['addDecorator'] = api.clientApi
.addDecorator as ClientApi['addDecorator'];
export const addParameters: ClientApi['addParameters'] = api.clientApi
.addParameters as ClientApi['addParameters'];
export const clearDecorators: ClientApi['clearDecorators'] = api.clientApi.clearDecorators;
export const setAddon: ClientApi['setAddon'] = api.clientApi.setAddon;
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender;
Expand Down
10 changes: 6 additions & 4 deletions app/aurelia/src/client/preview/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Constructable, CustomElement } from 'aurelia';
/* eslint-disable prefer-destructuring */
import { start } from '@storybook/core/client';
import client from '@storybook/core/client';
import { ClientStoryApi, Loadable } from '@storybook/addons';
import { text, boolean, number, date } from '@storybook/addon-knobs';

Expand All @@ -21,7 +21,7 @@ interface ClientApi extends ClientStoryApi<Partial<StoryFnAureliaReturnType>> {
load: (...args: any[]) => void;
}

const api = start(render);
const api = client.start(render);

export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({
Expand All @@ -32,8 +32,10 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
export { StoryFnAureliaReturnType, addRegistries, addContainer, Component, addComponents };

export const configure: ClientApi['configure'] = (...args) => api.configure(framework, ...args);
export const addDecorator: ClientApi['addDecorator'] = api.clientApi.addDecorator;
export const addParameters: ClientApi['addParameters'] = api.clientApi.addParameters;
export const addDecorator: ClientApi['addDecorator'] = api.clientApi
.addDecorator as ClientApi['addDecorator'];
export const addParameters: ClientApi['addParameters'] = api.clientApi
.addParameters as ClientApi['addParameters'];
export const clearDecorators: ClientApi['clearDecorators'] = api.clientApi.clearDecorators;
export const setAddon: ClientApi['setAddon'] = api.clientApi.setAddon;
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender;
Expand Down
11 changes: 3 additions & 8 deletions app/aurelia/src/client/preview/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,18 @@ import {
Constructable,
IViewModel,
} from 'aurelia';
import { RenderContext } from '@storybook/core';
import { RenderMainArgs } from './types';
import { generateKnobsFor } from '.';

const host = document.getElementById('root'); // the root iframe provided by storybook
let previousAurelia: Aurelia;
export default async function render({
storyFn,
selectedKind,
selectedStory,
showMain,
showError,
}: RenderMainArgs) {
export default async function render({ storyFn, showMain, showError }: RenderContext<any>) {
const element = storyFn();

if (!element) {
showError({
title: `Expecting an Aurelia component from the story: "${selectedStory}" of "${selectedKind}".`,
title: `Expecting an Aurelia component from the story.`,
description: `
Did you forget to return the Aurelia component from the story?
Use "() => ({ template: '<custom-component></custom-component>' })" when defining the story.
Expand Down
11 changes: 6 additions & 5 deletions app/ember/src/client/preview/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { start } from '@storybook/core/client';
import client from '@storybook/core/client';

import './globals';
import render from './render';

const { configure: coreConfigure, clientApi, forceReRender } = start(render);
const { configure: coreConfigure, clientApi, forceReRender } = client.start(render);

export const {
setAddon,
Expand All @@ -15,8 +15,9 @@ export const {
} = clientApi;

const framework = 'ember';
export const storiesOf = (...args: any) =>
clientApi.storiesOf(...args).addParameters({ framework });
export const configure = (...args: any) => coreConfigure(framework, ...args);
export const storiesOf = (kind: string, m: NodeModule) =>
clientApi.storiesOf(kind, m).addParameters({ framework });
export const configure = (loadable: any, m: NodeModule, showDeprecationWarning?: boolean) =>
coreConfigure(framework, loadable, m, showDeprecationWarning);

export { forceReRender };
8 changes: 7 additions & 1 deletion app/ember/src/client/preview/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ function render(options: OptionsArgs, el: ElementArgs) {
});
}

export default function renderMain({ storyFn, kind, name, showMain, showError }: RenderContext) {
export default function renderMain({
storyFn,
kind,
name,
showMain,
showError,
}: RenderContext<OptionsArgs>) {
const element = storyFn();

if (!element) {
Expand Down
10 changes: 6 additions & 4 deletions app/html/src/client/preview/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable prefer-destructuring */
import { start } from '@storybook/core/client';
import client from '@storybook/core/client';
import { ClientStoryApi, Loadable } from '@storybook/addons';

import './globals';
Expand All @@ -17,7 +17,7 @@ interface ClientApi extends ClientStoryApi<StoryFnHtmlReturnType> {
raw: () => any; // todo add type
}

const api = start(render);
const api = client.start(render);

export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({
Expand All @@ -26,8 +26,10 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
};

export const configure: ClientApi['configure'] = (...args) => api.configure(framework, ...args);
export const addDecorator: ClientApi['addDecorator'] = api.clientApi.addDecorator;
export const addParameters: ClientApi['addParameters'] = api.clientApi.addParameters;
export const addDecorator: ClientApi['addDecorator'] = api.clientApi
.addDecorator as ClientApi['addDecorator'];
export const addParameters: ClientApi['addParameters'] = api.clientApi
.addParameters as ClientApi['addParameters'];
export const clearDecorators: ClientApi['clearDecorators'] = api.clientApi.clearDecorators;
export const setAddon: ClientApi['setAddon'] = api.clientApi.setAddon;
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender;
Expand Down
4 changes: 2 additions & 2 deletions app/marionette/src/client/preview/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { start } from '@storybook/core/client';
import client from '@storybook/core/client';

import './globals';
import render from './render';

const { load: coreLoad, clientApi, configApi, forceReRender } = start(render);
const { load: coreLoad, clientApi, configApi, forceReRender } = client.start(render);

export const {
setAddon,
Expand Down
4 changes: 2 additions & 2 deletions app/marko/src/client/preview/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { start } from '@storybook/core/client';
import client from '@storybook/core/client';

import './globals';
import render from './render';

const { configure: coreConfigure, clientApi, forceReRender } = start(render);
const { configure: coreConfigure, clientApi, forceReRender } = client.start(render);

export const {
setAddon,
Expand Down
4 changes: 2 additions & 2 deletions app/mithril/src/client/preview/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { start } from '@storybook/core/client';
import client from '@storybook/core/client';

import './globals';
import { ClientStoryApi, Loadable } from '@storybook/addons';
import render from './render';

import { IStorybookSection, StoryFnMithrilReturnType } from './types';

const { configure: coreConfigure, clientApi, forceReRender } = start(render);
const { configure: coreConfigure, clientApi, forceReRender } = client.start(render);

const framework = 'mithril';

Expand Down
10 changes: 8 additions & 2 deletions app/mithril/src/client/preview/render.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { document } from 'global';
/** @jsx m */

import m from 'mithril';
import m, { ComponentTypes } from 'mithril';
import dedent from 'ts-dedent';

import { RenderContext } from './types';

const rootEl = document.getElementById('root');

export default function renderMain({ storyFn, kind, name, showMain, showError }: RenderContext) {
export default function renderMain({
storyFn,
kind,
name,
showMain,
showError,
}: RenderContext<ComponentTypes>) {
const element = storyFn();

if (!element) {
Expand Down
10 changes: 6 additions & 4 deletions app/preact/src/client/preview/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable prefer-destructuring */
import { start } from '@storybook/core/client';
import client from '@storybook/core/client';

import './globals';
import render from './render';
import { ClientApi } from './types';

const framework = 'preact';
const api = start(render);
const api = client.start(render);

export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({
Expand All @@ -15,8 +15,10 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
};

export const configure: ClientApi['configure'] = (...args) => api.configure(framework, ...args);
export const addDecorator: ClientApi['addDecorator'] = api.clientApi.addDecorator;
export const addParameters: ClientApi['addParameters'] = api.clientApi.addParameters;
export const addDecorator: ClientApi['addDecorator'] = api.clientApi
.addDecorator as ClientApi['addDecorator'];
export const addParameters: ClientApi['addParameters'] = api.clientApi
.addParameters as ClientApi['addParameters'];
export const clearDecorators: ClientApi['clearDecorators'] = api.clientApi.clearDecorators;
export const setAddon: ClientApi['setAddon'] = api.clientApi.setAddon;
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender;
Expand Down
8 changes: 7 additions & 1 deletion app/preact/src/client/preview/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ function preactRender(element: StoryFnPreactReturnType | null): void {
}
}

export default function renderMain({ storyFn, kind, name, showMain, showError }: RenderContext) {
export default function renderMain({
storyFn,
kind,
name,
showMain,
showError,
}: RenderContext<StoryFnPreactReturnType>) {
const element = storyFn();

if (!element) {
Expand Down
4 changes: 2 additions & 2 deletions app/rax/src/client/preview/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { start } from '@storybook/core/client';
import client from '@storybook/core/client';

import './globals';
import render from './render';

const { configure: coreConfigure, clientApi, forceReRender } = start(render);
const { configure: coreConfigure, clientApi, forceReRender } = client.start(render);

export const {
setAddon,
Expand Down
10 changes: 6 additions & 4 deletions app/react/src/client/preview/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable prefer-destructuring */
import { start } from '@storybook/core/client';
import client from '@storybook/core/client';
import { ClientStoryApi, Loadable } from '@storybook/addons';

import './globals';
Expand All @@ -17,7 +17,7 @@ interface ClientApi extends ClientStoryApi<StoryFnReactReturnType> {
raw: () => any; // todo add type
}

const api = start(render);
const api = client.start(render);

export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({
Expand All @@ -26,9 +26,11 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
};

export const configure: ClientApi['configure'] = (...args) => api.configure(framework, ...args);
export const addDecorator: ClientApi['addDecorator'] = api.clientApi.addDecorator;
export const addDecorator: ClientApi['addDecorator'] = api.clientApi
.addDecorator as ClientApi['addDecorator'];
export type DecoratorFn = Parameters<typeof addDecorator>[0];
export const addParameters: ClientApi['addParameters'] = api.clientApi.addParameters;
export const addParameters: ClientApi['addParameters'] = api.clientApi
.addParameters as ClientApi['addParameters'];
export const clearDecorators: ClientApi['clearDecorators'] = api.clientApi.clearDecorators;
export const setAddon: ClientApi['setAddon'] = api.clientApi.setAddon;
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender;
Expand Down
4 changes: 2 additions & 2 deletions app/riot/src/client/preview/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { start } from '@storybook/core/client';
import client from '@storybook/core/client';

import './globals';
import riot, { tag2, mount as vendorMount } from 'riot';
import render from './render';
import { compileNow as unboundCompileNow, asCompiledCode } from './compileStageFunctions';

const { configure: coreConfigure, clientApi, forceReRender } = start(render);
const { configure: coreConfigure, clientApi, forceReRender } = client.start(render);

export const {
setAddon,
Expand Down
1 change: 0 additions & 1 deletion app/server/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export {
addParameters,
configure,
getStorybook,
forceReRender,
raw,
} from './preview';

Expand Down
7 changes: 3 additions & 4 deletions app/server/src/client/preview/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { start } from '@storybook/core/client';
import client from '@storybook/core/client';
import { ClientStoryApi, Loadable } from '@storybook/addons';

import './globals';
Expand All @@ -16,7 +16,7 @@ interface ClientApi extends ClientStoryApi<StoryFnServerReturnType> {
raw: () => any; // todo add type
}

const api = start(render);
const api = client.start(render);

export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({
Expand All @@ -28,7 +28,7 @@ const setRenderFetchAndConfigure: ClientApi['configure'] = (loader, module, opti
if (options && options.fetchStoryHtml) {
setFetchStoryHtml(options.fetchStoryHtml);
}
api.configure(loader, module, framework);
api.configure(framework, loader, module);
};

export const configure: ClientApi['configure'] = setRenderFetchAndConfigure;
Expand All @@ -37,7 +37,6 @@ export const {
addParameters,
clearDecorators,
setAddon,
forceReRender,
getStorybook,
raw,
} = api.clientApi;
2 changes: 1 addition & 1 deletion app/server/src/client/preview/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function renderMain({
showError,
forceRender,
parameters,
}: RenderContext) {
}: RenderContext<Record<string, string>>) {
const storyParams = storyFn();

const {
Expand Down
11 changes: 6 additions & 5 deletions app/svelte/src/client/preview/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { start } from '@storybook/core/client';
import client from '@storybook/core/client';

import './globals';
import render from './render';

const { configure: coreConfigure, clientApi, forceReRender } = start(render);
const { configure: coreConfigure, clientApi, forceReRender } = client.start(render);

export const {
setAddon,
Expand All @@ -15,8 +15,9 @@ export const {
} = clientApi;

const framework = 'svelte';
export const storiesOf = (...args: any) =>
clientApi.storiesOf(...args).addParameters({ framework });
export const configure = (...args: any) => coreConfigure(framework, ...args);
export const storiesOf = (kind: string, m: NodeModule) =>
clientApi.storiesOf(kind, m).addParameters({ framework });
export const configure = (loadable: any, m: NodeModule, showDeprecationWarning?: boolean) =>
coreConfigure(framework, loadable, m, showDeprecationWarning);

export { forceReRender };
Loading

0 comments on commit a985e88

Please sign in to comment.