Rules Hub

Coding Rules Library

← Back to all rules
frontend ruleStack: typescript
typescriptclean-codeglobalarchitecturemaintenance

Consolidate global type augmentations

Centralize global type declarations in a single file and only define properties that are strictly consumed.

PR: Feat/FCK-1623 - Adding eAvis widget to the sidebar #3643Created: Dec 8, 2025

Bad example

Old codets
1// src/@types/window.d.ts
2// ❌ Creating a separate file for a single global augmentation
3// ❌ Typing unused properties creates unnecessary noise
4export {};
5
6declare global {
7 interface Window {
8 Header: {
9 user: {
10 id: number;
11 name: string;
12 email: string;
13 accessLevel: 'anonymous' | 'registered' | 'paper';
14 preferences: Record<string, any>;
15 };
16 settings: any;
17 };
18 }
19}

Explanation (EN)

Creating a separate file for a minor augmentation clutters the project structure. Defining the entire shape of the external object (including unused fields like 'email' or 'preferences') increases maintenance burden without adding value.

Objašnjenje (HR)

Kreiranje zasebne datoteke za malo proširenje stvara nered u strukturi projekta. Definiranje cijelog oblika vanjskog objekta (uključujući nekorištena polja poput 'email' ili 'preferences') povećava teret održavanja bez dodane vrijednosti.

Good example

New codets
1// src/typings.d.ts
2// ✅ Consolidate into the existing central declaration file
3// ✅ Only type the specific properties actively used in the app
4interface Window {
5 Header: {
6 user: {
7 accessLevel: 'anonymous' | 'registered' | 'paper' | 'b2b' | 'digital';
8 };
9 };
10}

Explanation (EN)

The augmentation is placed in the existing `typings.d.ts`, keeping global definitions centralized. Only the strictly used property (`accessLevel`) is typed, adhering to interface segregation principles and keeping the type definition clean.

Objašnjenje (HR)

Proširenje je postavljeno u postojeći `typings.d.ts`, držeći globalne definicije centraliziranima. Tipizirano je samo strogo korišteno svojstvo (`accessLevel`), poštujući princip segregacije sučelja i održavajući definiciju čistom.