Skip to content
Discussion options

You must be logged in to vote

The StyleX transform can compile the sx shorthand, but TypeScript is still checking React's normal JSX types. React's intrinsic button/div props do not include sx, so you need to add a local ambient type if you want to use that shorthand in TS.

For example, add something like src/stylex-jsx.d.ts and make sure it is included by your tsconfig:

import type { StyleXStyles } from '@stylexjs/stylex';

declare module 'react' {
  interface HTMLAttributes<T> {
    sx?: StyleXStyles;
  }

  interface SVGAttributes<T> {
    sx?: StyleXStyles;
  }
}

Then this should type-check:

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

const styles = stylex.create({
  button: { color: 'red' },
});

export function A…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nmn
Comment options

nmn Jun 21, 2026
Collaborator

Answer selected by nmn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants