SlideShare a Scribd company logo
1 of 21
Download to read offline
TypeScript導入のススメ

話す内容

1. TypeScript is 何

2. どうやって導入しよう

- 2-1 既存

- 2-2 新規

3. まとめ

 注 )TSの書き方や詳しい型のお話はしません。

    こういう感じに使ってみませんか。というご提案です🙋

1. TypeScript is 何  (超ざっくり)



- 型のあるJavascript

- コンパイルするとJSになる

- JSでできることはTSでできる



何が違うの? →
エラーに気づけるタイミングが違う 



→「プログラムを実行」した時



→「テキストエディターで入力」した時

使ってみて

- 実行前にエラーに気づける喜び

- 喜び > 勉強コスト



*anyを許容すればそんなに勉強いらない(そ
の分メリットは大きく下がるけど) 

2. どうやって導入する?どうやって使う?





JSプロジェクトがTSに比べ多い理由

多分大きく2点導入に至らない理由がある?

- 始めるのに手間がかかる

- JSのプロジェクトを置き換えるコストが高い

2-1 始めるのに時間かかる

TSのコンパイル設定面倒。時間ない

ちょっとしたLPにTSいらないかも

↓

完全同意

環境作りました

LPテンプレでTS使えるようにしました!

Reactもコンパイルできるようにしておきました。

SPAも作ってます!

↓

後でGithubリポジトリ共有します。





2-2 JSのプロジェクトを置き換えるコスト



1. TSCを追加する

2. 各ファイルの拡張子を変更する

3. 必要な部分に型をつけていく (←地獄)

4. ライブラリを使用している場合、ライブラリの型ファイルをインストールする

ts-migrate is 何

Airbnbの開発チームが出したJS→TS移行ツール

大きいプロジェクトでは時間かかるが、それでも多分1週間くらいで移行できる。

https://github.com/airbnb/ts-migrate



使い方まとめてみました

https://qiita.com/Sotq_17/items/56403d3b8137affc1d10

*今度ハンズオンで移行の仕方の勉強会(?)したいなと思います



ts-migrateを使った場合



1. TSCを追加する  *一部調整必要

2. 各ファイルの拡張子を変更する

3. 必要な部分に型をつけていく (←地獄)  *一部調整必要

4. ライブラリを使用している場合、ライブラリの型ファイルをインストールする

各ファイルの調整

型の追加が必要な部分は、ライブラリ側が自動でany型を追加

補完できない箇所は@ts-expect-errorで表示される

2-3 どういう風に使う?

JavaScriptに型を書いていくだけ(極論)



諸刃の剣 ANY型

何にでもなる型

使ったらJavascriptと同じ挙動になる

ANYに対する意見


公式は?

>After all, remember that all the convenience of any comes at the cost of losing type safety. Type
safety is one of the main motivations for using TypeScript and you should try to avoid using any when
not necessary. # 公式

超意訳 ) any使ったら便利やけど型安全性なくなるよ。できればやめて。





個人的な意見

Wizはとりあえずany許容で良いのでは(明示的にする)

anyでTS書く >>>> anyは意味ないからJSで書く



最低限のTSルール

できるだけ型書きましょう。でも急いでたら書かなくてもOK。

その場合はAny型じゃなくて、独自の型を作りましょう(ex.FixMe)

みんな時間ある時にFixMe消していきましょう!

まとめ

- JSのプロジェクトを置き換えるコストが高い

→Ts-migrateで置き換えよう!

- 始めるのに手間がかかる

→Tsテンプレ使おう!

- どうやって使うの?

→anyを独自型にして、まずは使おう!

ご静聴ありがとうございました

&

ご質問あれば!


More Related Content

Similar to Type scriptどう使う?

An Introduction to TypeScript: Definition, History, and Key Features
An Introduction to TypeScript: Definition, History, and Key FeaturesAn Introduction to TypeScript: Definition, History, and Key Features
An Introduction to TypeScript: Definition, History, and Key FeaturesMichael Coplin
 
What is TypeScript? It's Definition, History And Features
What is TypeScript? It's Definition, History And FeaturesWhat is TypeScript? It's Definition, History And Features
What is TypeScript? It's Definition, History And FeaturesHarryParker32
 
Nodejs & Typescript
Nodejs & TypescriptNodejs & Typescript
Nodejs & TypescriptKnoldus Inc.
 
Scenic City Summit 2018 - TypeScript 101
Scenic City Summit 2018 - TypeScript 101Scenic City Summit 2018 - TypeScript 101
Scenic City Summit 2018 - TypeScript 101Frances Coronel
 
근육 기억으로 주도하는 테스트 주도 개발 입문하기
근육 기억으로 주도하는 테스트 주도 개발 입문하기근육 기억으로 주도하는 테스트 주도 개발 입문하기
근육 기억으로 주도하는 테스트 주도 개발 입문하기Jeong-gyu Kim
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Gianluca Padovani
 
Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is ImportaintSana Nasar
 

Similar to Type scriptどう使う? (9)

An Introduction to TypeScript: Definition, History, and Key Features
An Introduction to TypeScript: Definition, History, and Key FeaturesAn Introduction to TypeScript: Definition, History, and Key Features
An Introduction to TypeScript: Definition, History, and Key Features
 
What is TypeScript? It's Definition, History And Features
What is TypeScript? It's Definition, History And FeaturesWhat is TypeScript? It's Definition, History And Features
What is TypeScript? It's Definition, History And Features
 
Nodejs & Typescript
Nodejs & TypescriptNodejs & Typescript
Nodejs & Typescript
 
The Heart Of Agile
The Heart Of AgileThe Heart Of Agile
The Heart Of Agile
 
Scenic City Summit 2018 - TypeScript 101
Scenic City Summit 2018 - TypeScript 101Scenic City Summit 2018 - TypeScript 101
Scenic City Summit 2018 - TypeScript 101
 
근육 기억으로 주도하는 테스트 주도 개발 입문하기
근육 기억으로 주도하는 테스트 주도 개발 입문하기근육 기억으로 주도하는 테스트 주도 개발 입문하기
근육 기억으로 주도하는 테스트 주도 개발 입문하기
 
210428kopo
210428kopo210428kopo
210428kopo
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
 
Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is Importaint
 

Recently uploaded

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Recently uploaded (20)

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

Type scriptどう使う?