microsoft / microsoft/TypeScript
Methods in simple mixin result as type any.
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la reproducción vinculada en Playground y compara el comportamiento tratado en los issues 32080 y pull request 29571. Rastrea cómo las llamadas anidadas a mixins infieren los tipos de one y two; se considera terminado cuando las seis líneas @ts-expect-error producen errores de tipo, incluidas las llamadas con argumentos adicionales.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100