Skip to content

Error message for type guards are vague about rules #6540

Closed
@DanielRosenwasser

Description

@DanielRosenwasser

From #6538

interface Animal {
    animal;
}

interface Dog extends Animal {
    dog;
}

interface Car {
    car;
}

let thing: Dog | Car;

function isAnimal(x: Car | Dog): x is Animal {
    return "animal" in x;
}

Currently we just report

Type 'Animal' is not assignable to 'Car | Dog'.
    etc.

But that should be the elaboration. The first thing the user sees should be something like

A type guard's type must be assignable to its parameter's type.`
    Type 'Animal' is not assignable to 'Car | Dog'.
        etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingFixedA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions