Mo support for typescript intersection and parenthesized types
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- babel, typescript
- Domain
- documentation
Research direction
Start with handleTSIntersectionType and the missing handleTSParenthesizedType mentioned in the issue, using blocks/styled-resolver/test/testComponents.tsx as the reproduction case. Compare the generated props with the expected output, then verify that children and icon are extracted without breaking existing intersection cases.
Written by the indexing model from the issue text.
Description
I wish this project would just use typescript to parse typescript as the old project react-docgen-typescript did. Why? Because we try to upgrade our design-system to use this new package "react-docgen" but we're already missing some core features.
A union type definition like the following is not parsed correctly:
type ButtonVariant = "standard" | "primary";
type ButtonWithChildren = {
children: ReactNode;
icon?: ReactNode;
};
type ButtonWithIconOnly = {
children?: never;
icon: ReactNode;
};
export type ButtonProps = {
className?: string;
variant?: ButtonVariant;
} & (ButtonWithChildren | ButtonWithIconOnly);
export const RegularFunctionComponent: FunctionComponent<ButtonProps> = (
props,
) => <div>Just a regular component</div>;
Result
{
"RegularFunctionComponent": {
"description": "",
"displayName": "RegularFunctionComponent",
"methods": [],
"props": {
"className": {
"required": false,
"tsType": {
"name": "string"
},
"description": ""
},
"variant": {
"required": false,
"tsType": {
"name": "union",
"raw": "\"standard\" | \"primary\"",
"elements": [
{
"name": "literal",
"value": "\"standard\""
},
{
"name": "literal",
"value": "\"primary\""
}
]
},
"description": ""
}
},
"path": "blocks/styled-resolver/test/testComponents.tsx"
}
}
The two props "children" and "icon" are missing in the result. Parsing the same thing with react-docgen-typescript would indeed find the two props, so i would expect the following output:
Expected
{
"RegularFunctionComponent": {
"description": "",
"displayName": "RegularFunctionComponent",
"methods": [],
"props": {
"children": {
"required": false,
"tsType": {
"name": "ReactNode"
},
"description": ""
},
"icon": {
"required": false,
"tsType": {
"name": "ReactNode"
},
"description": ""
},
"className": {
"required": false,
"tsType": {
"name": "string"
},
"description": ""
},
"variant": {
"required": false,
"tsType": {
"name": "union",
"raw": "\"standard\" | \"primary\"",
"elements": [
{
"name": "literal",
"value": "\"standard\""
},
{
"name": "literal",
"value": "\"primary\""
}
]
},
"description": ""
}
},
"path": "blocks/styled-resolver/test/testComponents.tsx"
}
}
But i'm also wondering why the official babel parser typescript plugin can't handle that case?
Update: A short test with babel parser itselfs shows me that babel indeed is parsing this case correctly and all information would be available to produce the expected result. It is just not implemented in this package.
Update 2: I'm working on a PR and it seems to be quite promising - the complex intersection case with multiple interfaces is working now, i had to modify the "handleTSIntersectionType" function and add the missing "handleTSParenthesizedType". Now only the types are getting in my way and i destroyed some existing cases with intersection.... still working on it, hopefully next week i can present a fix :)
- Dominant language
- TypeScript
- Stars
- 3.8k
- Forks
- 316
- Avg merge
- 3h 28m
- Merged PRs (30d)
- 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from reactjs/react-docgen
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
reactjs/react-docgen#1102 ·
-
Typescript Status Open
Difficulty 5/5 Over a week Newbie friendliness 20/100
reactjs/react-docgen#1005 · 4 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
reactjs/react-docgen#997 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
reactjs/react-docgen#994 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
reactjs/react-docgen#982 · 2 comments ·
All issues in reactjs/react-docgen
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug v2
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
modelcontextprotocol/inspector#2458 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
railmapgen/rmp-gallery#4068 ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
carbon-design-system/ibm-products#9907 ·