-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructured types to greatly reduce number of types created during c…
…ompilation (#1501) * Restructured types to greatly reduce number of types created during compilation BREAKING CHANGE: There are a few breaking changes, see below * withTheme now infers types properly and may require removing the manually specified generic parameter * The Theme generic parameter has been removed from a number of types exported from `@emotion/styled` and `@emotion/styled-base`. * Introduced new CreateThemedStyled type which is exported from emotion-theming, use type to create your own themed `styled` export. See updated docs * WithTheme should be imported from emotion-theming * CreateStyledComponentExtrinsic, CreateStyledComponentIntrinsic and CreateStyledComponentBase all have been replaced with CreateStyledComponent * Fixing tests * Fixed a bunch of tests and improved TypeScript docs * Updated a bunch of the TypeScript docs * Removed WithTheme type, not sure it's usage and there is no tests * Few small cleanups around styled-base * Fixed tests in a few more packages * Fixed serialise tests after changes in #1236 * Removed failing redundant test in sheet typescript tests. It is failing with the same compilation error as the previous line, but formatting is causing the test failure * Removed line with expected error, I am not sure the reason it should be failing. * Need to bump the typescript version for styled-base for the union type test * TypeScript tests passing * Upgrade build image version to get newer version of yarn * fix: styled component with static API * Added changes in https://github.com/JakeGinnivan/emotion/pull/1/files to other functions with similar signatures * fix: type issue where styled component passed in * Add some additional tests around theming and fix them * Restrict css function to css interpolation * Fixed emotion-theming linting issue * Reversed some incorrect type changes, withComponent has to include the previous components props otherwise styles on the original component may fail at runtime * Fixed some accidently formatted package.json files * Allowed theming of CreateStyled and StyledTags * Restructured generic type params to make it explicit about what component props should transfer with withComponent and which shouldn't Added tests * Cleaned up some tests and added additional assertions * Default the type of SpecificComponentProps in StyledComponent * Reverted changes around ThemeProvider and added tests * Added changeset * Fixed ThemeProvider after revert * Update tslint rules to fix error * Fixed linting issues * Fixed import path for css and clarified docs * Added comment about fragment shorthand without babel being a typescript limitation * Removed breaking change around some of the internal types It's implementation detail user doesn't need to know * Reverted changes around removing function interpolation from the return types of function interpolation * Renamed Omit to DistributiveOmit To make it clear it's different to the inbuilt Omit * Removed duplicate intersected type * Renamed all usages of SFC to FC * Fixed poor grammar * Ignore lint rule rather than exporting type * Updated generic constraints * Reverted TypeScript version bump in create-emotion types * Sync docs and test code * Constrained Theme to extend {} * Add tests for broken examples in #1298 * Fix typo * Add test which verifies #1226 is fixed by type changes
- Loading branch information
Showing
48 changed files
with
616 additions
and
498 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"releases": [ | ||
{ "name": "@emotion/css", "type": "minor" }, | ||
{ "name": "emotion-theming", "type": "minor" }, | ||
{ "name": "@emotion/serialize", "type": "minor" }, | ||
{ "name": "@emotion/styled-base", "type": "minor" }, | ||
{ "name": "@emotion/styled", "type": "minor" } | ||
], | ||
"dependents": [ | ||
{ | ||
"name": "babel-plugin-emotion", | ||
"type": "patch", | ||
"dependencies": ["@emotion/serialize"] | ||
}, | ||
{ | ||
"name": "@emotion/core", | ||
"type": "patch", | ||
"dependencies": [ | ||
"@emotion/css", | ||
"emotion-theming", | ||
"@emotion/serialize", | ||
"@emotion/styled" | ||
] | ||
}, | ||
{ | ||
"name": "create-emotion", | ||
"type": "patch", | ||
"dependencies": ["@emotion/serialize"] | ||
} | ||
] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
TypeScript types have been restructured. These changes: | ||
|
||
- Reduce build times when using emotion | ||
- In many cases remove the need for manually specifying generic parameters for your emotion components. | ||
|
||
If you encounter build issues after upgrade, try removing any manually specified generic types and let them be inferred. Otherwise refer to the breaking changes list below. | ||
|
||
## Improvements | ||
|
||
- useTheme added to EmotionTheming interface and can now create your own closed variation of withTheme. More information in the docs under the theming section. | ||
- Union types as props are better supported and should be inferred properly | ||
- Build times should be reduced significantly in larger projects. | ||
|
||
## Breaking changes | ||
|
||
- withTheme can now have the Theme type specified when calling it. For example `withTheme<MyTheme>(MyComponent)` | ||
|
||
**Breaking change:** Generic argument changed, if you were specifying the ComponentType you will need to remove the generic parameter. Recommend following example setup in the TypeScript docs under theming section | ||
|
||
- `css` function has been restricted to prevent passing of invalid types | ||
- `CreateStyled` functions no longer take a second `ExtraProps` argument. Instead move it to after the create styled call. For example | ||
|
||
`styled<typeof MyComponent, ExtraProps>(MyComponent)({})` | ||
to | ||
`styled(MyComponent)<ExtraProps>({})` | ||
|
||
- `StyledComponent` type no longer supports the third generic `Theme` parameter. Instead add the `theme` prop to the first `Props` argument. For example: | ||
|
||
`StyledComponent<Props, {}, MyTheme>` | ||
to | ||
`StyledComponent<Props & { theme?: MyTheme }>` |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import { | |
ComponentClass, | ||
Context, | ||
Provider, | ||
SFC, | ||
FC, | ||
ReactElement, | ||
ReactNode, | ||
Ref, | ||
|
@@ -30,7 +30,7 @@ export const ThemeContext: Context<object> | |
export const CacheProvider: Provider<EmotionCache> | ||
export function withEmotionCache<Props, RefType = any>( | ||
func: (props: Props, context: EmotionCache, ref: Ref<RefType>) => ReactNode | ||
): SFC<Props & ClassAttributes<RefType>> | ||
): FC<Props & ClassAttributes<RefType>> | ||
|
||
export const jsx: typeof createElement | ||
|
||
|
@@ -45,7 +45,9 @@ export interface GlobalProps<Theme> { | |
* @desc | ||
* JSX generic are supported only after [email protected] | ||
*/ | ||
export function Global<Theme = any>(props: GlobalProps<Theme>): ReactElement | ||
export function Global<Theme extends {} = any>( | ||
props: GlobalProps<Theme> | ||
): ReactElement | ||
|
||
export function keyframes( | ||
template: TemplateStringsArray, | ||
|
@@ -75,7 +77,7 @@ export interface ClassNamesProps<Theme> { | |
* @desc | ||
* JSX generic are supported only after [email protected] | ||
*/ | ||
export function ClassNames<Theme = any>( | ||
export function ClassNames<Theme extends {} = any>( | ||
props: ClassNamesProps<Theme> | ||
): ReactElement | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ import { | |
ClassNames, | ||
ClassNamesContent, | ||
Global, | ||
Interpolation, | ||
CacheProvider, | ||
css, | ||
jsx, | ||
keyframes, | ||
|
Oops, something went wrong.