{"id":13299,"date":"2021-02-28T18:07:00","date_gmt":"2021-02-28T09:07:00","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=13299"},"modified":"2023-05-27T23:26:44","modified_gmt":"2023-05-27T14:26:44","slug":"%e3%80%90typescript%e3%80%91%e3%80%8crecord%e3%80%8d%e5%9e%8b%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=13299","title":{"rendered":"\u3010TypeScript\u3011\u300cRecord\u300d\u578b\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>Record\u578b\u3068\u306f\uff1f<\/h2>\n<p>Mapped Types\u3092\u6271\u3046Utility Types\u306e\u4e00\u3064\u3067\u3001\u5165\u308c\u5b50\u306b\u306a\u3063\u3066\u3044\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u578b\u5b9a\u7fa9\u3092\u3059\u3063\u304d\u308a\u66f8\u304f\u305f\u3081\u306e\u3082\u306e\u3067\u3059\u3002TypeScript2.1\u3067\u8ffd\u52a0\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<h2>\u69cb\u6587<\/h2>\n<pre class=\"lang:default decode:true \">Record&lt;K,T&gt;<\/pre>\n<h3>K<\/h3>\n<p>\u30e6\u30cb\u30aa\u30f3\u578b\u306e\u30c7\u30fc\u30bf\u3092\u6301\u305f\u305b\u3066\u3042\u3052\u307e\u3059\u3002\uff08\u4f8b\uff1a'apple' | 'peach' | 'strawberry'\u306e\u3088\u3046\u306a\u578b\u306e\u3053\u3068\u3067\u3059\u3002\uff09<\/p>\n<h3>T<\/h3>\n<p>\u5165\u308c\u5b50\u306b\u306a\u3063\u3066\u3044\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5185\u5074\u306e\u30aa\u30d6\u30b8\u30a7\u30aft\u306e\u30c7\u30fc\u30bf\u578b\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<h4>\u4f8b<\/h4>\n<pre class=\"lang:default decode:true \">interface Person {\r\n  name: string;\r\n  age: number;\r\n}<\/pre>\n<p>\u6ce8\u610f\u70b9\u3068\u3057\u3066\u306f\u3001Record\u578b\u306f\u305d\u3053\u307e\u3067\u53b3\u5bc6\u3067\u306f\u306a\u3044\u306e\u3067\u3001\u4e0a\u8a18\u306ePerson\u3068\u304b\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u306a\u3044\u30ad\u30fc\u306b\u3082\u30a2\u30af\u30bb\u30b9\u304c\u3067\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u3002\uff08\u4f8b\uff1aage\u306a\u3069\uff09\u305d\u306e\u5834\u5408\u306fundefined\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u7528\u9014<\/h2>\n<p>\u4f8b\u3048\u3070\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u578b\u306e\u4e2d\u306b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u578b\u3092\u3044\u304f\u3064\u304b\u683c\u7d0d\u3059\u308b\u30b1\u30fc\u30b9\u304c\u3042\u3063\u305f\u5834\u5408\u306b\u5185\u5074\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u578b\u5b9a\u7fa9\u3092\u3057\u305f\u3044\u5834\u5408\u306f\u4e00\u3064\u4e00\u3064\u540c\u3058\u578b\u8868\u8a18\u3092\u4f55\u5ea6\u3082\u7e70\u308a\u8fd4\u3055\u306a\u3044\u3068\u3044\u3051\u307e\u305b\u3093\u3002<\/p>\n<pre class=\"lang:default decode:true\">interface Person {\r\n  name: string;\r\n  age: number;\r\n}\r\n\r\nconst member:{\r\n  one:Person,\r\n  two:Person,\r\n  three:Person,\r\n  four:Person,\r\n} = {\r\n  one: { name:'taro',age:12 },\r\n  two: { name:'hanako',age:15 },\r\n  three: { name:'saburo',age:18 },\r\n  four: { name:'siro',age:17 },\r\n}<\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u4fee\u6b63\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">interface Person {\r\n  name: string;\r\n  age: number;\r\n}\r\n\r\ntype members = 'one' | 'two' | 'three' | 'four'\r\n\r\nconst member:Record&lt;members,Person&gt; = {\r\n  one: { name:'taro',age:12 },\r\n  two: { name:'hanako',age:15 },\r\n  three: { name:'saburo',age:18 },\r\n  four: { name:'siro',age:17 },\r\n}<\/pre>\n<p>\u540c\u3058\u3088\u3046\u306a\u8a18\u8ff0\u304c\u306a\u304f\u306a\u3063\u3066\u3059\u3063\u304d\u308a\u66f8\u304d\u76f4\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Record\u578b\u3068\u306f\uff1f Mapped Types\u3092\u6271\u3046Utility Types\u306e\u4e00\u3064\u3067\u3001\u5165\u308c\u5b50\u306b\u306a\u3063\u3066\u3044\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u578b\u5b9a\u7fa9\u3092\u3059\u3063\u304d\u308a\u66f8\u304f\u305f\u3081\u306e\u3082\u306e\u3067\u3059\u3002TypeScript2.1\u3067\u8ffd\u52a0\u3055\u308c\u307e\u3057\u305f\u3002 \u69cb\u6587 Record [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[101],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13299"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13299"}],"version-history":[{"count":5,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13299\/revisions"}],"predecessor-version":[{"id":20602,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13299\/revisions\/20602"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13299"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}