Created
July 31, 2025 17:00
-
-
Save va9iff/e32dde1ce663151743f6c2cb6098cc26 to your computer and use it in GitHub Desktop.
Inferred empty arrays, even with static methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class A { | |
| static foo() { | |
| return true ? [] : [ new this() ] | |
| } | |
| } | |
| const arr = A.foo() // type: A[] |
Author
Author
nevermind. I made it to be able to extend and then use .all while having the extended class type inferred. but no, if I do class B extends A{}; new B().all it still sees it as A[]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I needed an empty array of type its class. I couldn't use the
thistype in static methods with JSDoc. I didn't wanted to instantiate an object so, I came up with this fuckery