reactjs / reactjs/react-docgen
Typescript: Component props not parsed with 'call signature' type
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 3.8k
- Fork
- 316
- Merge medio
- 5h 7m
- PR unite (30g)
- 4
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo l’esempio .tsx nel playground di react-docgen con Language impostato su Typescript, confrontando Component1 e Component2. Traccia il punto di ingresso del parsing TypeScript per i componenti a cui è assegnato un tipo con firma di chiamata; il lavoro è completo quando Component1 include gli stessi metadati della prop foo di Component2.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- react, typescript
- Ambito
- documentation, tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100