Closed
Description
TypeScript Version: 2.8.0-dev.20180302
Search Terms:
keyof, intersection, mapped type, generic, type parameter, never
Code
type Example1<T extends string, U extends string> = keyof (Record<T, any> & Record<U, any>)
type Result1 = Example1<'x', 'y'>
// Type of Result1 is never but it should be 'x' | 'y'
/** The additional examples below are just for context */
type Result2 = keyof (Record<'x', any> & Record<'y', any>)
// Type of Result2 is 'x' | 'y' as expected
type Example3<T extends string> = keyof (Record<T, any>)
type Result3 = Example3<'x' | 'y'>
// Type of Result3 is 'x' | 'y' as expected
type Example4<T extends string, U extends string> = (Record<T, any> & Record<U, any>)
type Result4 = keyof Example4<'x', 'y'>
// Type of Result4 is 'x' | 'y' as expected
type Example5<T, U> = keyof (T & U)
type Result5 = Example5<Record<'x', any>, Record<'y', any>>
// Type of Result5 is 'x' | 'y' as expected
Expected behavior:
Result1
should have a type of 'x' | 'y'
Actual behavior:
Result1
has a type of never
Playground Link:
Link
Related Issues:
Maybe #18538? I read through it but honestly I'm not clear on what is going on in that one so I can't say how related it is.