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

CreateStyled is not Templated in @emotion/native @next (11.0.0-next.12) #1861

Closed
andrewphillipo opened this issue May 5, 2020 · 2 comments
Closed

Comments

@andrewphillipo
Copy link

andrewphillipo commented May 5, 2020

I'm using @emotion/native@next and want to get a typed theme prop applied across all styled.<ReactNativeComponent> emotion components.

Currently I'm trying the example as laid out in the docs for React rather than React Native.

Unfortunately the CreateStyled interface is not Templated so I cannot pass my theme type in the same way on Native as with vanilla React.

import styled, { CreateStyled } from "@emotion/native";

type Theme = {
  color: {
    primary: string;
    positive: string;
    negative: string;
  };
  // ...
};

export default styled as CreateStyled<Theme>;

The error I get is Type 'CreateStyled' is not generic..

Expected behavior:

CreateStyled supports a prop for the shape of the Theme I've built and I get correct auto completion for theme properties such as colors in my Emotion Components.

Environment information:

  • react version: react@16.9.0
  • emotion version: @emotion/core@11.0.0-next.10 @emotion/native@11.0.0-next.12 etc.
@Andarist
Copy link
Member

Andarist commented May 5, 2020

Could u try this - #1606 (comment) ?

@andrewphillipo
Copy link
Author

Brilliant!

import "@emotion/react";
import theme from "../styles/theme";

type ThemeType = typeof theme;

declare module "@emotion/react" {
  export interface Theme extends ThemeType {}
}

This is what I ended up with thank you 👍🏻

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

2 participants