{"id":10121,"date":"2020-04-19T09:24:18","date_gmt":"2020-04-19T00:24:18","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=10121"},"modified":"2023-05-02T22:48:33","modified_gmt":"2023-05-02T13:48:33","slug":"%e3%80%90typescript%e3%80%91%e3%80%8cunknown%e5%9e%8b%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=10121","title":{"rendered":"\u3010TypeScript\u3011\u300cunknown\u578b\u300d\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>unknown\u578b\u3068\u306f\uff1f<\/h2>\n<p>\u300cnumber\u578b\u304b\u3082\u3057\u308c\u306a\u3044\u300d\u3001\u300cstring\u578b\u304b\u3082\u3057\u308c\u306a\u3044\u300d\u3068\u3044\u3046\u66d6\u6627\u306a\u578b\u306e\u3053\u3068\u3067\u3059\u3002TypeScript3.0\u3067\u5c0e\u5165\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p class=\"p1\"><span class=\"s1\">unknown<\/span>\u3092\u6307\u5b9a\u3059\u308b\u3068<span style=\"color: #ff0000;\"><strong>\u578b\u5b89\u5168\u304c\u4fdd\u969c\u3055\u308c\u308b\u30b3\u30fc\u30c9\u3067\u306a\u3051\u308c\u3070\u30b3\u30f3\u30d1\u30a4\u30eb\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059<\/strong><\/span>\u3002\u305f\u3060\u3001\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u30a8\u30e9\u30fc\u306b\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001\u3067\u304d\u308b\u3060\u3051\u5177\u4f53\u7684\u306a\u578b\u3092\u6307\u5b9a\u3057\u305f\u65b9\u304c\u826f\u3044\u3067\u3059\u3002<\/p>\n<h3>any\u3068\u4f3c\u3066\u3044\u308b<\/h3>\n<p>any\u3068\u540c\u3058\u3088\u3046\u306bnumber\u3067\u3082string\u3067\u3082\u306a\u3093\u3067\u3082\u5165\u308c\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3001any\u306b\u6bd4\u3079\u308b\u3068\u4f7f\u3046\u6642\u306b\u578b\u304c\u9055\u3063\u3066\u3044\u308b\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308b\u306e\u3067\u5c11\u3057\u53b3\u3057\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>\u30a8\u30e9\u30fc\u306b\u306a\u308b\u4f8b<\/h3>\n<pre class=\"lang:default decode:true \">const a = (): number =&gt; 2;\r\n\r\nlet c: unknown = a();\r\nlet c = b + 10;<\/pre>\n<p>\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>\u30a8\u30e9\u30fc\u306b\u306a\u3089\u306a\u3044\u4f8b<\/h3>\n<h3>typeof\u306b\u3088\u308b\u30bf\u30a4\u30d7\u30ac\u30fc\u30c9<\/h3>\n<p class=\"p1\"><span style=\"color: #ff0000;\"><strong>\u30bf\u30a4\u30d7\u30bb\u30fc\u30d5\uff08\u4f8b\uff1atypeof\u306b\u3088\u308a\u30c1\u30a7\u30c3\u30af\u3092\u3059\u308b\u3053\u3068\u3067\u3001\u7d76\u5bfe\u306bnumber\u578b\u306a\u3069\u3060\u3068\u308f\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u306e\u307f\u8a31\u3059\uff09<\/strong><\/span>\u3092\u8a18\u8ff0\u3059\u308b\u4e8b\u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u30a8\u30e9\u30fc\u304b\u3089\u56de\u907f\u3059\u308b\u4e8b\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">const a = (): number =&gt; 2;\r\n\r\nlet c: unknown = a();\r\nif (typeof c === 'number') {\r\n  let c = 10;\r\n}<\/pre>\n<h3>as(\u578b\u30a2\u30b5\u30fc\u30b7\u30e7\u30f3)\u3092\u4f7f\u3046<\/h3>\n<pre class=\"lang:default decode:true\">const a = (): number =&gt; 2;\r\n\r\nlet c: unknown = a();\r\n(c as number) = 10;\u305f<\/pre>\n<p>\u305f\u3060\u3001\u578b\u30a2\u30b5\u30fc\u30b7\u30e7\u30f3\u306f\u7121\u7406\u77e2\u7406\u4efb\u610f\u306e\u578b\u306b\u4e0a\u66f8\u304d\u3059\u308b\u884c\u70ba\u306a\u306e\u3067\u305d\u3082\u305d\u3082\u4f7f\u3046\u3053\u3068\u304c\u3042\u307e\u308a\u63a8\u5968\u3055\u308c\u307e\u305b\u3093\u3002\u578b\u5909\u63db\u81ea\u4f53\u306b\u554f\u984c\u304c\u3042\u3063\u305f\u3068\u3057\u3066\u3082\u305d\u306e\u5909\u63db\u304c\u8aa4\u3063\u3066\u3044\u308b\u3053\u3068\u3092\u5b9f\u884c\u6642\u306b\u521d\u3081\u3066\u6c17\u3065\u304f\u3053\u3068\u306b\u306a\u308b\u305f\u3081\u3067\u3059\u3002<\/p>\n<p>\u3067\u304d\u308b\u3060\u3051typeof\u306b\u3088\u308b\u30bf\u30a4\u30d7\u30ac\u30fc\u30c9\u3092\u5229\u7528\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>any\u3060\u3068\u578b\u304c\u8aa4\u3063\u3066\u3044\u3066\u3082\u5b9f\u884c\u6642\u306b\u3057\u304b\u6c17\u3065\u3051\u307e\u305b\u3093\u304c\u3001unknown\u3060\u3068\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u6c17\u3065\u304f\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067any\u3088\u308a\u306f\u826f\u3044\u3067\u3059\u3088\u3068\u3044\u3046\u611f\u3058\u306b\u306a\u308a\u307e\u3059\u3002\uff08\u3088\u308a\u30bf\u30a4\u30d7\u30bb\u30fc\u30d5\u306b\u306a\u3063\u305fany\u3068\u8a00\u3046\u4f4d\u7f6e\u4ed8\u3051\uff09<\/p>\n<p>\u305f\u3060\u3001\u3067\u304d\u308c\u3070any\u3082unknown\u3082\u3069\u3061\u3089\u3082\u4e0d\u5b9a\u578b\u306b\u306f\u306a\u308b\u306e\u3067\u4f7f\u308f\u306a\u3044\u3053\u3068\u306b\u306f\u8d8a\u3057\u305f\u3053\u3068\u306f\u306a\u3044\u3067\u3059\u3002\u65e2\u5b58\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067\u4f7f\u308f\u308c\u3044\u305f\u5834\u5408\u306b\u3053\u306e\u3088\u3046\u306a\u5bfe\u51e6\u6cd5\u3092\u3068\u308c\u3070\u5bfe\u5fdc\u3067\u304d\u308b\u3068\u8a00\u3046\u3053\u3068\u3060\u3051\u306f\u899a\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u7279\u306b\u5916\u90e8\u30d1\u30c3\u30b1\u30fc\u30b8\u306a\u3069\u5916\u90e8\u306e\u30bd\u30fc\u30b9\u3092\u53d6\u308a\u8fbc\u3080\u3068\u304d\u306b\u906d\u9047\u3057\u3084\u3059\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002any\u3092\u8fd4\u3059\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u95a2\u6570\u306a\u3069\u304c\u3042\u3063\u305f\u5834\u5408\u306b\u4e00\u5ea6unknown\u3067\u53d7\u3051\u3066\u30bf\u30a4\u30d7\u30ac\u30fc\u30c9\u3092\u884c\u3046\u307f\u305f\u3044\u306a\u6d41\u308c\u304c\u826f\u3044\u306e\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"unknown\u578b\u3068\u306f\uff1f \u300cnumber\u578b\u304b\u3082\u3057\u308c\u306a\u3044\u300d\u3001\u300cstring\u578b\u304b\u3082\u3057\u308c\u306a\u3044\u300d\u3068\u3044\u3046\u66d6\u6627\u306a\u578b\u306e\u3053\u3068\u3067\u3059\u3002TypeScript3.0\u3067\u5c0e\u5165\u3055\u308c\u307e\u3057\u305f\u3002 unknown\u3092\u6307\u5b9a\u3059\u308b\u3068\u578b\u5b89\u5168\u304c\u4fdd\u969c\u3055\u308c\u308b\u30b3\u30fc\u30c9\u3067\u306a\u3051\u308c\u3070\u30b3 [&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\/10121"}],"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=10121"}],"version-history":[{"count":6,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/10121\/revisions"}],"predecessor-version":[{"id":19469,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/10121\/revisions\/19469"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10121"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}