Skip to content

Commit

Permalink
docs(useImportType): add caveat section (#2444)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos authored Apr 14, 2024
1 parent b7f69c8 commit 421e953
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/biome_js_analyze/src/lint/style/use_import_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ declare_rule! {
/// The rule ensures that all imports used only as a type use a type-only `import`.
/// It also groups inline type imports into a grouped `import type`.
///
/// ## Caveat with TypeScript experimental decorators
///
/// Some frameworks like Angular and NestJS rely on
/// [experimental TypeScript decorators](https://www.typescriptlang.org/docs/handbook/decorators.html)
/// which allow code to be generated based on type annotations.
/// This is mainly used for dependency injection.
///
/// Since Biome doesn't know how a decorator is implemented,
/// it is unable to detect that an import used as a type is also used as a value in the code generated by a decorator.
/// This leads Biome to suggest importing some imports as type, which are actually used as value at runtime.
///
/// We haven't found a way to support this pattern yet.
/// We recommend disabling this rule when using such decorators.
///
/// ## Options
///
/// This rule respects the [`jsxRuntime`](https://biomejs.dev/reference/configuration/#javascriptjsxruntime)
Expand Down
14 changes: 14 additions & 0 deletions website/src/content/docs/linter/rules/use-import-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ This also ensures that some modules are not loaded at runtime.
The rule ensures that all imports used only as a type use a type-only `import`.
It also groups inline type imports into a grouped `import type`.

## Caveat with TypeScript experimental decorators

Some frameworks like Angular and NestJS rely on
[experimental TypeScript decorators](https://www.typescriptlang.org/docs/handbook/decorators.html)
which allow code to be generated based on type annotations.
This is mainly used for dependency injection.

Since Biome doesn't know how a decorator is implemented,
it is unable to detect that an import used as a type is also used as a value in the code generated by a decorator.
This leads Biome to suggest importing some imports as type, which are actually used as value at runtime.

We haven't found a way to support this pattern yet.
We recommend disabling this rule when using such decorators.

## Options

This rule respects the [`jsxRuntime`](https://biomejs.dev/reference/configuration/#javascriptjsxruntime)
Expand Down

0 comments on commit 421e953

Please sign in to comment.