Skip to content

Type parameters in custom type guards don't seem to have the same meaning as in their predicates #4212

Closed
@zpdDG4gta8XKpMCd

Description

@zpdDG4gta8XKpMCd

I know I am not supposed to use values of void, because one day they might be banned. But for time being I don't understand is it by design or by mistake that the isVoid guard works whereas isNonVoid doesn't in the example below:

function isVoid<a>(value: void | a): value is void {
    return undefined;
}

function isNonVoid<a>(value: void | a) : value is a {
    return undefined;
}

function foo<a>(value: void|a): void {
    if (isVoid(value)) {
        // value is void
    } else {
        // value is a
    }
}

function baz<a>(value: void|a): void {
      if (isNonVoid(value)) {
            // value is void | a
      } else {
            // value is {}
      }
}

How come that seemingly identical guard implementation breaks apart entirely?

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions