microsoft / microsoft/TypeScript
Missing error when mistyped value overwrites property of spreaded generic type parameter
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Bug Report
🔎 Search Terms
generic argument, rest spread, false positive
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about object spread and generics
I found a few relevant issues, but none of them fully correspond to the current one:
- https://github.com/microsoft/TypeScript/issues/35858
- https://github.com/microsoft/TypeScript/issues/38469
- https://github.com/microsoft/TypeScript/issues/30129
⏯ Playground Link
Playground link with relevant code
💻 Code
interface InputProps {
value: string;
}
const getProps = (props: InputProps): InputProps => ({
...props,
value: 123, // when there is no generic type, it shows an error, as expected
});
const getPropsGenericNoSpead = <T extends InputProps>(props: T): T => {
const newProps = {...props};
newProps.value = 123; // also error, as expected
return newProps;
};
const getPropsGeneric = <T extends InputProps>(props: T): T => ({
...props,
value: 123, // no error here
});
🙁 Actual behavior
Typescript allows assigning incompatible types
🙂 Expected behavior
Typescript shows an error
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 dall’esempio Playground collegato e confronta il caso di spread generico con i casi non generico e non spread mostrati nel report. Traccia il comportamento del controllo dei tipi per l’assegnazione value: 123 nello spread di oggetti generico e considera conclusa l’issue quando TypeScript segnala l’incompatibilità prevista senza introdurre regressioni negli altri esempi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100