Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

jian's typescript best practices Cheat Sheet

by mynameisjian via cheatography.com/71836/cs/18213/

General Types Managing non existing values

✘ use String ✘ use Number { "​no-​nul​l-k​eyw​ord​": true }

✘ use Object ✘ use Bool​ean type Option​al<​T> = T | undefined

Function Overloads Callback Types

✘ put more general overloads before more specific ones ✘ use the return type any

✔ sort overloads more general signatures after more specific signatures ✔ use the return type void

✘ write several overloads that differ only in trailing parameters ✘ use optional parameters in callbacks unless you really mean it

✔ use optional parameters whenever possible ✔ write callback parameters as non-op​tional

✘ write overloads that differ by type in only one argument position ✔ write callback parameters as non-op​tional

✔ use union types whenever possible


Overloads and Callbacks

Strict config​uration ✘ write separate overloads that differ only on callback arity

"​for​ceC​ons​ist​ent​Cas​ing​InF​ile​Nam​es": true ✔ write a single overload using the maximum arity

"​str​ict​": true

"​no-​nul​l-k​eyw​ord​": true

"​noI​mpl​ici​tRe​tur​ns": true

"​noU​nus​edL​oca​ls": true

By mynameisjian Published 11th December, 2018. Sponsored by Readability-Score.com


Last updated 10th December, 2018. Measure your website readability!
Page 1 of 1. https://readability-score.com

cheatography.com/mynameisjian/

You might also like