【问题标题】:Typescript build error - what is wrong with this?打字稿构建错误 - 这有什么问题?
【发布时间】:2018-05-06 05:49:03
【问题描述】:

我最近更新了 VS2017,我看到很多打字稿构建错误。

错误都是一样的,都和d.ts文件的有效性有关。

这是 d.ts 文件中导致打字稿编译错误 (TS2411) 的一些代码:

interface JQueryAjaxSettings {
}

interface DataSourceTransportCreate extends JQueryAjaxSettings {
    cache?: boolean;
    contentType?: string;
    data?: any;
    dataType?: string;
    type?: string;
    url?: any;
}

interface DataSourceTransport {
    create?: DataSourceTransportCreate;
    destroy?: DataSourceTransportDestroy;
    push?: Function;
    read?: DataSourceTransportRead;
    signalr?: DataSourceTransportSignalr;
    update?: DataSourceTransportUpdate;

    parameterMap?(data: DataSourceTransportParameterMapData, type: string): any;
}

interface DataSourceTransportOptions {
    success: (data?: any) => void;
    error: (error?: any) => void;
    data: any;
}

interface DataSourceTransportWithFunctionOperations extends DataSourceTransport {
    create?: (options: DataSourceTransportOptions) => void;
    destroy?: (options: DataSourceTransportOptions) => void;
    read?: (options: DataSourceTransportReadOptions) => void;
    update?: (options: DataSourceTransportOptions) => void;
}

错误是:

TS2430 (TS) 接口“DataSourceTransportWithFunctionOperations” 错误地扩展了接口“DataSourceTransport”。种类 属性“创建”不兼容。 类型“(选项:DataSourceTransportOptions)=> void”与类型“DataSourceTransportCreate”没有共同的属性。脚本 (tsconfig 项目)C:\Users****\typings\kendo\kendo.all.d.ts 1202 活动“

对于许多其他属性,此错误会重复出现。

我的问题是 - 这个定义有效吗?是否有一些更改会导致它突然变得无效(即在 VS 中显示为构建错误)?

【问题讨论】:

  • DataSourceTransportCreate 的类型是什么?是否有可能您更新了 typescript 版本并破坏了一些界面?
  • 我已编辑答案以添加 DataSourceTransportCreate 的定义。
  • AFAIK 打字稿版本在我的 csproj 文件中指定: 2.3 并且这没有改变。虽然我的 tsconfig 文件有这个:“{ "version": "1.8.0"," 不确定这是否与这个问题有关。
  • 它有用吗? DataSourceTransportCreate 根本不匹配类型,你的新类型是一个函数
  • 正如@Axnyff 所说,在 interface DataSourceTransport 中,create? 具有类型 DataSourceTransportCreate 并在 DataSourceTransportWithFunctionOperations 具有类型 (options: DataSourceTransportOptions) => void

标签: typescript


【解决方案1】:

不,定义无效。 DataSourceTransportWithFunctionOperationscreate(options: DataSourceTransportOptions): void 的覆盖与基本 create: DataSourceTransportCreate 不兼容,这根本不是一个函数,而是一个选项包。

Typescript 自 2.4 以来仅在选项包中检测到这些错误,而这个特定的错误可能仅从 2.5 开始,因为它涉及一种方法类型。变化可能是您最新的 VS 更新将您从 Typescript 2.3 或 2.4 或更高版本切换。

根本问题是剑道打字已经过时了。正如你所发现的,官方打字在 8 月得到了修复。如果你更新你的类型,大多数应该被修复为在较新版本的 Typescript 上编译没有错误。

【讨论】:

  • 谢谢。 VS2017 的最新更新现在似乎将 TSC 版本 2.5.3 放在它的 PATH 上,因此出现了这个问题。我能够更新剑道打字,但随后遇到了敲除打字和其他我没有时间修复的打字问题。我在 tsconfig 文件中发现了另一个有用的选项,您可以在编译器选项下添加:"skipLibCheck": true。这并不能解决问题,只是像以前一样将它们隐藏起来 - 所以请谨慎使用。
猜你喜欢
  • 2021-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多