{"id":13201,"date":"2026-03-17T06:29:18","date_gmt":"2026-03-17T06:29:18","guid":{"rendered":"https:\/\/withcode.tech\/media\/?p=13201"},"modified":"2026-07-01T15:28:27","modified_gmt":"2026-07-01T15:28:27","slug":"typescript-conditional-types-guide","status":"publish","type":"post","link":"https:\/\/withcode.tech\/media\/typescript-conditional-types-guide\/","title":{"rendered":"TypeScript Conditional Type\u5b8c\u5168\u30ac\u30a4\u30c9\uff5cT extends U\u30fbUnion Distribution\u30fbinfer\u30fb\u518d\u5e30\u7684\u6761\u4ef6\u578b\u30fb\u7d44\u307f\u8fbc\u307f\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u578b\u306e\u5b9f\u88c5\u30fb\u5b9f\u8df5\u30ab\u30b9\u30bf\u30e0\u578b\u307e\u3067\u5fb9\u5e95\u89e3\u8aac"},"content":{"rendered":"\n<div class=\"wp-block-group swl-box\"><div class=\"wp-block-group__inner-container\">\n<h2 class=\"wp-block-heading\">\u3053\u306e\u8a18\u4e8b\u3067\u308f\u304b\u308b\u3053\u3068<\/h2>\n<ul class=\"wp-block-list\">\n<li>Conditional Type\uff08T extends U ? X : Y\uff09\u306e\u57fa\u672c\u69cb\u6587\u3068\u578b\u968e\u5c64\u306e\u95a2\u4fc2<\/li>\n<li>\u5206\u914d\u7684\u6761\u4ef6\u578b\uff08Union Distribution\uff09\u306e\u4ed5\u7d44\u307f\u3068\u5206\u914d\u306e\u6291\u5236\u65b9\u6cd5<\/li>\n<li>infer\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u4f7f\u3063\u305f\u95a2\u6570\u30fbPromise\u30fb\u30bf\u30d7\u30eb\u304b\u3089\u306e\u578b\u62bd\u51fa<\/li>\n<li>DeepPartial\u30fbDeepReadonly\u30fbFlatten\u306a\u3069\u518d\u5e30\u7684\u6761\u4ef6\u578b\u306e\u5b9f\u88c5<\/li>\n<li>\u3088\u304f\u3042\u308b\u843d\u3068\u3057\u7a74\uff08never\u30fbany\u306e\u6319\u52d5\uff09\u3068\u578b\u30c6\u30b9\u30c8\u306e\u66f8\u304d\u65b9<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n<div class=\"swell-block-balloon\"><div class=\"c-balloon -bln-left\" data-col=\"gray\"><div class=\"c-balloon__icon -square\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/withcode.tech\/media\/wp-content\/uploads\/2025\/06\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2025-06-15-14.48.08.jpg\" alt=\"\" class=\"c-balloon__iconImg\" width=\"80px\" height=\"80px\"><span class=\"c-balloon__iconName\">\u751f\u5f92<\/span><\/div><div class=\"c-balloon__body -speaking -border-none\"><div class=\"c-balloon__text\">\n  <p><strong>TypeScript\u306e\u578b\u3067if\u6587\u307f\u305f\u3044\u306a\u6761\u4ef6\u5206\u5c90\u3092\u3057\u305f\u3044\u3093\u3067\u3059\u304c\u2026\u2026Conditional Type\u3068\u3044\u3046\u306e\u3092\u805e\u3044\u305f\u3053\u3068\u304c\u3042\u308b\u3093\u3067\u3059\u304c\u3001\u96e3\u3057\u305d\u3046\u3067<\/strong><\/p>\n  <span class=\"c-balloon__shapes\"><span class=\"c-balloon__before\"><\/span><span class=\"c-balloon__after\"><\/span><\/span><\/div><\/div><\/div><\/div>\n\n  <div class=\"swell-block-balloon\"><div class=\"c-balloon -bln-right\" data-col=\"gray\"><div class=\"c-balloon__icon -square\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/withcode.tech\/media\/wp-content\/uploads\/2025\/06\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2025-06-15-15.11.23.jpg\" alt=\"\" class=\"c-balloon__iconImg\" width=\"80px\" height=\"80px\"><span class=\"c-balloon__iconName\">\u30da\u30f3\u535a\u58eb<\/span><\/div><div class=\"c-balloon__body -speaking -border-none\"><div class=\"c-balloon__text\">\n  <p><strong>Conditional Type\u306fTypeScript\u306e\u5f37\u529b\u306a\u6a5f\u80fd\u306e\u4e00\u3064\u3058\u3083\uff01\u4e09\u9805\u6f14\u7b97\u5b50\u306e\u3088\u3046\u306a\u5f62\u3067\u300c\u578b\u304cA\u306a\u3089X\u306e\u578b\u3092\u8fd4\u3057\u3001\u305d\u3046\u3067\u306a\u3051\u308c\u3070Y\u306e\u578b\u3092\u8fd4\u3059\u300d\u3068\u3044\u3046\u6761\u4ef6\u5206\u5c90\u304c\u578b\u30ec\u30d9\u30eb\u3067\u3067\u304d\u308b\u3093\u3058\u3083\u3002infer\u30ad\u30fc\u30ef\u30fc\u30c9\u3067\u578b\u3092\u300c\u5909\u6570\u3068\u3057\u3066\u6355\u6349\u300d\u3059\u308b\u3053\u3068\u3067\u3001ReturnType\u3084Extract\u306a\u3069\u306e\u7d44\u307f\u8fbc\u307f\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u578b\u3082\u81ea\u4f5c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3057\u3001DeepPartial\u306e\u3088\u3046\u306a\u518d\u5e30\u7684\u306a\u578b\u3082\u5b9f\u88c5\u3067\u304d\u308b\u305e\uff01<\/strong><\/p>\n  <span class=\"c-balloon__shapes\"><span class=\"c-balloon__before\"><\/span><span class=\"c-balloon__after\"><\/span><\/span><\/div><\/div><\/div><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7d50\u8ad6\uff1aConditional Type\uff08<code>T extends U ? X : Y<\/code>\uff09\u306fTypeScript\u3067\u578b\u30ec\u30d9\u30eb\u306e\u6761\u4ef6\u5206\u5c90\u3092\u5b9f\u73fe\u3059\u308b\u6a5f\u80fd\u3067\u3059\u3002<\/strong>Union Distribution\u3067\u30e6\u30cb\u30aa\u30f3\u578b\u306e\u5404\u30e1\u30f3\u30d0\u30fc\u306b\u500b\u5225\u9069\u7528\u3067\u304d\u3001infer\u30ad\u30fc\u30ef\u30fc\u30c9\u3067\u578b\u3092\u5909\u6570\u3068\u3057\u3066\u6355\u6349\u3067\u304d\u307e\u3059\u3002ReturnType\u30fbExtract\u30fbExclude\u306a\u3069\u306e\u7d44\u307f\u8fbc\u307f\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u578b\u3082\u3059\u3079\u3066\u3053\u306e\u6a5f\u80fd\u3067\u5b9f\u88c5\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u8a18\u4e8b\u3067\u306f\u3001<strong><span class=\"swl-marker mark_yellow\">Conditional Type\u306e\u57fa\u672c\u69cb\u6587\u30fb\u5206\u914d\u7684\u6761\u4ef6\u578b\u3068\u975e\u5206\u914d\u7684\u6761\u4ef6\u578b\u30fbUnion Distribution\uff08\u30e6\u30cb\u30aa\u30f3\u306e\u5206\u914d\uff09\u30fbinfer\u30ad\u30fc\u30ef\u30fc\u30c9\u306e\u591a\u69d8\u306a\u5fdc\u7528\u30fb\u5168\u7d44\u307f\u8fbc\u307f\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u578b\u306e\u81ea\u4f5c\u30fb\u518d\u5e30\u7684\u6761\u4ef6\u578b\uff08DeepPartial\u30fbDeepReadonly\u30fbFlatten\uff09\u30fb\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30ea\u30c6\u30e9\u30eb\u578b\u3068\u306e\u7d44\u307f\u5408\u308f\u305b\u30fb\u5b9f\u8df5\u7684\u306a\u30ab\u30b9\u30bf\u30e0\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u578b\u30fb\u3088\u304f\u3042\u308b\u843d\u3068\u3057\u7a74\u3068\u89e3\u6c7a\u7b56<\/span><\/strong>\u3092\u5b8c\u5168\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Conditional Type\u306e\u57fa\u672c\u69cb\u6587<\/h2>\n\n\n\n  <pre class=\"wp-block-code\"><code>>\/\/ \u57fa\u672c\u69cb\u6587: T extends U ? X : Y\n\/\/ T \u304c U \u306e\u30b5\u30d6\u30bf\u30a4\u30d7\uff08U \u306b\u4ee3\u5165\u53ef\u80fd\uff09\u3067\u3042\u308c\u3070 X \u3092\u3001\u305d\u3046\u3067\u306a\u3051\u308c\u3070 Y \u3092\u8fd4\u3059\n\n\/\/ \u30b7\u30f3\u30d7\u30eb\u306a\u4f8b\ntype IsNumber<T> = T extends number ? true : false\n\ntype T1 = IsNumber<10>       \/\/ true\ntype T2 = IsNumber<'hello'>  \/\/ false\ntype T3 = IsNumber<number>   \/\/ true\ntype T4 = IsNumber<string>   \/\/ false\n\n\/\/ TypeScript\u306e\u578b\u968e\u5c64\uff08\u30b5\u30d6\u30bf\u30a4\u30d7\u306e\u95a2\u4fc2\uff09\n\/\/ number extends number       \u2192 true\n\/\/ 42 extends number           \u2192 true\uff08\u30ea\u30c6\u30e9\u30eb\u578b\u306fnumber\u306e\u30b5\u30d6\u30bf\u30a4\u30d7\uff09\n\/\/ string extends number       \u2192 false\n\/\/ string extends string|number \u2192 true\uff08string\u306fstring|number\u306e\u30b5\u30d6\u30bf\u30a4\u30d7\uff09\n\/\/ never extends string        \u2192 true\uff08never\u306f\u3059\u3079\u3066\u306e\u578b\u306e\u30b5\u30d6\u30bf\u30a4\u30d7\uff09\n\/\/ string extends unknown      \u2192 true\uff08\u3059\u3079\u3066\u306e\u578b\u306funknown\u306e\u30b5\u30d6\u30bf\u30a4\u30d7\uff09\n\n\/\/ \u30cd\u30b9\u30c8\u3057\u305f\u6761\u4ef6\u578b\ntype TypeName<T> =\n  T extends string   ? 'string'   :\n  T extends number   ? 'number'   :\n  T extends boolean  ? 'boolean'  :\n  T extends null     ? 'null'     :\n  T extends undefined? 'undefined':\n  T extends object   ? 'object'   :\n  'unknown'\n\ntype TN1 = TypeName<'hello'>    \/\/ 'string'\ntype TN2 = TypeName<42>         \/\/ 'number'\ntype TN3 = TypeName<true>       \/\/ 'boolean'\ntype TN4 = TypeName<null>       \/\/ 'null'\ntype TN5 = TypeName<{}>         \/\/ 'object'\ntype TN6 = TypeName<symbol>     \/\/ 'unknown'<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5206\u914d\u7684\u6761\u4ef6\u578b\uff08Distributive Conditional Types\uff09<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Conditional Type\u306b\u306f<strong>\u300c\u5206\u914d\u300d<\/strong>\u3068\u3044\u3046\u91cd\u8981\u306a\u6027\u8cea\u304c\u3042\u308a\u307e\u3059\u3002\u578b\u5909\u6570T\u306bUnion\u578b\u304c\u6e21\u3055\u308c\u308b\u3068\u3001Union\u578b\u306e\u5404\u30e1\u30f3\u30d0\u30fc\u306b\u5bfe\u3057\u3066\u500b\u5225\u306bConditional Type\u304c\u9069\u7528\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n  <pre class=\"wp-block-code\"><code>>\/\/ \u5206\u914d\u7684\u6761\u4ef6\u578b\u306e\u4f8b\n\ntype ToArray<T> = T extends any ? T[] : never\n\n\/\/ T\u306bUnion\u578b\u3092\u6e21\u3059\u3068\u5206\u914d\u304c\u8d77\u304d\u308b\ntype StringOrNumberArray = ToArray<string | number>\n\/\/ \u2192 string[] | number[]\n\/\/ \uff08string | number\uff09[] \u3068\u306f\u7570\u306a\u308b\uff01\n\n\/\/ \u5185\u90e8\u52d5\u4f5c\u306e\u30a4\u30e1\u30fc\u30b8\uff1a\n\/\/ string extends any ? string[] : never \u2192 string[]\n\/\/ number extends any ? number[] : never \u2192 number[]\n\/\/ \u7d50\u679c: string[] | number[]\n\n\/\/ \u30e6\u30cb\u30aa\u30f3\u3092\u5206\u914d\u3057\u3066\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\ntype FilterBoolean<T> = T extends boolean ? never : T\n\ntype Mixed = string | number | boolean | null\ntype NonBoolean = FilterBoolean<Mixed>\n\/\/ \u2192 string | number | null\uff08boolean\u304c\u9664\u53bb\u3055\u308c\u308b\uff09\n\n\/\/ \u5206\u914d\u304c\u767a\u751f\u3059\u308b\u306e\u306f\u300c\u578b\u5909\u6570\u300d\u3068\u3057\u3066\u88f8\u3067\u4f7f\u308f\u308c\u308b\u5834\u5408\u306e\u307f\n\/\/ tuple\/array\u3067\u30e9\u30c3\u30d7\u3059\u308b\u3068\u5206\u914d\u3092\u6291\u5236\u3067\u304d\u308b\ntype IsNever<T> = [T] extends [never] ? true : false\n\/\/                \u2191 \u30e9\u30c3\u30d7\u3067\u5206\u914d\u3092\u6291\u5236\n\ntype Test1 = IsNever<never>         \/\/ true\ntype Test2 = IsNever<string>        \/\/ false\ntype Test3 = IsNever<string | never> \/\/ false\uff08never\u306funion\u304b\u3089\u6d88\u3048\u308b\u305f\u3081\uff09\n\n\/\/ \u6bd4\u8f03: \u5206\u914d\u7684\u306a\u5834\u5408\ntype IsNeverDistributive<T> = T extends never ? true : false\ntype TestD1 = IsNeverDistributive<never>  \/\/ never\uff08\u5206\u914d\u3067never\u306f\u4f55\u3082\u9069\u7528\u3055\u308c\u306a\u3044\uff01\uff09<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Union Distribution\u306e\u6d3b\u7528\u4f8b\uff5cExtract\u30fbExclude\u30fbNonNullable<\/h3>\n\n\n\n  <pre class=\"wp-block-code\"><code>>\/\/ ===== \u7d44\u307f\u8fbc\u307f\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u578b\u306e\u81ea\u4f5c =====\n\n\/\/ Extract<T, U>: T \u304b\u3089U\u306e\u30b5\u30d6\u30bf\u30a4\u30d7\u306e\u307f\u3092\u62bd\u51fa\ntype MyExtract<T, U> = T extends U ? T : never\n\ntype JobGrade = 'S' | 'A' | 'B' | 'C' | 'D'\ntype HighGrade = MyExtract<JobGrade, 'S' | 'A'>\n\/\/ \u2192 \"S\" | \"A\"\n\n\/\/ Exclude<T, U>: T \u304b\u3089U\u306e\u30b5\u30d6\u30bf\u30a4\u30d7\u3092\u9664\u5916\ntype MyExclude<T, U> = T extends U ? never : T\n\ntype LowGrade = MyExclude<JobGrade, 'S' | 'A'>\n\/\/ \u2192 \"B\" | \"C\" | \"D\"\n\n\/\/ NonNullable<T>: null \u3068 undefined \u3092\u9664\u5916\ntype MyNonNullable<T> = T extends null | undefined ? never : T\n\ntype MaybeString = string | null | undefined\ntype DefiniteString = MyNonNullable<MaybeString>  \/\/ string\n\n\/\/ Filter\uff08\u6c4e\u7528\u30d5\u30a3\u30eb\u30bf\u30fc\u578b\uff09\ntype Filter<T, U> = T extends U ? T : never  \/\/ = Extract \u3068\u540c\u3058\ntype Reject<T, U> = T extends U ? never : T  \/\/ = Exclude \u3068\u540c\u3058\n\n\/\/ \u7279\u5b9a\u306e\u578b\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u30ad\u30fc\u306e\u307f\u3092\u62bd\u51fa\uff08\u5b9f\u7528\u7684\uff01\uff09\ntype PickByValue<T, V> = {\n  [K in keyof T as T[K] extends V ? K : never]: T[K]\n}\n\ninterface User {\n  id: number\n  name: string\n  email: string\n  age: number\n  isAdmin: boolean\n}\n\ntype StringKeys = PickByValue<User, string>\n\/\/ \u2192 { name: string; email: string }\n\ntype NumberKeys = PickByValue<User, number>\n\/\/ \u2192 { id: number; age: number }<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">infer\u30ad\u30fc\u30ef\u30fc\u30c9\uff5c\u578b\u3092\u300c\u63a8\u8ad6\u3057\u3066\u62bd\u51fa\u300d\u3059\u308b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>infer<\/code> \u306f Conditional Type \u306e\u6761\u4ef6\u90e8\u3067\u4f7f\u3048\u308b\u30ad\u30fc\u30ef\u30fc\u30c9\u3067\u3001<strong>\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u3057\u305f\u578b\u3092\u5909\u6570\u3068\u3057\u3066\u6355\u6349<\/strong>\u3067\u304d\u307e\u3059\u3002\u300c\u578b\u30ec\u30d9\u30eb\u306e\u6b63\u898f\u8868\u73fe\u30ad\u30e3\u30d7\u30c1\u30e3\u300d\u306e\u3088\u3046\u306a\u30a4\u30e1\u30fc\u30b8\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u95a2\u6570\u578b\u304b\u3089\u306einfer\u6d3b\u7528<\/h3>\n\n\n\n  <pre class=\"wp-block-code\"><code>>\/\/ ===== \u95a2\u6570\u578b\u306b\u95a2\u3059\u308binfer =====\n\n\/\/ ReturnType<T>\u306e\u81ea\u4f5c\uff08\u95a2\u6570\u306e\u623b\u308a\u5024\u578b\u3092\u62bd\u51fa\uff09\ntype MyReturnType<T> = T extends (...args: any[]) => infer R ? R : never\n\ntype Fn1 = () => number\ntype Fn2 = (x: string) => string[]\ntype Fn3 = () => Promise<{ id: number }>\ntype AsyncFn = () => Promise<string>\n\ntype R1 = MyReturnType<Fn1>  \/\/ number\ntype R2 = MyReturnType<Fn2>  \/\/ string[]\ntype R3 = MyReturnType<Fn3>  \/\/ Promise<{ id: number }>\ntype R4 = MyReturnType<string>  \/\/ never\uff08\u95a2\u6570\u3067\u306a\u3044\u305f\u3081\uff09\n\n\/\/ Parameters<T>\u306e\u81ea\u4f5c\uff08\u95a2\u6570\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u578b\u3092Tuple\u3067\u53d6\u5f97\uff09\ntype MyParameters<T> = T extends (...args: infer P) => any ? P : never\n\ntype P1 = MyParameters<(x: string, y: number) => void>  \/\/ [string, number]\ntype P2 = MyParameters<() => void>                       \/\/ []\ntype P3 = MyParameters<(ids: number[]) => void>          \/\/ [number[]]\n\n\/\/ FirstParam\uff08\u6700\u521d\u306e\u5f15\u6570\u306e\u578b\u306e\u307f\u53d6\u5f97\uff09\ntype FirstParam<T> = T extends (first: infer F, ...rest: any[]) => any ? F : never\ntype FP = FirstParam<(id: number, name: string) => void>  \/\/ number\n\n\/\/ ConstructorParameters<T>\u306e\u81ea\u4f5c\uff08\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u30fc\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u578b\uff09\ntype MyConstructorParameters<T> = T extends new (...args: infer P) => any ? P : never\n\nclass MyClass {\n  constructor(public name: string, public value: number) {}\n}\ntype CP = MyConstructorParameters<typeof MyClass>  \/\/ [string, number]\n\n\/\/ InstanceType<T>\u306e\u81ea\u4f5c\uff08\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u578b\u3092\u53d6\u5f97\uff09\ntype MyInstanceType<T> = T extends new (...args: any[]) => infer I ? I : never\ntype IT = MyInstanceType<typeof MyClass>  \/\/ MyClass<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Promise\u30fb\u914d\u5217\u30fb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078\u306einfer\u6d3b\u7528<\/h3>\n\n\n\n  <pre class=\"wp-block-code\"><code>>\/\/ ===== \u914d\u5217\u30fbPromise\u304b\u3089\u306einfer =====\n\n\/\/ Promise\u306e\u4e2d\u306e\u578b\u3092\u53d6\u308a\u51fa\u3059\uff08Awaited<T>\u306e\u81ea\u4f5c\uff09\ntype UnwrapPromise<T> = T extends Promise<infer U> ? UnwrapPromise<U> : T\n\/\/ \u518d\u5e30\u7684\u306bPromise\u3092\u30a2\u30f3\u30e9\u30c3\u30d7\n\ntype P1 = UnwrapPromise<Promise<string>>                   \/\/ string\ntype P2 = UnwrapPromise<Promise<Promise<number>>>          \/\/ number\ntype P3 = UnwrapPromise<Promise<Promise<Promise<boolean>>>> \/\/ boolean\ntype P4 = UnwrapPromise<string>                            \/\/ string\uff08Promise\u3067\u306a\u3044\u306e\u3067\u305d\u306e\u307e\u307e\uff09\n\n\/\/ Awaited<T>\uff08TypeScript 4.5\u4ee5\u964d\u306e\u7d44\u307f\u8fbc\u307f\u578b\uff09\ntype A1 = Awaited<Promise<string>>  \/\/ string\uff08\u7d44\u307f\u8fbc\u307f\u3067\u540c\u3058\u52d5\u4f5c\uff09\n\n\/\/ \u914d\u5217\u306e\u8981\u7d20\u578b\u3092\u53d6\u308a\u51fa\u3059\ntype ElementType<T> = T extends ReadonlyArray<infer E> ? E : never\n\ntype E1 = ElementType<string[]>          \/\/ string\ntype E2 = ElementType<readonly number[]> \/\/ number\ntype E3 = ElementType<[string, number]>  \/\/ string | number\uff08tuple\u306e\u5834\u5408\uff09\n\n\/\/ \u30bf\u30d7\u30eb\u64cd\u4f5c\ntype Head<T extends any[]> = T extends [infer H, ...any[]] ? H : never\ntype Tail<T extends any[]> = T extends [any, ...infer T] ? T : never\ntype Last<T extends any[]> = T extends [...any[], infer L] ? L : never\ntype Init<T extends any[]> = T extends [...infer I, any] ? I : never\n\ntype Tuple = [string, number, boolean, null]\ntype H = Head<Tuple>   \/\/ string\ntype Ta = Tail<Tuple>  \/\/ [number, boolean, null]\ntype L = Last<Tuple>   \/\/ null\ntype I = Init<Tuple>   \/\/ [string, number, boolean]\n\n\/\/ ===== \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u578b\u304b\u3089\u306einfer =====\n\n\/\/ Promise\u306e\u623b\u308a\u5024\u306e\u578b\u3092\u95a2\u6570\u304b\u3089\u76f4\u63a5\u53d6\u5f97\ntype AsyncReturnType<T> = T extends (...args: any[]) => Promise<infer R> ? R : never\n\nasync function fetchUser(id: number): Promise<{ id: number; name: string }> {\n  return { id, name: 'Taro' }\n}\ntype UserType = AsyncReturnType<typeof fetchUser>\n\/\/ \u2192 { id: number; name: string }\n\n\/\/ \u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u578b\u3092\u53d6\u5f97\ntype PropType<T, K extends keyof T> = T[K] extends infer V ? V : never\n\ntype UserName = PropType<{ id: number; name: string }, 'name'>  \/\/ string<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u518d\u5e30\u7684\u6761\u4ef6\u578b\uff5cDeepPartial\u30fbDeepReadonly\u30fbFlatten<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">TypeScript 4.1\u4ee5\u964d\u3001<strong>\u518d\u5e30\u7684\u306a\u6761\u4ef6\u578b<\/strong>\u304c\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u307e\u3057\u305f\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30cd\u30b9\u30c8\u3057\u305f\u578b\u3092\u6df1\u304f\u5909\u63db\u3059\u308b\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u578b\u304c\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n  <pre class=\"wp-block-code\"><code>>\/\/ DeepPartial: \u6df1\u3044\u30ec\u30d9\u30eb\u307e\u3067\u5168\u30d7\u30ed\u30d1\u30c6\u30a3\u3092optional\u306b\u3059\u308b\ntype DeepPartial<T> = T extends object\n  ? { [K in keyof T]?: DeepPartial<T[K]> }\n  : T\n\n\/\/ \u7d44\u307f\u8fbc\u307f\u306ePartial<T>\u306f1\u30ec\u30d9\u30eb\u306e\u307f\ntype ShallowPartial = Partial<{\n  user: { name: string; address: { city: string } }\n}>\n\/\/ \u2192 { user?: { name: string; address: { city: string } } }\n\/\/ user.name \u3084 user.address.city \u306foptional\u306b\u306a\u3089\u306a\u3044\n\ntype DeepPartialExample = DeepPartial<{\n  user: { name: string; address: { city: string; zip: string } }\n  settings: { theme: 'light' | 'dark'; fontSize: number }\n}>\n\/\/ \u2192 { user?: { name?: string; address?: { city?: string; zip?: string } }; settings?: ... }\n\n\/\/ \u4f7f\u3044\u65b9\uff08\u30d5\u30a9\u30fc\u30e0\u306e\u90e8\u5206\u7684\u306a\u66f4\u65b0\u306b\u4fbf\u5229\uff09\nfunction updateUser(patch: DeepPartial<User>): void {\n  \/\/ patch\u306f\u5168\u30d7\u30ed\u30d1\u30c6\u30a3\u304coptional\uff08\u6df1\u3044\u30ec\u30d9\u30eb\u3067\u3082\uff09\n}\n\n\/\/ ===== DeepReadonly =====\ntype DeepReadonly<T> = T extends (infer U)[]\n  ? ReadonlyArray<DeepReadonly<U>>\n  : T extends object\n  ? { readonly [K in keyof T]: DeepReadonly<T[K]> }\n  : T\n\ntype Config = {\n  database: {\n    host: string\n    port: number\n    credentials: { username: string; password: string }\n  }\n  features: string[]\n}\n\ntype ImmutableConfig = DeepReadonly<Config>\n\/\/ \u5168\u30d7\u30ed\u30d1\u30c6\u30a3\u30fb\u30cd\u30b9\u30c8\u3055\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30fb\u914d\u5217\u304creadonly\n\n\/\/ ===== Flatten\uff08\u914d\u5217\u3092\u30d5\u30e9\u30c3\u30c8\u5316\u3059\u308b\u578b\uff09=====\ntype Flatten<T> = T extends Array<infer U> ? Flatten<U> : T\n\ntype F1 = Flatten<string[][][]>    \/\/ string\ntype F2 = Flatten<number[]>        \/\/ number\ntype F3 = Flatten<string>          \/\/ string\uff08\u914d\u5217\u3067\u306a\u3044\u306e\u3067\u305d\u306e\u307e\u307e\uff09\n\n\/\/ ===== DeepOmit\uff08\u6df1\u3044\u30cd\u30b9\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u9664\u5916\uff09=====\n\/\/ \u5358\u7d14\u306a\u5b9f\u88c5\u4f8b\ntype DeepOmit<T, K extends string | number | symbol> = T extends object\n  ? { [P in Exclude<keyof T, K>]: DeepOmit<T[P], K> }\n  : T\n\ntype WithoutPassword = DeepOmit<{\n  user: { id: number; name: string; password: string }\n  admin: { id: number; password: string; role: string }\n}, 'password'>\n\/\/ \u2192 { user: { id: number; name: string }; admin: { id: number; role: string } }<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30ea\u30c6\u30e9\u30eb\u578b\u3068\u306e\u7d44\u307f\u5408\u308f\u305b<\/h2>\n\n\n\n  <pre class=\"wp-block-code\"><code>>\/\/ \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30ea\u30c6\u30e9\u30eb\u578b + Conditional Type + infer\n\n\/\/ Split: \u6587\u5b57\u5217\u578b\u3092\u30c7\u30ea\u30df\u30bf\u3067\u5206\u5272\u3057\u3066Tuple\u306b\u5909\u63db\ntype Split<S extends string, D extends string> =\n  S extends `${infer T}${D}${infer U}`\n    ? [T, ...Split<U, D>]\n    : [S]\n\ntype S1 = Split<'a.b.c', '.'>  \/\/ [\"a\", \"b\", \"c\"]\ntype S2 = Split<'hello-world', '-'>  \/\/ [\"hello\", \"world\"]\ntype S3 = Split<'no-delimiter', ','>  \/\/ [\"no-delimiter\"]\n\n\/\/ Join: Tuple\u3092\u6587\u5b57\u5217\u306b\u7d50\u5408\ntype Join<T extends string[], D extends string> =\n  T extends [infer F extends string, ...infer R extends string[]]\n    ? `${F}${R extends [] ? '' : `${D}${Join<R, D>}`}`\n    : ''\n\ntype J1 = Join<['a', 'b', 'c'], '.'>  \/\/ \"a.b.c\"\n\n\/\/ CamelCase \u2192 snake_case \u5909\u63db\ntype CamelToSnake<T extends string> =\n  T extends `${infer Head}${infer Tail}`\n    ? Tail extends Uncapitalize<Tail>\n      ? `${Lowercase<Head>}${CamelToSnake<Tail>}`\n      : `${Lowercase<Head>}_${CamelToSnake<Tail>}`\n    : T\n\n\/\/ \u203b\u6ce8\u610f: \u4e0a\u8a18\u306f\u7c21\u6613\u5b9f\u88c5\u3002\u5b9f\u969b\u306f\u5927\u6587\u5b57\u306e\u30d1\u30bf\u30fc\u30f3\u304c\u8907\u96d1\n\n\/\/ Paths\uff08\u30cd\u30b9\u30c8\u3057\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5168\u30d1\u30b9\u3092\u62bd\u51fa\uff09\ntype Paths<T, P extends string = ''> =\n  T extends object\n    ? { [K in keyof T & string]:\n        P extends '' ? K | `${K}.${Paths<T[K], K>}`\n                     : `${K}` | `${K}.${Paths<T[K], K>}`\n      }[keyof T & string]\n    : never\n\ntype Config = {\n  user: { name: string; address: { city: string; zip: string } }\n  theme: string\n}\n\ntype ConfigPaths = Paths<Config>\n\/\/ \"user\" | \"user.name\" | \"user.address\" | \"user.address.city\" | \"user.address.zip\" | \"theme\"\n\n\/\/ \u30d5\u30a9\u30fc\u30e0\u3084getter\u306e\u5b9f\u88c5\u306b\u4f7f\u3048\u308b\u30d1\u30bf\u30fc\u30f3\nfunction getConfigValue<T extends Config>(obj: T, path: Paths<T>): unknown {\n  \/\/ path\u306b\u57fa\u3065\u3044\u3066\u30cd\u30b9\u30c8\u3057\u305f\u5024\u3092\u53d6\u5f97\n  return path.split('.').reduce((acc, key) => (acc as any)?.[key], obj)\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u8df5\u7684\u306a\u30ab\u30b9\u30bf\u30e0\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u578b<\/h2>\n\n\n\n  <pre class=\"wp-block-code\"><code>>\/\/ ===== API\u30ec\u30b9\u30dd\u30f3\u30b9\u7528\u306e\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u578b =====\n\n\/\/ API\u30ec\u30b9\u30dd\u30f3\u30b9\u306e\u6210\u529f\/\u5931\u6557\u578b\u304b\u3089\u5b9f\u969b\u306e\u30c7\u30fc\u30bf\u578b\u3092\u53d6\u308a\u51fa\u3059\ntype ApiResponse<T> =\n  | { status: 'success'; data: T }\n  | { status: 'error'; code: string; message: string }\n\ntype ExtractData<R> = R extends { status: 'success'; data: infer D } ? D : never\ntype ExtractError<R> = R extends { status: 'error' } ? R : never\n\ntype UserResponse = ApiResponse<{ id: number; name: string }>\ntype UserData = ExtractData<UserResponse>\n\/\/ \u2192 { id: number; name: string }\n\n\/\/ \u30ea\u30af\u30a8\u30b9\u30c8\/\u30ec\u30b9\u30dd\u30f3\u30b9\u306e\u578b\u3092\u5b89\u5168\u306b\u6271\u3046\ntype ApiResult<T> =\n  | { ok: true; data: T }\n  | { ok: false; error: Error }\n\nfunction isOk<T>(result: ApiResult<T>): result is { ok: true; data: T } {\n  return result.ok === true\n}\n\n\/\/ ===== \u30d5\u30a9\u30fc\u30e0\u7528\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u578b =====\n\n\/\/ \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5168\u30ad\u30fc\u3092\u6587\u5b57\u5217\u3067\u30d1\u30b9\u5316\ntype FieldPath<T> = {\n  [K in keyof T]: K extends string\n    ? T[K] extends Record<string, any>\n      ? K | `${K}.${FieldPath<T[K]>}`\n      : K\n    : never\n}[keyof T]\n\ntype FormValues = {\n  user: { name: string; email: string }\n  age: number\n  address: { city: string; zip: string }\n}\ntype FormPaths = FieldPath<FormValues>\n\/\/ \"user\" | \"user.name\" | \"user.email\" | \"age\" | \"address\" | \"address.city\" | \"address.zip\"\n\n\/\/ ===== \u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u8a2d\u8a08\u7528\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u578b =====\n\n\/\/ PropsWithChildren \u306e\u6c4e\u7528\u7248\ntype WithChildren<T = {}> = T & { children?: React.ReactNode }\n\n\/\/ className \u3092 optional \u306b\u8ffd\u52a0\ntype WithClassName<T = {}> = T & { className?: string }\n\n\/\/ \u7279\u5b9a\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u53ef\u80fd\u306b\u3059\u308b\ntype Override<T, U> = Omit<T, keyof U> & U\n\n\/\/ a\u30bf\u30b0\u304bbutton\u30bf\u30b0\u304b\u3092\u578b\u3067\u5207\u308a\u66ff\u3048\u308b\u30dd\u30ea\u30e2\u30fc\u30d5\u30a3\u30c3\u30af\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\ntype PolymorphicRef<T extends React.ElementType> =\n  React.ComponentPropsWithRef<T>['ref']\n\ntype PolymorphicProps<T extends React.ElementType, Props = {}> = {\n  as?: T\n  ref?: PolymorphicRef<T>\n} & Props & Omit<React.ComponentPropsWithoutRef<T>, keyof Props | 'as'>\n\n\/\/ ===== \u72b6\u614b\u7ba1\u7406\u7528\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u578b =====\n\n\/\/ \u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u30fc\u578b\u3092\u81ea\u52d5\u751f\u6210\ntype EventHandlers<T> = {\n  [K in keyof T as K extends string ? `on${Capitalize<K>}` : never]?: (value: T[K]) => void\n}\n\ntype State = { count: number; name: string; active: boolean }\ntype Handlers = EventHandlers<State>\n\/\/ \u2192 { onCount?: (value: number) => void; onName?: (value: string) => void; onActive?: (value: boolean) => void }<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u3088\u304f\u3042\u308b\u843d\u3068\u3057\u7a74\u3068\u89e3\u6c7a\u7b56<\/h2>\n\n\n\n  <pre class=\"wp-block-code\"><code>>\/\/ ===== \u3088\u304f\u3042\u308b\u843d\u3068\u3057\u7a74 =====\n\n\/\/ \u843d\u3068\u3057\u7a741: never \u3068 Union Distribution\ntype IsNeverWrong<T> = T extends never ? true : false\ntype WrongResult = IsNeverWrong<never>  \/\/ never\uff01\uff08true\u306b\u306a\u3089\u306a\u3044\uff09\n\n\/\/ \u7406\u7531: never \u304cUnion Distribution\u306b\u6e21\u3055\u308c\u308b\u3068\u4f55\u3082\u5206\u914d\u3055\u308c\u305anever\u304c\u8fd4\u308b\n\/\/ \u89e3\u6c7a: [] \u3067\u30e9\u30c3\u30d7\u3057\u3066\u5206\u914d\u3092\u6291\u5236\u3059\u308b\ntype IsNeverCorrect<T> = [T] extends [never] ? true : false\ntype CorrectResult = IsNeverCorrect<never>  \/\/ true \u2705\n\n\/\/ \u843d\u3068\u3057\u7a742: any \u306f\u5168\u3066\u306e extends \u3092 true \u306b\u3059\u308b\ntype IsString<T> = T extends string ? true : false\ntype AnyResult = IsString<any>  \/\/ boolean\uff08true | false\uff09\n\n\/\/ any \u3092\u6e21\u3059\u3068\u6761\u4ef6\u304c\u4e0d\u5b9a\u306b\u306a\u308aboolean\u578b\u306b\u306a\u308b\n\/\/ \u89e3\u6c7a: any\u3092\u7279\u5225\u6271\u3044\u3059\u308b\ntype IsStringStrict<T> = [T] extends [string] ? true : false\n\/\/ \u3053\u308c\u3067\u3082any\u306ftrue\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u5834\u5408\u304c\u3042\u308b\u305f\u3081\u3001any\u30c1\u30a7\u30c3\u30af\u3092\u52a0\u3048\u308b\n\n\/\/ \u843d\u3068\u3057\u7a743: Union Distribution\u304c\u610f\u56f3\u3057\u306a\u3044\u5206\u914d\u3092\u8d77\u3053\u3059\u5834\u5408\ntype WrapInArray<T> = T extends any ? [T] : never\ntype WrappedUnion = WrapInArray<string | number>\n\/\/ \u2192 [string] | [number]\uff08\u5206\u914d\u3067\u5225\u3005\u306e\u30bf\u30d7\u30eb\u306b\u306a\u308b\uff09\n\n\/\/ \u5206\u914d\u3092\u6291\u5236\u3057\u305f\u3044\u5834\u5408\ntype WrapInArrayNoDistribute<T> = [T] extends [any] ? [T] : never\ntype Wrapped = WrapInArrayNoDistribute<string | number>\n\/\/ \u2192 [string | number]\uff08Union\u5168\u4f53\u3092\u3072\u3068\u3064\u306e\u30bf\u30d7\u30eb\u306b\uff09\n\n\/\/ \u843d\u3068\u3057\u7a744: infer\u306e\u5171\u5909\u30fb\u53cd\u5909\n\/\/ \u95a2\u6570\u306e\u5f15\u6570\u306finfer\u3067\u53d6\u308a\u51fa\u3059\u3068Union\u3067\u306f\u306a\u304fIntersection\u306b\u306a\u308b\ntype FnUnion = ((x: string) => void) | ((x: number) => void)\ntype ParamsUnion = FnUnion extends (...args: infer P) => void ? P : never\n\/\/ \u2192 [x: string & number]\uff08Intersection\u306b\u306a\u308b\uff01\uff09\n\n\/\/ \u89e3\u6c7a: Union\u578b\u306e\u5f15\u6570\u3092\u5225\u3005\u306b\u6271\u3046\u5834\u5408\u306f\u500b\u5225\u306b\u51e6\u7406\u3059\u308b<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u578b\u30c6\u30b9\u30c8\u306e\u66f8\u304d\u65b9<\/h2>\n\n\n\n  <pre class=\"wp-block-code\"><code>>\/\/ ===== \u578b\u30c6\u30b9\u30c8\u306e\u65b9\u6cd5 =====\n\n\/\/ \u65b9\u6cd51: @ts-expect-error \u3092\u4f7f\u3063\u305f\u30c6\u30b9\u30c8\nconst test: string = '' as unknown as string\n\/\/ @ts-expect-error: string \u306f number \u306b\u4ee3\u5165\u4e0d\u53ef\nconst shouldFail: number = test  \/\/ \u30a8\u30e9\u30fc\u304c\u51fa\u308b\u3053\u3068\u3092\u78ba\u8a8d\n\n\/\/ \u65b9\u6cd52: Expect + Equal \u578b\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\uff08type-fest\u30e9\u30a4\u30d6\u30e9\u30ea\uff09\ntype Expect<T extends true> = T\ntype Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false\n\ntype TestSuite = [\n  Expect<Equal<MyReturnType<() => string>, string>>,\n  Expect<Equal<MyExtract<'a' | 'b' | 'c', 'a'>, 'a'>>,\n  Expect<Equal<UnwrapPromise<Promise<number>>, number>>,\n  Expect<Equal<Head<[1, 2, 3]>, 1>>,\n]\n\/\/ \u2191 \u5168\u3066 true \u306b\u306a\u308c\u3070\u578b\u30c6\u30b9\u30c8\u901a\u904e\n\n\/\/ \u65b9\u6cd53: tsd \u30e9\u30a4\u30d6\u30e9\u30ea\uff08\u578b\u30c6\u30b9\u30c8\u5c02\u7528\u30c4\u30fc\u30eb\uff09\n\/\/ npm install --save-dev tsd\nimport { expectType, expectError } from 'tsd'\n\nexpectType<string>('' as MyReturnType<() => string>)\nexpectType<'a' | 'b'>('' as MyExtract<'a' | 'b' | 'c', 'a' | 'b'>)\n\n\/\/ \u578b\u30c6\u30b9\u30c8\u3092 CI\/CD \u306b\u7d44\u307f\u8fbc\u3093\u3067\u578b\u306e\u6b63\u78ba\u6027\u3092\u4fdd\u8a3c<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u3088\u304f\u3042\u308b\u8cea\u554f\uff08FAQ\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Q1. Conditional Type\u3068\u578b\u30ac\u30fc\u30c9\u306f\u3069\u3046\u4f7f\u3044\u5206\u3051\u307e\u3059\u304b\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>A.<\/strong> Conditional Type \u306f<strong>\u578b\u5b9a\u7fa9\u306e\u6642\u70b9\u3067\uff08\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\uff09<\/strong>\u578b\u3092\u6761\u4ef6\u5206\u5c90\u3055\u305b\u308b\u3082\u306e\u3067\u3059\u3002\u578b\u30ac\u30fc\u30c9\u306f<strong>\u30e9\u30f3\u30bf\u30a4\u30e0\u3067<\/strong>\u6761\u4ef6\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066TypeScript\u306b\u300c\u3053\u306e\u5206\u5c90\u306e\u4e2d\u3067\u306f\u3053\u306e\u578b\u3060\u300d\u3068\u6559\u3048\u308b\u3082\u306e\u3067\u3059\u3002<code>function isString(x: unknown): x is string { return typeof x === 'string' }<\/code> \u306e\u3088\u3046\u306a\u578b\u30ac\u30fc\u30c9\u306f\u5b9f\u884c\u6642\u306b\u52d5\u4f5c\u3057\u3001Conditional Type\u306f\u578b\u8a08\u7b97\u306e\u969b\u306b\u306e\u307f\u8a55\u4fa1\u3055\u308c\u307e\u3059\u3002\u4e21\u8005\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u3046\u3053\u3068\u304c\u591a\u304f\u3001Conditional Type\u3067\u300c\u3042\u308b\u95a2\u6570\u304c\u8fd4\u3059\u578b\u3092\u8a08\u7b97\u300d\u3057\u3001\u578b\u30ac\u30fc\u30c9\u3067\u300c\u5b9f\u884c\u6642\u306b\u305d\u306e\u578b\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u300d\u3059\u308b\u30d1\u30bf\u30fc\u30f3\u304c\u5b9f\u8df5\u7684\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Q2. \u518d\u5e30\u7684\u306a\u6761\u4ef6\u578b\u3067TypeScript\u304c\u9045\u304f\u306a\u308b\u5834\u5408\u306f\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u3067\u3059\u304b\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>A.<\/strong> \u518d\u5e30\u7684\u306a\u578b\u306f\u6df1\u3059\u304e\u308b\u3068 <strong>\u300cType instantiation is excessively deep\u300d<\/strong> \u30a8\u30e9\u30fc\u304c\u51fa\u307e\u3059\u3002\u89e3\u6c7a\u7b56\u306f\u2460\u518d\u5e30\u306e\u6df1\u3055\u3092\u5236\u9650\u3059\u308b\u30ab\u30a6\u30f3\u30bf\u30fc\u3092\u578b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3067\u6301\u3064\u2461<code>interface<\/code>\u3092\u4f7f\u3063\u305f\u9045\u5ef6\u8a55\u4fa1\u2462\u305d\u3082\u305d\u3082\u6df1\u3044\u518d\u5e30\u304c\u5fc5\u8981\u306a\u5834\u5408\u306f\u5b9f\u884c\u6642\u51e6\u7406\u306b\u5207\u308a\u66ff\u3048\u308b\u306e3\u3064\u3067\u3059\u3002TypeScript\u306e\u30b3\u30f3\u30d1\u30a4\u30e9\u30fc\u306f\u578b\u306e\u518d\u5e30\u6df1\u3055\u306b\u4e0a\u9650\uff08\u30c7\u30d5\u30a9\u30eb\u30c81000\uff09\u304c\u3042\u308b\u305f\u3081\u3001\u5b9f\u969b\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u30c7\u30fc\u30bf\u306e\u6df1\u3055\u306b\u5408\u308f\u305b\u305f\u8a2d\u8a08\u304c\u91cd\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Q3. infer\u3067\u63a8\u8ad6\u3055\u308c\u305f\u578b\u306e\u7bc4\u56f2\u306f\u3069\u3046\u5236\u9650\u3057\u307e\u3059\u304b\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>A.<\/strong> TypeScript 4.7\u4ee5\u964d\u3001<code>infer R extends string<\/code> \u306e\u3088\u3046\u306b<strong>infer\u306b extends\u5236\u7d04\u3092\u4ed8\u3051\u308b<\/strong>\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<code>type FirstString&lt;T&gt; = T extends [infer F extends string, ...any[]] ? F : never<\/code> \u306e\u3088\u3046\u306b\u66f8\u304f\u3068\u3001F\u306fstring\u306e\u30b5\u30d6\u30bf\u30a4\u30d7\u3068\u3057\u3066\u30ad\u30e3\u30d7\u30c1\u30e3\u3055\u308c\u307e\u3059\u30024.7\u4ee5\u524d\u306f\u63a8\u8ad6\u5f8c\u306b\u5225\u306eConditional Type\u3067\u5236\u7d04\u3092\u304b\u3051\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Q4. Conditional Type\u3068Mapped Type\u306f\u3069\u3046\u4f7f\u3044\u5206\u3051\u307e\u3059\u304b\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>A.<\/strong> <strong>Mapped Type\uff08<code>{ [K in keyof T]: ... }<\/code>\uff09<\/strong>\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5404\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5909\u63db\u3059\u308b\u306e\u306b\u4f7f\u3044\u307e\u3059\u3002<strong>Conditional Type<\/strong>\u306f\u578b\u305d\u306e\u3082\u306e\u3092\u6761\u4ef6\u3067\u5207\u308a\u66ff\u3048\u308b\u306e\u306b\u4f7f\u3044\u307e\u3059\u3002\u5b9f\u969b\u306b\u306f\u4e21\u8005\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u304c\u591a\u304f\u3001Mapped Type\u306eKey Remapping\uff08<code>as<\/code>\u7bc0\uff09\u3067Conditional Type\u3092\u4f7f\u3063\u3066\u7279\u5b9a\u30ad\u30fc\u3092\u9664\u5916\u30fb\u30ea\u30cd\u30fc\u30e0\u3059\u308b\u30d1\u30bf\u30fc\u30f3\u304c\u5f37\u529b\u3067\u3059\u3002\u4f8b\u3048\u3070 <code>[K in keyof T as T[K] extends string ? K : never]<\/code> \u306e\u3088\u3046\u306b\u66f8\u3044\u3066\u6587\u5b57\u5217\u578b\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3060\u3051\u3092\u62bd\u51fa\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Q5. never\u578b\u304c\u6761\u4ef6\u578b\u306e\u4e2d\u3067\u300c\u6d88\u3048\u308b\u300d\u306e\u306f\u306a\u305c\u3067\u3059\u304b\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>A.<\/strong> TypeScript\u3067\u306f <code>A | never<\/code> \u306f <code>A<\/code> \u3068\u540c\u7b49\u3067\u3059\u3002Union\u578b\u306bnever\u304c\u542b\u307e\u308c\u308b\u3068\u81ea\u52d5\u7684\u306b\u53d6\u308a\u9664\u304b\u308c\u307e\u3059\u3002\u307e\u305f\u5206\u914d\u7684\u6761\u4ef6\u578b\u3067\u306f\u3001never\u3092\u578b\u5909\u6570\u306b\u6e21\u3059\u3068\u300c\u5206\u914d\u3059\u308b\u30e1\u30f3\u30d0\u30fc\u304c0\u500b\u300d\u3068\u3044\u3046\u72b6\u614b\u306b\u306a\u308b\u305f\u3081\u3001\u7d50\u679c\u3082never\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u308c\u306fExclude\u306a\u3069\u306e\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u578b\u3067\u610f\u56f3\u7684\u306b\u5229\u7528\u3055\u308c\u3066\u3044\u307e\u3059\uff08\u9664\u5916\u3057\u305f\u3044\u578b\u3092never\u306b\u3059\u308b\u3053\u3068\u3067Union\u304b\u3089\u53d6\u308a\u9664\u304f\uff09\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n  <ul class=\"wp-block-list\">\n    <li><strong>\u57fa\u672c\u69cb\u6587<\/strong>\uff1a<code>T extends U ? X : Y<\/code> \u3067T\u304cU\u306e\u30b5\u30d6\u30bf\u30a4\u30d7\u304b\u3092\u5224\u5b9a\u3057\u3066\u578b\u3092\u5206\u5c90\u3055\u305b\u308b\u3002<\/li>\n    <li><strong>Union Distribution\uff08\u5206\u914d\uff09<\/strong>\uff1aT\u304c\u578b\u5909\u6570\u3067Union\u578b\u306e\u5834\u5408\u3001\u5404\u30e1\u30f3\u30d0\u30fc\u306b\u500b\u5225\u306b\u6761\u4ef6\u578b\u304c\u9069\u7528\u3055\u308c\u308b\u3002Extract\u3084Exclude\u306f\u3053\u308c\u3092\u5229\u7528\u3002<\/li>\n    <li><strong>\u5206\u914d\u306e\u6291\u5236<\/strong>\uff1a<code>[T] extends [U]<\/code> \u306e\u3088\u3046\u306b\u30bf\u30d7\u30eb\u3067\u30e9\u30c3\u30d7\u3059\u308b\u3068\u5206\u914d\u3092\u6291\u5236\u3002never\u306e\u30c1\u30a7\u30c3\u30af\u306b\u91cd\u8981\u3002<\/li>\n    <li><strong>infer<\/strong>\uff1a\u6761\u4ef6\u90e8\u3067\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u3057\u305f\u578b\u3092\u5909\u6570\u3068\u3057\u3066\u6355\u6349\u3002ReturnType\u30fbParameters\u30fbUnwrapPromise\u7b49\u306e\u5b9f\u88c5\u306b\u6d3b\u7528\u3002<\/li>\n    <li><strong>\u7d44\u307f\u8fbc\u307f\u578b\u306e\u81ea\u4f5c<\/strong>\uff1aExclude\u30fbExtract\u30fbNonNullable\u30fbParameters\u30fbConstructorParameters\u30fbInstanceType\u5168\u3066Conditional Type\u3067\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b\u3002<\/li>\n    <li><strong>\u518d\u5e30\u7684\u6761\u4ef6\u578b<\/strong>\uff1aTypeScript 4.1\u4ee5\u964d\u3067\u5bfe\u5fdc\u3002DeepPartial\u30fbDeepReadonly\u30fbFlatten\u306a\u3069\u306e\u6df1\u3044\u5909\u63db\u578b\u304c\u5b9f\u88c5\u53ef\u80fd\u3002<\/li>\n    <li><strong>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30ea\u30c6\u30e9\u30eb\u578b\u3068\u306e\u7d44\u307f\u5408\u308f\u305b<\/strong>\uff1aSplit\u30fbJoin\u30fbCamelToSnake\u30fbPaths\u306a\u3069\u5f37\u529b\u306a\u6587\u5b57\u5217\u578b\u64cd\u4f5c\u304c\u53ef\u80fd\u3002<\/li>\n    <li><strong>\u3088\u304f\u3042\u308b\u843d\u3068\u3057\u7a74<\/strong>\uff1anever\u306eDistribution\u30fbany\u306e\u6319\u52d5\u30fb\u95a2\u6570\u306e\u5f15\u6570\u306eIntersection\u5316\u306b\u6ce8\u610f\u3002<\/li>\n  <\/ul>\n\n\n\n  <p class=\"wp-block-paragraph\"><strong><span class=\"swl-marker mark_yellow\">Conditional Type\u306fTypeScript\u306e\u300c\u578b\u3092\u30d7\u30ed\u30b0\u30e9\u30e0\u3059\u308b\u300d\u6a5f\u80fd\u306e\u4e2d\u6838\u3067\u3059\u3002\u307e\u305a\u306fReturnType\u30fbExtract\u30fbExclude\u3092\u81ea\u4f5c\u3057\u3066\u52d5\u4f5c\u3092\u4f53\u611f\u3057\u3066\u304b\u3089\u3001infer\u3092\u4f7f\u3063\u305fUnwrapPromise\u3084DeepPartial\u306e\u5b9f\u88c5\u306b\u6311\u6226\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u578b\u30d1\u30ba\u30eb\u3092\u697d\u3057\u307f\u306a\u304c\u3089\u5b66\u3076\u3068\u7406\u89e3\u304c\u6df1\u307e\u308a\u307e\u3059\u3002<\/span><\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">WithCode\u3092\u4f53\u9a13\u3067\u304d\u308b\u521d\u7d1a\u30b3\u30fc\u30b9\u516c\u958b\u4e2d\uff01<\/h2>\n\n\n\n  <div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n  <div class=\"wp-block-button\"><a class=\"wp-block-button__link has-white-color has-text-color has-background wp-element-button\" href=\"https:\/\/withcode.tech\/reservation\/\" style=\"background-color:#ffbf00\"><strong>\u516c\u5f0f\u30b5\u30a4\u30c8\u304b\u3089\u7121\u6599\u30ab\u30a6\u30f3\u30bb\u30ea\u30f3\u30b0\u306b\u7533\u3057\u8fbc\u3080 \u2192<\/strong><\/a><\/div>\n  <\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>TypeScript Conditional Type\uff08T extends U ? X : Y\uff09\u306e\u57fa\u672c\u304b\u3089\u5fdc\u7528\u307e\u3067\u5b8c\u5168\u89e3\u8aac\u3002Union Distribution\u30fbinfer\u306b\u3088\u308b\u578b\u62bd\u51fa\u30fbDeepPartial\/DeepReadonly\u306a\u3069\u518d\u5e30\u7684\u6761\u4ef6\u578b\u306e\u5b9f\u88c5\u30fb\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30ea\u30c6\u30e9\u30eb\u578b\u3068\u306e\u7d44\u307f\u5408\u308f\u305b\u30fb\u3088\u304f\u3042\u308b\u843d\u3068\u3057\u7a74\u307e\u3067\u5b9f\u8df5\u30b3\u30fc\u30c9\u4ed8\u304d\u3067\u7db2\u7f85\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"swell_btn_cv_data":"","footnotes":"","vk-ltc-link":"","vk-ltc-target":"0"},"categories":[34,359],"tags":[],"class_list":["post-13201","post","type-post","status-publish","format-standard","hentry","category-programming","category-javascript-programming"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/withcode.tech\/media\/wp-json\/wp\/v2\/posts\/13201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/withcode.tech\/media\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/withcode.tech\/media\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/withcode.tech\/media\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/withcode.tech\/media\/wp-json\/wp\/v2\/comments?post=13201"}],"version-history":[{"count":2,"href":"https:\/\/withcode.tech\/media\/wp-json\/wp\/v2\/posts\/13201\/revisions"}],"predecessor-version":[{"id":13995,"href":"https:\/\/withcode.tech\/media\/wp-json\/wp\/v2\/posts\/13201\/revisions\/13995"}],"wp:attachment":[{"href":"https:\/\/withcode.tech\/media\/wp-json\/wp\/v2\/media?parent=13201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/withcode.tech\/media\/wp-json\/wp\/v2\/categories?post=13201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/withcode.tech\/media\/wp-json\/wp\/v2\/tags?post=13201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}