stylex icon indicating copy to clipboard operation
stylex copied to clipboard

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

Open romanchekashov opened this issue 5 months ago • 10 comments

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

romanchekashov avatar Jan 05 '24 19:01 romanchekashov

I've created a pull request with fix: https://github.com/facebook/stylex/pull/314

romanchekashov avatar Jan 05 '24 19:01 romanchekashov

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

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

nmn avatar Jan 05 '24 23:01 nmn

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 avatar Jan 05 '24 23:01 romanchekashov

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

romanchekashov avatar Jan 05 '24 23:01 romanchekashov

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.

nmn avatar Jan 06 '24 00:01 nmn

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 avatar Jan 06 '24 01:01 daulric

this is the error i had Screenshot (93)

daulric avatar Jan 06 '24 01:01 daulric

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

bmg02 avatar Jan 06 '24 08:01 bmg02

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?

nmn avatar Jan 06 '24 09:01 nmn

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({

romanchekashov avatar Jan 06 '24 13:01 romanchekashov

Upgrading the typescript solved the issue, thanks.

bmg02 avatar Jan 07 '24 05:01 bmg02

Added a single Jest snapshot test in this repo:

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

nmn avatar Jan 07 '24 06:01 nmn