NodeJS“class.function不是函数”

时间:2017-06-19 18:21:50

标签: node.js typescript

logic.ts

import * as ModelA from "./ModelA";
import * as ModelB from "./ModelB";


export function ProcessPurchases(purchases: ModelA.Purchase[], useInfo: boolean = false): ModelA.Purchase[] {
    ...
    return purchases;

};

export function findSavings(Products: ModelA.Purchase[], OtherProducts: ModelA.Purchase[]): ModelA.Savings{
      ....
      return savings;
};

server.ts

import * as ModelA from "./ModelA";
import * as ModelB from "./ModelB";
import * as Algorithms from "./logic";


import * as _ from "lodash";


var tp = require('tedious-promises');
var dbConfig = {
    ...
};

var TYPES = require('tedious').TYPES;
tp.setConnectionConfig(dbConfig); // global scope
tp.setPromiseLibrary('es6');

const express = require('express')
const bodyParser = require('body-parser')
var request = require('request');

const app = express();
app.use(bodyParser.json());

app.listen(3000, function (err) {
  if (err) {
    throw err
  }
  console.log('Server started on port 3000')
})


interface IKeyValue { [key: string]: any };

namespace ProcessLogic{

    function PurchaseSHR(Group: number[], Manufacturer: number, Category: number, useInfo= false): ModelA.Savings{
    ...
    if (useInfo) {
        var result= Algorithms.ProcessPurchases(myActualPurchases); //Algorithms.ProcessPurchases is not a function
        ...
        return result;
    }
    else {
        ...
      }
  }


}

}

抛出Algorithms.ProcessPurchases不是函数的错误,仅在运行时没有构建错误。所有文件都在同一目录下 我尝试过的事情:

将逻辑函数包装在命名空间“Algorithms”下并按如下方式导入它们:

import {Algorithms} from "./logic"

还试图通过以下方式引用:/// <reference path="logic.ts" />

1 个答案:

答案 0 :(得分:0)

我通过创建新的.ts文件解决了这个问题,并重写了其中的所有代码。奇怪的是,现在一切似乎都运转良好..