Skip to content

Commit

Permalink
#7: Add type annotation for withContexts story decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Y. Li committed Apr 18, 2019
1 parent e825ff9 commit 793c92b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions addons/addon-contexts/src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ declare type ReactNode = import('react').ReactNode;
declare type ReactElement = import('react').ReactElement;
declare type FC<P> = import('react').FunctionComponent<P>;

// auxiliary @types
// auxiliary types
declare type FCNoChildren<P> = FC<{ children?: never } & P>;
declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
declare type GenericFnWithReturn<T> = (...args: any[]) => T;
declare type GenericProps = { [key: string]: GenericProps } | null;
export declare type StringObject = { [key: string]: string };
export declare type StringTuple = [string, string];

// config @types
// config types
export declare type AddonOptions = {
deep?: boolean;
disable?: boolean;
Expand All @@ -38,7 +38,7 @@ export declare type ContextNode = Required<AddonSetting> & {
nodeId: string;
};

// duck @types
// duck types
export declare type UPDATE_PROPS_MAP = {
type: 'UPDATE_PROPS_MAP';
payload: {
Expand All @@ -50,7 +50,7 @@ export declare type PropsTreeUpdaterType = (
nodes: ContextNode[]
) => ([nodeId, name]: StringTuple) => UPDATE_PROPS_MAP;

// helper @types
// helper types
export declare type RenderAggregatedComponents = (
...arg: [ComponentType[], GenericProps, AddonOptions, number]
) => GenericFnWithReturn<unknown>;
Expand All @@ -65,7 +65,7 @@ export declare type UseChannel = (
input?: unknown[]
) => void;

// Component @types
// Component types
export declare type Wrapper = (...arg: [Function, unknown, WrapperSettings]) => ReactNode;
export declare type TAddonManager = FCNoChildren<{
channel: Channel;
Expand Down Expand Up @@ -100,3 +100,6 @@ export declare type TToolBarMenuOptions = FCNoChildren<{
list: string[];
onSelectOption: (name: string) => () => void;
}>;

// core types
export declare type WithContexts = (contexts: AddonSetting[]) => any;
4 changes: 2 additions & 2 deletions addons/addon-contexts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createElement as h, Fragment } from 'react';
import addons, { makeDecorator } from '@storybook/addons';
import { AddonWrapper } from './containers/AddonWrapper';
import { ID, PARAM } from './libs/constants';
import { Wrapper } from './@types';
import { WithContexts, Wrapper } from './@types';

const wrapper: Wrapper = (getStory, context, settings) =>
h(AddonWrapper, {
Expand All @@ -11,7 +11,7 @@ const wrapper: Wrapper = (getStory, context, settings) =>
children: (ready: boolean) => () => (ready ? getStory(context) : h(Fragment)),
});

export const withContexts = makeDecorator({
export const withContexts: WithContexts = makeDecorator({
name: ID,
parameterName: PARAM,
skipIfNoParametersOrOptions: true,
Expand Down

0 comments on commit 793c92b

Please sign in to comment.