microsoft / microsoft/TypeScript
A trivial generic interface extending a generic type handles assignability differently than the base type
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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>.
Related Issues: N/A
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TypeScript reproduction in the issue and compare the assignability results for the type alias and interface forms in Test0 and Test1. Trace the compiler's generic-interface and assignability behavior, then add a regression test showing that Rebox is assignable to Rebox and that both assertion sets resolve without errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100