feat: allow overriding type of stylex.env in TypeScript#1514
feat: allow overriding type of stylex.env in TypeScript#1514mellyeliu merged 3 commits intofacebook:mainfrom
stylex.env in TypeScript#1514Conversation
|
@pawelblaszczyk5 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
| ) => ':where-any-sibling', | ||
| }; | ||
|
|
||
| export type StyleX$Env = $ReadOnly<{ [string]: mixed }>; |
There was a problem hiding this comment.
Moved the type into StyleXTypes.d.ts and StyleXTypes.js to make it possible to make them different across Flow/TS
| [babel plugin options](/docs/api/configuration/babel-plugin/#env)._ | ||
|
|
||
| ```tsx | ||
| declare module '@stylexjs/stylex/lib/types/StyleXTypes' { |
There was a problem hiding this comment.
As mentioned in the description - these could be just "@stylexjs/stylex" if we exported this from entry point, that would probably also mean adding some "mock" type in Flow, because entry point is auto generated? Or am I missing something obvious here?
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
mellyeliu
left a comment
There was a problem hiding this comment.
Also some open questions around what the default shape of stylex.env should be, but this is an improvement to what's currently in main. Thanks!
What changed / motivation ?
As explained in #1507 this allows user to override type of
stylex.envif they're using TypeScript. It uses declaration merging and exposesRegistertype that can be augmented in the user land.stylex.envis typed by either the default, existing type or whatever user sets asenvin theRegistertype.Example usage:
You get sweet autocompletion and type checking here and if you adjust types of the
envyou'll get type errors everywhere where you didn't update the usage. Both constants and utility functions can be typed this way.Linked PR/Issues
Fixes #1507
Additional Context
Open points:
Registerfrom@stylexjs/stylex/lib/types/StyleXTypeswhich user needs to refer when augmenting module. It could go directly to@stylexjs/stylexbut then Flow version would need to export some basically unused type, because the entry point for TS is generated from Flow file if I understand correctly?typescript-testsit'll currently impact all files and it doesn't verify whetherstylex.envis still the fallback if user didn't override this. This could be fixed by splittingtsconfig.jsoninto multiple projects but I didn't want to pollute it too much and I'm not 100% sure about the value.stylex.envcurrently it's only in the API section and it doesn't feel fully like API, it feels more like guide.stylex.envallows - object with constants and functions. Not sure how important it is, I've checked out and many TS libraries doesn't verify this.Open to addressing any of them, I guess some of them could be nice possible improvements for the future.
Pre-flight checklist
Contribution Guidelines