Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TypeScript リテラル型について

797d5998ec494edb7ade9ffe8783d105?s=47 Kosuke Ogawa
September 18, 2020

TypeScript リテラル型について

Webナイト宮崎 Vol.10 ~てげTypeScriptを学びたい~ - connpass https://tegehoge.connpass.com/event/186724/

797d5998ec494edb7ade9ffe8783d105?s=128

Kosuke Ogawa

September 18, 2020
Tweet

Transcript

  1. KOSUKE OGAWA 2020 WebφΠτٶ࡚ No. 10 Ϧςϥϧܕʹ͍ͭͯ

  2. ࣗݾ঺հ w 0HBXB,PTVLFʢ!LPPHBXBʣ w Ξϧגࣜձࣾʢ౦ژʣ w ٶ࡚͔ΒϑϧϦϞʔτ w J04 4XJGU

    "OESPJE ,PUMJO 5ZQF4DSJQU $44 7VFKT /VYUKTͳͲ w ࠷ۙ͸ϑϩϯτΤϯυ͕ϝΠϯ
  3. ͋Δ೔ ͱ͋ΔίʔυΛಡΜͰ͍ͨΒɺ ͜ΜͳίʔυΛݟ͚ͭͨ

  4. w AAͱ͔AAͱ͍͏ܕ͕͋Δʂʁ w BOVNCFSͳΒΘ͔Δ

  5. • 6 ΍ 2000 ͔͠ڐ͞Εͳ͍ܕ • จࣈྻͷϦςϥϧܕ΋͋Δ • const b:

    'bar' = 'foo'; // Τϥʔ: Type '"foo"' is not assignable to type ‘"bar"'. Ϧςϥϧܕͱ͍͏Β͍͠
  6. • จࣈྻͷϦςϥϧܕΛ࣋ͭ஋͸stringܕͱͯ͠ѻ͏͜ͱ͕Ͱ͖Δ จࣈྻͷϦςϥϧܕ

  7. • ܕ஫ऍΛলུͯ͠΋ͪΌΜͱਪ࿦͞ΕΔ Ϧςϥϧܕͱܕਪ࿦

  8. ࢖͍ಓ

  9. • ϝϯόม਺ͷ஋Λมߋͯ͠΄͘͠ͳ͍ͱ͖ ࢖͍ಓ1

  10. • ϢχΦϯܕͰ݁߹͢Δ ࢖͍ಓ2

  11. ͋Γ͕ͱ͏͍͟͝·ͨ͠