TypeScriptに入門した
約 2 分
目次
概要
初期作業
typescript環境を作っていきます。
$ mkdir ts-app
$ cd ts-app
$ npm init
$ npm install typescript
$ export PATH=`pwd`/node_modules/.bin:PATH
$ node_modules/.bin/tsc --version
# Version 4.1.3
package.json
{
"name": "ts-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc"
},
"author": "",
"license": "ISC",
"dependencies": {
"typescript": "^4.1.3"
}
}
とりあえずHello World
まず、次のサンプルコードを作成します。
main.ts
const hello = (arg: string): void => {
if (arg.length > 0) {
for (let i = 0; i < 10; i++) {
console.log(`Hello ${arg}`);
}
}
};
let world: string = 'world';
hello(world);
typescriptファイルをビルドします。
npm run build main.ts
main.js
var hello = function(arg) {
if (arg.length > 0) {
for (var i = 0; i < 10; i++) {
console.log('Hello ' + arg);
}
}
};
var world = 'world';
hello(world);おすすめの記事
最新の記事
よく読まれている記事
タグから探す
- javascript130
- typescript67
- node.js54
- linux54
- 画像処理48
- amazon-aws48
- アルゴリズム37
- canvas35
- html529
- 画像処理100本ノック27
- php24
- centos24
- python22
- 競技プログラミング21
- mac21
- mysql20
- opencv17
- 雑談16
- 機械学習16
- docker16
- wordpress15
- atcoder14
- apache12
- データベース12
- amazon-s312
- red-hat12
- prisma12
- ubuntu11
- github10
- git10
- react10
- mariadb10
- vue.js9
- next.js9
- aws-cdk9
- css38
- 可視化8
- 小ネタ8
- nestjs8
- amazon-lightsail7
- ブログ6
- cms6
- oracle6
- perl6
- gitlab6
- iam5
- amazon-ec25
- 資格試験5
- aws-amplify5
- curl4