Skip to content

fix(typescript): Preserve props union type #1252

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

Merged
merged 3 commits into from
Mar 11, 2019
Merged

fix(typescript): Preserve props union type #1252

merged 3 commits into from
Mar 11, 2019

Conversation

eps1lon
Copy link
Contributor

@eps1lon eps1lon commented Feb 28, 2019

What:

  • change Omit to be distributive over union types

Why:

  • withTheme and styled loose union type informaton

How:

Checklist:

  • Documentation N/A
  • Tests
  • Code complete N/A

@netlify
Copy link

netlify bot commented Feb 28, 2019

Preview Docs

Built with commit 238e41e

https://deploy-preview-1252--emotion.netlify.com

@eps1lon eps1lon changed the title Fix/typescript/union props fix(typescript): Preserve props union type Feb 28, 2019
@@ -10,6 +10,6 @@ export type PropsOf<C extends React.ComponentType<any>> = C extends React.SFC<
: never)
: never

export type Omit<T, U> = Pick<T, Exclude<keyof T, U>>
export type Omit<T, U> = T extends any ? Pick<T, Exclude<keyof T, U>> : never
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a ts user but in the recommended pattern you linked to, it says T extends unknown rather than T extends any, should it be using unknown or is there a reason for using any?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know T extends any would not evaluate to true for every type so unknown is safer. However for objects it should always be true. It is used since unknown was only released in typescript 3.0. If your types don't support 2.x we might as well go full in.

Also

use any instead of unknown for backwards compatibility. If you don't support typescript 2.x we can use unknown

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, didn't see that! I'd rather keep compatibility so I'm good with this.

@emmatown emmatown merged commit 1b262be into emotion-js:master Mar 11, 2019
@eps1lon eps1lon deleted the fix/typescript/union-props branch March 11, 2019 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants