{"id":13322,"date":"2021-03-14T19:37:15","date_gmt":"2021-03-14T10:37:15","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=13322"},"modified":"2023-05-27T23:25:26","modified_gmt":"2023-05-27T14:25:26","slug":"%e3%80%90typescript%e3%80%91%e3%80%8cexclude%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=13322","title":{"rendered":"\u3010TypeScript\u3011\u300cExclude\u300d\u3001\u300cExtract\u300d\u3001\u300cNonNullable\u300d\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>Exclude\u3068\u306f\uff1f<\/h2>\n<p>TypeScript2.8\u304b\u3089\u5c0e\u5165\u3055\u308c\u305f\u90e8\u5206\u96c6\u5408\u3092\u5b9f\u73fe\u3059\u308bUtility Types\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>\u578b\u5b9a\u7fa9<\/h3>\n<pre class=\"lang:default decode:true\">Exclude&lt;T, U&gt;<\/pre>\n<p>\u7b2c\u4e00\u5f15\u6570\u306eUnion\u578b\u304b\u3089\u7b2c\u4e8c\u5f15\u6570\u306b\u578b\u3092\u6307\u5b9a\u3057\u3066\u9664\u5916\u3057\u3066\u65b0\u305f\u306a\u578b\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">type testType = string | number;\r\ntype stringType = Exclude&lt;testType, number&gt;;<\/pre>\n<p>\u4f8b\u3048\u3070\u3001\u4e0a\u8a18\u306e\u4f8b\u3067\u8a00\u3048\u3070\u3001stringType\u306fnumber\u578b\u304c\u9664\u5916\u3055\u308c\u3066string\u578b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>Extract\u3068\u306f\uff1f<\/h2>\n<p>\u3053\u308c\u3082Exclude\u3068\u540c\u3058\u304fTypeScript2.8\u304b\u3089\u5c0e\u5165\u3055\u308c\u305f\u90e8\u5206\u96c6\u5408\u3092\u5b9f\u73fe\u3059\u308bUtility Types\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>\u578b\u5b9a\u7fa9<\/h3>\n<pre class=\"lang:default decode:true\">Extract&lt;T, U&gt;<\/pre>\n<p>\u9006\u306b\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3059\u308c\u3070Union\u578b\u304b\u3089\u7279\u5b9a\u306e\u578b\u306e\u307f\u3092\u53d6\u308a\u51fa\u3059\u3068\u3044\u3063\u305f\u3053\u3068\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">type testType = string | number;\r\ntype numberType = Extract&lt;testType, number&gt;;<\/pre>\n<p>\u4e0a\u8a18\u4f8b\u3067\u8a00\u3048\u3070\u3001testType\u304b\u3089number\u578b\u3092\u53d6\u308a\u51fa\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3060\u3051\u3067\u306f\u4f55\u304c\u4fbf\u5229\u306a\u306e\u304b\u3088\u304f\u308f\u304b\u308a\u307e\u305b\u3093\u3088\u306d\u3002\u4f8b\u3048\u3070\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b<span style=\"color: #ff0000;\"><strong>Function<\/strong><\/span>\u306e\u578b\u3060\u3051\u3092\u53d6\u308a\u51fa\u3059\u3068\u3044\u3063\u305f\u6307\u5b9a\u3082\u3067\u304d\u305f\u308a\u3059\u308b\u306e\u3067\u305d\u3046\u3044\u3046\u5834\u5408\u306b\u304b\u306a\u308a\u4fbf\u5229\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">type functionType1 = () =&gt; void;\r\ntype functionType2 = () =&gt; number;\r\ntype functionUnion = functionType1 | functionType2 | number;\r\ntype functionType3 = Extract&lt;functionUnion, Function&gt;;\r\n<\/pre>\n<h2>NonNullable\u3068\u306f\uff1f<\/h2>\n<p>\u3053\u308c\u306fTypeScript2.0\u304b\u3089\u5c0e\u5165\u3055\u308c\u307e\u3057\u305f\u3002undefined\u3084null\u306f\u5b9f\u88c5\u30b3\u30fc\u30c9\u4e0a\u306e\u30ea\u30b9\u30af\u306b\u306a\u308b\u306e\u3067\u53d6\u308a\u9664\u304d\u307e\u3057\u3087\u3046\u3068\u3044\u3046\u601d\u60f3\u3067\u3059\u3002<\/p>\n<h3>\u578b<\/h3>\n<pre class=\"lang:default decode:true \">NonNullable&lt;T&gt;<\/pre>\n<p>null\u3068undefined\u3092Union\u578b\u304b\u3089\u9664\u5916\u3057\u3066\u304f\u308c\u308b\u578b\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">type testType = string | number | null | undefined;\r\ntype NonNullType = NonNullable&lt;testType&gt;;<\/pre>\n<p>NonNullable\u306e\u5f15\u6570\u306b\u578b\u3092\u6307\u5b9a\u3059\u308b\u3068\u305d\u306e\u6307\u5b9a\u3057\u305f\u578b\u304b\u3089null\u3068undefined\u3092\u9664\u5916\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Exclude\u3068\u306f\uff1f TypeScript2.8\u304b\u3089\u5c0e\u5165\u3055\u308c\u305f\u90e8\u5206\u96c6\u5408\u3092\u5b9f\u73fe\u3059\u308bUtility Types\u306b\u306a\u308a\u307e\u3059\u3002 \u578b\u5b9a\u7fa9 Exclude&lt;T, U&gt; \u7b2c\u4e00\u5f15\u6570\u306eUnion\u578b\u304b\u3089\u7b2c\u4e8c\u5f15\u6570\u306b\u578b\u3092\u6307\u5b9a\u3057\u3066\u9664\u5916 [&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\/13322"}],"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=13322"}],"version-history":[{"count":8,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13322\/revisions"}],"predecessor-version":[{"id":20601,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13322\/revisions\/20601"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13322"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}