Open
Description
TypeScript Version: 3.6.0-dev.20190803
Search Terms: assigning keyof generic key
Code
type A = { a: number }
type B = { b: number }
interface Foo {
a: A
b: B
}
declare let target: Foo
declare let source: Foo
declare let key: keyof Foo
target[key] = source[key]
Expected behavior:
I expect it to allow the assignment. Since typeof target
and typeof source
are the same, I expect typeof target[key]
to always be the same as typeof source[key]
.
Actual behavior:
error TS2322: Type 'A | B' is not assignable to type 'A & B'.
Related Issues: #31665 (but it was closed and the comments seem to indicate that this should work 🤔) ping @RyanCavanaugh