首页 > 解决方案 > 不兼容的相同类型

问题描述

有几次,我遇到了不寻常的类型错误,形式如下:

Type 'SomeType<SomeGeneric>' is not assignable to type 'SomeType<SomeGeneric>'.

奇怪的是,据我所知,这两种类型似乎是相同的。它们都来自同一个模块。只是模块存在于两个地方。它存在于 的顶层node_modules,也作为另一个模块的依赖存在。TypeScript 认为这两种类型是不兼容的,尽管在检查这两种类型的来源后,它们似乎是相同的。两个模块的版本相同。

这个问题的另一个奇怪的方面是,虽然类型错误出现在独立的 TypeScript 编译器中,但它没有出现在Atom using ide-typescript.

有什么理由会出现这种情况吗?

这是tsconfig.json

{
    "composite": true,
    "declaration": true,
    "sourceMap": true,
    "target": "es2015",
    "module": "ES6",
    "moduleResolution": "node",
    "baseUrl": "./",
    "outDir": "./build/",
    "lib":
    [
        "es2015",
        "es2017"
    ],
    "removeComments": true,
    "downlevelIteration": true,
    "alwaysStrict": true,
    "allowSyntheticDefaultImports": true,
    "strictNullChecks": true,
    "resolveJsonModule": true,
    "paths":
    {
        "common/*": ["../Common/*"]
    },
    "watch": true
}

任何帮助将非常感激!

标签: typescript

解决方案


推荐阅读