{"id":1631,"date":"2021-08-08T17:53:44","date_gmt":"2021-08-08T08:53:44","guid":{"rendered":"http:\/\/www.agile-software.site\/?p=1631"},"modified":"2023-08-06T12:01:28","modified_gmt":"2023-08-06T03:01:28","slug":"typescript","status":"publish","type":"post","link":"https:\/\/agile-software.net\/?p=1631","title":{"rendered":"TypeScript"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">TypeScript\u3068\u306f\uff1f<\/h2>\n\n\n\n<p>JavaScript\u306b\u578b\u30b7\u30b9\u30c6\u30e0\u3092\u639b\u3051\u5408\u308f\u305b\u305f\u3082\u306e\u3002<br>\u6700\u7d42\u7684\u306b\u306f\u30b3\u30f3\u30d1\u30a4\u30eb\u3067 JavaScript \u306b\u5909\u63db<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"760\" height=\"428\" src=\"http:\/\/www.agile-software.site\/wp-content\/uploads\/2021\/08\/\u30b3\u30f3\u30d1\u30a4\u30eb.png\" alt=\"\" class=\"wp-image-1636\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">.ts\u62e1\u5f35\u5b50\u3068.tsx\u62e1\u5f35\u5b50\u306e\u9055\u3044<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">.ts\u62e1\u5f35\u5b50<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7d14\u7c8b\u306aTypeScript\u30d5\u30a1\u30a4\u30eb<\/li>\n\n\n\n<li>JSX\u8981\u7d20\u306e\u8ffd\u52a0\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u306a\u3044<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">.tsx\u62e1\u5f35\u5b50<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>JSX\u3092\u542b\u3080\u30d5\u30a1\u30a4\u30eb<\/li>\n\n\n\n<li>\u578b\u30a2\u30b5\u30fc\u30b7\u30e7\u30f3\u306e\u8a18\u6cd5\u3068\u3057\u3066&nbsp;<code>value as type<\/code>&nbsp;\u3068&nbsp;<code>&lt;type&gt;value<\/code>&nbsp;\u306e2\u901a\u308a\u3042\u308b\u304c\u3001\u5f8c\u8005\u306f&nbsp;<code>.tsx<\/code>&nbsp;\u306b\u306f\u66f8\u3051\u306a\u3044<br>\uff08&nbsp;<code>&lt;&gt;<\/code>&nbsp;\u306fJSX\u30bf\u30b0\u306e\u30de\u30fc\u30ab\u30fc\u3067\u3042\u308b\u305f\u3081\uff09<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">TypeScript\u306b\u5fc5\u8981\u306a\u3082\u306e<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">Node.js(npm)<\/h4>\n\n\n\n<p>Node.js\u3068\u3044\u3046\u306e\u306fJavaScript\u30a8\u30f3\u30b8\u30f3\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059\u3002<br>\u3053\u308c\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u3067JavaScript\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u30d1\u30bd\u30b3\u30f3\u5185\u3067\u76f4\u63a5\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<br>\u3053\u306eNode.js\u306b\u306f\u69d8\u3005\u306aJavaScript\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u985e\u3092\u7ba1\u7406\u3059\u308b\u30d1\u30c3\u30b1\u30fc\u30b8\u7ba1\u7406\u30c4\u30fc\u30eb\u300cnpm\u300d\u304c\u7d44\u307f\u8fbc\u307e\u308c\u3066\u3044\u307e\u3059\u3002<br>JavaScript\u95a2\u4fc2\u306e\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u306f\u3059\u3079\u3066\u3053\u306enpm\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u5229\u7528\u3067\u304d\u308b\u3068\u3044\u3063\u3066\u3082\u3044\u3044\u3067\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">TypeScript\u672c\u4f53<\/h4>\n\n\n\n<p>npm\u3068\u3044\u3046\u30d1\u30c3\u30b1\u30fc\u30b8\u7ba1\u7406\u30c4\u30fc\u30eb\u3092\u4f7f\u3044\u3001\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Webpack<\/h4>\n\n\n\n<p>Webpack\u306f\u591a\u6570\u306e\u30ea\u30bd\u30fc\u30b9\u985e\u3092\u4e00\u3064\u306b\u307e\u3068\u3081\u308b\u3082\u306e\u3067\u3059\u3002<br>\u672c\u683c\u7684\u306a\u30a2\u30d7\u30ea\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306f\u3053\u306eWebpack\u3092\u4f7f\u3063\u3066\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u751f\u6210\u3059\u308b\u3082\u306e\u304c\u591a\u3044\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">TypeScript\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>npm install -g typescript<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">webpack<\/h2>\n\n\n\n<p>\u8907\u6570\u306e\u30d5\u30a1\u30a4\u30eb\u30921\u3064\u306b\u307e\u3068\u3081\u308b<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ts-loader<\/h2>\n\n\n\n<p>Webpack\u3068\u9023\u52d5\u3057\u3066TypeScript\u30b3\u30f3\u30d1\u30a4\u30e9\u3092\u8d77\u52d5<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">webpack-cil<\/h2>\n\n\n\n<p>\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u3067webpack\u3092\u4f7f\u3048\u308b<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">webpack-dev-server<\/h2>\n\n\n\n<p>Webpack\u306e\u30d3\u30eb\u30c9<br>\u958b\u767a\u7528Web\u30b5\u30fc\u30d0\u30fc\u306e\u8d77\u52d5<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">webpack.config.js<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>const path = require(&#39;path&#39;);\nmodule.exports = {\n  \/\/ \u30e2\u30b8\u30e5\u30fc\u30eb\u30d0\u30f3\u30c9\u30eb\u3092\u884c\u3046\u8d77\u70b9\u3068\u306a\u308b\u30d5\u30a1\u30a4\u30eb\u306e\u6307\u5b9a\n  \/\/ \u6307\u5b9a\u3067\u304d\u308b\u5024\u3068\u3057\u3066\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u6587\u5b57\u5217\u3084\u3001\u305d\u308c\u3092\u4e26\u3079\u305f\u914d\u5217\u3084\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\n  \/\/ \u4e0b\u8a18\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u3057\u3066\u6307\u5b9a\u3057\u305f\u4f8b\n  entry: {\n    bundle: &#39;.\/src\/index.ts&#39;\n  },\n  \/\/ \u30e2\u30b8\u30e5\u30fc\u30eb\u30d0\u30f3\u30c9\u30eb\u3092\u884c\u3063\u305f\u7d50\u679c\u3092\u51fa\u529b\u3059\u308b\u5834\u6240\u3084\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u6307\u5b9a\n  output: {\n    path: path.join(__dirname, &#39;dist&#39;), \/\/ &quot;__dirname&quot;\u306f\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3059\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\n    filename: &#39;[name].js&#39;  \/\/ [name]\u306fentry\u3067\u8a18\u8ff0\u3057\u305f\u540d\u524d\uff08\u3053\u306e\u8a2d\u5b9a\u306a\u3089bundle\uff09\n  },\n  \/\/ import\u6587\u3067\u30d5\u30a1\u30a4\u30eb\u62e1\u5f35\u5b50\u3092\u66f8\u304b\u305a\u306b\u540d\u524d\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306e\u8a2d\u5b9a\n  \/\/ \u4f8b...\u300cimport World from &#39;.\/world&#39;\u300d\u3068\u8a18\u8ff0\u3059\u308b\u3068&quot;world.ts&quot;\u3068\u3044\u3046\u540d\u524d\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u3057\u3066\u63a2\u3059\n  resolve: {\n    extensions:[&#39;.ts&#39;,&#39;.js&#39;] \/\/ React\u306e.tsx\u3084.jsx\u306e\u62e1\u5f35\u5b50\u3082\u6271\u3044\u305f\u3044\u5834\u5408\u306f\u914d\u5217\u5185\u306b\u8ffd\u52a0\u3059\u308b\n  },\n  devServer: {\n    contentBase: path.join(__dirname, &#39;dist&#39;), \/\/ webpack-dev-server\u306e\u516c\u958b\u30d5\u30a9\u30eb\u30c0\n    open: true \/\/ \u30b5\u30fc\u30d0\u30fc\u8d77\u52d5\u6642\u306b\u30d6\u30e9\u30a6\u30b6\u3092\u958b\u304f\n  },\n  \/\/ \u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u9069\u7528\u3059\u308b\u30eb\u30fc\u30eb\u306e\u8a2d\u5b9a\uff08\u30ed\u30fc\u30c0\u30fc\u306e\u8a2d\u5b9a\u3092\u884c\u3046\u4e8b\u304c\u591a\u3044\uff09\n  module: {\n    rules: [\n      {\n        \/\/ \u62e1\u5f35\u5b50\u304c.ts\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u5bfe\u3057\u3066TypeScript\u30b3\u30f3\u30d1\u30a4\u30e9\u3092\u9069\u7528\u3059\u308b\n        \/\/ React\u3067\u7528\u3044\u308b.tsx\u306e\u62e1\u5f35\u5b50\u306b\u3082\u9069\u7528\u3059\u308b\u5834\u5408\u306f test:\/\\.(ts|tsx)$\/,\n        test: \/\\.ts$\/,\n        loader: &#39;ts-loader&#39;\n      }\n    ]\n  }\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u95a2\u6570<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>function \u95a2\u6570\u540d(\u5f15\u6570\u540d:\u5f15\u6570\u306e\u578b,\u5f15\u6570\u540d:\u5f15\u6570\u306e\u578b\u30fb\u30fb\u30fb)\n{\n\u51e6\u7406:\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">NextPage<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">interface<\/h2>\n\n\n\n<p>TypeScript\u306e<code>interface<\/code>\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5f62\u72b6\uff08\u30d7\u30ed\u30d1\u30c6\u30a3\u3068\u30e1\u30bd\u30c3\u30c9\u306e\u69cb\u9020\uff09\u3092\u5b9a\u7fa9\u3059\u308b\u305f\u3081\u306e\u4ed5\u7d44\u307f\u3067\u3059\u3002JavaScript\u3068\u540c\u69d8\u306b\u3001TypeScript\u3067\u3082\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u3063\u3066\u60c5\u5831\u3092\u307e\u3068\u3081\u305f\u308a\u3001\u95a2\u9023\u3059\u308b\u30d7\u30ed\u30d1\u30c6\u30a3\u3084\u30e1\u30bd\u30c3\u30c9\u3092\u30b0\u30eb\u30fc\u30d7\u5316\u3057\u305f\u308a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>interface Person {\n  name: string;\n  age: number;\n  sayHello: () =&gt; void;\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e<code>Person<\/code>\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306f\u3001<code>name<\/code>\u3068<code>age<\/code>\u3068\u3044\u3046\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u3042\u308a\u3001\u305d\u308c\u305e\u308c\u6587\u5b57\u5217\u578b\u3068\u6570\u5024\u578b\u3092\u6301\u3061\u3001<code>sayHello<\/code>\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5f62\u72b6\u3092\u8868\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u578b\u5b9a\u7fa9\u30d5\u30a1\u30a4\u30eb<\/h2>\n\n\n\n<p>TypeScript\u306b\u306fJavaScript\u306e\u30e2\u30b8\u30e5\u30fc\u30eb<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">null\u304b\u3082\u3057\u308c\u306a\u3044\u5024<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>type data = [name:string, age?:number]\n\nconst taro:data = [&quot;taro&quot;, 39]\nconst hanako:data = [&quot;hanako&quot;]\nconsole.log(taro)\nconsole.log(hanako)<\/code><\/pre><\/div>\n\n\n\n<p>hanako\u306e\u307b\u3046\u306f[&#8220;hanako&#8221;]\u3068\u3044\u3046\u3088\u3046\u306b\u4e00\u3064\u306e\u5024\u3057\u304b\u3042\u308a\u307e\u305b\u3093\u3002\u305d\u308c\u3067\u3082\u554f\u984c\u306a\u304f\u5024\u3092\u4f5c\u6210\u3067\u304d\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>type data = [name:string, age?:number]<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u308c\u306fage?\u304c\u3064\u3051\u3089\u308c\u3066\u3044\u308b\u305f\u3081\u3067\u3059\u3002\u3053\u308c\u306fage\u306e\u5024\u304c\u306a\u3044\u5834\u5408\u3082\u3042\u308b\u3053\u3068\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002<br>\u3053\u306e?\u3092\u524a\u9664\u3059\u308b\u3068\u5909\u6570hanako\u306e\u6587\u306b\u30a8\u30e9\u30fc\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<br>\u3053\u306e\u3088\u3046\u306b\u5024\u3092\u7528\u610f\u3059\u308b\u969b\u3001\u540d\u524d\u306e\u5f8c\u306b?\u3092\u3064\u3051\u308b\u3053\u3068\u3067\u5024\u304c\u5b58\u5728\u3057\u306a\u5834\u5408\u3092\u8a31\u5bb9\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Node.js\u306e\u5f15\u6570<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>process.argv[0]<\/td><td>node\u30b3\u30de\u30f3\u30c9\u306e\u30d1\u30b9<\/td><\/tr><tr><td>process.argv<img decoding=\"async\" class=\"ranking-number\" src=\"https:\/\/agile-software.net\/wp-content\/themes\/jin\/img\/rank01.png\" \/><\/td><td>\u30b9\u30af\u30ea\u30d7\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9<\/td><\/tr><tr><td>process.argv<img decoding=\"async\" class=\"ranking-number\" src=\"https:\/\/agile-software.net\/wp-content\/themes\/jin\/img\/rank02.png\" \/><\/td><td>\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u6642\u306b\u6e21\u3055\u308c\u308b\u5f15\u6570<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>TypeScript\u3068\u306f\uff1f JavaScript\u306b\u578b\u30b7\u30b9\u30c6\u30e0\u3092\u639b\u3051\u5408\u308f\u305b\u305f\u3082\u306e\u3002\u6700\u7d42\u7684\u306b\u306f\u30b3\u30f3\u30d1\u30a4\u30eb\u3067 JavaScript \u306b\u5909\u63db .ts\u62e1\u5f35\u5b50\u3068.tsx\u62e1\u5f35\u5b50\u306e\u9055\u3044 .ts\u62e1\u5f35\u5b50 .tsx\u62e1\u5f35\u5b50 TypeScript<\/p>\n","protected":false},"author":1,"featured_media":1738,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jin_ogp_image_url":"","_jin_last_featured_id":0,"footnotes":""},"categories":[44],"tags":[],"class_list":["post-1631","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-typescript"],"_links":{"self":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/1631","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1631"}],"version-history":[{"count":9,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/1631\/revisions"}],"predecessor-version":[{"id":2766,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/1631\/revisions\/2766"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/media\/1738"}],"wp:attachment":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1631"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}