ChainSafe / ChainSafe/lodestar

Export and import types

Open
#7,159 2 comments 0 reactions 1 assignee Claimed by @nazarhussain View on GitHub
meta-feature-request
Dominant language
TypeScript
Stars
1.4k
Forks
483
Avg merge
1d 16h
Merged PRs (30d)
150

Description

### 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.

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

export { MyType };
```

and for import

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

### Solution description

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

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

export { type MyType };
```

and for import

```ts
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.