【发布时间】:2020-02-18 11:12:02
【问题描述】:
我有一个简单的 TypeScript 'sn-ps' 项目,我遇到了一个问题,即多个 .ts 文件将具有相同的类型名称(例如 Foo)。
//file-a.ts
type Foo = {
}
//file-b.ts
type Foo = {
}
如果我尝试编译它,我会得到:
error TS2300: Duplicate identifier 'Foo'.
这对我来说没有意义——因为这些类型应该特定于模块。
我使用的是 typescript 3.7.5 版,而我的 tsconfig.json 有这些属性(其他都是默认值):
{
"compilerOptions": {
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
"strict": true, /* Enable all strict type-checking options. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}
这里发生了什么? The actual code here.
【问题讨论】:
标签: typescript