Fix TS 4.8 errors

This commit is contained in:
Ian VanSchooten 2022-11-02 22:41:03 -04:00
parent 4560a33187
commit 0add1a99b4
4 changed files with 17 additions and 10 deletions

View File

@ -1,6 +1,11 @@
import type { API } from '@storybook/api'; import type { API } from '@storybook/api';
import { ADDON_ID } from './constants'; import { ADDON_ID } from './constants';
type State = {
selected: string;
isRotated: boolean;
};
const getCurrentViewportIndex = (viewportsKeys: string[], current: string): number => const getCurrentViewportIndex = (viewportsKeys: string[], current: string): number =>
viewportsKeys.indexOf(current); viewportsKeys.indexOf(current);
@ -24,7 +29,7 @@ export const registerShortcuts = async (api: API, setState: any, viewportsKeys:
defaultShortcut: ['shift', 'V'], defaultShortcut: ['shift', 'V'],
actionName: 'previous', actionName: 'previous',
action: () => { action: () => {
const { selected, isRotated } = api.getAddonState(ADDON_ID); const { selected, isRotated } = api.getAddonState<State>(ADDON_ID);
setState({ setState({
selected: getPreviousViewport(viewportsKeys, selected), selected: getPreviousViewport(viewportsKeys, selected),
isRotated, isRotated,
@ -37,7 +42,7 @@ export const registerShortcuts = async (api: API, setState: any, viewportsKeys:
defaultShortcut: ['V'], defaultShortcut: ['V'],
actionName: 'next', actionName: 'next',
action: () => { action: () => {
const { selected, isRotated } = api.getAddonState(ADDON_ID); const { selected, isRotated } = api.getAddonState<State>(ADDON_ID);
setState({ setState({
selected: getNextViewport(viewportsKeys, selected), selected: getNextViewport(viewportsKeys, selected),
isRotated, isRotated,
@ -50,7 +55,7 @@ export const registerShortcuts = async (api: API, setState: any, viewportsKeys:
defaultShortcut: ['alt', 'V'], defaultShortcut: ['alt', 'V'],
actionName: 'reset', actionName: 'reset',
action: () => { action: () => {
const { isRotated } = api.getAddonState(ADDON_ID); const { isRotated } = api.getAddonState<State>(ADDON_ID);
setState({ setState({
selected: 'reset', selected: 'reset',
isRotated, isRotated,

View File

@ -152,7 +152,7 @@ export const deepDiff = (value: any, update: any): any => {
}; };
export const NO_TARGET_NAME = ''; export const NO_TARGET_NAME = '';
export function groupArgsByTarget<TArgs = Args>({ export function groupArgsByTarget<TArgs extends Args = Args>({
args, args,
argTypes, argTypes,
}: StoryContext<AnyFramework, TArgs>) { }: StoryContext<AnyFramework, TArgs>) {
@ -166,6 +166,8 @@ export function groupArgsByTarget<TArgs = Args>({
return groupedArgs; return groupedArgs;
} }
export function noTargetArgs<TArgs = Args>(context: StoryContext<AnyFramework, TArgs>) { export function noTargetArgs<TArgs extends Args = Args>(
context: StoryContext<AnyFramework, TArgs>
) {
return groupArgsByTarget(context)[NO_TARGET_NAME]; return groupArgsByTarget(context)[NO_TARGET_NAME];
} }

View File

@ -80,7 +80,7 @@ const defaultProjectAnnotations: ProjectAnnotations<ReactFramework> = {
* @param [projectAnnotations] - e.g. (import * as projectAnnotations from '../.storybook/preview') this can be applied automatically if you use `setProjectAnnotations` in your setup files. * @param [projectAnnotations] - e.g. (import * as projectAnnotations from '../.storybook/preview') this can be applied automatically if you use `setProjectAnnotations` in your setup files.
* @param [exportsName] - in case your story does not contain a name and you want it to have a name. * @param [exportsName] - in case your story does not contain a name and you want it to have a name.
*/ */
export function composeStory<TArgs = Args>( export function composeStory<TArgs extends Args = Args>(
story: Store_ComposedStory<ReactFramework, TArgs>, story: Store_ComposedStory<ReactFramework, TArgs>,
componentAnnotations: Meta<TArgs | any>, componentAnnotations: Meta<TArgs | any>,
projectAnnotations?: ProjectAnnotations<ReactFramework>, projectAnnotations?: ProjectAnnotations<ReactFramework>,