reactjs / reactjs/react-docgen
Typescript: Component props not parsed with 'call signature' type
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 3.8k
- Forks
- 316
- Ø Merge
- 5 Std. 7 Min.
- Gemergte PRs (30 T.)
- 4
Beschreibung
Description
In Typescript, it's possible to type a function using a call signature.
For example, this is valid TS:
interface A {
foo: string;
}
type FnType = (props: A) => string;
const Fn1: FnType = (props) => props.foo; // valid
const Fn2 = (props: A) => props.foo; // also valid
See example in TS Playground
In the above example, react-docgen generates types for Fn2, but does not generate types for Fn1 which is defined with a call signature type.
Expected Behavior
This code:
// component.tsx
interface A {
foo: string;
}
type ComponentType = (props: A) => JSX.Element;
const Component1: ComponentType = (props) => <div />; // does not include generated props
const Component2 = (props: A) => <div />; // includes generated props
Produces this output:
[
{
"description": "",
"displayName": "Component1",
"methods": [],
"props": {
"foo": {
"required": true,
"tsType": {
"name": "string"
},
"description": ""
}
}
},
{
"description": "",
"displayName": "Component2",
"methods": [],
"props": {
"foo": {
"required": true,
"tsType": {
"name": "string"
},
"description": ""
}
}
}
]
Actual Behavior
The same code produces this output:
[
{
"description": "",
"displayName": "Component1",
"methods": []
},
{
"description": "",
"displayName": "Component2",
"methods": [],
"props": {
"foo": {
"required": true,
"tsType": {
"name": "string"
},
"description": ""
}
}
}
]
Steps to Reproduce
Paste the .tsx sample code from the "Expected Behavior" section in the react-docgen playground with Language set to Typescript.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das .tsx-Beispiel im react-docgen-Playground mit auf Typescript gesetztem Language zu reproduzieren und Component1 und Component2 zu vergleichen. Verfolge den TypeScript-Parsing-Einstiegspunkt für Komponenten, denen ein Call-Signature-Typ zugewiesen ist; abgeschlossen ist es, wenn Component1 dieselben foo-Prop-Metadaten wie Component2 enthält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- react, typescript
- Bereich
- documentation, tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100