reactjs / reactjs/react-docgen
Order of intersection types leads to non-deterministic results
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 3.8k
- Fork
- 316
- Merge medio
- 5h 7m
- PR unite (30g)
- 4
Descrizione
The following:
import React from 'react';
type Props = { children: React.ReactNode; } & { children?: React.ReactNode; }
const Component = ({ children }: Props) => {
return <div>{children}</div>
}
export default Component;
Gives these results:
{
"description": "",
"displayName": "Component",
"methods": [],
"props": {
"children": {
"required": false,
"tsType": {
"name": "ReactReactNode",
"raw": "React.ReactNode"
},
"description": ""
}
}
}
As you can see, children are NOT required, however, if I switch the order of the intersection type:
import React from 'react';
type Props = { children?: React.ReactNode; } & { children: React.ReactNode; }
const Component = ({ children }: Props) => {
return <div>{children}</div>
}
export default Component;
Then the result is different, with children now being required...
{
"description": "",
"displayName": "Component",
"methods": [],
"props": {
"children": {
"required": true,
"tsType": {
"name": "ReactReactNode",
"raw": "React.ReactNode"
},
"description": ""
}
}
}
Is this expected behaviour?
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 il problema con i due esempi di intersezioni TypeScript riportati e confronta i metadati props generati. Traccia come l'output della documentazione determina se children è obbligatorio per ciascun ordine di intersezione. Il lavoro è completato quando entrambi gli ordini producono lo stesso risultato corretto sull'obbligatorietà.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- react, typescript
- Ambito
- documentation
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100