Skip to content
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

v11: TypeScript infers incorrect type when composing styles/classes #1655

Closed
frankwallis opened this issue Nov 26, 2019 · 12 comments
Closed
Milestone

Comments

@frankwallis
Copy link
Contributor

Current behavior:

When composing styles the type of the created styled component is inferred to be a union of the created type and any element types referenced in the template literal

To reproduce:

The following code gives a TypeScript error using v11 but not under v10:

const Label = styled.label``
const Input = styled.input`
  & + ${Label}: {
    margin-left: 3px;
  }
`
;<Input onChange={(evt: React.ChangeEvent<HTMLInputElement>) => console.log(evt.target.value)} />

The resultant type becomes HTMLInputElement & HTMLLabelElement (or similar) and so the onChange handler is not allowed

Expected behavior:

In the above code the Input component should be inferred to be just HTMLInputElement

Environment information:

  • react version: 16.11.0
  • emotion version: 11.0.0-next.5
@Andarist
Copy link
Member

cc @JakeGinnivan

@frankwallis
Copy link
Contributor Author

It seems to relate to this code which has been removed:

| Equal<MP, undefined, never, FunctionInterpolation<MP>>

And now in the template arguments the ${Label} is being inferred as a FunctionInterpolation instead of a ComponentSelector

@Andarist
Copy link
Member

Thank you for investigating, it will be a great help in fixing this ❤️

@Andarist Andarist added this to the v11 milestone Nov 28, 2019
JakeGinnivan added a commit to JakeGinnivan/emotion that referenced this issue Dec 2, 2019
@frankwallis
Copy link
Contributor Author

@JakeGinnivan thank you for finding a solution for this, I'm not sure I would have found it. Is it ready for a PR into the next branch?
Let me know if there is anything I can do to help.

@JakeGinnivan
Copy link
Contributor

@frankwallis the fix is already in the current @next on NPM. If you could give it another spin to see if there are any other issues that would be great!

@JakeGinnivan
Copy link
Contributor

@frankwallis oh wait, no I was getting confused with another fix. There was a few additional comments to sort, will get it done today!

@frankwallis
Copy link
Contributor Author

awesome, thanks!

Andarist added a commit that referenced this issue Dec 8, 2019
#1664)

* Created additional overload to prevent AdditionalProps getting inferred as the composed component type

Fixes #1655

* Added additional test showing additional props

* Update .changeset/lucky-swans-kneel.md

Co-Authored-By: Mateusz Burzyński <mateuszburzynski@gmail.com>
@Andarist
Copy link
Member

Andarist commented Dec 8, 2019

@JakeGinnivan so this was not yet fixed by #1664?

@JakeGinnivan
Copy link
Contributor

@Andarist it just wasn't merged, once v11 gets released again it will

@Andarist
Copy link
Member

Andarist commented Dec 8, 2019

It got merged in few minutes ago - I'll cut a new release soon, so if the fix is already on next I would prefer to close this issue already. Stay tuned for a new release!

@frankwallis
Copy link
Contributor Author

I can confirm that our build is now working fine with no changes using v11 (we are not using theming). The build time has gone down from ~38 seconds to ~26 seconds which is really awesome, and I think will have a big impact when using VSCode. Thanks for the great work!

@Andarist
Copy link
Member

Thank you for checking!

louisgv pushed a commit to louisgv/emotion that referenced this issue Sep 6, 2020
emotion-js#1664)

* Created additional overload to prevent AdditionalProps getting inferred as the composed component type

Fixes emotion-js#1655

* Added additional test showing additional props

* Update .changeset/lucky-swans-kneel.md

Co-Authored-By: Mateusz Burzyński <mateuszburzynski@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants