This repository was archived by the owner on Dec 13, 2018. It is now read-only.
feat(typescript): Improved theme typing and tests#160
Merged
kentcdodds merged 3 commits intopaypal:nextfrom Jun 2, 2017
Merged
feat(typescript): Improved theme typing and tests#160kentcdodds merged 3 commits intopaypal:nextfrom
kentcdodds merged 3 commits intopaypal:nextfrom
Conversation
BREAKING CHANGE: The updated theme typing will complain if existing usage of theme is unsafe
Codecov Report
@@ Coverage Diff @@
## master #160 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 10 10
Lines 138 138
Branches 35 35
=====================================
Hits 138 138Continue to review full report at Codecov.
|
Collaborator
|
Great! 😃 Since Typescript 2.3 it's possible to set default generics type microsoft/TypeScript#13487. It's useful here as it cuts off a little boilerplate. See: // Without the default generics
export interface StyledFunction<Props, Properties> {
<CustomProps, ThemeProps>(
// ...
): GlamorousComponent<Props & CustomProps>
}
...
const Title = glamorous.h1<{ color: string }, {}>(
{
"fontSize": "10px",
"zIndex": "auto",
},
(props) => ({
"color": props.color,
}),
);
// With the default generic
export interface StyledFunction<Props, Properties> {
<CustomProps, ThemeProps = {}>(
// ...
): GlamorousComponent<Props & CustomProps>
}
...
const Title = glamorous.h1<{ color: string }>(
{
"fontSize": "10px",
"zIndex": "auto",
},
(props) => ({
"color": props.color,
}),
);I'll commit the changes for this improvement |
added default type (empty object literal) for ThemeProps generic in StyledFunction
removed redundant generic
ErikCupal
approved these changes
Jun 2, 2017
|
Thanks friends! So I'd like to avoid a major version bump if I can. At least, if we're doing that we should probably do other breaking changes while we're at it. So I'm going to merge this into |
kentcdodds
pushed a commit
that referenced
this pull request
Jun 4, 2017
* feat(typescript): Improved theme typing and tests * fix(typescript): tweaked StyledFunction added default type (empty object literal) for ThemeProps generic in StyledFunction * fix(typescript): removed boilerplate from tests removed redundant generic
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
BREAKING CHANGE: The updated theme typing will complain if existing usage of theme is unsafe
What:
Updated the typings around themes to get better safety around usage
Why:
We're implementing theming in a component library and wanted safety.
How:
Updated the typescript definition files and tests.
Checklist: