{"id":10117,"date":"2020-04-19T09:16:57","date_gmt":"2020-04-19T00:16:57","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=10117"},"modified":"2023-05-27T23:28:01","modified_gmt":"2023-05-27T14:28:01","slug":"%e3%80%90typescript%e3%80%91%e3%80%8c%e3%82%a8%e3%82%a4%e3%83%aa%e3%82%a2%e3%82%b9%e5%9e%8btype%ef%bc%89%e3%80%8d%e3%80%81%e3%80%8cinterface%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=10117","title":{"rendered":"\u3010TypeScript\u3011\u300c\u30a8\u30a4\u30ea\u30a2\u30b9\u578b(type\uff09\u300d\u3001\u300cinterface\u300d\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>\u30a8\u30a4\u30ea\u30a2\u30b9\u578b(type)<\/h2>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u30a8\u30a4\u30ea\u30a2\u30b9\u540d\u306e\u5148\u982d\u6587\u5b57\u306f\u5927\u6587\u5b57\u306b\u3059\u308b<\/strong><\/span>\u306e\u304c\u898f\u5247\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u6c17\u3092\u3064\u3051\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"lang:default decode:true \">type \u30a8\u30a4\u30ea\u30a2\u30b9\u540d = :\u65e2\u5b58\u306e\u578b;<\/pre>\n<h3>\u5b9f\u88c5\u4f8b<\/h3>\n<pre class=\"lang:default decode:true \">type Str = :string;<\/pre>\n<h3>typeof\u306b\u3064\u3044\u3066<\/h3>\n<p class=\"p1\"><span style=\"color: #ff0000;\"><strong>\u300c\u5909\u6570\u540d<span class=\"s1\">2<\/span>\u306e\u578b\u300d\u3092\u62bd\u51fa\u3057\u3066\u300c\u5909\u6570\u540d<span class=\"s1\">1<\/span>\u306e\u578b\u300d\u306b\u4ee3\u5165\u3059\u308b\u4e8b\u304c\u53ef\u80fd<\/strong><\/span>\u3067\u3059\u3002\u4eee\u306b\u5909\u6570\u540d<span class=\"s1\">2<\/span>\u306e\u578b\u304c\u4eca\u5f8c\u5909\u66f4\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u3063\u305f\u3068\u3057\u3066\u3082<span class=\"s1\">typeof<\/span>\u3092\u4f7f\u3063\u3066\u8a18\u8ff0\u3057\u3066\u3044\u308c\u3070\u8ffd\u5f93\u3057\u3066\u5408\u308f\u305b\u308b\u4e8b\u304c\u53ef\u80fd\u306b\u306a\u308a\u4fdd\u5b88\u6027\u304c\u4e0a\u304c\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">type \u5909\u6570\u540d1 = typeof \u5909\u6570\u540d2;<\/pre>\n<h3>\u4ea4\u5dee\u578b(intersection\u578b)<\/h3>\n<p><span style=\"color: #ff0000;\"><strong>\u65e2\u5b58\u306e\u578b\u3092\u751f\u304b\u3057\u3064\u3064\u65b0\u305f\u306a\u578b\u3092\u4f5c\u3063\u3066\u3044\u304f\u5408\u7406\u7684\u306a\u578b<\/strong><\/span>\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4>\u5b9f\u88c5\u4f8b<\/h4>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306b\u65e2\u5b58\u306e\u578b\u3092&amp;\u3092\u4f7f\u3063\u3066\u7d50\u5408\u3057\u3066\u65b0\u305f\u306a\u578b\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">type a = {\r\n  name: string;\r\n};\r\n\r\ntype b = {\r\n  age: number;\r\n};\r\n\r\ntype c = a &amp; b;\r\n\r\nconst d: c = {\r\n  name: '\u7530\u4e2d',\r\n  age: 24,\r\n};<\/pre>\n<h2>interface<\/h2>\n<p class=\"p1\"><span class=\"s1\">type<\/span>\u3068\u307b\u307c\u540c\u3058\u4f7f\u3044\u9053\u3067<span class=\"s1\">interface<\/span>\u304c\u3042\u308a\u307e\u3059\u3002type\u306fstring\u3084number\u306a\u3069\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u4ee5\u5916\u306e\u5225\u540d\u3068\u3044\u3046\u3088\u3046\u306a\u7528\u9014\u3067\u3082\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u304c\u3001<span style=\"color: #ff0000;\"><strong>interface\u306e\u7528\u9014\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u9650\u3089\u308c\u307e\u3059\u3002<\/strong><\/span><\/p>\n<pre class=\"lang:default decode:true\">interface \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u540d {\r\n  \u5909\u65701: \u30c7\u30fc\u30bf\u578b1;\r\n  \u5909\u65702: \u30c7\u30fc\u30bf\u578b2;\r\n}<\/pre>\n<h3>readonly<\/h3>\n<p>class\u69cb\u6587\u3068\u304b\u3067\u4f7f\u3048\u308breadonly\u306f\u666e\u901a\u306binterface\u306b\u3082\u3064\u3051\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">interface \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u540d {\r\n  readonly \u5909\u65701: \u30c7\u30fc\u30bf\u578b1;\r\n}<\/pre>\n<h3>\u7d99\u627f<\/h3>\n<pre class=\"lang:default decode:true \">interface \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u540d extends \u5225\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u540d {\r\n  \u5909\u65701: \u30c7\u30fc\u30bf\u578b1;\r\n}<\/pre>\n<p>\u306a\u304a\u3001\u7d99\u627f\u3055\u305b\u308b\u5bfe\u8c61\u306finterface\u3067\u3082type\u3067\u3082\u3069\u3061\u3089\u3082\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u30e1\u30ea\u30c3\u30c8<\/h3>\n<h4>\u308f\u304b\u308a\u3084\u3059\u3044\u3002<\/h4>\n<p>interface\u306ftype\u3068\u9055\u3063\u3066\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3057\u304b\u6271\u3048\u307e\u305b\u3093\u3002\u306a\u306e\u3067interface\u3092\u4f7f\u3063\u3066\u3044\u308b\u5834\u5408\u306fobject\u306a\u306e\u3060\u306a\u3068\u3059\u3050\u306b\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3066type\u306b\u6bd4\u3079\u3066\u4ed6\u306e\u958b\u767a\u8005\u306e\u7406\u89e3\u3078\u3082\u512a\u3057\u3044\u6587\u6cd5\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4>\u62e1\u5f35\u6027\u304c\u9ad8\u3044<\/h4>\n<pre class=\"lang:default decode:true\">interface person {\r\n  name: string;\r\n  age: number;\r\n}\r\n\r\ninterface person {\r\n\u3000\u3000height: number;\r\n}\r\n\r\n----\u2193\u2193\u2193\u3053\u3046\u306a\u3063\u3066\u3044\u308b\u3002\u2193\u2193\u2193----\r\n\r\ninterface person {\r\n  name: string;\r\n  age: number;\r\n\u3000\u3000height: number;\r\n}\u3067<\/pre>\n<h3>\u30c7\u30e1\u30ea\u30c3\u30c8<\/h3>\n<p>\u77e5\u3089\u306a\u3044\u9593\u306b\u62e1\u5f35\u3055\u308c\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002<\/p>\n<h3 class=\"p1\"><span class=\"s1\">type<\/span>\u3068\u306e\u4f7f\u3044\u5206\u3051\u306f\uff1f<\/h3>\n<p class=\"p1\">\u4e00\u6982\u306b\u3069\u3061\u3089\u3092\u4f7f\u3048\u3070\u826f\u3044\u3068\u3044\u3046\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3057\u3001\u307b\u3068\u3093\u3069\u9055\u3044\u306f\u306a\u3044\u3067\u3059\u3002<\/p>\n<p>\u305f\u3060\u3001<span style=\"color: #ff0000;\"><strong>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3084class\u3092\u4f7f\u3046\u5834\u5408\u306finterface\u3092\u4f7f\u3063\u305f\u65b9\u304c\u826f\u3044<\/strong><\/span>\u3067\u3057\u3087\u3046\u3002\u306a\u305c\u306a\u3089type\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u4ee5\u5916\u306b\u3082\u30c7\u30fc\u30bf\u578b\u3092\u6271\u3048\u3066\u3057\u307e\u3046\u306e\u3067\u4ed6\u306e\u958b\u767a\u8005\u306b\u308f\u304b\u308a\u3065\u3089\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u305f\u3081\u3067\u3059\u3002<\/p>\n<p class=\"p1\">\u696d\u52d9\u4e0a\u306f\u3069\u3061\u3089\u306e\u4ed5\u69d8\u3092\u62bc\u3055\u3048\u305f\u4e0a\u3067\u4f7f\u3044\u3084\u3059\u3044\u65b9\u3092\u9078\u3076\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u4e00\u822c\u7684\u306b\u306f<span class=\"s1\">interface<\/span>\u306e\u65b9\u304c\u3088\u304f\u5229\u7528\u3055\u308c\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<span class=\"s1\">interface<\/span>\u306b\u306f\u65e2\u5b58\u306e\u578b\u3092\u62e1\u5f35\u3059\u308b\u4e8b\u304c\u3067\u304d\u308b<span style=\"color: #ff0000;\"><strong>\u300c\u30de\u30fc\u30b8\u6a5f\u80fd\u300d<\/strong><\/span>\u3068\u3044\u3046\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u30a8\u30a4\u30ea\u30a2\u30b9\u578b(type) \u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002\u30a8\u30a4\u30ea\u30a2\u30b9\u540d\u306e\u5148\u982d\u6587\u5b57\u306f\u5927\u6587\u5b57\u306b\u3059\u308b\u306e\u304c\u898f\u5247\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u6c17\u3092\u3064\u3051\u307e\u3057\u3087\u3046\u3002 type \u30a8\u30a4\u30ea\u30a2\u30b9\u540d = :\u65e2\u5b58\u306e\u578b; \u5b9f\u88c5\u4f8b type Str = :string;  [&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\/10117"}],"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=10117"}],"version-history":[{"count":11,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/10117\/revisions"}],"predecessor-version":[{"id":20606,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/10117\/revisions\/20606"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10117"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}