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

TypeScript error while using stylex.types - the inferred type cannot be named without a reference #857

Open
pawelblaszczyk5 opened this issue Jan 14, 2025 · 4 comments · May be fixed by #867
Labels
bug Something isn't working

Comments

@pawelblaszczyk5
Copy link

pawelblaszczyk5 commented Jan 14, 2025

Describe the issue

Hello 👋

stylex.types functions are typed to return specific class instances for each of the types - all of these are imported from VarTypes file. However, these aren't exported anywhere so TypeScript can't properly typecheck/generate declaration for this. If I didn't use stylex.types and just use standard string value - declaration file would look like this:

Image

In cases where I use stylex.types there's no type that it can use in place for a given var value - because as mentioned, it's not exported.

Here you can see TS error that's caused by this:

Image

Image

Expected behavior

Project can be properly typechecked via tsc when declaration generation is enabled and stylex.types are used on exported member

Steps to reproduce

  1. Install StyleX
  2. Enable declaration generating in your tsconfig by setting declaration to true
  3. Try to declare and export stylex.defineVars from a file
  4. Observe error in IDE/tsc failing

I've created small reproduction: https://github.com/pawelblaszczyk5/stylex-incorrect-types-repro

Test case

Enable declaration in your tsconfig and try this code anywhere:

import * as stylex from "@stylexjs/stylex";

export const example = stylex.defineVars({
  etst: stylex.types.angle("20deg"),
});

Additional comments

I'm pretty sure this could be fixed by just exporting the classes that are used as a return type from stylex.types functions

@pawelblaszczyk5 pawelblaszczyk5 added the bug Something isn't working label Jan 14, 2025
@nmn
Copy link
Contributor

nmn commented Jan 17, 2025

@pawelblaszczyk5 I can't seem to open the repro you linked. I'm getting a 404.

@pawelblaszczyk5
Copy link
Author

@pawelblaszczyk5 I can't seem to open the repro you linked. I'm getting a 404.

Oh, sorry made it private by accident while pushing - fixed now

@nmn
Copy link
Contributor

nmn commented Jan 18, 2025

I see the issue. AFAIK, this is a recent change in Typescript but it's easy to fix. Putting up a PR now.

@nmn nmn linked a pull request Jan 18, 2025 that will close this issue
@pawelblaszczyk5
Copy link
Author

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants