microsoft / microsoft/TypeScript
Methods in simple mixin result as type any.
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
TypeScript Version: 3.9.2
Search Terms:
typescript mixin method is any
Code
type AnyCtor = new (...a: any[]) => any
function Foo<T extends AnyCtor>(Base: T) {
return class Foo extends Base {
foo() {}
}
}
function Bar<T extends AnyCtor>(Base: T) {
return class Bar extends Base {
bar() {}
}
}
function One<T extends AnyCtor>(Base: T) {
return class One extends Base {
one() {}
}
}
function Two<T extends AnyCtor>(Base: T) {
return class Two extends Base {
two() {}
}
}
function Three<T extends AnyCtor>(Base: T) {
return class Three extends One(Two(Base)) {
three() {}
}
}
class MyClass extends Three(Foo(Bar(Object))) {
test() {
// @ts-expect-error
this.foo(123)
// @ts-expect-error
this.bar(123)
// @ts-expect-error // ERROR
this.one(123) // this.one is type `any`!
// @ts-expect-error // ERROR
this.two(123) // this.two is type `any`!
// @ts-expect-error
this.three(123)
console.log('no runtime errors')
}
}
const m = new MyClass()
m.test()
Expected behavior:
There should be an error on all the lines marked with // @ts-expect-error
Actual behavior:
There is no type error on the lines with this.one and this.two because this.one and this.two are seen as type any.
The expectation is that the one and two methods have the proper type (with zero parameters) which would therefore cause a type error from passing in arguments.
Related Issues:
Someone from the Discord chat thought perhaps https://github.com/microsoft/TypeScript/pull/29571 might be related, but not with 100% certainty. They do however think this is a bug.
Ultimately, making mixins in TypeScript is too hard. It's too easy to get them wrong and they become a very inconvenient in TypeScript (whereas they are very convenient in plain JavaScript).
Also related: https://github.com/microsoft/TypeScript/issues/32080
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der verknüpften Playground-Reproduktion und vergleiche das in den Issues 32080 und Pull Request 29571 diskutierte Verhalten. Verfolge, wie die verschachtelten Mixin-Aufrufe die Typen von one und two ableiten; abgeschlossen ist die Aufgabe, wenn alle sechs @ts-expect-error-Zeilen Typfehler erzeugen, einschließlich der Aufrufe mit zusätzlichen Argumenten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100