Show Menu

jian's typescript best practices Cheat Sheet by

Best practices for typescripts
typescript

General Types

✘ use String
✘ use Number
✘ use Object
✘ use Bool­ean

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 config­uration

"­for­ceC­ons­ist­ent­Cas­ing­InF­ile­Nam­es": true
"­str­ict­": true
"­no-­nul­l-k­eyw­ord­": true
"­noI­mpl­ici­tRe­tur­ns": true
"­noU­nus­edL­oca­ls": true

Managing non existing values

{ "­no-­nul­l-k­eyw­ord­": true }
type Option­al<­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-op­tional
✔︎ write callback parameters as non-op­tional

Overloads and Callbacks

✘ write separate overloads that differ only on callback arity
✔︎ write a single overload using the maximum arity

Download the jian's typescript best practices Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/mynameisjian_jian-s-typescript-best-practices.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Notizen zu Typescript Cheat Sheet
          Mit Javascript unter Node.js entwickeln Cheat Sheet