Skip to content

Conversation

Gavriel-M
Copy link

@Gavriel-M Gavriel-M commented Jul 14, 2025

🛠️ Fix: Improve Type IntelliSense by Refining Pixel Definition

Issue:

The current Pixel type is defined as string | number, which causes IntelliSense to prioritize raw values over theme tokens (e.g., 'sm', 'md', etc.) when used in union types like Space = ThemeSpace | Pixel.

Solution:

Redefine Pixel as (string & {}) | (number & {}), which maintains compatibility with raw values at runtime but defers IntelliSense suggestions in favor of theme tokens.

// Before
export type Pixel = string | number;

// After
export type Pixel = (string & {}) | (number & {});

This enables cleaner developer experience with proper token autocompletion while retaining full runtime flexibility.

@Gavriel-M
Copy link
Author

@quantizor Do you think that's something we can merge?
I'm working with custom space tokens (ie. 'space0', 'space2', 'space4' and so on) and I cannot get intellisense for them.

@agriffis
Copy link
Collaborator

I don't have sufficient knowledge of TypeScript for this, and I'm not currently in the business of merging xstyled PR's anyway, but I have one request: This sort of non-obvious code should always include internal documentation to explain it and preferably point to reference documentation.

@Gavriel-M
Copy link
Author

@agriffis Thanks for the note!
This behavior is due to a well-known TypeScript issue where string | number overrides IntelliSense for more specific union types like theme tokens.

I’ll add a comment above the type definition explaining the reasoning and linking to that issue.

Curious — do you have a preferred way of documenting this kind of subtle or non-obvious type behavior? Always happy to align with your expectations.

@agriffis
Copy link
Collaborator

Internal documentation seems to be a lost art in the modern era...

Something like this:

// This syntax enables Intellisense to prioritize theme tokens over raw values.
// See https://github.com/microsoft/TypeScript/issues/29729

@Gavriel-M
Copy link
Author

Haha, it really is. I keep hearing “your code should document itself!” — but sometimes it needs a little help.

Just pushed a clear inline comment to document the intention. Thanks again for the suggestion!

@Gavriel-M
Copy link
Author

@agriffis For better reference, here’s the IntelliSense improvement in action:

xStyledTSFix

It's a super minimal change, but it makes a big impact on developer experience.
Merging this would help a lot — right now I’m having to override the type just to restore proper suggestions.

Copy link
Collaborator

@agriffis agriffis left a comment

Choose a reason for hiding this comment

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

LGTM

@agriffis
Copy link
Collaborator

@quantizor I contributed a review and some comments here, but I won't step on your toes by merging it directly. Assume you'll do that when you're ready.

Copy link

@galangel galangel left a comment

Choose a reason for hiding this comment

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

+1

@galangel
Copy link

👋🏻 @gregberge WDYT?

@gregberge
Copy link
Collaborator

👋🏻 @gregberge WDYT?

Hey, I am no longer maintaining xstyled. If you use it you should migrate to Tailwind CSS 😌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants