Closed
Description
TypeScript Version: nightly (2.2.0-dev.20161211)
Code
type Mapped1<T> = {
[P in keyof T]: T[P];
}
type Mapped2<T> = {
[P in keyof T]: T[P];
}
function asMapped2<T>(a: Mapped1<T>): Mapped2<T> {
return a;
}
Expected behavior:
No error.
Actual behavior:
test.ts(10,10): error TS2322: Type 'Mapped1<T>' is not assignable to type 'Mapped2<T>'.
Type 'T[P]' is not assignable to type 'T[P]'. Two different types with this name exist, but they are
unrelated.
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
ahejlsberg commentedon Jan 3, 2017
Agreed. I think we need a rule that a mapped type
{ [P1 in K1] : X1 }
is related to a mapped type{ [P2 in K2]: X2 }
whenK1
is related toK2
andX1
is related to an instantiation ofX2
that substitutesP1
forP2
.BigDataSamuli commentedon Jan 4, 2017
FWIW, my original use case was similar to the following:
which errors with
I presumed the issue in the OP is the underlying cause for this.