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

docs: add onlyRemoveTypeImports to (preset|plugin-transform)typescript #2185

Merged
merged 6 commits into from Mar 17, 2020

Conversation

kaicataldo
Copy link
Member

Refs babel/babel#11173 (comment)

This PR adds documentation for the new onlyRemoveTypeImports configuration option in the upcoming 7.9.0 release.

Questions:

  1. This is my first time working in this repo. Did I miss anything?
  2. I fixed up the docs so that they matched and did a little editing. Is it okay that I didn't backport these changes to the older versions of the docs?

@netlify
Copy link

netlify bot commented Feb 28, 2020

Deploy preview for babel ready!

Built with commit 183d619

https://deploy-preview-2185--babel.netlify.com

@existentialism
Copy link
Member

I fixed up the docs so that they matched and did a little editing. Is it okay that I didn't backport these changes to the older versions of the docs?

It's not critical, but I personally think we should backport :)

@kaicataldo
Copy link
Member Author

@existentialism Which parts do you think we should backport? Everything but the new option?

@nicolo-ribaudo
Copy link
Member

We should also add the equivalent tsc option to the "TypeScript Compiler Options" section.

@@ -198,6 +206,8 @@ equivalents in Babel can be enabled by some configuration options or plugins.
```
- `--importHelpers`
This is the equivalent of the `@babel/plugin-transform-runtime` package.
- `---importsNotUsedAsValues`
You can the `onlyRemoveTypeImports` option to replicate this behavior. `onlyRemoveTypeImports: true` is equivalent to `importsNotUsedAsValues: preserve`, while `onlyRemoveTypeImports: false` is equivalent to `importsNotUsedAsValues: remove`. There is no equivalent for `importsNotUsedAsValues: error`.
Copy link
Member Author

Choose a reason for hiding this comment

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

Does this seem correct/clear?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can't mention that onlyRemoveTypeImports: false isn't 100% accurate because we don't do any type analysis, and link to babel/babel#8361 as an example? Also, it's the reason why we don't support importsNotUsedAsValues: error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mind clarifying what you mean?

Copy link
Member

Choose a reason for hiding this comment

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

Sure!

Consider this example:

// dep.ts

export type T = string;
// main.ts

import { T } from "./dep";
export { T };

onlyRemoveTypeImports: false leave main.ts as-is, because we don't have the type information necessary to understand that T is a type.
However, TypeScript's importsNotUsedAsValues: remove transforms it to an empty file because it knows that T is a type.

@kaicataldo
Copy link
Member Author

Thanks for the comments! Ready for re-review :)

@JLHwung JLHwung added this to the v7.9.0 milestone Mar 6, 2020
@nicolo-ribaudo nicolo-ribaudo merged commit 65d2255 into master Mar 17, 2020
@nicolo-ribaudo nicolo-ribaudo deleted the add-only-remove-type-imports-docs branch March 17, 2020 01:05
@kaicataldo
Copy link
Member Author

Thanks for updating this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants