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

Export and import types #7159

Open
nazarhussain opened this issue Oct 14, 2024 · 1 comment
Open

Export and import types #7159

nazarhussain opened this issue Oct 14, 2024 · 1 comment
Labels
meta-discussion Indicates a topic that requires input from various developers. meta-feature-request Issues to track feature requests.

Comments

@nazarhussain
Copy link
Contributor

Problem description

A discussion point raised during recent refactoring. Should we export/import types with the Typescript, which we currently don't.

That's our current use case.

// module.ts
type MyType = string | number;

export { MyType };

and for import

import {MyType} from "./module.js"

Solution description

TS recommends to use to type based export/import for types.

// module.ts
type MyType = string | number;

export { type MyType };

and for import

import type {MyType} from "./module.js"

This pattern have some advantages:

  1. Bundlers and compilers other than TS can easily detect and remove the types from the compiled JS
  2. Avoiding Unintentional Side Effects

This pattern have some disadvantages:

  1. Use of extra type keyword for the types at time of import.
  2. Split the exports of objects and types explicitly

Additional context

https://biomejs.dev/linter/rules/use-export-type
https://biomejs.dev/linter/rules/use-import-type

@nazarhussain nazarhussain added meta-feature-request Issues to track feature requests. meta-discussion Indicates a topic that requires input from various developers. labels Oct 14, 2024
@nflaig
Copy link
Member

nflaig commented Oct 14, 2024

import type {MyType} from "./module.js"

this makes sense if you only import types from the file / module, this will completely remove it from dist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta-discussion Indicates a topic that requires input from various developers. meta-feature-request Issues to track feature requests.
Projects
None yet
Development

No branches or pull requests

2 participants