Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Props don't work anymore with TypeScript 3.4.1 #1298

Closed
screendriver opened this issue Mar 30, 2019 · 9 comments
Closed

Props don't work anymore with TypeScript 3.4.1 #1298

screendriver opened this issue Mar 30, 2019 · 9 comments

Comments

@screendriver
Copy link

  • emotion version: 10.0.10
  • react version: 16.8.6

Relevant code:

const Container = styled.div((props: { test: number }) => ({
  width: props.test,
}));

What you did:

Updated TypeScript to the latest version 3.4.1

What happened:

error TS2345: Argument of type '(props: { test: number; }) => { width: number; }' is not assignable to parameter of type 'TemplateStringsArray'.
  Type '(props: { test: number; }) => { width: number; }' is missing the following properties from type 'TemplateStringsArray': raw, concat, join, slice, and 16 more.

Reproduction:

Just create a fresh empty project with TypeScript and emotion and paste my code above into it. I can do that for you if you want, but it's so simple to reproduce that I thought it is not necessary.

Problem description:

Does not compile anymore. With the TypeScript version before (3.3.4000) it worked.

Suggested solution:

Fix TypeScript definition.

@Dudeonyx
Copy link

Dudeonyx commented Apr 5, 2019

Solution:

const Container = styled.div<{ test: number }>((props) => ({
  width: props.test,
}));

✌️

@skovhus
Copy link

skovhus commented Apr 11, 2019

And with the other syntax styled('div'), you can do:

styled('div')<{ test: number }>`...`

@ndelangen
Copy link
Contributor

ndelangen commented Jul 5, 2019

I'm finding I have to add <{}> is lots of places in order to make typescript happy again after upgrading.

const Container = styled.div<{}>(({ theme }) => ({
  width: theme.width,
}));

@Andarist
Copy link
Member

Andarist commented Jul 5, 2019

@ndelangen could you check which version exactly has started to "fail" for you? I could try to locate the commit which has introduced the change then and try to assess if something is wrong or is it expected.

@ndelangen
Copy link
Contributor

ndelangen commented Jul 5, 2019

@Andarist, thanks for helping. Super appreciated!

I was in a terrible situation with yarn.lock being semi-corrupt.

I ended up having to remove it and re-generate it.

I went from version "10.0.10" to version "10.0.14", whilst my dependency in package.json being: "@emotion/core@^10.0.9"

In case it helps: (fair warning it's a HUGE PR, with loads of changes)
storybookjs/storybook#7329

typescript version "3.5.2"

@EddyVinck
Copy link

I was getting this error:
Property 'theme' is missing in type '{ children: (string | Element)[]; color: string; }' but required in type '{ theme: Theme; }'. on an Emotion styled('h1').
Updating my Emotion dependencies fixed the issue:

// package.json
{
  "dependencies": {
    "@emotion/core": "^10.0.16",
    "@emotion/styled": "^10.0.15",
    "emotion-theming": "^10.0.14"
  },
  "devDependencies": {
    "babel-plugin-emotion": "^10.0.16",
    "typescript": "^3.5.3"
  }
}

@Andarist
Copy link
Member

@JakeGinnivan could you check how your PR affects this issue?

JakeGinnivan pushed a commit to JakeGinnivan/emotion that referenced this issue Oct 29, 2019
@JakeGinnivan
Copy link
Contributor

Just added the above as a test, works fine in #1501

The workaround solution also still works. Pushed the additional tests too

@Andarist
Copy link
Member

Thanks for checking! Closing this issue because #1501 is intended to fix it.

Andarist pushed a commit that referenced this issue Nov 4, 2019
…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
louisgv pushed a commit to louisgv/emotion that referenced this issue Sep 6, 2020
…ompilation (emotion-js#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 emotion-js#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 emotion-js#1298

* Fix typo

* Add test which verifies emotion-js#1226 is fixed by type changes
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

No branches or pull requests

7 participants