Closed
Description
TypeScript Version: 3.8.3
Search Terms:
no-op mapped type, assignable
Code
type Foo<IdentifierT extends Record<PropertyKey, PropertyKey>> =
IdentifierT
;
type Bar<IdentifierT extends Record<PropertyKey, PropertyKey>, T> =
{
[k in keyof T] : Foo<IdentifierT & { k : k }>
}
;
type Merge2<T> = { [k in keyof T] : T[k] }
type Bar2<IdentifierT extends Record<PropertyKey, PropertyKey>, T> =
{
[k in keyof T]: Foo<Merge2<IdentifierT & { k: k }>>
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Works in 3.5.1
// Works in 3.6.3
// Works in 3.7.5
// Fails in 3.8.3
}
;
type Identity<T> = T;
type Merge3<T> = Identity<{ [k in keyof T] : T[k] }>
type Bar3<IdentifierT extends Record<PropertyKey, PropertyKey>, T> =
{
[k in keyof T]: Foo<Merge3<IdentifierT & { k: k }>>
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Works in 3.5.1
// Works in 3.6.3
// Works in 3.7.5
// Fails in 3.8.3
}
;
Expected behavior:
Passes type checking
Actual behavior:
Fails in TS 3.8.3
Playground Link:
Related Issues:
Not that I could find
Well, it isn't exactly a "no-op" mapped type.
It will strip call and constructor signatures, but "no-op mapped type" was the best name I had for it.
Activity
phiresky commentedon May 16, 2020
I think I have the same issue with https://github.com/phiresky/ts-typed-sql, which destroys type inference everywhere, means our whole project is stuck on 3.7 for now :(
AnyhowStep commentedon May 21, 2020
I've been stuck at 3.5.1 forever now =(
phiresky commentedon May 23, 2020
I just bisected the ts compiler to find the cause using
build.sh
bisect reports:
first bad commit: [357f715] Check combined intersection properties against target index signatures (#35143) by @ahejlsberg
ahejlsberg commentedon May 24, 2020
A simpler repro for this issue:
We shouldn't error above and strangely we don't if the declaration of
Foo
is changed toThat's definitely a bug.
The example above worked before #35143 because we were very lax in our checking of relations involving intersections on the source side.