TypeScriptを振り回せ!
by
uhyo
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
5ZQF4DSJQUΛৼΓճͤʂ VIZP )BSBKVLVUT
Slide 2
Slide 2 text
֓ཁ 5ZQF4DSJQUʹৼΓճ͞Ε͍ͯ·ͤΜ͔ʁ ʮܕΑ͔͘Βͳ͍͚ͲͱΓ͋͑ͣίϯύΠϧ௨͔ͬͨΒ0,ʯ ʮ5ZQF4DSJQU͕͋ΔԸܙΛ͋·Γײ͡ͳ͍ʯ ʮϩδοΫతʹOVMM͕དྷͳ͍ॴͳͷʹܕʹOVMM͕͍ͬͯΔʯ ʮؔͷฦΓ͕BOZͰίϯύΠϧΤϥʔʹ ͳΒͳ͍ͷͰؾʹ͠ͳ͍ʯ
Slide 3
Slide 3 text
֓ཁ 5ZQF4DSJQUΛ͍͜ͳ͢ஈ֊εςοϓΞοϓ͠Α͏ 5ZQF4DSJQUॳֶऀɾॳΊͯϓϩμΫγϣϯ͚5ZQF4DSJQU Λॻ͘ਓͳͲʹଃΔτʔΫ
Slide 4
Slide 4 text
ܕγεςϜͷׂͱత
Slide 5
Slide 5 text
ܕγεςϜͷׂʢҰൠʣ ܕݕࠪ ೖྗࢧԉ ίʔυੜ ਖ਼͕͠͞ূ໌Ͱ͖ͳ͍ϓϩάϥϜʹରͯ͠ ίϯύΠϧΤϥʔΛग़ͯ͘͠ΕΔ ܕใΛͱʹೖྗิͳͲΛఏڙͯ͘͠ΕΔ ܕใΛͱʹίϯύΠϧޙͷϝϞϦϨΠΞτ ͳͲ͕ܾ·Δ ʢi64ϏοτΈ͍ͨͳʣ
Slide 6
Slide 6 text
ܕγεςϜͷతʢҰൠʣ ܕݕࠪ ೖྗࢧԉ ίʔυੜ ਖ਼͕͠͞ূ໌Ͱ͖ͳ͍ϓϩάϥϜʹରͯ͠ ίϯύΠϧΤϥʔΛग़ͯ͘͠ΕΔ ϓϩάϥϜͷʢ͋Δछͷʣਖ਼͠͞Λอূ͢ΔͨΊʹར༻ ܕใΛͱʹೖྗิͳͲΛఏڙͯ͘͠ΕΔ ։ൃޮͷ্ͷͨΊʹར༻ ܕใΛͱʹίϯύΠϧޙͷϝϞϦϨΠΞτͳͲ ͕ܾ·Δ ͦͦίʔυΛίϯύΠϧͯ͠ಈ͔ͨ͢Ίʹඞཁ ʢ࣮ࡍʹEZOBNJDUZQFʹର͢ΔCPYJOHͱ͔͋Δ͕ʜʜʣ
Slide 7
Slide 7 text
ܕγεςϜͷతʢҰൠʣ ίʔυੜ ܕใΛͱʹίϯύΠϧޙͷϝϞϦϨΠΞτͳͲ ͕ܾ·Δ ͦͦίʔυΛίϯύΠϧͯ͠ಈ͔ͨ͢Ίʹඞཁ ʢ࣮ࡍʹEZOBNJDUZQFʹର͢ΔCPYJOHͱ͔͋Δ͕ʜʜʣ ίʔυੜʹܕ͕ඞཁͳݴޠͰͪΌΜͱܕΛ͚ͳ͍ͱ ϓϩάϥϜ͕ಈ͔ͳ͍ ίϯύΠϧΛ௨͢͜ͱ͕ͻͱͭͷΰʔϧʹͳΔ
Slide 8
Slide 8 text
Ұํɺ5ZQF4DSJQUͰ ܕݕࠪ ೖྗࢧԉ ίʔυੜ ਖ਼͕͠͞ূ໌Ͱ͖ͳ͍ϓϩάϥϜʹରͯ͠ ίϯύΠϧΤϥʔΛग़ͯ͘͠ΕΔ ϓϩάϥϜͷʢ͋Δछͷʣਖ਼͠͞Λอূ͢ΔͨΊʹར༻ ܕใΛͱʹೖྗิͳͲΛఏڙͯ͘͠ΕΔ ։ൃޮͷ্ͷͨΊʹར༻ 5ZQF4DSJQUͰ+BWB4DSJQUͷมʢτϥϯεύΠϧʣ ʹܕใΛ༻͍ͳ͍ ʢ͔ͩΒ#BCFMͰมͰ͖Δʣ
Slide 9
Slide 9 text
Ұํɺ5ZQF4DSJQUͰ ίʔυੜ 5ZQF4DSJQUͰ+BWB4DSJQUͷมʢτϥϯεύΠϧʣ ʹܕใΛ༻͍ͳ͍ ʢ͔ͩΒ#BCFMͰมͰ͖Δʣ ʮಈ͚͍͍ʯͱ͍͏ߟ͑ํͩͱͲ͜·ͰམͪΔ͜ͱ͕Ͱ͖Δ ʢ࠷ѱશ෦BOZͰಈ͘ʣ
Slide 10
Slide 10 text
Ұํɺ5ZQF4DSJQUͰ ܕݕࠪ ೖྗࢧԉ ਖ਼͕͠͞ূ໌Ͱ͖ͳ͍ϓϩάϥϜʹରͯ͠ ίϯύΠϧΤϥʔΛग़ͯ͘͠ΕΔ ϓϩάϥϜͷʢ͋Δछͷʣਖ਼͠͞Λอূ͢ΔͨΊʹར༻ ܕใΛͱʹೖྗิͳͲΛఏڙͯ͘͠ΕΔ ։ൃޮͷ্ͷͨΊʹར༻ ϓϩάϥϜͷਖ਼͠͞Λ্͢Δͱ͍͏తҙ͕ࣝ 5ZQF4DSJQUΛ͏্Ͱॏཁ
Slide 11
Slide 11 text
5ZQF4DSJQUͰܕγεςϜΛ׆༻͢Δ ϓϩάϥϜͷਖ਼͠͞Λ্͢Δͱ͍͏తҙ͕ࣝ 5ZQF4DSJQUΛ͏্Ͱॏཁ ඞཁ࠷ݶͷܕ͚ͩॻ͘ͷͰͳ͘ɺೳಈతʹܕΛ׆༻͢Δ ͜ͱͰ5ZQF4DSJQUͷྗΛҾ͖ग़͢͜ͱ͕Ͱ͖Δ
Slide 12
Slide 12 text
5ZQF4DSJQUͰܕγεςϜΛ׆༻͢Δ 2ೳಈతʹܕΛ׆༻͢ΔͨΊʹඞཁͳͷʁ
Slide 13
Slide 13 text
5ZQF4DSJQUͰܕγεςϜΛ׆༻͢Δ 2ೳಈతʹܕΛ׆༻͢ΔͨΊʹඞཁͳͷʁ "Δؾͱ୳ڀ৺ͱࣝ
Slide 14
Slide 14 text
ܕΛ׆༻͢ΔͨΊʹඞཁͳ Δؾͱ୳ڀ৺ͱࣝ
Slide 15
Slide 15 text
ྫTUSJDU/VMM$IFDLTΛΕ͍ͯͨʂ // TypeScript + React ͷྫ // string ܕͷεςʔτͳͷʹॳظΛnullʹ͍ͯ͠Δʂ const [name, setName] = useState(null);
Slide 16
Slide 16 text
ྫTUSJDU/VMM$IFDLTΛΕ͍ͯͨʂ // TypeScript + React ͷྫ // string ܕͷεςʔτͳͷʹॳظΛnullʹ͍ͯ͠Δʂ const [name, setName] = useState(null); TUSJDUUSVFʹ͠ͳ͍ͱίϯύΠϧ͕௨ͬͯ͠·͏ มOBNFTUSJOHܕͳͷʹOVMM͕ೖ͍ͬͯΔঢ়ଶʹͳΔ ίʔυͷ҆શੑ͕͍ঢ়ଶ ˒ ίϯύΠϥΦϓγϣϯͳΔ͘ݫͯ͘͠͠5ZQF4DSJQUͷԸܙΛΑΓଟ͘ड͚Α͏ʂ
Slide 17
Slide 17 text
ࣝͰΛղܾ͢ΔγφϦΦ // TypeScript + React ͷྫ // string ܕͷεςʔτͳͷʹॳظΛnullʹ͍ͯ͠Δʂ const [name, setName] = useState(null); 5ZQF4DSJQUOVMM҆શੑΛඋ͑ͨݴޠͰ͋Δͱ͍͏ࣝΛ͍࣋ͬͯΔ ࠓճOVMM҆શੑ͕ಇ͍͍ͯͳ͍͜ͱʹٙΛ๊͘ TUSJDU/VMM$IFDLT͕ແޮʹͳ͍ͬͯΔ͜ͱʹؾͮ͘
Slide 18
Slide 18 text
Δؾͱ୳ڀ৺ͰΛղܾ͢ΔγφϦΦ // TypeScript + React ͷྫ // string ܕͷεςʔτͳͷʹॳظΛnullʹ͍ͯ͠Δʂ const [name, setName] = useState(null); TUSJOHܕͳͷʹOVMMͷՄೳੑ͕͋Δͱ͔͓͔͍͠ʂ ͬͱ҆શੑΛߴΊΔΓํ͕͋ΔͷͰʁʢΔؾʣ άάΔʢ୳ڀ৺ʣ TUSJDU/VMM$IFDLT͕ແޮʹͳ͍ͬͯΔ͜ͱʹؾͮ͘
Slide 19
Slide 19 text
5ZQF4DSJQUΛ͍͜ͳͨ͢Ίͷͭͷಓے ᶃ ͱʹ͔ࣝ͘Λ͚ͭͯϕετϓϥΫςΟεΛ࣮ફ͢Δ ᶄ ৗʹݱঢ়ʹٙΛ࣋ͪ͞Βʹ༏ΕͨΓํΛ୳ٻ͢Δ
Slide 20
Slide 20 text
5ZQF4DSJQUΛ͍͜ͳͨ͢Ίͷͭͷಓے ᶃ ͱʹ͔ࣝ͘Λ͚ͭͯϕετϓϥΫςΟεΛ࣮ફ͢Δ ᶄ ৗʹݱঢ়ʹٙΛ࣋ͪ͞Βʹ༏ΕͨΓํΛ୳ٻ͢Δ ͓͢͢Ί Δؾ͕͋Ε͕ࣝͳͯ͘Ͱ͖Δ lಈ͘z͜ͱ͕ελʔτͳ5ZQF4DSJQUͱ૬ੑ͕ྑ͍Γํ ݶք·Ͱ౸ୡ͢ΕᶃʹҠߦͰ͖Δ
Slide 21
Slide 21 text
ྫλϒΛΓସ͑Δͭ // TypeScript + React ͷྫ const [tab, setTab] = useState(“home”);
Slide 22
Slide 22 text
ྫλϒΛΓସ͑Δͭ // TypeScript + React ͷྫ const [tab, setTab] = useState(“home”); // λϒΓସ͑ setTab(“home”); setTab(“search”); // ίϯςϯπΛදࣔ switch (tab) { case “home”: return ; case “search”: return ; default: // ൃੜ͠ͳ͍ return null; }
Slide 23
Slide 23 text
ྫλϒΛΓସ͑Δͭ // TypeScript + React ͷྫ const [tab, setTab] = useState(“home”); // λϒΓସ͑ setTab(“home”); setTab(“search”); ϛε͍͢͠ setTab(“serach”); ൃੜ͠ͳ͍ذΛॻ͍͍ͯΔ // ίϯςϯπΛදࣔ switch (tab) { case “home”: return ; case “search”: return ; default: // ൃੜ͠ͳ͍ return null; }
Slide 24
Slide 24 text
5ZQF4DSJQU༻࣌ʹ͓͢͢Ίͷߟ͑ํ ʮਓ͕ؒؾΛ͚ͭͳ͚ΕͳΒͳ͍ʯ ͱ͍͏໘ʹग़ձͬͨΒٙʹࢥ͏ 5ZQF4DSJQUʹνΣοΫͯ͠Β͑ͳ͍͔ߟ͑Δ ͪΖΜ5ZQF4DSJQUʹݶք͋ΔͷͰແཧͳ͜ͱ͋Δ͕ɺ ͦΕͰߟ͑Δ͜ͱͰ5ZQF4DSJQUͷྗ͕͖·͢ Ϣχοτςετͷํ͕ద͍ͯ͠Δ߹͋Δ͕ɺͦΕΛݟ͚Δ ͷ5ZQF4DSJQUྗͷ͏ͪͰ͢
Slide 25
Slide 25 text
ྫλϒΛΓସ͑Δͭʢղܾฤʣ type Tab = “home” | “search”; const [tab, setTab] = useState(“home”); // λϒΓସ͑ setTab(“home”); setTab(“search”); // ίϯςϯπΛදࣔ switch (tab) { case “home”: return ; case “search”: return ; // default: // // ൃੜ͠ͳ͍ // return null; }
Slide 26
Slide 26 text
ྫλϒΛΓସ͑Δͭʢղܾฤʣ type Tab = “home” | “search”; const [tab, setTab] = useState(“home”); // λϒΓସ͑ setTab(“home”); setTab(“search”); UZQPίϯύΠϧΤϥʔʹʂ setTab(“serach”); ൃੜ͠ͳ͍ذॻ͘ඞཁ͕ͳ͍ // ίϯςϯπΛදࣔ switch (tab) { case “home”: return ; case “search”: return ; // default: // // ൃੜ͠ͳ͍ // return null; }
Slide 27
Slide 27 text
ίʔυʹҙਤΛࠐΊΑ͏
Slide 28
Slide 28 text
ྑ͍ίʔυҙਤ͕Θ͔Δ Ұൠ ྑ͍ίʔυಡΊҙਤ͕Θ͔Δ ίϝϯτίʔυຊମ͔ΒಡΈऔΕͳ͍ҙਤΛ ิ͏ͷͰ͋Δ ͨͩಈ͚ͩ͘ͷίʔυΑΓɺଞͷਓ͕ಡΜͰ ҙਤΛཧղ͍͢͠ίʔυΛॻ͖͘
Slide 29
Slide 29 text
ίʔυ͔ΒಡΈऔΒΕΔҙਤͷྫ const [tab, setTab] = useState(“home”); // ίϯςϯπΛදࣔ switch (tab) { case “home”: return ; case “search”: return ; default: return null; } TUSJOHͳͷͰ͋ΒΏΔจࣈྻ Λड͚ೖΕΔTUBUFͰ͋Δ IPNF TFBSDIҎ֎Կදࣔ ͠ͳ͍ͱ͍͏༷Ͱ͋Δ
Slide 30
Slide 30 text
࣮ࡍͷҙਤ const [tab, setTab] = useState(“home”); // ίϯςϯπΛදࣔ switch (tab) { case “home”: return ; case “search”: return ; default: return null; } TUSJOHͳͷͰ͋ΒΏΔจࣈྻ Λड͚ೖΕΔTUBUFͰ͋Δ IPNF TFBSDIҎ֎Կදࣔ ͠ͳ͍ͱ͍͏༷Ͱ͋Δ ಛఆͷจࣈྻ͔͠ೖΒͳ͍ ͚ͲTUSJOHͱॻ͍͍ͯΔ ࣮ࡍʹൃੜ͠ͳ͍έʔε͚ͩͲԿ͔ฦ͞ͳ ͍ͱίϯύΠϧΤϥʔʹͳΔͷͰॻ͍͍ͯΔ
Slide 31
Slide 31 text
࣮ࡍͷҙਤ const [tab, setTab] = useState(“home”); // ίϯςϯπΛදࣔ switch (tab) { case “home”: return ; case “search”: return ; default: // ൃੜ͠ͳ͍ return null; } ίʔυ͔ΒಡΈऔΕͳ͍ҙਤΛ ิ͏ίϝϯτ
Slide 32
Slide 32 text
վྑ͞Εͨίʔυ͔ΒΘΔҙਤ type Tab = “home” | “search”; const [tab, setTab] = useState(“home”); // ίϯςϯπΛදࣔ switch (tab) { case “home”: return ; case “search”: return ; } ಛఆͷจࣈྻ͔͠ड͚͚ ͳ͍͜ͱ͕໌ࣔ͞Ε͍ͯΔ EFGBVMU͕ແ͍͜ͱͰ ཏੑΛΞϐʔϧ ʢEFGBVMU͕ແ͍ͷʹίϯύΠϧΤϥʔ͕ग़ͳ͍͜ͱ͔ΒܕͰཏੑ͕อূ͞Ε͍ͯΔͱཧղͰ͖Δʣ
Slide 33
Slide 33 text
ྑ͍5ZQF4DSJQUίʔυͱ ࣮ࡍͷҙਤͱίʔυ͔ΒಡΈऔΒΕΔҙਤ͕ Ұக͍ͯ͠Δίʔυ औΓಘΔΛਖ਼֬ʹهड़ͨ͠ܕΛ͏ ʢstringͰͳ͘TabͳͲʣ ࠷େݶMFUͰͳ͘DPOTUΛ͏ SFBEPOMZΛͳΔ͚͘Δ ؔͷฦΓͷܕΛ໌ه͖͢໘Ͱ໌ه͢Δ ͳͲͳͲʜ
Slide 34
Slide 34 text
ྫແ͍͔͠Εͳ͍σʔλ type Session = { userId: string | null; userName: string | null; userRole: “ADMIN” | “MEMBER” | null; // … }; ͋Γ͕ͪͳσʔλߏɿ ϩάΠϯ͍ͯͨ͠ΒVTFS*E VTFS/BNF VTFS3PMF͕શ෦ଘࡏ͢Δ
Slide 35
Slide 35 text
ྫແ͍͔͠Εͳ͍σʔλ // ϩάΠϯલ { userId: null, userName: null, userRole: null, } ͋Γ͕ͪͳσʔλߏɿ ϩάΠϯ͍ͯͨ͠ΒVTFS*E VTFS/BNF VTFS3PMF͕શ෦ଘࡏ͢Δ // ϩάΠϯޙ { userId: “xxxxxxxx”, userName: “uhyo”, userRole: “MEMBER”, }
Slide 36
Slide 36 text
ྫແ͍͔͠Εͳ͍σʔλ // ϩάΠϯલ { userId: null, userName: null, userRole: null, } ͋Γ͕ͪͳσʔλߏɿ ϩάΠϯ͍ͯͨ͠ΒVTFS*E VTFS/BNF VTFS3PMF͕શ෦ଘࡏ͢Δ // ϩάΠϯޙ { userId: “xxxxxxxx”, userName: “uhyo”, userRole: “MEMBER”, } " / 5 *1" 5 5 &3 /
Slide 37
Slide 37 text
ྫແ͍͔͠Εͳ͍σʔλ // ͜ΕԿʁ { userId: null, userName: “uhyo”, userRole: null, } ɿ ͜ͷΑ͏ͳσʔλͷଘࡏΛڐͯ͠͠·͏ ʢຊདྷͷҙਤͱίʔυ͔ΒΘΔҙਤͷဃʣ
Slide 38
Slide 38 text
ྫແ͍͔͠Εͳ͍σʔλʢղܾฤʣ type Session = { user: { id: string; name: string; role: “ADMIN” | “MEMBER”; } | null; }; ਖ਼͍͠σʔλߏɿ JE OBNF SPMFશ෦ଘࡏ͢Δ͔શ෦ଘࡏ͠ͳ͍͔ͷ
Slide 39
Slide 39 text
ྫͷϙΠϯτ ϙΠϯτɿ ϢχΦϯܕϦςϥϧܕΛ͏͜ͱͰຊདྷͷҙਤʹ͔ͳΓ͍ۙܕΛ දݱՄೳ ˒ ʮ%JTDSJNJOBUFE6OJPOʯΛ·ͩΒͳ͍ਓཁνΣοΫʂ ݕࡧͯ͠ΈΑ͏
Slide 40
Slide 40 text
ͳΔ͘5ZQF4DSJQUΛ׆༻͢Δ ί ồ υ ͷ ਖ਼ ͠ ͞ ܕͷਖ਼͠͞ ʢ5ZQF4DSJQU͕ܕνΣοΫ ͯ͘͠ΕΔʣ ϩδοΫͷਖ਼͠͞ ʢਓ͕ؒؤுͬͯอূɾ ςετΛॻ͘ʣ ܕ͕Χόʔ͢ΔྖҬΛ ૿ͦ͏
Slide 41
Slide 41 text
ͳΔ͘5ZQF4DSJQUΛ׆༻͢Δ ί ồ υ ͷ ਖ਼ ͠ ͞ ܕͷਖ਼͠͞ ʢ5ZQF4DSJQU͕ܕνΣοΫ ͯ͘͠ΕΔʣ ϩδοΫͷਖ਼͠͞ ʢਓ͕ؒؤுͬͯอূɾ ςετΛॻ͘ʣ ͳΔ͘ݫ͍͠ίϯύΠϥΦϓγϣϯʹ͢Δ ҙਤΛਖ਼֬ʹදͨ͠ܕΛॻ͘ͳͲ
Slide 42
Slide 42 text
ͳΔ͘5ZQF4DSJQUΛ׆༻͢Δ ί ồ υ ͷ ਖ਼ ͠ ͞ ܕͷਖ਼͠͞ ʢ5ZQF4DSJQU͕ܕνΣοΫ ͯ͘͠ΕΔʣ ϩδοΫͷਖ਼͠͞ ʢਓ͕ؒؤுͬͯอূɾ ςετΛॻ͘ʣ ܕͷ΄͏͕ྑ͍ཧ༝ɿ • ܕγεςϜͷ΄͏͕ཧతഎܠʹ༏Εͯ ͓ΓɺཏతʹνΣοΫͰ͖Δ • ϢχοτςετΑΓܕऍͷ΄͏͕ υΩϡϝϯςʔγϣϯͱͯ͠༏Ε͍ͯΔ ʢҙਤ͕ΘΓ͍͢ʣ • ܕγεςϜͷ΄͏͕։ൃମݧ͕ྑ͍͜ͱ ͕ଟ͍
Slide 43
Slide 43 text
·ͱΊ
Slide 44
Slide 44 text
·ͱΊ5ZQF4DSJQUΛৼΓճͨ͢Ίʹ ϓϩάϥϜͷਖ਼͠͞ͷͨΊʹ5ZQF4DSJQUΛ׆༻͢Δ ͱ͍͏తҙࣝΛ࣋ͱ͏ ਓؒͰͳ͘5ZQF4DSJQU͕ؤுΔྖҬΛ૿ͦ͏ ͞Βʹ5ZQF4DSJQUΛ׆༻Ͱ͖ͳ͍͔ৗʹࡧ͠Α͏ 5ZQF4DSJQUॊೈͳݴޠͰ͋ΔͨΊɺΓํʹΑͬͯ҆શੑϨϕϧʹ͕ࠩग़Δ ݴޠͰ͢ɻΑΓߴ͍҆શੑϨϕϧΛࢦͯ͠ྗ͠·͠ΐ͏
Slide 45
Slide 45 text
͓·͚εϥΠυ'"2 2ݫ͍͠ίϯύΠϥΦϓγϣϯʹ͢Δͱ։ൃޮ͕མͪΔ 2͍͠ܕΛॻ͘ͷ։ൃޮ͕མͪΔ "ؾͷ͍ͤͰ͢ɻ ΦϓγϣϯܕΛ؇ͨ͘͜͠ͱͷπέɺʮෆ۩߹ͷ૿Ճʯ͔ ʮػցͷΘΓʹਓ͕ؒߟ͑Δ͜ͱͷ૿Ճʯͱݴ͏ܗͰݱΕ·͢ɻ લऀຊసͩ͠ɺޙऀͬͱ։ൃޮ͕མ͍ͪͯ·͢ɻ