【发布时间】:2020-12-10 01:54:56
【问题描述】:
我正在 Webstorm 中使用以下文件结构开发一个项目
| src
| ...
| many files
| types
| SomeInterface
| index.d.ts
| AnotherInterface
| index.d.ts
| index.d.ts
我想让SomeInterface 全局可用(使用接口而不需要导入)。
我的主要index.d.ts如下:
import { SomeInterface } from './SomeInterface'
import { AnotherInterface} from './AnotherInterface'
declare global {
interface MainInterface extends SomeInterface {
someAttribute?: number[]
names: SomeInterface[]
contactData: AnotherInterface[]
}
}
每当我尝试在src/some/path/to/file.ts 中实现类型定义时:
function someFunctionName(parsedData: MainInterface):void{...}
我收到以下消息:
ESLint: 'MainInterface' is not defined.(no-undef)
这是我当前的 tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"allowJs": true,
"checkJs": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"noImplicitAny": false,
"baseUrl": "./",
"paths": {
"*": ["src/*"]
}
},
"include": ["src", "types/index.d.ts"],
"exclude": ["node_modules"]
}
我错过了什么吗?我知道不建议让东西在全球范围内可用,但是我被要求以这种方式专门这样做。
【问题讨论】:
-
所以这个问题是关于使用 ES Lint 和 TypeScript 的?
-
@AluanHaddad 起初我不确定这是类型定义问题还是 linter 问题。根据 Brad 的回答,看起来这是一个 ESLint/TsLint 问题
标签: typescript eslint typescript-typings typescript-eslint