日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

TypeScript 素描 - 模块解析、声明合并

發(fā)布時(shí)間:2024/4/17 编程问答 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TypeScript 素描 - 模块解析、声明合并 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

模塊解析

模塊解析有兩種方式

相對方式? 也就是以/或 ./或…/開頭的,比如import jq? from “/jq”

非相對方式? 比如 import model? from “modelA”

TypeScript的模塊解析吸取了Node與Classic兩種方式的好處并結(jié)合在一起

例如當(dāng)前文件夾是? root/src/,其中a.ts導(dǎo)入了modelB

相對方式

  • /root/src/moduleB.ts
  • /root/src/moduleB.tsx
  • /root/src/moduleB.d.ts
  • /root/src/moduleB/package.json (如果指定了"typings"屬性)
  • /root/src/moduleB/index.ts
  • /root/src/moduleB/index.tsx
  • /root/src/moduleB/index.d.ts
  • 非相對方式

  • /root/src/node_modules/moduleB.ts
  • /root/src/node_modules/moduleB.tsx
  • /root/src/node_modules/moduleB.d.ts
  • /root/src/node_modules/moduleB/package.json (如果指定了"typings"屬性)
  • /root/src/node_modules/moduleB/index.ts
  • /root/src/node_modules/moduleB/index.tsx
  • /root/src/node_modules/moduleB/index.d.ts
  • /root/node_modules/moduleB.ts
  • /root/node_modules/moduleB.tsx
  • /root/node_modules/moduleB.d.ts
  • /root/node_modules/moduleB/package.json (如果指定了"typings"屬性)
  • /root/node_modules/moduleB/index.ts
  • /root/node_modules/moduleB/index.tsx
  • /root/node_modules/moduleB/index.d.ts
  • /node_modules/moduleB.ts
  • /node_modules/moduleB.tsx
  • /node_modules/moduleB.d.ts
  • /node_modules/moduleB/package.json (如果指定了"typings"屬性)
  • /node_modules/moduleB/index.ts
  • /node_modules/moduleB/index.tsx
  • /node_modules/moduleB/index.d.ts
  • 除此之外,TypeScript還考慮到其它的復(fù)雜情況,給出了我們 路徑映射 與 虛擬目錄,這些都是要到tsconfig中進(jìn)行配置的,這里就不細(xì)談了。有需要再去看相關(guān)資料吧

    ?

    聲明合并

    TypeScript允許兩個(gè)接口合并為一個(gè)接口,像下面這樣。

    interface Box {height: number;width: number; }interface Box {scale: number; }let box: Box = { height: 5, width: 6, scale: 10 };

    除了接口與接口還支持

    命名空間與命名空間

    命名空間與類、函數(shù)、枚舉

    但是類不可以與類進(jìn)行合并,類也不可以與函數(shù)合并

    轉(zhuǎn)載于:https://www.cnblogs.com/LiangSW/p/6266737.html

    總結(jié)

    以上是生活随笔為你收集整理的TypeScript 素描 - 模块解析、声明合并的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。