我想知道是否有可能按特征/组件将ts的定义分解为单独的文件。这样,每个组件都会有自己的定义,从而扩展主定义命名空间,就像这样
@types
我的文件夹结构:
index.ts
index.d.ts
app
shared
shared.ts
shared.d.ts
user.ts
config.ts
login
login.ts
login.d.ts
login.component.ts
login.component.html
我的定义文件:
// shared.d.ts
export namespace shared {
interface IConfig {
url: string;
}
}
// login.d.ts
export namespace login {
interface ILogin {
logIn(): Promise<any>;
logOut(): Promise<any>;
}
}
// index.d.ts
import * as sharedModule from './app/shared/shared';
import * as loginModule from './app/login/login';
declare module App {
// extend the App module with the imported definitions. How?
}
我的tsconfig。json
{
"compilerOptions": {
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"typeRoots": ["node_modules/@types/", "src/"]
},
"compileOnSave": false,
"filesGlob": [
"src/**/*.ts",
"src/**/*.tsx",
"!node_modules/**"
]
}