Typescript 入門學習1

2021-09-22 16:50:42 字數 1316 閱讀 9761

最近新學typescript遇到的問題:

入口:index.ts:  

import  from './type'

import xhr from "./xhr.js"

function allpass(config:allpassconfig)

let conf =

allpass(conf);

export default allpass;

邏輯**:

import  from "./type";

//在這個檔案實現具體邏輯方法

}

type 介面定義檔案: type/index.ts

// 作為專案公共型別檔案

export type method = "get" | "get" | "delete" | "delete" | "head" | "head" | "post" | "put" | "patch";

export inte***ce allpassconfig

tsconfig.json 檔案:

"moduleresolution": "node",

"target": "es5",

"module": "es2015", /* specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'esnext'. */

"lib": ["es2015","dom"],

tsc 之後,然後載入到html中執行:

去掉: type="module" 立馬報錯:

設定type屬性設為module,瀏覽器就知道這是乙個 es6 模組。

瀏覽器對於帶有type="module"的,都是非同步載入外部指令碼,不會造成堵塞瀏覽器。

TypeScript 學習筆記1

inte ces typescript 的 type checking 專注於值的 shape inte ces的作用在於命名值使其便於檢測,同時作為軟體與軟體 軟體內部交流的工具。用於檢測,編譯成js的話沒有相應的語句 ts inte ce squareconfig function creats...

TypeScript入門須知

1.強型別語言 不允許改變變數的資料型別,除非進行強制型別轉換 2.弱型別語言 變數可以被賦予不同的資料型別 3.靜態型別語言 在編譯階段確定所有的變數型別 4.動態型別語言 在執行階段確定所有的變數型別 1.初始化 npm init y 2.全域性安裝ts cnpm i typescript g ...

TypeScript 入門(二) 函式

一 函式定義 1 先看一下es5中定義函式 function fn 匿名函式 var fn1 function 2 在ts中定義函式 function fn string 匿名函式 var fn1 function string 二 函式的傳參 1 ts中函式的傳參 function show na...