Skip to content

unsound type constraints #8459

Closed
Closed
@zpdDG4gta8XKpMCd

Description

@zpdDG4gta8XKpMCd
interface I {
    fn: <T>(t: T) => void;
}
interface X {
    x: number;
}
function toI<T extends X>() : I {
    return {
        fn: (t: T) => { // <-- expected a warning from the compiler that the type constraint cannot be enforced
            alert(t.x);
        }
    };
}
function test(i: I): void {
    i.fn({}); // <-- problem unnoticed
}
test(toI<X>()); // displays "undefined"

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