This repository was archived by the owner on Oct 12, 2022. It is now read-only.
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
this
needs an explanation for the example given in this-based type guards
#247
Open
Description
class FileSystemObject {
isFile(): this is File { return this instanceof File; }
isDirectory(): this is Directory { return this instanceof Directory;}
isNetworked(): this is (Networked & this) { return this.networked; } <- what is *this* in (Networked & this)
constructor(public path: string, private networked: boolean) {}
}
In the example above, I understand that the type guard checks if the object has a Network object and this
is defined.
However, aside from the Network interface kind of just hanging out there (which is something else I do not understand), I'm not sure what this
as pointed out in the code sample above is supposed to point to.
I've asked around with some people who write TS daily and I'm getting WTF? looks like I'm not even writing typescript...