Skip to content

Commit 07d99f8

Browse files
committed
better decorator types
1 parent 1ebbab0 commit 07d99f8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/react-docgen/src/handlers/componentDocblockHandler.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ import resolveToValue from '../utils/resolveToValue.js';
55
import type { NodePath } from '@babel/traverse';
66
import type { ComponentNode } from '../resolver/index.js';
77
import type { Handler } from './index.js';
8+
import type { Decorator } from '@babel/types';
89

910
function getDocblockFromComponent(path: NodePath): string | null {
1011
let description: string | null = null;
1112

1213
if (path.isClassDeclaration() || path.isClassExpression()) {
14+
const decorators = path.get('decorators') as
15+
| Array<NodePath<Decorator>>
16+
| null
17+
| undefined;
18+
1319
// If we have a class declaration or expression, then the comment might be
1420
// attached to the last decorator instead as trailing comment.
15-
if (path.node.decorators && path.node.decorators.length > 0) {
16-
description = getDocblock(
17-
path.get('decorators')[path.node.decorators.length - 1],
18-
true,
19-
);
21+
if (decorators && decorators.length > 0) {
22+
description = getDocblock(decorators[decorators.length - 1]!, true);
2023
}
2124
}
2225
if (description == null) {

0 commit comments

Comments
 (0)