Created
November 28, 2022 05:28
-
-
Save denisos/2063f3aa8ad76189b8cc2ad6c03764bc to your computer and use it in GitHub Desktop.
typescript cheatsheet hints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// typing functions | |
type FocusListener = (isFocussed: boolean) => void | |
const addListener = (onFocusChanged: FocusListener) => { | |
return true | |
} | |
// type object lietral map, can use | |
const cache: { [id: string]: string } = { | |
"1": "apples", | |
"2": "oranges" | |
}; | |
const recordCache: Record<number, string> = { | |
1: "denis", | |
2: "jane" | |
} | |
// typing try catch | |
try { | |
throw "Just a string" | |
} catch(e: any) { | |
if (e instanceof Error) { | |
return e.message; | |
} | |
// do something with an e which is not Error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment