Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Don't add runtime type guards for values already guaranteed by the type system
If a parameter is already typed as a string, a typeof string check is dead defensive code; remove it unless the value genuinely crosses an untyped boundary.
Bad example
| 1 | function format(position: string) { |
| 2 | if (typeof position === 'string') return position.replace('-', ''); |
| 3 | } |
Explanation (EN)
A repeated guard adds a misleading missing return path when every legitimate internal caller already supplies a string.
Objašnjenje (HR)
Good example
| 1 | function format(position: string) { |
| 2 | return position.replace('-', ''); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Remove a runtime type guard only on a trusted internal path where validated producers and the declared type already guarantee it.
Exceptions / Tradeoffs (EN)
Types are erased. Keep guards for JSON, raw database rows, JavaScript callers, any, assertions and versioned external data unless validation already occurred.