Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
A Non-Zero Number of TypeScript Tips
Search
Toby Ho
August 20, 2018
Programming
0
680
A Non-Zero Number of TypeScript Tips
An introduction to TypeScript.
Toby Ho
August 20, 2018
Tweet
Share
More Decks by Toby Ho
See All by Toby Ho
Debugging Ajax Calls
airportyh
0
93
How to Learn 3
airportyh
2
75
How to Learn 2
airportyh
0
74
How To Learn
airportyh
7
1.3k
Test-Driven Development that Feels Great
airportyh
0
8.8k
Other Decks in Programming
See All in Programming
Amazon Qを使ってIaCを触ろう!
maruto
0
380
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
540
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
250
ヤプリ新卒SREの オンボーディング
masaki12
0
110
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
240
Importmapを使ったJavaScriptの 読み込みとブラウザアドオンの影響
swamp09
4
1.3k
CSC509 Lecture 09
javiergs
PRO
0
140
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
140
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.3k
僕がつくった48個のWebサービス達
yusukebe
20
17k
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
300
役立つログに取り組もう
irof
28
9.4k
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
136
6.6k
Typedesign – Prime Four
hannesfritz
40
2.4k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Gamification - CAS2011
davidbonilla
80
5k
Unsuck your backbone
ammeep
668
57k
Optimizing for Happiness
mojombo
376
69k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
92
16k
Happy Clients
brianwarren
97
6.7k
Docker and Python
trallard
40
3.1k
Music & Morning Musume
bryan
46
6.2k
Automating Front-end Workflow
addyosmani
1366
200k
The Pragmatic Product Professional
lauravandoore
31
6.3k
Transcript
A non-zero number of TypeScript Tips
Agenda • What and why • Interfaces • Optional Properties
• Class • Generic functions / methods • Strict Null Checks • VS Code Shortcuts
What is TypeScript?
What is TypeScript • Super set of JavaScript / EcmaScript
• EcmaScript Future Proof
Why TypeScript?
Type Definitions
Interfaces the shape of an object
Interface
Interface
Interface
Interface
Implementing an Interface with a Class
Class Constructor Shorthand Equivalent shorthand to previous slide
Interface Extension
Optional Properties
None
None
Optional Properties This property is optional
Type assertion (or casting)
Type assertion (or casting) Don’t do this!!!
TypeScript Static type checking with loopholes.
Interface with Methods
Implementing an Interface with Methods
Generic Functions
Put a number in a list
Put a string in a list
Generic a thing in a list
Generic Function/Methods
Generic Function/Methods TypeScript knows!!!
Generic Types
Parameterized Types (generics) T is a type parameter
Parameterized Types
Parameterized Type: Promises
Promises Uses the fetch API
Promises
Promises Uses the fetch API
Generic Function with Generic Type!!!
Generic getItems
Generic getItems But what is articles? What is T?
Generic getItems
Generic getItems Define T explicitly
Generic getItems Or define related type and let TS infer
what T is
Generic getItems T is inferred to be IArticle based on
this related type declaration
Generic getItems
Strict Null Checks
Strict Null Checks This property is optional
Strict Null Checks tsconfig.json
Strict Null Checks
Strict Null Checks
Strict Null Checks
VS Code Help
VSCode Auto Import Helper
VSCode Auto Import Helper Click that!!!
VSCode Auto Import Helper
VSCode: Looking up type definitions Mac: Command+click Windows: Control+click Mac:
Command+hover Windows: Control+hover Popup: Drilldown:
Popup
Drilldown
Summary • What and why • Interfaces • Optional Properties
• Class • Generic functions / methods • Strict Null Checks • VS Code Shortcuts