-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Indexing mapped type with keyof type param #16018
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Interesting. I'd posted a similar issue at #16244. |
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! 😃 |
@tycho01 Awesome, thanks! That appears to work 😸 Here's an updated playground. |
Coming over from #16244, I just ran into another one super similar to yours, though here it doesn't seem fixable by defaults: type Inc = [1, 2, 3, 4, 5];
type ObjectHasKey<O extends {}, K extends string> = ({[K in keyof O]: '1' } & { [k: string]: '0' })[K];
type Length<R extends {}, I extends number = 0> = { 1: Length<R, Inc[I]>, 0: I }[ObjectHasKey<R, I>];
type TestLenA = Length<{ 0: 'a', 1: 'b' }>;
// ^ ok, 2
type Wrap<O> = Length<O>;
// type Wrap<O, Len extends Length<O> = Length<O>> = Len;
// ^ old work-around, same result here
type TestLenB = Wrap<{ 0: 'a', 1: 'b' }>;
// ^ 0 :( With the |
seems like a duplicate of #15756 |
Fixed by #18042. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.2.2
Code
On playground
Expected behavior:
Types
Alpha1
andAlpha2
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 }
The text was updated successfully, but these errors were encountered: