Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A trivial generic interface extending a generic type handles assignability differently than the base type #41370

Open
tjjfvi opened this issue Nov 2, 2020 · 1 comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Milestone

Comments

@tjjfvi
Copy link
Contributor

tjjfvi commented Nov 2, 2020

TypeScript Version: 4.0.5, 4.1.0-beta, 4.1.0-dev.20201102

Search Terms: generic interface assignability

Code

type Assert<T, U extends T> = U;

type A = { value: 5, a: true };
type B = { value: 5, b: true };

interface Box<T> {
    value: T;
}

type _Rebox<T extends Box<any>> = Box<T["value"]>;

namespace Test0 {
    type Rebox<T extends Box<any>> = _Rebox<T>;

    export type Assertions = [
        Assert<Box<5>, Rebox<A>>, // Correctly passes
        Assert<Rebox<A>, Box<5>>, // Correctly passes

        Assert<Box<5>, Rebox<B>>, // Correctly passes
        Assert<Rebox<B>, Box<5>>, // Correctly passes

        Assert<Rebox<A>, Rebox<B>>, // Correctly passes
    ];
}

namespace Test1 {
    interface Rebox<T extends Box<any>> extends _Rebox<T> {};

    export type Assertions = [
        Assert<Box<5>, Rebox<A>>, // Correctly passes
        Assert<Rebox<A>, Box<5>>, // Correctly passes

        Assert<Box<5>, Rebox<B>>, // Correctly passes
        Assert<Rebox<B>, Box<5>>, // Correctly passes

        Assert<Rebox<A>, Rebox<B>>, // Incorrectly fails
    ];
}

Expected behavior: Test0.Assertions and Test1.Assertions should both resolve with no errors.

Actual behavior: When Rebox is an interface (in Test1), Rebox<B> is not assignable to Rebox<A>.

Playground Link

Related Issues: N/A

@tjjfvi
Copy link
Contributor Author

tjjfvi commented Nov 3, 2020

This also fails:

interface Rebox<T extends Box<any>> extends Box<T["value"]> {};

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Nov 10, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

2 participants