Skip to content

Naked generic type returned from iterator method #59161

Description

@reverofevil

🔎 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

Link

💻 Code

classBase{static*[Symbol.iterator]<T>(this: T){yieldthis;}}classChildextendsBase{}consttest=function*(){yield*Child};constvalue=[...test()][0];// Tconsole.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

classBase{staticfoo<T>(this: T){returnthis;}}classChildextendsBase{}constvalue=Child.foo();// Childconsole.log(value);// Child

On the other hand, this is a nice way to create unique types for opaque type implementation! 🙃

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: This-TypingThe issue relates to providing types to this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions