Check out this simplified code snippet:
class Thing<InState extends boolean = boolean> {
public inState(): this is Thing<true> {
return true;
}
}
const y = new Thing();
if (y.inState()) {
y
}
When I hover over y
in VSCode, I see something strange:
https://i.sstatic.net/kZOi0RDb.png
Despite calling inState()
, y
remains a Thing<boolean>
instead of a Thing<true>
. Why could that be?
I came across this concept in discord.js here, and I'm curious about why they are able to achieve this while I cannot reproduce it.