Skip to content
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
@tonyeung

Description

@tonyeung
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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions