Skip to content

type guards strangeness #7224

@zpdDG4gta8XKpMCd

Description

@zpdDG4gta8XKpMCd

TypeScript Version:

1.8.0

Code

const enum AsNonBlank {}
export function isNonBlank(value: string) : value is string & AsNonBlank {
    return !/^\s*$/g.test(value);
}
let value: string;
if (isNonBlank(value)) {
    doThis(value); // expected value to be string & AsNonBlank, actual: string
} else {
    doThat(value);
}
function doThis(value: string & AsNonBlank): void {
}
function doThat(value: string) : void {
}

Expected behavior:
value should either be string & AsNonBlank
or there must be a message saying that the type guard is invalid or something
Actual behavior:
value is a string

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions