Emotion: Incorrect TypeScript errors about a missing css prop

Created on 10 Jul 2019  路  7Comments  路  Source: emotion-js/emotion

Most helpful comment

I ran into the same issue today while I was working on a package where I was importing components from another package that were created (and typed) as styled() components from @emotion/styled, all on version 10.0.17.

The issue went away after adding a import '@emotion/core' to the index.ts file of my package. I think the problem resided in the fact that the type definitions to support the css prop would otherwise not be properly resolved by TypeScript somehow.

All 7 comments

Have you experienced this problem before with emotion@10 or have you just upgraded to version 10 and it has popped up?

It started after moving to emotion 10.

I am also getting this error when using @emotion/styled@^10.0.14 with Typescript

const ClickableElement = styled.button`
  padding: 0;
  border: none;
  font: inherit;
  color: inherit;
  background-color: transparent;
  cursor: pointer;

  &:focus {
    outline: 2px solid rgba(42, 171, 130, 0.5);
  }
`;
<ClickableElement onClick={onClose}>
  Click here
</ClickableElement>

And the TS issue I get is

Property 'css' is missing in type '{ children: Element; onClick: any; }' but required in type 'Pick<DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "color" | "hidden" | "style" | "disabled" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | ... 257 more ... | "formTarget">'.ts(2741)

Could you prepare an isolated repository with the issue reproduced? I'm trying to reproduce this in our repo and can't do it, also css prop is defined everywhere as optional - so not sure how this could happen.

I'm also bumping into this issue.
Not entirely sure about the cause, but i _think_ it can be replicated when using a Pick or Omit (which depends on Pick).

In my case, I have some code doing the following:

export interface OnlyButtonProps {
  children?: React.ReactNode;
}

export type ButtonProps = OnlyButtonProps & Omit<React.HTMLProps<HTMLButtonElement>, 'ref'>;

For me the error only appears when i build, not sure why 馃し鈥嶁檪

I'll try and get a rerpo

I ran into the same issue today while I was working on a package where I was importing components from another package that were created (and typed) as styled() components from @emotion/styled, all on version 10.0.17.

The issue went away after adding a import '@emotion/core' to the index.ts file of my package. I think the problem resided in the fact that the type definitions to support the css prop would otherwise not be properly resolved by TypeScript somehow.

Typings are currently getting a serious makeover in https://github.com/emotion-js/emotion/pull/1501 and we plan to rethink how the theme can be typed. Closing this to clear up the issue tracker, but if you are interested in this please follow that PR, give your feedback if necessary and stay tuned for upcoming changes!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mitchellhamilton picture mitchellhamilton  路  3Comments

kentcdodds picture kentcdodds  路  3Comments

Zn4rK picture Zn4rK  路  3Comments

MrFungusEli picture MrFungusEli  路  3Comments

johnbrett picture johnbrett  路  3Comments