Skip to content

is type guards for properties #11796

Closed
Closed
@thorn0

Description

@thorn0

TypeScript Version: 2.0.3

Code

From the typings for the vinyl module.

declare class File {
    // ...
    /**
     * Type: Buffer|Stream|null (Default: null)
     */
    public contents: Buffer | NodeJS.ReadableStream;

    /**
     * Returns true if file.contents is a Buffer.
     */
    public isBuffer(): boolean;

    /**
     * Returns true if file.contents is a Stream.
     */
    public isStream(): boolean;

    /**
     * Returns true if file.contents is null.
     */
    public isNull(): boolean;

    // ...
}

Expected behavior:

Possibility to specify something like this.contents is Buffer instead of just boolean for the return type of the methods isBuffer, isStream, isNull.

Actual behavior:

The language doesn't support this.

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