ファイルの拡張子は、ts
greeter.ts
下記のコマンドを実行すると greeter.jsが出力される。
greeter.tsとgreeter.jsは、空白行を除いて同じものになる。
じゃ なにがいいの
Type annotations(タイプの注釈)
functionの引数にannotation(注釈)をつけることができて、型が違うとエラーになる。
tcs greeter.tsを実行すると
greeter.ts(7,35): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'string'.
と表示される。
(エラーがあっても greeter.jsはできるよ)
tcs greeter.tsを実行してどんなjavascriptのコードになってるか確認してね。
と表示される。
(エラーがあっても greeter.jsはできるよ)
Interfaces
interfaceを使ってobjectの定義みたいなものができる。
Classes
最後に、typescriptは、class-based object-oriented programming ができるよ
Studentというclassにはconstructorといくつかのpublicフィールドからできている
class Studentとinterfaceに関連があることに気がついたか
(firstName, lastNameがあること)
あとconstructorの引数のpublicというのは、自動的にpropertiesを作ってくれるけんね。
Studentというclassにはconstructorといくつかのpublicフィールドからできている
class Studentとinterfaceに関連があることに気がついたか
(firstName, lastNameがあること)
あとconstructorの引数のpublicというのは、自動的にpropertiesを作ってくれるけんね。
TypeScript web appの実行
下に書いてある greeter.html を作ってブラウザで開いてみろ
あとvisual studioがどうしたとか書いてるけど 関係ないから省略
0 件のコメント:
コメントを投稿