Skip to content

Commit

Permalink
update docusaurus
Browse files Browse the repository at this point in the history
  • Loading branch information
mkosir committed Dec 2, 2024
1 parent 1b8de77 commit ebbf07c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions website/src/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,28 @@ const x: Array<string> = ['foo', 'bar'];
const y: ReadonlyArray<string> = ['foo', 'bar'];
```
### Type Imports and Exports
TypeScript allows specifying a `type` keyword on imports to indicate that the export exists only in the type system, not at runtime.
Type imports must always be separated <Rule href="https://typescript-eslint.io/rules/consistent-type-imports/" />:
- 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.
- 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.
- Improves code clarity by making the distinction between runtime dependencies and type-only imports explicit.
```ts
// ❌ Avoid using `import` for both runtime and type
import { MyClass } from 'some-library';

// Even if MyClass is only a type, the entire module might be included in the bundle.

// ✅ Use `import type`
import type { MyClass } from 'some-library';

// This ensures only the type is imported and no runtime code from "some-library" ends up in the bundle.
```
### Services
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.
Expand Down

0 comments on commit ebbf07c

Please sign in to comment.