Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Use import type for type-only imports
Use import type when the symbol is only used as a type to support isolated transpilation.
Bad example
| 1 | import {User} from './types'; |
| 2 |
|
| 3 | export function formatUser(u: User) { |
| 4 | return u.name; |
| 5 | } |
Explanation (EN)
In some build modes (isolated transpilation), type-only imports can require explicit annotation to avoid runtime import expectations.
Objašnjenje (HR)
U nekim build modovima (isolated transpilation) type-only importi trebaju eksplicitnu oznaku da se izbjegnu runtime očekivanja importa.
Good example
| 1 | import type {User} from './types'; |
| 2 |
|
| 3 | export function formatUser(u: User) { |
| 4 | return u.name; |
| 5 | } |
Explanation (EN)
import type documents intent and keeps type-only dependencies clean for file-by-file builds.
Objašnjenje (HR)
import type jasno pokazuje namjeru i drži type-only dependencyje čistima za file-by-file build.
Notes (EN)
You can also use: import {type User, valueThing} from './mod';
Bilješke (HR)
Možeš i: import {type User, valueThing} from './mod';
Exceptions / Tradeoffs (EN)
Use regular imports when you need the value at runtime or for side effects.
Iznimke / Tradeoffi (HR)
Koristi običan import kada trebaš vrijednost na runtimeu ili side effect.