Skip to content

[styled-component] Support css prop #31245

@sarod

Description

@sarod
  • I tried using the @types/styled-component package and had problems.
  • I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • Mention the authors (see Definitions by: in index.d.ts) so they can respond.

I tried using the new css prop (https://medium.com/styled-components/announcing-native-support-for-the-css-prop-in-styled-components-245ca5252feb) with the babel typescript presets and the styled-component babel-plugin.

This runs fine but type-checking fails because type definition does not extend builtin components (div, button...) with the 'css' prop.

Note that a similar prop seems to be supported in emotionjs type definitions by globally extending the react module:

declare module 'react' {
  interface DOMAttributes<T> {
    css?: InterpolationWithTheme<any>
  }
}

See
https://github.com/emotion-js/emotion/blob/1b7333a837813949fa4fe301bb0d53887e784b8b/packages/core/types/index.d.ts#L83

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions