Skip to content

Type error with union types (fromDataUnion) #375

@ychailler

Description

@ychailler

I sometimes get a type error in the fromDataUnion(data) method in the switch expression :

static fromDataUnion(data: RoleUnion): RoleUnion {
        if (!data) {
            return data;
        }
        switch (data.role) {
            case "ROLE_A":
                return RoleA.fromData(data);
            case "ROLE_B":
                return RoleB.fromData(data);
            case "ROLE_C":
                return RoleC.fromData(data); // here
...

I had to add a cast to make it work :
RoleC.fromData(<RoleC> data);

Maybe we could add automatically this cast in every switch case to avoid type errors ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions