Closed
Description
TypeScript Version: 2.1.4 and 2.2.0-dev.20161215
Code
function test<T>(data: T, keys: (keyof T)[]) { }
interface User {
username: string
email?: string
}
test<User>({ username: '' }, ['email'])
test<User | { foo: string }>({ username: '' }, ['email'])
Expected behavior: No error.
Actual behavior: Error as keyof T
is never[]
instead of ("username" | "email" | "foo")[]
.
Possibly related to #12815, #10256 and #8896, except this is from the key side. It makes it really hard to use pick
on any unions.