Closed
Description
TypeScript Version: 2.2.2
Code
type Eg = { foo: string, bar: number }
type VariantRec<T> = {[K in keyof T]: { type: K, value: T[K] }}
type Alpha1 = VariantRec<Eg>[keyof Eg]
type VariantType<T> = VariantRec<T>[keyof T]
type Alpha2 = VariantType<Eg>
const assignable12: Alpha2 = null as Alpha1
const assignable21: Alpha1 = null as Alpha2
Expected behavior:
Types Alpha1
and Alpha2
should be the identical.
Actual behavior:
Alpha2
incorrectly becomes: { type: 'foo' | 'bar', value: string | number }
It should be: { type: 'foo', value: string } | { type: 'bar', value: number }
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
KiaraGrouwstra commentedon Jun 9, 2017
Interesting. I'd posted a similar issue at #16244.
KiaraGrouwstra commentedon Jun 11, 2017
Hey, we found a solution for mine by separating the steps using generic defaults; still kinda feels like a bug, but I think a workaround like that may solve your case too! 😃
liam-goodacre-hpe commentedon Jun 12, 2017
@tycho01 Awesome, thanks! That appears to work 😸 Here's an updated playground.
KiaraGrouwstra commentedon Jun 30, 2017
Coming over from #16244, I just ran into another one super similar to yours, though here it doesn't seem fixable by defaults:
With the
wrap
wording I'm a bit reminded of #10247, though that concerned wrapping generic functions, while this is wrapping a generic type. Unfortunately, while in that other case one could observe the degenerating generics in the transformed output function, over here the inner workings feel somewhat opaque...mhegazy commentedon Aug 23, 2017
seems like a duplicate of #15756
KiaraGrouwstra commentedon Aug 25, 2017
Fixed by #18042.
mhegazy commentedon Sep 8, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.