You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds examples/tests of constructing generic types.
This mostly works as expected, with the one caveat that constructing a generic `Foo<T>` with `ctor.new(Foo)` actually results in a return-only generic. TypeScript is a little awkward about these and it will actually be typed as `Foo<unknown>`. This is unfortunate, and the best practice around return-only generics is generally considered casting them to the desired type at each call site. This means that a user should really do `ctor.new(Foo) as ctor<Foo<T>>`, which is a bit annoying syntatically, but not that big a deal in the grand scheme of things.
More annoyingly is that TypeScript does not allow type parameters in the `extends` clause of a class when used as an expression. This makes sense for TypeScript because a class type `T` is not known until the class is instantiated, long after it was declared as extending a different class. However, with the recent changes in `ctor<T>`, the inheritance hierarchy is not built until construction-time, so we actually do know the value of `T`. Unfortunately this can't be expressed in TypeScript, so our best option is to simply `@ts-ignore` the error. This is not ideal, but TypeScript *mostly* does what we want in this case. The one issue here is that superclass members are typed as `any`, which is quite unfortunate but I don't see a good way around that.
See: microsoft/TypeScript#26154 (comment)
0 commit comments