Skip to content

Allow method type guards #11117

@vagarenko

Description

@vagarenko

TypeScript Version: 2.0.3

Code

Why I can have function type guard:

function hasValue<T>(value: T | undefined): value is T { return value !== undefined; }

but not method type guard:

export class Maybe<T> {
    constructor(public value: T | undefined) {}

    hasValue(): this.value is T { return this.value !== undefined; }
    //              ^ '{' or ';' expected.
}

?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions