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

suggestion on type errors #706

Closed
veeramarni opened this issue May 2, 2019 · 4 comments
Closed

suggestion on type errors #706

veeramarni opened this issue May 2, 2019 · 4 comments

Comments

@veeramarni
Copy link

veeramarni commented May 2, 2019

Type: Infrastructure

After upgrading to 10+ we noticing few type errors.

Packages Version
fela 10.2.4

Description

Following type errors we see.

// styles

    otherSelectors: {
        // .a .sub-class
        '& .sub-class': {
            color: 'blue',
            // they can contain nested objects e.g.
            // .a .sub-class:hover
            ':hover': {
                color: 'black',
            },
        },
    },

// type errors

Type '({ fontScale, theme }: OwnProps & FelaWithThemeProps<Theme>) => { container: { display: string; flexDirection: "column"; alignItems: string; }; firstSection: ({ theme }: OwnProps & FelaWithThemeProps<Theme>) => { ...; }; secondSection: { ...; }; thirdSection: { ...; }; otherSelectors: { ...; }; }' is not assignable to type 
'TMultiRule<OwnProps & FelaWithThemeProps<Theme>, Styles>'.
  Type '({ fontScale, theme }: OwnProps & FelaWithThemeProps<Theme>) => { container: { display: string; flexDirection: "column"; alignItems: string; }; firstSection: ({ theme }: OwnProps & FelaWithThemeProps<Theme>) => { ...; }; secondSection: { ...; }; thirdSection: { ...; }; otherSelectors: { ...; }; }' is not assignable to type 'TMultiRuleFunction<OwnProps & FelaWithThemeProps<Theme>, Styles>'.
    Type '{ container: { display: string; flexDirection: "column"; alignItems: string; }; firstSection: ({ theme }: OwnProps & FelaWithThemeProps<Theme>) => { backgroundColor: string; fontSize: string; }; secondSection: { ...; }; thirdSection: { ...; }; otherSelectors: { ...; }; }' is not assignable to type 
'TMultiRuleObject<OwnProps & FelaWithThemeProps<Theme>, Styles>'.
      Types of property 'otherSelectors' are incompatible.
        Type '{ '& .sub-class': { color: string; ':hover': { color: string; }; }; }' is not assignable to type 'IStyle | TRule<OwnProps & FelaWithThemeProps<Theme>>'.
          Type '{ '& .sub-class': { color: string; ':hover': { color: string; }; }; }' is not assignable to type 'TRule<OwnProps & FelaWithThemeProps<Theme>>'.
            Type '{ '& .sub-class': { color: string; ':hover': { color: string; }; }; }' provides no match for the signature '(props: OwnProps & FelaWithThemeProps<Theme>, renderer: IRenderer): IStyle'.

@veeramarni
Copy link
Author

Currently, this is one of the solutions suggested in csstypes. Wondering if there is any better way to generate .d.ts from styles file.

    otherSelectors: {
        // .a .sub-class
        ['& .sub-class' as any]: {
            color: 'blue',
            // they can contain nested objects e.g.
            // .a .sub-class:hover
            ':hover': {
                color: 'black',
            },
        },
    },

@veeramarni
Copy link
Author

I have tried something like this, still no luck.

@sample-stack/counter-module-browser:       TS2322: Type '() => { container: { display: string; flexDirection: string; alignItems: string; }; firstSection: ({ theme }: { theme: any; }) => { backgroundColor: any; fontSize: string; }; secondSection: ({ theme, fontScale }: { theme: any; fontScale: any; }) => { ...; }; thirdSection: ({ theme, fontScale }: { ...; }) => { ...; }...' is not assignable to type 'TMultiRule<OwnProps & FelaWithThemeProps<Theme>, { container: { display: string; flexDirection: string; alignItems: string; }; firstSection: ({ theme }: { theme: any; }) => { backgroundColor: any; fontSize: string; }; secondSection: ({ theme, fontScale }: { ...; }) => { ...; }; thirdSection: ({ theme, fontScale }: {...'.
@sample-stack/counter-module-browser:   Type '() => { container: { display: string; flexDirection: string; alignItems: string; }; firstSection: ({ theme }: { theme: any; }) => { backgroundColor: any; fontSize: string; }; secondSection: ({ theme, fontScale }: { theme: any; fontScale: any; }) => { ...; }; thirdSection: ({ theme, fontScale }: { ...; }) => { ...; }...' is not assignable to type 'TMultiRuleFunction<OwnProps & FelaWithThemeProps<Theme>, { container: { display: string; flexDirection: string; alignItems: string; }; firstSection: ({ theme }: { theme: any; }) => { backgroundColor: any; fontSize: string; }; secondSection: ({ theme, fontScale }: { ...; }) => { ...; }; thirdSection: ({ theme, fontSc...'.
@sample-stack/counter-module-browser:     Type '{ container: { display: string; flexDirection: string; alignItems: string; }; firstSection: ({ theme }: { theme: any; }) => { backgroundColor: any; fontSize: string; }; secondSection: ({ theme, fontScale }: { theme: any; fontScale: any; }) => { ...; }; thirdSection: ({ theme, fontScale }: { ...; }) => { ...; }; othe...' is not assignable to type 'TMultiRuleObject<OwnProps & FelaWithThemeProps<Theme>, { container: { display: string; flexDirection: string; alignItems: string; }; firstSection: ({ theme }: { theme: any; }) => { backgroundColor: any; fontSize: string; }; secondSection: ({ theme, fontScale }: { ...; }) => { ...; }; thirdSection: ({ theme, fontScal...'.
@sample-stack/counter-module-browser:       Types of property 'container' are incompatible.
@sample-stack/counter-module-browser:         Type '{ display: string; flexDirection: string; alignItems: string; }' is not assignable to type 'IStyle | TRule<OwnProps & FelaWithThemeProps<Theme>>'.
@sample-stack/counter-module-browser:           Type '{ display: string; flexDirection: string; alignItems: string; }' is not assignable to type 'IStyle'.
@sample-stack/counter-module-browser:             Types of property 'flexDirection' are incompatible.
@sample-stack/counter-module-browser:               Type 'string' is not assignable to type 'FlexDirectionProperty'.

@robinweser
Copy link
Owner

@veeramarni Feel free to send a PR improving the TypeScript types. I'm not a TypeScript user nor expert so I can't really help out here at all.

@sgrishchenko
Copy link
Contributor

I think this problem is alreay soved, see fela-plugin-typescript, there is explanation there how to use this plugin to achive typechecking in nested css rules

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