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).
Import ambient global types explicitly
Add an explicit import for a type even when it already resolves through a `declare global {}` ambient block. Relying on ambient resolution hides the dependency, so refactoring the global block to a named export breaks consumers with no missing-import to point at.
Bad example
| 1 | // no import; resolves only via declare global { interface ICategoryLabel } |
| 2 | interface Args { |
| 3 | categoryUrlNames: ICategoryLabel[]; |
| 4 | } |
Explanation (EN)
The dependency on ICategoryLabel is invisible at the file level, so a future refactor of the ambient block silently removes the type with no obvious fix.
Objašnjenje (HR)
Ovisnost o ICategoryLabel nije vidljiva na razini datoteke, pa buduce preuredjenje ambijentalnog bloka tiho uklanja tip bez ocitog popravka.
Good example
| 1 | import { ICategoryLabel } from '../interfaces/config'; |
| 2 |
|
| 3 | interface Args { |
| 4 | categoryUrlNames: ICategoryLabel[]; |
| 5 | } |
Explanation (EN)
An explicit import makes the dependency real, so a rename or move surfaces as a normal import error.
Objašnjenje (HR)
Eksplicitan import cini ovisnost stvarnom, pa se preimenovanje ili premjestanje pojavi kao uobicajena greska importa.