microsoft / microsoft/TypeScript
Create a new type after deleting a property from object
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
TypeScript Version: v4.13
Search Terms: delete property from object new type
Code
interface ApiData {
foo?: string | null;
}
interface Props {
foo?: string;
}
function test(props: Props) {
console.log(props.foo);
}
const bar: ApiData = {
foo: null
}
if (bar.foo === null) {
delete bar.foo;
}
test(bar);
Expected behavior:
No type error should occur when calling test with the argument bar since we have deleted foo from bar when foo is null.
Actual behavior:
The following error is reported by TS: Argument of type 'ApiData' is not assignable to parameter of type 'Props'.
Types of property 'foo' are incompatible.
Type 'string | null | undefined' is not assignable to type 'string | undefined'.
Type 'null' is not assignable to type 'string | undefined'.(2345)
Related Issues: https://github.com/microsoft/TypeScript/issues/13783
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 TypeScript v4.13 nel Playground collegato e confronta l'errore di assegnabilità riportato con il comportamento previsto dopo l'eliminazione di bar.foo. Leggi l'issue correlata #13783 per il contesto precedente; il lavoro è concluso quando l'esempio non segnala più l'errore, mantenendo al contempo la gestione corretta delle proprietà nullable.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100