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
5分でTypeScript入門!〜既存JS環境に引導を渡そう〜
Search
nsym-m
April 23, 2021
Programming
39
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
5分でTypeScript入門!〜既存JS環境に引導を渡そう〜
TypeScriptあんまり触ったことないですが、TS入門のLT資料を作ってみました。
nsym-m
April 23, 2021
More Decks by nsym-m
See All by nsym-m
Flutter入門してみた
nsym
0
120
O’ReillyでGo言語入門
nsym
0
130
Other Decks in Programming
See All in Programming
Foundation Models frameworkで画像分析
ryodeveloper
1
610
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
1.6k
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
180
Jindong: Introducing Declarative Haptics in Compose Multiplatform
l2hyunwoo
0
110
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.6k
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
110
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
150
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
270
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
490
FDEが実現するAI駆動経営の現在地
gonta
2
280
Building a Meta Ray-Ban display app
akkeylab
0
140
Featured
See All Featured
Evolving SEO for Evolving Search Engines
ryanjones
0
250
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
700
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
It's Worth the Effort
3n
188
29k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
960
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.2k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
260
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Transcript
5分でTypeScript入門! 〜既存JS環境に引導を渡そう〜
TypeScriptとは? • JavaScriptの静的型付け版の言語 • Microsoftがオープンソースで開発している • Googleでも社内標準言語として利用されている • TypeScriptをJavaScriptにコンパイルして実行する
なぜTypeScript? • 型が保証されている(型推論も使える) • 型があることで改修時のバグ発生率が下がり保守性の向上 • 型を書けるので気持ちがいい(Developer eXperience) • エディタの入力補完を受けられることで開発効率の向上
• 型チェックの厳しさをプロジェクトごと決められる ◦ → 導入障壁が低い!!!
TypeScriptを導入してみよう 弊社のお掃除ロボットるんばちゃんの状況をリアルタイムで知らせる「る んばちゃんbot」のチャットを投稿しているJavaScriptのプログラムに TypeScriptを導入してみようと思います。
ざっくり手順 1. typescriptのinstallとtsconfig.jsonの作成 2. tsconfig.jsonの設定を緩めに指定 3. ファイルの拡張子を .js → .ts
に変更する 4. コンパイルエラーを修正する とっても簡単!!!!(?)
typescriptのinstallと tsconfig.jsonの作成 • typescriptはTypeScriptのコンパイラのモジュール • tsconfig.jsonはTypeScriptコンパイルの設定ファイル
tsconfig.jsonの設定を緩めに指定① • 最初は型チェックに関する設定を緩めにする
tsconfig.jsonの設定を緩めに指定② ☆ポイント • 優先すべきは「TypeScript」導入を完了させること ◦ 「厳密な型を使う」のはあとからでも追加できる • any型を許容する(大事) • 型を緩くしていてもJavaScriptよりも堅い型チェックやエディタによる
補完などのサポートを受けられる
ファイル拡張子を.js → .tsに変更 • `rename`コマンドは追加する必要あり(Mac) • Linuxの`rename`コマンドとは若干違うらしい(未検証) • Windowsの場合は`ren`コマンドが使えそう?(未検証)
コンパイルエラーを修正①
コンパイルエラーを修正② • プロパティを定義していない状態でオブジェクトを作成していたの で、オブジェクト定義の時にプロパティも同時に定義する • ついでに「type」でオブジェクトの型も定義する(必須ではない)
コンパイルエラーを修正③
エラーが出なければOK!! これであなたもTypeScripterの仲間入り!! いざ、ビルド!
ご清聴ありがとうございました。 良いTypeScriptライフを!!!! 参考記事: https://eh-career.com/engineerhub/entry/2019/04/16/103000 https://tech.raksul.com/2019/07/22/introduce-typescript-to-existing-product/ https://komiyak.hatenablog.jp/entry/20170421/1492752232