typescript:declaration_merging

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
typescript:declaration_merging [2025/03/30 08:34] lingaotypescript:declaration_merging [2025/03/30 08:39] (current) lingao
Line 1: Line 1:
 +====== Article ======
 +
 Official Website: https://www.typescriptlang.org/docs/handbook/declaration-merging.html Official Website: https://www.typescriptlang.org/docs/handbook/declaration-merging.html
  
Line 223: Line 225:
 </codeprism> </codeprism>
 鉴于现代前端开发已经迈入全 ''Module'' 化了,并且在 ''Ambient Module'' 里边引入啥类型都要拖个 ''import("...")''. 的前缀很麻烦,我完全不建议任何人再使用 ''Ambient Module'',而是使用现代化的 ''declare global'' 鉴于现代前端开发已经迈入全 ''Module'' 化了,并且在 ''Ambient Module'' 里边引入啥类型都要拖个 ''import("...")''. 的前缀很麻烦,我完全不建议任何人再使用 ''Ambient Module'',而是使用现代化的 ''declare global''
 +
 +====== Comments ======
 +
 +Q: "那么假如你故意不加任何 import/export 语句让 TS 认为某个文件不是个 module 呢?答案显而易见,它会被视为一个全局可用的 script,其中定义的任何变量、类型都会全局可用"
 +为啥我的项目中的global.d.ts一定要加export {}才能变成全局的,不加的话就识别不到[大哭]
 +
 +A: tsconfig.json有个选项moduleDetection,设置为"force"时会强制将所有文件识别为module,你这边不被识别为script有可能是这个原因。我也看不到你的global.d.ts和tsconfig长什么样,只能猜一猜原因[思考]
 +
 +
  • typescript/declaration_merging.1743323655.txt.gz
  • Last modified: 2025/03/30 08:34
  • by lingao