-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript