Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP2universalStack: TypeScript
singletonoopapi-design
For singletons, export the instance rather than the class
Export `SomeClass.Instance` as the module default so callers don't repeat `.Instance` everywhere and cannot accidentally `new` the class.
PR: hegnar-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | export class AppConfig { static get Instance() { ... } } |
| 2 | // callers everywhere: AppConfig.Instance.flytoget |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | class AppConfig { static get Instance() { ... } } |
| 2 | export default AppConfig.Instance; |
| 3 | // caller: import config from './AppConfig'; config.flytoget |
Explanation (EN)
Objašnjenje (HR)