Slide 1

Slide 1 text

2022-05-14 uhyo 5ZQF4DSJQUͱ ܕϨϕϧϓϩάϥϛϯά

Slide 2

Slide 2 text

About Speaker VIZP –-*/&ͷϑϩϯτΤϯυΤϯδχΞ –5ZQF4DSJQUͱ3FBDU͕ઐ໳ 5ZQF4DSJQUͷೖ໳ॻൃചதʂ

Slide 3

Slide 3 text

型レベルプログラミングとは? ܕͰΑΓਖ਼֬ͳϩδοΫΛهड़͠ɺ ίʔυͷ҆શੑΛߴΊΔͨΊʹ طଘͷܕ͔Β৽ͨͳܕΛ૑ग़͢Δख๏ͷ૯শ ʢVIZPͷݟղͰ͢ʣ

Slide 4

Slide 4 text

型レベルプログラミングに使われる主な道具 –LFZPGܕ – ΦϒδΣΫτܕ͔ΒจࣈྻϦςϥϧܕΛಘΒΕΔك༗ͳଘࡏ –UZQFPGܕ – ஋ͷੈք͔Βܕͷੈք΁ͷڮ౉͠Λͯ͘͠ΕΔ –NBQQFEUZQFT – ΦϒδΣΫτܕͷ૑଄ʹඞཁෆՄܽ –DPOEJUJPOBMUZQFT – ϩδοΫͱ͍͑͹৚݅෼ذɻJOGFSʹΑΔܕͷύλʔϯϚον΋ڧྗ –VOJPOEJTUSJCVUJPO – ϢχΦϯܕΛࣗ༝ࣗࡏʹૢ࡞Ͱ͖Δڧྗͳػߏ –UFNQMBUFMJUFSBMUZQFT – ܕϨϕϧจࣈྻૢ࡞Λ͍ͨ͠ͱ͖ʹ͓ੈ࿩ʹͳΔ

Slide 5

Slide 5 text

最近業務で書いた実例 type ResolversWhereTypesAreRemoved = Pick< Required, { [K in keyof Resolvers]-?: NonNullable extends { __isTypeOf?: unknown } ? never : K; }[keyof Resolvers] >;

Slide 6

Slide 6 text

TypeScript 4.7の新機能たち ৭ʑ৽ػೳ͕͋Δ͕ɺܕϨϕϧϓϩάϥϛϯάʹ໾ཱͭػೳ ΋௥Ճ͞Εͨ –FYUFOET $POTUSBJOUTPO JOGFS 5ZQF7BSJBCMFT –*OTUBOUJBUJPO&YQSFTTJPOT –0QUJPOBM7BSJBODF"OOPUBUJPOTGPS5ZQF1BSBNFUFST

Slide 7

Slide 7 text

extends Constraints on infer Type Variables // Before (〜TS 4.6) type FirstString = T extends [infer S, ...unknown[]] ? S extends string ? S : never : never; // After (TS 4.7) type FirstString = T extends [infer S extends string, ...unknown[]] ? S : never; Announcing TypeScript 4.7 RC ͔ΒҾ༻

Slide 8

Slide 8 text

Instantiation Expressions δΣωϦΫεؔ਺ܕͷಛఆͷܕҾ਺ʹ͓͚ΔฦΓ஋ͷܕ ΛಘΔͷָ͕ʹͳͬͨ const func = (elm: T) => [elm]; // Before (〜TS 4.6) const _f = () => { return func(0) }; type FuncRetForNumber = ReturnType; // After(TS 4.7) type FuncRetForNumber = ReturnType>;

Slide 9

Slide 9 text

Optional Variance Annotations for Type Parameters ܕʹແཧ΍ΓมੑΛ෇༩͢Δͷ͕ैདྷΑΓָ͔ͭએݴత ʹͳͬͨ // 諸般の事情でTに対して共変にしたい // Before(〜TS 4.6) const _s = Symbol(); type Obj1 = { [_s]?: T; } // After(TS 4.7) type Obj2 = {};

Slide 10

Slide 10 text

まとめ օ͞Μ΋ָ͍͠ܕϨϕϧϓϩάϥϛϯάϥΠϑΛʂ