【问题标题】:Class 'GeoJSON' incorrectly extends base class 'FeatureGroup'“GeoJSON”类错误地扩展了基类“FeatureGroup”
【发布时间】:2018-02-01 07:15:03
【问题描述】:

在我的一个项目中,我收到以下错误消息:

test/node_modules/@types/leaflet/index.d.ts(856,11): error TS2415: Class 'GeoJSON' incorrectly extends base class 'FeatureGroup'.
  Types of property 'setStyle' are incompatible.
    Type '(style: StyleFunction) => this' is not assignable to type '(style: PathOptions) => this'.
      Types of parameters 'style' and 'style' are incompatible.
        Type 'PathOptions' is not assignable to type 'StyleFunction'.
          Type 'PathOptions' provides no match for the signature '(feature?: Feature<GeometryObject>): PathOptions'.

这里是输入文件:

test.ts

import { LatLngExpression } from 'leaflet'

package.json

{
  "name": "test",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/leaflet": "^1.0.68",
    "gulp": "^3.9.1",
    "gulp-typescript": "^3.2.2",
    "typescript": "^2.4.2"
  }
}

tsconfig.json

{
  "compileOnSave": true,
  "compilerOptions": {
    "noEmitOnError": true,
    "target": "es5",
    "module": "amd",
    "moduleResolution": "node"
  },
  "include": [
    "test.ts"
  ]
}

gulpfile.js

const gulp = require('gulp');
const ts = require("gulp-typescript");

const tsProject = ts.createProject("tsconfig.json");

gulp.task('default', () => {
    const tsResult = tsProject.src().pipe(tsProject());
    return tsResult.js.pipe(gulp.dest(''));
});

如果我执行“yarn && gulp”,则会出现错误——但如果我使用“npm install”而不是yarn,则不会出现错误,如果我使用“tsc -p”则不会。而不是 gulp 文件。 此外,只要我有 Typescript 2.4.1,就完全没有错误——它是在我更新到 Typescript 2.4.2 之后出现的。

我想将此报告为错误 - 但我不知道是哪个部分负责:yarn、typescript、gulp-typescript、@types/leaflet?

我怎么能弄到这个?

显然,我从一个较大的项目中提取了这个测试用例,我想在其中使用“yarn && gulp”,这会导致错误。所以我想要修复 - 不是上面的任何“解决方法”。

【问题讨论】:

    标签: typescript npm leaflet yarnpkg gulp-typescript


    【解决方案1】:

    看来这已“自动”修复。我的猜测是,npm 和 yarn 的存储库之间存在不一致。

    很难说——而且可能没用。所以这个问题可能会被关闭或删除。

    【讨论】:

    • 我确实有同样的问题,所以我想这个问题应该保留。
    【解决方案2】:

    在将 Typescript 从 2.4 版升级到 2.5 版后,我也遇到了类似的问题。更新 @types/leaflet 模块为我解决了这个问题。

    npm update @types/leaflet 
    

    【讨论】:

      猜你喜欢
      • 2017-12-01
      • 1970-01-01
      • 2017-12-07
      • 2018-01-18
      • 1970-01-01
      • 2017-12-04
      • 2017-11-25
      • 2020-09-08
      • 2019-04-01
      相关资源
      最近更新 更多