Open
Description
π Search Terms
generic generator static
π Version & Regression Information
- I was unable to test this on prior versions because there is still no online version of every-ts bisect
β― Playground Link
π» Code
class Base {
static *[Symbol.iterator]<T>(this: T) {
yield this;
}
}
class Child extends Base {}
const test = function* () { yield* Child };
const value = [...test()][0]; // T
console.log(value); // Child
π Actual behavior
The result is typed as T, whatever generic parameter outside of generic code means.
π Expected behavior
T should be instantiated with Child during a call to [Symbol.iterator]
Additional information about the issue
For regular static method calls it works as expected, by instantiating T
class Base {
static foo<T>(this: T) {
return this;
}
}
class Child extends Base {}
const value = Child.foo(); // Child
console.log(value); // Child
On the other hand, this is a nice way to create unique types for opaque type implementation! π