Skip to content

Commit

Permalink
Fix types of useOf
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Mar 5, 2023
1 parent ce9bd7f commit ade8805
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions code/ui/blocks/src/blocks/Canvas.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react/destructuring-assignment */
import React, { Children, useContext } from 'react';
import type { FC, ReactElement, ReactNode } from 'react';
import type { ModuleExport, ModuleExports, Renderer } from '@storybook/types';
import type { ModuleExport, ModuleExports, PreparedStory, Renderer } from '@storybook/types';
import { deprecate } from '@storybook/client-logger';
import dedent from 'ts-dedent';
import type { Layout, PreviewProps as PurePreviewProps } from '../components';
Expand Down Expand Up @@ -157,7 +157,7 @@ export const Canvas: FC<CanvasProps & DeprecatedCanvasProps> = (props) => {
const { children, of, source } = props;
const { isLoading, previewProps } = useDeprecatedPreviewProps(props, docsContext, sourceContext);

let story;
let story: PreparedStory;
let sourceProps;
/**
* useOf and useSourceProps will throw if they can't find the story, in the scenario where
Expand Down
9 changes: 7 additions & 2 deletions code/ui/blocks/src/blocks/useOf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { DocsContextProps, ModuleExport, ResolvedModuleExportType } from '@storybook/types';
import type {
DocsContextProps,
ModuleExport,
ResolvedModuleExportType,
ResolvedModuleExportFromType,
} from '@storybook/types';
import { useContext } from 'react';
import { DocsContext } from './DocsContext';

Expand All @@ -13,7 +18,7 @@ export type Of = Parameters<DocsContextProps['resolveOf']>[0];
export const useOf = <TType extends ResolvedModuleExportType>(
moduleExportOrType: ModuleExport | TType,
validTypes?: TType[]
): ReturnType<DocsContextProps['resolveOf']> => {
): ResolvedModuleExportFromType<TType> => {
const context = useContext(DocsContext);
return context.resolveOf(moduleExportOrType, validTypes);
};

0 comments on commit ade8805

Please sign in to comment.