question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@types/rebass and Emotion

See original GitHub issue

Hey, wanted to get a discussion going about this.

With the switch from styled-components to emotion as the default css-in-js in version 4.0, I think it would make sense to have the DefinetlyTyped typings follow suit.

Right now the types have been updated to match Rebass 4.0 - But, they are using styled-components as the base. This works for the most part, except for css prop, which conflicts with the Emotion definition. Sure you might mostly be using the sx prop for styling Rebass, but it will result in an error if you try to create a component that composes the BoxProps.

// This causes a TypeScript error when using Emotion
type Props = BoxProps & {
 customProp: string
}

Basically the problem is this definition:

export interface BaseProps extends React.RefAttributes<any> {
    as?: React.ElementType;
    css?:
        | StyledComponents.CSSObject
        | StyledComponents.FlattenSimpleInterpolation
        | string;
}

It should look like this when using Emotion:

export interface BaseProps extends React.RefAttributes<any> {
    as?: React.ElementType;
    css?: InterpolationWithTheme<any>
}

I’m not 100% sure of the best way to handle this in DefinetlyTyped, but I think it would make sense to have them split:

  • @types/rebass
  • @types/rebass_styled-components or @types/rebass/styled-components

I’ve been trying to get it solved in this pull request but surprisingly hard to get the build to pass. I might just try again in a new branch. I’ve created a local copy of the typings, that are working fine on the project i’m working on.

See also #664 which is caused by this issue.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:14
  • Comments:9

github_iconTop GitHub Comments

22reactions
russellr922commented, Feb 18, 2020

For anyone else needing to resolve this immediately, put a rebass.overrides.ts file in the src directory with the code below, add any other Prop interfaces from Rebass you may need.:

import { InterpolationWithTheme } from '@emotion/core'

declare module "rebass" {
  interface FlexProps {
    as?: React.ElementType;
    css?: InterpolationWithTheme<any>;
  }
  interface BoxProps {
    as?: React.ElementType;
    css?: InterpolationWithTheme<any>;
  }
  interface TextProps {
    as?: React.ElementType;
    css?: InterpolationWithTheme<any>;
  }
}

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

declare global {
  namespace JSX {
    interface IntrinsicAttributes {
      css?: InterpolationWithTheme<any>;
    }
  }
}
5reactions
lluiacommented, Dec 25, 2019

I could override the error above by pointing TS to the declaration file:

// tsconfig.json
{
  ...,
  "paths": {
    "rebass/styled-components": ["node_modules/@types/rebass"]
  }
}

Not ideal but it kinda saved the day. I’ll keep watching  👀 this issue and consider find time to fix the types on DefinitivelyTyped 👍🏻

Read more comments on GitHub >

github_iconTop Results From Across the Web

rebass - CodeSandbox
@rebass/forms. 4.0.6 · @rebass/preset. 4.0.5 · @types/rebass. 4.0.4 · @types/rebass__forms. 4.0.0 · emotion-theming. 10.0.27 · react. 16.12.0 · react-dom. 16.12.0.
Read more >
Rebass Test - StackBlitz
"emotion-theming";. import theme from "@rebass/preset";. import { Box, Card, Image, Heading, Text }. from "rebass";. interface AppProps {}.
Read more >
@backtothecode/vm-ui-library NPM | npm.io
Vault Maker | UI Component Library. A library for shared components for Vault Maker related apps. Key Links.
Read more >
@backtothecode/vault-maker-ui - npm
@emotion/core · @makerdao/dai · @makerdao/dai-plugin-mcd · @rebass/forms ... @types/marked · @types/rebass · dotenv · emotion-normalize · emotion-theming ...
Read more >
types/rebass__grid - 3mard/DefinitelyTyped - Gitiles - GerritHub.io
types / rebass __grid. tree: 1802fd3fd9475020f42ebe675549700c8c9bc185 [path history] [tgz]. emotion.d.ts · index.d.ts · rebass__grid-tests.tsx ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found