为了module的interface可以全局环境下动态添加定义
// ./src/global.d.ts
declare module FileServeModule {
export interface IConfig {
maxClients: number;
}
}
// ./src/file-hand.ts
declare module FileServeModule {
export interface IConfig {
port: number;
}
}
// ./src/main.ts
let config: FileServeModule.IConfig = {
maxClients: 123,
port: 123
}
编译器并没有检查出任何错误,但是运行时报找不到FileServeModule,很想实现全局定义,方便扩展
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
// "program": "${workspaceFolder}\\index.js",
"args": [
//"${file}" // 入口文件
"${workspaceFolder}/src/main.ts"
],
"runtimeArgs": [
"--nolazy",
"-r",
"ts-node/register"
],
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
我现在的解决办法是按照文档来(之前文档看的不够仔细)
./types/FileServeModule/global.d.ts
上面这样写完全没的问题,玩美……