Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

アプリ文言のパースで学ぶ 文字列Literal型パズル入門

Saji
November 15, 2024
740

アプリ文言のパースで学ぶ 文字列Literal型パズル入門

Saji

November 15, 2024
Tweet

Transcript

  1. 5FNQMBUF-JUFSBM5ZQFT +BWB4DSJQUͷ5FNQMBUF-JUFSBMͱಉ͡ߏจͰɺܕΛੜ੒ɾਪ࿦ͯ͘͠ΕΔ 6OJPOͷ෼഑ͱ͔΋ͯ͘͠ΕΔ type World = 'world'; type Greeting =

    `hello ${World}`; // type Greeting = "hello world" type Ts = 'ts'; type Js = 'js'; type Config = `config.${Ts | Js}`; // type Config = 'config.ts' | 'config.js';
  2. վྑ\<LFZ>TUSJOH^ͷܗʹ w 1MBDFIPMEFSͷܕ 51) ΛLFZͱ͢Δ{[key] : string}ͷܕΛ࡞Δ w ࠶ىతʹݺͼग़ͨ݁͠ՌΛަࠩܕͰܨ͛Δ type

    GetPlaceholderOption<T> = T extends `${string}{{${infer TPH}}}${infer TAfter}` ? { [K in TPH]: string; } & GetPlaceholderOption<TAfter> : {};