type Identity<A> =
A extends object
? {[K in keyof A]: Identity<A[K]>}
: A;
type HasValue1<A> = {
value:Identity<A>;
}
type HasValue2<A> = {
value:Identity<A>;
}
function test<B>(a:HasValue1<B>) {}
function foo1<A>(a:HasValue1<A[]>) {test(a)} // OK
function foo2<A>(a:HasValue2<A[]>) {test(a)} // type-error
🙁 Actual behavior
The body of foo2 does not type-check because the wrong type for type-variable B is inferred.
🙂 Expected behavior
The body of foo2 should type-check exactly as foo1 since HasValue1 and HasValue2 are structurally the same type.
Bug Report
🔎 Search Terms
inference identical
🕗 Version & Regression Information
3.5-3.9, 4.0-4.6, 4.7.0-dev.20220304 (did not test earlier versions)
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The body of
foo2
does not type-check because the wrong type for type-variable B is inferred.🙂 Expected behavior
The body of
foo2
should type-check exactly asfoo1
sinceHasValue1
andHasValue2
are structurally the same type.