Skip to content

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

Open
@pawelblaszczyk5

Description

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

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions