TypeScript基本語法

2021-10-24 18:17:53 字數 793 閱讀 4023

1、安裝typescript

2、生成對應js檔案
// ts檔案

let message:

string

="hello world"

let num1:number =

13let num2:

any=[1

,2,4

]console

.log

(message, num1, num2)

console

.log

(typeof num1)

// js檔案

var message =

"hello world"

;var num1 =13;

var num2 =[1

,2,4

];console.

log(message, num1, num2)

;console.

log(

typeof num1)

;

3、tsc 常用編譯引數
tsc test.ts --watch

引數值

引數說明

–watch

在監視模式下執行編譯器。實時編譯檔案成js

–out

編譯多個檔案並合併到乙個輸出的檔案

4、ts 與物件導向

筆記 TypeScript函式語法

宣告方式function 函式名 資料型別let 函式名 function 資料型別function 函式名 引數1 資料型別,引數2 資料型別 返回值資料型別function 函式名 引數1 資料型別,引數2 資料型別 返回值資料型別function 函式名 引數1 資料型別,引數2 資料型別 預...

typescript的基本型別

1.布林boolean 2.數字number 3.字串string 4.陣列number 或者array 5.元組tuple 6.列舉enum 7.給變數指定任何型別any 8.返回值任何型別void 9.無返回型別never 10.非原始型別object 表示除了上述的型別之外的 11斷言 第一種...

TypeScript基本型別檢查

ts是乙個可選的靜態的型別系統 如何進行型別約束let aaa string hello function sum a number,b number number let nums number 1,2,3 let num number sum 3,4 第一種 let numss array 1,...