Rules Hub

Coding Rules Library

← Back to all rules
fullstack ruleStack: general
clean-codemodern-jsweb-apisreadabilityfeature-detection

Assume standard global objects exist

Do not use typeof checks for standard global objects like AbortSignal or URL; only feature-detect new methods on them if needed.

PR: Feat/FCK-2245 - Cache Bellsheep and profile loaders with TanStack Query #343Created: Dec 10, 2025

Bad example

Old codets
1function mergeSignals(signals: AbortSignal[]) {
2 // Bad: Redundant check for the AbortSignal class itself
3 if (typeof AbortSignal !== 'undefined' && 'any' in AbortSignal) {
4 return AbortSignal.any(signals);
5 }
6 // ...fallback logic
7}

Explanation (EN)

Checking `typeof AbortSignal !== 'undefined'` is defensive noise. Modern environments (browsers/Node.js) guarantee the existence of standard classes like `AbortSignal`, `URL`, or `Promise`.

Objašnjenje (HR)

Provjera `typeof AbortSignal !== 'undefined'` je suvišna. Moderna okruženja (preglednici/Node.js) garantiraju postojanje standardnih klasa kao što su `AbortSignal`, `URL` ili `Promise`.

Good example

New codets
1function mergeSignals(signals: AbortSignal[]) {
2 // Good: Only check for the specific new method you need
3 if ('any' in AbortSignal) {
4 return AbortSignal.any(signals);
5 }
6 // ...fallback logic
7}

Explanation (EN)

We assume the base `AbortSignal` class exists and only feature-detect the specific static method (`any`) which might be missing in older versions.

Objašnjenje (HR)

Pretpostavljamo da osnovna klasa `AbortSignal` postoji i provjeravamo samo specifičnu statičku metodu (`any`) koja može nedostajati u starijim verzijama.