-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
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
bre1470, sindresorhus, jcalz, bysdxt, TeamworkGuy2 and 12 more
Metadata
Metadata
Assignees
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsSuggestionAn idea for TypeScriptAn idea for TypeScript