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

View File

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

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 [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>,
componentAnnotations: Meta<TArgs | any>,
projectAnnotations?: ProjectAnnotations<ReactFramework>,