Skip to content

Commit 637492e

Browse files
committed
Fix Typescript types
1 parent bae15f9 commit 637492e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/react-docgen/src/utils/getFlowType.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import type {
3333
UnionTypeAnnotation,
3434
} from '@babel/types';
3535

36-
const flowTypes = {
36+
const flowTypes: Record<string, string> = {
3737
AnyTypeAnnotation: 'any',
3838
BooleanTypeAnnotation: 'boolean',
3939
MixedTypeAnnotation: 'mixed',
@@ -50,7 +50,13 @@ const flowLiteralTypes = {
5050
StringLiteralTypeAnnotation: 1,
5151
};
5252

53-
const namedTypes = {
53+
const namedTypes: Record<
54+
string,
55+
(
56+
path: NodePath<any>,
57+
typeParams: TypeParameters | null,
58+
) => TypeDescriptor | null
59+
> = {
5460
ArrayTypeAnnotation: handleArrayTypeAnnotation,
5561
GenericTypeAnnotation: handleGenericTypeAnnotation,
5662
ObjectTypeAnnotation: handleObjectTypeAnnotation,
@@ -420,7 +426,7 @@ function getFlowTypeWithResolvedTypes(
420426
}
421427

422428
if (path.node.type in flowTypes) {
423-
type = { name: flowTypes[path.node.type] };
429+
type = { name: flowTypes[path.node.type]! };
424430
} else if (path.node.type in flowLiteralTypes) {
425431
type = {
426432
name: 'literal',
@@ -437,7 +443,7 @@ function getFlowTypeWithResolvedTypes(
437443
}`,
438444
};
439445
} else if (path.node.type in namedTypes) {
440-
type = namedTypes[path.node.type](path, typeParams);
446+
type = namedTypes[path.node.type]!(path, typeParams);
441447
}
442448

443449
if (!type) {

0 commit comments

Comments
 (0)