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

vars used in stylex.create generate error with eslint(@stylexjs/valid-styles) #769

Open
Mikescops opened this issue Nov 11, 2024 · 4 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Mikescops
Copy link

Mikescops commented Nov 11, 2024

Describe the issue

My project is in typescript and I use the @stylexjs/eslint-plugin package.

I'm defining variables as follow:

export const tokens = stylex.defineVars({
    // Background and Foreground
    background: "#ffffff",
    foreground: "#171717",

Whenever I use my created variable as below, eslint complains about the variable not being the expected type.

const styles = stylex.create({
    primary: {
        backgroundColor: tokens.background
    }
})
image

warning color value must be one of: a string literal ...

image

Expected behavior

eslint should not complain about the variable as it is meant to be written that way

Steps to reproduce

Create a project with the eslint plugin and create variables as described in the problem statement above.
When used in stylex.create eslint should display an error (or warning depending on your eslint settings).

Test case

// tokens.stylex.ts
 export const tokens = stylex.defineVars({
    background: "#ffffff"
    });

// App.tsx
const styles = stylex.create({
    primary: {
        backgroundColor: tokens.background
    }
});

Additional comments

No response

@Mikescops Mikescops added the bug Something isn't working label Nov 11, 2024
@nmn
Copy link
Contributor

nmn commented Nov 11, 2024

stylex.defineVars must be defined in it's own file and the file must be named with a .stylex.ts extension.

When you import the variables directly from that file, you should not see this error.

It is currently not legal to define variables with defineVars in the same file as where they are used.

@Mikescops
Copy link
Author

@nmn I may have simplified how I use it for writing this issue, but initially I indeed defined them as you mentioned and I still have the error.

image

@Mikescops
Copy link
Author

So I've figure out something interesting, I removed the "allowImportingTsExtensions": false in tsconfig.

And here is the behaviour:
image

without .js in the import

image image

@nmn
Copy link
Contributor

nmn commented Nov 11, 2024

Interesting! Thanks for the bug report. Will fix this problem.

@nmn nmn added good first issue Good for newcomers help wanted Extra attention is needed labels Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants