Skip to content

Conversation

@dwei-figma
Copy link
Collaborator

What changed / motivation ?

There seems to be a divergence between the type of TTokens in Flow vs. in TypeScript. This causes defineConsts to reject number values in TypeScript, like so:

export const zIndex = stylex.defineConsts({
  // Type 'number' is not assignable to type 'string | CSSType<string | number | null> | { [key: string]: string; }'.ts(2322)
  connector: 1,
  bifurcatedPicker: 2,
})

Sync the type of TTokens in packages/@stylexjs/stylex/src/types/StyleXTypes.d.ts against that of packages/@stylexjs/stylex/src/types/StyleXTypes.js to fix this.

Additional Context

Test case added to packages/typescript-tests/src/typetests.ts.

Pre-flight checklist

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 23, 2025
| Readonly<{
default: NestedVarObject<T>;
[key: `@${string}`]: NestedVarObject<T>;
[key: AtRuleStr]: NestedVarObject<T>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AtRuleStr is an alias for the template string type `@${string}` earlier in the file, so this should have no effect.

Was looking to understand why this restriction doesn't seem to currently apply to defineVars and defineConsts. Seems like it's because these two take a generic that extends TTokens instead of TTokens directly.

Not sure if our intention is to actually clamp down, but if we do, I can look into how to make this work.

Copy link
Member

@mellyeliu mellyeliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good - thanks for flagging this. We’ve historically optimized our types for flow, so ts has a few rough edges (see also: #1024) that we've been slowly working through fixing.

@mellyeliu mellyeliu merged commit fedbc6a into facebook:main Sep 26, 2025
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

2 participants