support global typescript theme definition#1453
Merged
kof merged 1 commit intocssinjs:masterfrom Feb 15, 2021
k-yle:typescript-theme
Merged
support global typescript theme definition#1453kof merged 1 commit intocssinjs:masterfrom k-yle:typescript-theme
kof merged 1 commit intocssinjs:masterfrom
k-yle:typescript-theme
Conversation
Member
|
Most users will be lazy and will not create the |
Member
Author
|
hi @moshest, if users don't extend the this matches the old behaviour, so it won't be a breaking a change. |
Member
|
merged, thanks! |
Member
|
will be released with the next release, we aggregate a bit |
Member
|
Released in v10.6.0 |
This was referenced Mar 15, 2021
This was referenced Mar 16, 2021
This was referenced Mar 17, 2021
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a number of things that make react-jss's
createUseStylesless convenient for TypeScript users.The problems:
createUseStylesis tedious because you need to pass the theme as a type argument every time, which has to be imported from somewhere (createUseStyles<MyTheme>(theme => { ... }))This is because, if you supply a type argument, the union type (
"myHeader" | "myFooter"in the screenshot) just becomesstring.
To fix this, you have to duplicate every class name, and now the code looks horrendous:
createUseStyles<MyTheme>()syntax is not possible in JS files.This PR fixes these 3 issues.
Anyone (TypeScript and JavaScript users) can create a file called
global.d.tsanywhere in their project. It is not imported by anything; TypeScript and/or VSCode's TSServer finds it automatically. It could like this:Now, when call
createUseStyles()you don't need to provide any type arguments to get type definitions for the theme, and the class names (see screenshot above) are automatically inferred by typescript without defining them separately.I have added tests to confirm that this works and that TypeScript produces errors if you make a typo in the
classesobject or thethemeobject.Todo