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

stylex.create({}) show error TS2554: Expected  0  arguments, but got  1 #313

Closed
romanchekashov opened this issue Jan 5, 2024 · 12 comments

Comments

@romanchekashov
Copy link

Please remove const from:

export type Stylex$Create = <
  const S extends {
    [key: string]: UserAuthoredStyles | ((...args: any) => UserAuthoredStyles);
  },
>(
  styles: S,
) => MapNamespaces<S>;

romanchekashov added a commit to romanchekashov/stylex that referenced this issue Jan 5, 2024
@romanchekashov
Copy link
Author

I've created a pull request with fix: #314

@nmn
Copy link
Contributor

nmn commented Jan 5, 2024

The const is needed. Without it, the types aren't specific enough.

Please share an example of the issue you're seeing.

@romanchekashov
Copy link
Author

You can see bellow highlights. If I remove const error disappears.

Screenshot 2024-01-06 at 12 41 06 AM Screenshot 2024-01-06 at 12 39 07 AM

@romanchekashov
Copy link
Author

I thought that const cannot be used inside generics <...> but maybe this bug related to IntelliJ IDEA 2023.2.2?

@nmn
Copy link
Contributor

nmn commented Jan 6, 2024

const can be used within generics for functions and classes, but not type aliases.

This feels like an IntelliJ bug. This all works in VS Code. Leaving the issue open for you to verify on your end.

@daulric
Copy link

daulric commented Jan 6, 2024

const can be used within generics for functions and classes, but not type aliases.

This feels like an IntelliJ bug. This all works in VS Code. Leaving the issue open for you to verify on your end.

i had that error but I didn't know when I was using VSCode as well. This is an error on Stylex Side

@daulric
Copy link

daulric commented Jan 6, 2024

this is the error i had
Screenshot (93)

@bmg02
Copy link

bmg02 commented Jan 6, 2024

I'm facing the same error. Any solution for this?

@nmn
Copy link
Contributor

nmn commented Jan 6, 2024

You're most likely using an old version of Typescript. As you can see on the nextjs example in the repo itself, there are no typescript errors.

Can you both verify the version of Typescript you're using?

@romanchekashov
Copy link
Author

romanchekashov commented Jan 6, 2024

const can be used within generics for functions and classes, but not type aliases. - This is a new feature of latest TypeScript 5.3.3 and doesn't work with TS 4.8.4;(

Just upgrade TS version in package.json with "typescript": "^5.3.3".

@nmn Please provide example of running jest tests in Nextjs 14 with stylexjs? I've managed a lot to be able to use stylexjs with Next js 14 but I cannot move further with falling tests( I'm using Jest with React Testing Library and getting error:

 ● Test suite failed to run

    stylex.defineVars should never be called. It should be compiled away.

      82 | };
      83 |
    > 84 | export const text = stylex.defineVars({

@bmg02
Copy link

bmg02 commented Jan 7, 2024

Upgrading the typescript solved the issue, thanks.

@nmn
Copy link
Contributor

nmn commented Jan 7, 2024

Added a single Jest snapshot test in this repo:

https://github.com/nmn/nextjs-app-dir-stylex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants