TypeScript error while using stylex.types
- the inferred type cannot be named without a reference
#857
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:
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:
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
- Install StyleX
- Enable declaration generating in your
tsconfig
by settingdeclaration
totrue
- Try to declare and export
stylex.defineVars
from a file - 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