{"id":13279,"date":"2021-02-28T10:52:37","date_gmt":"2021-02-28T01:52:37","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=13279"},"modified":"2023-05-27T23:27:14","modified_gmt":"2023-05-27T14:27:14","slug":"%e3%80%90typescript%e3%80%91%e3%80%8cpartial%e3%80%8d%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=13279","title":{"rendered":"\u3010typescript\u3011\u300cPartial\u300d\u3001\u300cRequired\u300d\u3001\u300cReadonly\u300d\u306b\u3064\u3044\u3066"},"content":{"rendered":"<p>TypeScript2.1\u304b\u3089Utility Types\uff08\u4fbf\u5229\u306a\u95a2\u6570\u306e\u3088\u3046\u306a\u578b\u306e\u3053\u3068\uff09\u3068\u3044\u3046\u6a5f\u80fd\u304c\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u3059\u3002Partial\u3084Required\u3001ReadOnly\u306f\u305d\u306e\u3046\u3061\u306e\u4e00\u3064\u3067\u3059\u3002<\/p>\n<h2>Partial\u3068\u306f\uff1f<\/h2>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306bPartial\u3068\u3044\u3046\u69cb\u6587\u3092\u4f7f\u7528\u3057\u3066\u578b\u3092\u4f5c\u308b\u3068\u30b8\u30a7\u30cd\u30ea\u30af\u30b9\u3067\u6307\u5b9a\u3057\u305f\u578b\u3092\u52d5\u7684\u306b\u30aa\u30d7\u30b7\u30e7\u30f3\u578b\u306b\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">type Person = {\r\n  name: string;\r\n  age: number;\r\n}\r\n\r\ntype PertialType = Partial&lt;Person&gt;;<\/pre>\n<p>\u5b9f\u969bPertialType\u306e\u4e2d\u8eab\u3092\u898b\u3066\u307f\u308b\u3068\u4e0b\u8a18\u306e\u3088\u3046\u306b<span style=\"color: #ff0000;\"><strong>\u5168\u3066\u304c\u30aa\u30d7\u30b7\u30e7\u30f3<\/strong><\/span>\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">type PertialType = {\r\n    name?: string | undefined;\r\n    age?: number | undefined;\r\n}<\/pre>\n<h3>\u6ce8\u610f\u70b9<\/h3>\n<p>\u30cd\u30b9\u30c8\u3055\u308c\u3066\u3044\u3066\u968e\u5c64\u306e\u3042\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u306f\u5bfe\u5fdc\u3057\u3066\u304a\u3089\u305a\u9069\u7528\u3057\u305f\u3068\u3057\u3066\u3082\u30b3\u30f3\u30d1\u30a4\u30eb\u30a8\u30e9\u30fc\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u3042\u304f\u307e\u3067\u968e\u5c64\u306e\u306a\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u3057\u304b\u4f7f\u3048\u306a\u3044\u3067\u3059\u3002<\/p>\n<h2>Required<\/h2>\n<p>Partial\u3068\u306f\u9006\u306b<span style=\"color: #ff0000;\"><strong>\u5168\u3066\u304c\u5fc5\u9808<\/strong><\/span>\u306b\u306a\u3063\u3066\u3044\u308b\u578b\u3092\u4f5c\u308a\u305f\u3044\u5834\u5408\u306fRequired\u3068\u3044\u3046\u69cb\u6587\u3092\u4f7f\u3048\u3070\u52d5\u7684\u306b\u751f\u6210\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">type Person = {\r\n  name: string;\r\n  age?: number;\r\n}\r\n\r\ntype RequiredPerson = Required&lt;Person&gt;;<\/pre>\n<h2>Partial\u3001Required\u306e\u30e1\u30ea\u30c3\u30c8<\/h2>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306b\u624b\u52d5\u3067\u30aa\u30d7\u30b7\u30e7\u30f3\u578b\u3092\u5225\u9014\u7528\u610f\u3059\u308b\u5834\u5408\u306b\u6bd4\u3079\u3066\u30b3\u30fc\u30c9\u306e\u4fdd\u5b88\u6027\u304c\u4e0a\u304c\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">type Person = {\r\n  name: string;\r\n  age: number;\r\n}\r\n\r\ntype Person2 = {\r\n  name?: string;\r\n  age?: number;\r\n}<\/pre>\n<h2>ReadOnly\u3068\u306f\uff1f<\/h2>\n<pre class=\"lang:default decode:true \">type aaa = {\r\n  b: string;\r\n  c: string;\r\n};\r\n\r\nconst ddd: Readonly&lt;aaa&gt; = { b: 'bbb', c: 'ccc' };\r\nddd.b = 'newBBB'; \/\/ Error: Attempt to assign to const or readonly variable<\/pre>\n<p>\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8aad\u307f\u53d6\u308a\u5c02\u7528\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u4e00\u5ea6\u4ee3\u5165\u3057\u305f\u3089\u7d76\u5bfe\u306b\u5024\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u304f\u3067\u304d\u308b\u306e\u3067\u56fa\u5b9a\u5024\u3084\u5b9a\u6570\u306e\u76ee\u7684\u3067\u3082\u4f7f\u3048\u305d\u3046\u3067\u3059\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"TypeScript2.1\u304b\u3089Utility Types\uff08\u4fbf\u5229\u306a\u95a2\u6570\u306e\u3088\u3046\u306a\u578b\u306e\u3053\u3068\uff09\u3068\u3044\u3046\u6a5f\u80fd\u304c\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u3059\u3002Partial\u3084Required\u3001ReadOnly\u306f\u305d\u306e\u3046\u3061\u306e\u4e00\u3064\u3067\u3059\u3002 Partial\u3068\u306f\uff1f \u4e0b\u8a18\u306e\u3088 [&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\/13279"}],"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=13279"}],"version-history":[{"count":5,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13279\/revisions"}],"predecessor-version":[{"id":20604,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13279\/revisions\/20604"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13279"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}