Skip to content

unsound type constraints #8459

Closed
Closed

Description

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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