-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
in typescript 2.8, a common definition of Omit causes declarations that don't compile to be generated #25041
Comments
export type Omit<T, K extends keyof T> = Pick<T,
({ [P in keyof T]: P } & { [P in K]: never } )[keyof T]>; contains a mapped type which is unintentionally homomorphic - a mapped type templated over For the OP, to fix that definition of omit, you should write: export type Omit<T, K extends keyof T> = Pick<T,
({ [P in keyof T]-?: P } & { [P in K]: never } )[keyof T]>; to explicitly strip the input optionality (note the For us: We should issue an error on export type Omit<T, K extends keyof T> = Pick<T,
({ [P in keyof T]: P } & { [P in K]: never } )[keyof T]>; as the homomorphic mapped type |
cc @ahejlsberg to whom I was talking about this earlier today. Fixing this by including |
@RyanCavanaugh we need to consider the implications of fixing this one. |
#### Summary Updates some typings that cause build errors on `tsc` in Typescript v3.2.1 #### Description - new Omit is from microsoft/TypeScript#25041 (comment) - stops implicity 'any' error on next parameter - fixes destructuring confusion
TypeScript Version:
Reproduces with 3.0.0-dev.201xxxxx, 2.9.2, 2.8.4
Search terms
omit, declaration, pick, undefined
Example
generates
The interface returning a function seems to be required to get typescript to collapse the Omit to a Pick statement (otherwise you just get Omit<IXProps, "unwatedProp"> in the declaration file).
I think this is a bug in typescript because it's produced a declaration file with syntax errors in it.
Expected behavior:
undefined should not be present in the Pick statement
Playground Link:
the playground does not provide the ability to generate declartions
Related Issues:
#12215
note that if the definition of Omit is replaced with the newer declaration possible in typescript 2.9
then
results as expected.
I actually encountered this issue using when using connect() in react-redux with a component with an optional property, where the definition of Omit is:
The text was updated successfully, but these errors were encountered: