Skip to content

Commit 4fd750a

Browse files
committed
more ts fixes
# Conflicts: # packages/react-docgen/src/babelParser.ts
1 parent 3f0fc08 commit 4fd750a

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

packages/react-docgen/src/babelParser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ const TYPESCRIPT_EXTS = new Set(['.cts', '.mts', '.ts', '.tsx']);
88
function getDefaultPlugins(
99
options: TransformOptions,
1010
): NonNullable<ParserOptions['plugins']> {
11-
const extension = extname(options.filename || '');
12-
1311
return [
1412
'jsx',
15-
TYPESCRIPT_EXTS.has(extension) ? 'typescript' : 'flow',
13+
options.filename && TYPESCRIPT_EXTS.has(extname(options.filename))
14+
? 'typescript'
15+
: 'flow',
1616
'asyncDoExpressions',
1717
'decimal',
1818
['decorators', { decoratorsBeforeExport: false }],
@@ -84,5 +84,5 @@ export default function babelParser(
8484
throw new Error('Unable to parse source code.');
8585
}
8686

87-
return ast;
87+
return ast as File;
8888
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ function handleTypeofTypeAnnotation(
391391
return getFlowTypeWithResolvedTypes(path.get('argument'), typeParams);
392392
}
393393

394-
let visitedTypes = {};
394+
let visitedTypes: Record<string, TypeDescriptor | boolean> = {};
395395

396396
function getFlowTypeWithResolvedTypes(
397397
path: NodePath<FlowType>,
@@ -405,13 +405,15 @@ function getFlowTypeWithResolvedTypes(
405405
// When we see a TypeAlias mark it as visited so that the next
406406
// call of this function does not run into an endless loop
407407
if (isTypeAlias) {
408-
if (visitedTypes[parent.node.id.name] === true) {
408+
const visitedType = visitedTypes[parent.node.id.name];
409+
410+
if (visitedType === true) {
409411
// if we are currently visiting this node then just return the name
410412
// as we are starting to endless loop
411413
return { name: parent.node.id.name };
412-
} else if (typeof visitedTypes[parent.node.id.name] === 'object') {
414+
} else if (typeof visitedType === 'object') {
413415
// if we already resolved the type simple return it
414-
return visitedTypes[parent.node.id.name];
416+
return visitedType;
415417
}
416418
// mark the type as visited
417419
visitedTypes[parent.node.id.name] = true;

0 commit comments

Comments
 (0)