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

v11: fix for typescript definitions when using isolated modules #1627

Merged
merged 4 commits into from
Nov 13, 2019

Conversation

frankwallis
Copy link
Contributor

@frankwallis frankwallis commented Nov 12, 2019

Renaming:
styled/types/base.ts to styled/types/base.d.ts
styled/types/helper.ts to styled/types/helper.d.ts

Because when importing @emotion/styled/base with isolatedModules turned on, TypeScript was giving a compiler error:

ERROR: 21:3   expect  TypeScript@next compile error: 
Cannot re-export a type when the '--isolatedModules' flag is provided.

This happens because when transpiling a re-export with isolatedModules turned on TypeScript does not know if the exported item is a type or a runtime object and so cannot elide re-exported types.

By renaming the files to be definition files, this restriction no longer applies.

Checklist:

  • Documentation - N/A
  • Tests
  • Code complete
  • Changeset - N/A

I have not created a changeset as this PR is against next and will go out with the next prerelease.
Thanks for all your hard work, really looking forward to the improvements in v11.
Let me know if you need me to make any more changes or create a changeset.

@changeset-bot
Copy link

changeset-bot bot commented Nov 12, 2019

🦋 Changeset is good to go

Latest commit: 79012d8

We got this.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 12, 2019

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 79012d8:

Sandbox Source
Emotion Configuration

@frankwallis frankwallis changed the title fix for typescript definitions when using isolated modules v11: fix for typescript definitions when using isolated modules Nov 12, 2019
@Andarist
Copy link
Member

Hm, I would say this deserves a changeset as well - we are releasing prereleases often and seeing this in a changelog might help somebody. We will probably have to clean up the generated changelog before releasing final v11 anyway (to keep there only things that actually were done and to avoid noisy stuff).

Thanks for the PR! I wouldn't know that this has such effect without investigating this for quite a bit of time probably, so this is a great time-saver ❤️

@@ -2,6 +2,7 @@
"compilerOptions": {
"baseUrl": "../",
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you see any downsides of using this in here? I can't think of any, cc @JakeGinnivan

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isolatedModules will cause the compilation to emit errors if the code is not able to be transpiled in single-file mode (ie. babel or ts.transpile). So it will raise errors for doing type re-exports or using const enums. AFAIK all other errors will also be emitted so I think it is safe to keep it turned on and it may even be worth adding it to the other configuration files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some info about the impact here: microsoft/TypeScript#16351

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may even be worth adding it to the other configuration files.

Yeah, I was thinking about this as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add that to the PR if you want when I get home this evening.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged this one in as we can add this flag in other configs in separate PR. Thanks for the fix!

frankwallis and others added 2 commits November 13, 2019 08:23
Co-Authored-By: Mateusz Burzyński <mateuszburzynski@gmail.com>
Co-Authored-By: Mateusz Burzyński <mateuszburzynski@gmail.com>
@Andarist Andarist merged commit e6e079c into emotion-js:next Nov 13, 2019
@Andarist Andarist mentioned this pull request Nov 13, 2019
louisgv pushed a commit to louisgv/emotion that referenced this pull request Sep 6, 2020
…bination with `isolatedModules` option (emotion-js#1627)

* fix for typescript definitions when using isolated modules

* add changeset

* Update .changeset/odd-insects-cough.md

Co-Authored-By: Mateusz Burzyński <mateuszburzynski@gmail.com>

* Update .changeset/odd-insects-cough.md

Co-Authored-By: Mateusz Burzyński <mateuszburzynski@gmail.com>
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

Successfully merging this pull request may close these issues.

3 participants