-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
keyof
union type should produce union of keys, not intersection of keys
#12948
Comments
This isn't safe for the same reason as #12815. |
@ahejlsberg Can you elaborate on why that is, because the reason of the types in #12815 (comment) is not valid when we're only getting the keys. For more context, I have a database query that accepts export async function createOrUpdateSecondary <In, Out extends Dates> (
tableName: string,
data: In,
key: r.r.StringLike<string> | r.r.NumberLike<number>,
index: string,
updateKeys: (keyof In)[],
filterBy?: (row: r.RDatum<Out>) => r.RBoolean<boolean>
): Promise<Out> {} Edit: I can see it should be invalid if you use that to select the key that may not exist for the reasons in #12815, but in type positions shouldn't it be valid as without it, you can't actually model Edit 2: Also, if we needed to narrow the keys available on both sets, we could do that ourselves using |
Also, if we had exact types (#12936) would this change any opinion on how properties of a union can be operated on? |
A core assumption we make is that The picture changes with exact types, both for regular property access and |
Thanks. I think I understand the usage of |
TypeScript Version: 2.1.4 and 2.2.0-dev.20161215
Code
Expected behavior: No error.
Actual behavior: Error as
keyof T
isnever[]
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.The text was updated successfully, but these errors were encountered: