TypeScript
Beyond the basics π
Overview
- What is the talk about? π€
- My origin story π¦ΈββοΈ
- What do you know now? πββοΈ
- What will you know at the end? π‘
Overview
- What is the talk about? π€
-
- Showcasing lesser known features
- Advanced TypeScript concepts
- My origin story π¦ΈββοΈ
- What do you know now? πββοΈ
- What will you know at the end? π‘
Overview
- What is the talk about? π€
- My origin story π¦ΈββοΈ
-
- Why am I giving this presentation?
- What do you know now? πββοΈ
- What will you know at the end? π‘
Overview
- What is the talk about? π€
- My origin story π¦ΈββοΈ
- What do you know now? πββοΈ
-
- Superset of JavaScript
- Static type analysis
- Extends JavaScript with new features
- What will you know at the end? π‘
Overview
- What is the talk about? π€
- My origin story π¦ΈββοΈ
- What do you know now? πββοΈ
- What will you know at the end? π‘
-
- One or two new features/tricks
- When/why to use them
- Whether you just wasted 20 minutes π
Declaration Merging
Declaration
"A statement which introduces a name into the program"
Chat GPT 2024
Instant legacy code! Just run
tsc!
Branded Types
Did we use the right security group?
No!
(And TypeScript didn't catch our mistake π’)
any, unknown and never
Foundational Concepts
- Narrow and wide types
- Type compatibility
Narrow vs. wide wypes
-
Any & Unknown
- Widest possible type
- Anything can be assigned to them
-
Never
- Narrowest possible type
- Nothing can be assigned to it
When to use "any"?
- β
Non-production code (e.g. prototype or PoC)
- β
Within a well defined boundary
- β
When type safety is difficult or impossible
- β When you don't know the type
- β As a function parameter or return
When to use "unknown"?
- β
When you don't know the type
- β
As a function parameter or return
TLDR;
Use "unknown" any time you would use "any" - unless you have a good
reason not to.
When to use "never"?
- β
Complex generics
- β
Exhaustivness checking
- β
Functions that don't return
Conclusion
- Declaration Merging
- Branded Types
- Any, Unknown and Never
Further Reading
-
Articles
-
Tools
-
Zod (runtime type checking)
-
Reveal.js (presentation framework)
π
Scan me to view slides!