类型'类型的争论不能分配给类型'功能'的参数。

时间:2018-01-19 21:16:51

标签: typescript

我正在尝试创建一个模块,我的应用程序中的其他控制器可以使用它来确定正确的导出格式。我对TypeScript很陌生,这个错误让我摸不着头脑:

我有两个文件 - 一个是模块,另一个是存储一堆常量的文件。第一个文件是download_types.ts

# imports the `RenderFormats` constant from my `download_types_constants` file
import RenderFormats from "./download_types_constants";
import _ from "underscore";
import angular from "angular";

export class DownloadType {
  downloadFormats(options: any) {
    if (options.canRenderElement) { return options.exportFormats; }

    const { exportFormats } = options;

    return _.omit(exportFormats, RenderFormats);
  }
}

export const ngModule = angular.module('myapp.common.scheduler', [])
  .service('DownloadType', DownloadType);

这是download_types_constants.ts

export const RenderFormats = ["png"];

但是,当我重新加载页面时,出现以下错误:

./delivery_formats/download_type.ts
(11,34): error TS2345: Argument of type 'typeof "/scheduled_plan_dialog/scheduled_pl...' is not assignable to parameter of type 'Function'.
  Property 'name' is missing in type 'typeof "/scheduled_plan_dialog/scheduled_pl...'.

我不太确定问题是什么..

1 个答案:

答案 0 :(得分:0)

您要从./download_types_constants而不是数组RenderFormats导入默认导出。报告的类型错误有点令人困惑,因为它引用了omit的最后一次重载(其中第二个参数是一个函数。)如果你将导入更改为

,它应该有用。
import { RenderFormats } from "./download_types_constants";