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
TS5.4と5.5のいいやつ
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
めろたんたんめん
May 23, 2024
0
200
TS5.4と5.5のいいやつ
めろたんたんめん
May 23, 2024
Tweet
Share
More Decks by めろたんたんめん
See All by めろたんたんめん
Nuxt.jsからNext.jsに 乗り換えるにあたって 大変だったこと
renyamizuno
0
290
HoudiniによるCSS錬金術
renyamizuno
0
110
MisocaでReactした話
renyamizuno
1
2.4k
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
The Curious Case for Waylosing
cassininazir
0
240
Accessibility Awareness
sabderemane
0
56
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
86
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.6k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Are puppies a ranking factor?
jonoalderson
1
2.7k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
420
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
160
Transcript
TS5.4と5.5のこれ便利そう @merotan
雑自己紹介 めろたん X(Twitter): @renyamizuno_ - 株式会社Leaner Technologiesで働いてる。 - フロントエンドを主軸にガヤガヤしてる人。 -
サーバーサイドもやってる(最近はやってない())。
TS5.4
NoInfer
NoInfer ジェネリック関数で引数の型をもとに、他の引数の形を推測できるようになる。
declare function doSomething<T extends string>(a: T[], b: T): void doSomething(["cat",
"dog"], "hamster")
declare function doSomething<T extends string> (a: T[], b: NoInfer<T>): void
doSomething(["cat", "dog"], "hamster")
None
Narrowing
Preserved Narrowing in Closures Following Last Assignments クロージャーの中で変数の型をよしなにしてくれる(雑 クロージャーの外で定義した変数の型推論がよりよくなる。 最後に代入された値の型になる。
function doSomething(names: string[], word: string | undefined) { if (word
=== undefined) { word = "hello!!"; } return names.map(name => `${name} ${word.toUpperCase()}`) }
function doSomething(names: string[], word: string | undefined) { if (word
=== undefined) { word = "hello!!"; } return names.map(name => `${name} ${word.toUpperCase()}`) }
TS5.5 (Beta)
Inferred Type Predicates
Inferred Type Predicates より良い感じに型を推論してくれる(雑 x === null とかを行った場合、より適切な型推論を行うようになる。 「is」が不要になることがある。
const array = [1,2,3,null,5].filter(x => x !== null) array.reduce((a, b)
=> a + b, 0)
const array = [1,2,3,null,5].filter(x => x !== null) array.reduce((a, b)
=> a + b, 0)
おわり https://devblogs.microsoft.com/typescript/announcing-typescript-5-4/ https://devblogs.microsoft.com/typescript/announcing-typescript-5-5-beta/
Control Flow Narrowing for Constant Indexed Accesses
function f(obj: Record<string, unknown>, key: string) { if (typeof obj[key]
=== "string") { obj[key].toUpperCase(); } }
function f(obj: Record<string, unknown>, key: string) { if (typeof obj[key]
=== "string") { obj[key].toUpperCase(); } }