Skip to content

Commit ebbf07c

Browse files
committed
update docusaurus
1 parent 1b8de77 commit ebbf07c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

website/src/pages/index.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,28 @@ const x: Array<string> = ['foo', 'bar'];
402402
const y: ReadonlyArray<string> = ['foo', 'bar'];
403403
```
404404
405+
### Type Imports and Exports
406+
407+
TypeScript allows specifying a `type` keyword on imports to indicate that the export exists only in the type system, not at runtime.
408+
409+
Type imports must always be separated <Rule href="https://typescript-eslint.io/rules/consistent-type-imports/" />:
410+
411+
- Tree Shaking and Dead Code Elimination: If you use `import` for types instead of `import type`, the bundler might include the imported module in the bundle unnecessarily, increasing the size. Separating imports ensures that only necessary runtime code is included.
412+
- Minimizing Dependencies: Some modules may contain both runtime and type definitions. Mixing type imports with runtime imports might lead to accidental inclusion of unnecessary runtime code.
413+
- Improves code clarity by making the distinction between runtime dependencies and type-only imports explicit.
414+
415+
```ts
416+
// ❌ Avoid using `import` for both runtime and type
417+
import { MyClass } from 'some-library';
418+
419+
// Even if MyClass is only a type, the entire module might be included in the bundle.
420+
421+
// ✅ Use `import type`
422+
import type { MyClass } from 'some-library';
423+
424+
// This ensures only the type is imported and no runtime code from "some-library" ends up in the bundle.
425+
```
426+
405427
### Services
406428
407429
Documentation becomes outdated the moment it's written, and worse than no documentation is wrong documentation. The same applies to types when describing the modules your app interacts with, such as APIs, messaging systems, databases etc.

0 commit comments

Comments
 (0)