Cheatography
https://cheatography.com
Best practices for typescripts
General Types✘ use String | ✘ use Number | ✘ use Object | ✘ use Boolean |
Function Overloads✘ put more general overloads before more specific ones | ✔︎ sort overloads more general signatures after more specific signatures | ✘ write several overloads that differ only in trailing parameters | ✔︎ use optional parameters whenever possible | ✘ write overloads that differ by type in only one argument position | ✔︎ use union types whenever possible |
Strict configuration"forceConsistentCasingInFileNames": true | "strict": true | "no-null-keyword": true | "noImplicitReturns": true | "noUnusedLocals": true |
Managing non existing values{ "no-null-keyword": true } | type Optional<T> = T | undefined |
| | Callback Types✘ use the return type any | ✔︎ use the return type void | ✘ use optional parameters in callbacks unless you really mean it | ✔︎ write callback parameters as non-optional | ✔︎ write callback parameters as non-optional |
Overloads and Callbacks✘ write separate overloads that differ only on callback arity | ✔︎ write a single overload using the maximum arity |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets