1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【TypeScript】はじめてのHello World!!

Last updated at Posted at 2021-02-14

※ node.jsインストール済前提です

TypeScriptのインストール

ターミナル
$ npm i -g typescript

// tscコマンドが使える
$ tsc -v
Version 4.1.3

任意のディレクトリ直下に"index.ts"ファイルを作成

変数hellostring型を指定

index.ts
let hello: string = 'Hello World!'
console.log(hello)

TypeScriptをJavaScriptに変換(コンパイル)

ターミナル
$ tsc index.ts

するとindex.jsが自動で生成!

index.js
var hello = 'Hello World!';
console.log(hello);

実行する

ターミナル
$ node index.js

=> Hello World!

成功!

ブラウザで実行するときは・・・

index.js
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="UTF-8">
    <title>Document</title>
  </head>
  <body>
    <script src="index.js"></script>
  </body>
</html>

いつも通りですね!^^

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?