Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Unknownのことをちゃんと知りたい_関西フロントエンド忘年会
[email protected]
×...
Search
is_ryo
December 06, 2024
Technology
51
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Unknownのことをちゃんと知りたい_関西フロントエンド忘年会
[email protected]
× KINTOテクノロジーズ
is_ryo
December 06, 2024
More Decks by is_ryo
See All by is_ryo
生成AIとエンジニアの仕事と私~実践知を添えて~
is_ryo
0
130
tRPC入門
is_ryo
1
350
TypeScriptでWebAssemblyに入門しよう
is_ryo
0
400
Honoが良さそう🔥
is_ryo
1
1.4k
LambdaのNodejsをアップデートしたら困った話
is_ryo
2
1.4k
頑張らないオレオレVuex規約を作った話
is_ryo
4
2.9k
AppSyncで始めるGraphQL
is_ryo
1
660
Other Decks in Technology
See All in Technology
ASTを使って影響範囲を特定する
nealle
0
140
Amazon S3 Tablesに全部任せてみた結果——コンパクション/スナップショット管理は本当に手放せるか
shigeruoda
1
460
SQL文一行も書けない人事がCortexもろもろを使って人事業務を楽にしてみる
ponponmikankan
1
210
Gitは怖い?共有ワークスペースから始めるSnowflakeチーム開発
coco_se
0
110
GoCon2026 - Open Source, Open World
sanposhiho
3
3.1k
Slack上でインフラをトラブルシュートする! Agentic Platform Engineeringの第一歩
teru0x1
2
400
あるけみー式LTスライド作成術
alchemy1115
1
170
Snowflakeで実現する全社横断の顧客の声(VOC)分析・活用基盤@Snowflake World Tour Tokyo 2026
yuto16
0
160
ペアプロの価値はコードを書くことだけじゃない
codmoninc
PRO
0
160
Redmine 7.0で私が開発した新機能の狙いと背景
vividtone
1
160
GuardDuty 検知対応を DevOps Agent で効率化しようとしている話 / GuardDuty Investigations with DevOps Agent
masahirokawahara
1
350
HRC_Frontend_Conference_Fukuoka_2026.pdf
ts020
0
400
Featured
See All Featured
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
The Curse of the Amulet
leimatthew05
2
14k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
600
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
HDC tutorial
michielstock
2
860
Building Applications with DynamoDB
mza
96
7.2k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.8k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
560
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
490
Transcript
Unknownのことをちゃんと 知りたい 関西フロントエンド忘年会
[email protected]
× KINTOテクノロジーズ_2024/12/06
いずりょー #EngineeringManager #TypeScriptが好き #JavaScriptは嫌い #最近は生成 AIと戯れている #kansai.ts Organizer X →
@is_ryo Bluesky → is-ryo
今日は Unknownのことちゃんと 理解して使ってる? という話をします
質問 unknown型を 意識して使っている人
終 制作・著作 ━━━━━ いずりょー
結論 ちゃんとUnknownのことを理 解できたら anyはいらない (多分…きっと…知らんけど )
サバイバル TypeScriptによると • TypeScriptのunknown型は、型が何かわからないときに使う型です • unknown型にはどのような値も代入できます • unknown型はよく「型安全なany型」と言われ、any型と対比されます • any型はどのような型の変数にも代入できますが、unknown型の値は具
体的な型へ代入できません • などと書いてある
unknown型にはどのような値も代入できる
unknown型は「型安全な any型」
unknown型とany型の違い • unknown型もany型もどのような値も代入できる • unknown型はunknown型にしか再代入できない • any型に代入したオブジェクトのプロパティ、メソッドは使用することができ るが、unknown型は使用できないし実行もできない ◦ 意図しない実行時エラーを検知することができる
ざっくり言うと unknown型は安全に型を ぶっ飛ばして any型はTSを捨てる という感じ
any型を使っていいのは TSを捨てる覚悟のあるやつだけだ …
unknown型の使い方 • any型の値をより安全にする • 型アサーションの制約を回避する • TypeGuardを利用して正しい型をつける
None
None
まとめ • とりあえず「型が何かわからない 」という時に any型 を使うのではなくて unkonwn型 を使うことで堅牢なコードに1歩近づく • その結果コード量は増えるケースが多いとは思うので、そこはいい塩梅を
探す必要がある • (個人的には) 多少コード量が多くなっても any型 がない世界を目指した い ◦ コードレビューで any型 を排除する活動をし始めている
結論 ちゃんとUnknownのことを理 解できたら anyはいらない (多分…きっと…知らんけど )
Thanks!!!