microsoft / microsoft/TypeScript
Private class field helpers throw a confusing error when in unbound method with undefined `this`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 Search Terms
this undefined bind private identifier class __classPrivateFieldSet __classPrivateFieldGet bound unbound
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
class Foo {
#value = 1234;
getValue() { return this.#value; }
}
const foo = new Foo();
console.log(`foo.getValue() = ${foo.getValue()}`);
// Oops, I didn't bind!
const getValue = foo.getValue;
// Throws: Cannot read private member from an object whose class did not declare it
console.log(`getValue() = ${getValue()}`)
🙁 Actual behavior
Throws Cannot read private member from an object whose class did not declare it.
But the actual problem is that this is undefined and I had no idea!
🙂 Expected behavior
A special error for this when undefined; IIRC there's no possible way this would normally pass, so a special error would be a lot more clear.
Additional information about the issue
No response
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’accesso a un campo privato non associato nel TypeScript Playground collegato e confrontalo con la chiamata associata mostrata nell’issue. Traccia il modo in cui l’helper di private-field generato dal compilatore segnala l’errore, poi fai in modo che il caso undefined-this produca l’errore più chiaro descritto e verifica entrambi gli esempi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, 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
- 25/100