microsoft / microsoft/TypeScript
Javascript: Object.assign to assign property values for classes is not respected
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Perhaps TS should be able to identify Object.assign(this, ...) then infer the properties that are assigned to this? Or is this not possible to do? I am not sure.
TypeScript Version:
Version 3.0.3
Search Terms:
- object assign
- class
- does not exist on type
Code
A.js
export default class A {
constructor ({ x, y, z }) {
Object.assign(this, {x, y, z});
}
f () {
return this.x;
}
}
Expected behavior:
TS should be able to identify x as a property of this.
Actual behavior:
Throwing:
Property 'x' does not exist on type 'A'.
Related Issues:
no
Side Note:
I am using TS with Javascript because YouCompleteMe switched to using TSServer for semantic completion. I absolutely love TS so was really happy about the switch! Thanks for the great work!
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 con la riproduzione collegata in TypeScript Playground ed esamina come viene verificato Object.assign(this, {x, y, z}) nel costruttore della classe. Determina il comportamento atteso del controllo dei tipi per this.x e aggiungi un test di regressione; il lavoro è completato quando l’errore di proprietà segnalato è risolto ed esiste una copertura per questo schema.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, 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
- 35/100