Skip to content

restrict to exact type by type name #28547

@ORESoftware

Description

@ORESoftware

The following will compile

interface Foo {
  success: boolean
}

interface Bar {
  success: boolean
}


const foo = (v: Foo) =>{

};

const bar = (v: Bar) =>{

};


bar(<Foo>{success: true});
bar(<Bar>{success: true});

it will compile because of the way that TS works, which is usually very convenient. But in some cases we may want to restrict to the exact type.

Basically, I am looking to prevent compilation for:

bar(<Foo>{success: true});

I want it to be restricted to:

bar(<Bar>{success: true}); 

is that possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions