The Laws of Sparse Typescript
The Primary Laws
- All Sparse Typescript Laws must adhere to the Laws defined in
Sparse.md.No Exceptions. - All Typescript specific Sparse Laws must be specified within this file.
No Exceptions.
Typescript Specific Laws
- Use
strictmode intsconfig.json.No Exceptions. - Use
unknowninstead ofanyfor variables with uncertain types.No Exceptions. - All function inputs must be
readonly.No Exceptions. - All functions must have explicit return types.
No Exceptions. - All exported classes, functions, and interfaces must use explicit types for parameters and return values.
No Exceptions. - All functions must use arrow function syntax, not function declarations.
No Exceptions. - Only use implicit types for local variables.
No Exceptions. - All object shapes must be defined using interfaces.
No Exceptions. - All primitives, unions, and mapped/conditional types must be defined using type aliases.
No Exceptions. - All variant objects must use discriminated unions, not class hierarchies.
No Exceptions. - Use unions of literal types instead of enums.
No Exceptions. - Use Promises for your own async control flow: only use callbacks for framework-mandated signatures.
No Exceptions. - All export statements must be at the bottom of the file.
No Exceptions. - All exports must use named exports, no default exports.
No Exceptions.
No Exceptions.