打字稿+ Eslint进口假阳性+`宣告全球`

问题描述

我的`.d.ts。文件看起来像这样:

import type { typesAsObj } from 'entityTypes';

declare global {
  type EntityType = keyof typeof typesAsObj;
}

这将产生:

'typesAsObj' is not defined. eslint no-undef

但是,这可行:

import type { typesAsObj } from 'entityTypes';

type _EntityType = keyof typeof typesAsObj;

declare global {
  type EntityType = _EntityType;
}

为什么第一个不起作用?

解决方法

关闭“ no-undef”:“ off”(除非使用/*global */注释,否则禁止使用未声明的变量),并由打字稿编译器本身处理。

使用 配置文件中的“ extends”:“ eslint:recommended”属性

 "extends": [
        "eslint:recommended",//<---
        'plugin:jasmine/recommended','plugin:jsdoc/recommended'
    ],