stylex
stylex copied to clipboard
stylex.create({}) show error `TS2554: Expected 0 arguments, but got 1`
Please remove const
from:
export type Stylex$Create = <
const S extends {
[key: string]: UserAuthoredStyles | ((...args: any) => UserAuthoredStyles);
},
>(
styles: S,
) => MapNamespaces<S>;
https://github.com/facebook/stylex/blob/a3528b69d567bcf5c61c6e92e86312bcac8e6122/packages/stylex/src/StyleXTypes.d.ts#L108
I've created a pull request with fix: https://github.com/facebook/stylex/pull/314
The const
is needed. Without it, the types aren't specific enough.
Please share an example of the issue you're seeing.
You can see bellow highlights. If I remove const
error disappears.
I thought that const
cannot be used inside generics <...>
but maybe this bug related to IntelliJ IDEA 2023.2.2?
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.
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
this is the error i had
I'm facing the same error. Any solution for this?
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?
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({
Upgrading the typescript solved the issue, thanks.
Added a single Jest snapshot test in this repo:
https://github.com/nmn/nextjs-app-dir-stylex