microsoft / microsoft/TypeScript
Missing type error for invalid use of #private field
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Bug Report
ES #private fields are not source-positional, but scoped to each instance of a class. (That is unfortunate, in my humble opinion). However TypeScript is not detecting this case.
🔎 Search Terms
typescript no type error private field mixin
🕗 Version & Regression Information
4.3-beta (I didn't try earlier)
⏯ Playground Link
Playground link with relevant code
💻 Code
type Ctor<T = {}> = new (...args: any[]) => T
function FooMixin<C extends Ctor>(Base: C) {
return class Foo extends Base {
#foo = 123
test(foo: Foo) {
console.log(foo.#foo)
}
}
}
class Cat extends FooMixin(Object) {}
class Dog extends FooMixin(Object) {}
const c = new Cat
c.test(new Dog) // Should there be a type error here, perhaps?
🙁 Actual behavior
No type error, but only a runtime error.
🙂 Expected behavior
There should perhaps also be a type error, if that's possible.
Mixin docs
The TypeScript Mixin documentation advertises that people can use #private fields with class-factory mixins:
// Mixins may not declare private/protected properties // however, you can use ES2020 private fields
This may lead people to the try them and they'll have this issue.
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 il TypeScript Playground collegato e riproduci l’esempio di mixin che coinvolge campi #private, FooMixin, Cat e Dog. Esamina il comportamento del controllo dei tipi relativo all’identità dei campi privati e determina quale diagnostica, se presente, dovrebbe essere prodotta per c.test(new Dog); il lavoro richiede di concordare una semantica e una copertura di regressione corrispondente.
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
- 30/100