无法调用构造函数:TypeError:Converter不是函数

时间:2015-12-15 11:32:02

标签: typescript typescript1.6

问题:以下示例代码所代表的实际代码将成功编译,但在Javascript控制台中进行测试时,它不会。

export class Converter {
  fields: Array<Field>;

  constructor (djangoRestMeta: any, fieldFactoryFn: IFieldFactory) {
    this.fields = [];
    for (var fieldName in djangoRestMeta) {
      var fieldConfig = djangoRestMeta[fieldName];
      fieldConfig.name = fieldName;
      this.fields.push(DjangoRestConfig.factory(<IDjangoRestFieldOptions>fieldConfig, fieldFactoryFn));
    };
  }

  public convert() {
    var configObjects: Array<AngularFormly.IFieldConfigurationObject> = [];
    this.fields.forEach(function(field) {
      configObjects.push(field.getConfigurationObject());
    });
    return configObjects;
  };
}


export function DjangoRestFrameworkAdapter(djangoRestMeta: Array<IDjangoRestFieldOptions>, fieldFactoryFn?: IFieldFactory) {
  var converter = new Converter(djangoRestMeta, fieldFactoryFn);
  return converter.convert();
}

,编译的代码是:

var DjangoRestConfig_1 = require("./DjangoRestConfig");
var Converter = (function () {
    function Converter(djangoRestMeta, fieldFactoryFn) {
        this.fields = [];
        for (var fieldName in djangoRestMeta) {
            var fieldConfig = djangoRestMeta[fieldName];
            fieldConfig.name = fieldName;
            this.fields.push(DjangoRestConfig_1.DjangoRestConfig.factory(fieldConfig, fieldFactoryFn));
        }
        ;
    }
    Converter.prototype.convert = function () {
        var configObjects = [];
        this.fields.forEach(function (field) {
            configObjects.push(field.getConfigurationObject());
        });
        return configObjects;
    };
    ;
    return Converter;
})();
exports.Converter = Converter;
function DjangoRestFrameworkAdapter(djangoRestMeta, fieldFactoryFn) {
    var converter = new Converter(djangoRestMeta, fieldFactoryFn);
    return converter.convert();
}
exports.DjangoRestFrameworkAdapter = DjangoRestFrameworkAdapter;

执行完全失败:var converter = new Converter(...)我收到了这个错误:

  

TypeError:转换器不是函数

我看到编译的代码是有效的ES5代码,应该可以工作,我不会在这里看到错误

有关信息:已在Chrome v47.0.2526.80(64位)上测试,在MacOS El Capitain上运行

0 个答案:

没有答案