带有npm和节点模块包的Visual Studio Typescript引用问题

时间:2018-08-29 02:58:42

标签: asp.net-mvc typescript

因此,我将打字稿用于ASP NET MVC项目,该打字稿正在管理前端JS和angularJs。

我有一个viewmodels文件夹,其中包含许多.ts文件。因此,我尝试将它们分开并将其托管在私有npm软件包下。

接下来,我使用npm将它们下载到node_modules文件夹中,但是这些打字稿视图模型的引用不再起作用。

说所有ts都在同一个命名空间下。仅有一部分是本地Typescript文件夹,另一部分是节点模块文件夹。

出现问题后我采取的措施

  1. 项目包括/node_modules/@privatescope/viewmodels/*.ts以及* .js
  2. 确保捆绑包定位到node_modules / @ privatescope / viewmodels / *。js
  3. 项目可以像以前一样调试和工作,但是我的本地打字稿无法获得正确的引用

我也尝试在本地打字稿文件中对此进行尝试

/// <reference path="node_modules/@privatescope/viewmodels/CurrencyViewModel.ts" />

甚至是这个

var currencyViewModel = require("node_modules/@privatescope/viewmodels/CurrencyViewModel.ts")

// error here
export class CurrencyRepository extends Repository<currencyViewModel> implements IRepository<currencyViewModel>

两者都不能帮助我解决引用问题和tslint。

//我的tsconfig

{
   "compileOnSave": true,
   "compilerOptions": {
    "target": "es5",
    "lib": [
        "dom",
        "es5",
        "scripthost",
        "es6"
    ],
    "module": "commonjs",
    "noImplicitAny": true,
    //"strictNullChecks": true,
    "noEmitOnError": false,
    "removeComments": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "sourceMap": true,
},
"exclude": [
    "node_modules",
    "obj",
    "bin"
]
}



// viewmodel in node_module
namespace test.data {
'use strict';
    export class CurrencyViewModel extends CurrencyGenViewModel { 
    }
}

//base class also in mode_module

'use strict';

namespace test.data {
    export interface IGenCurrencyViewModel { 
        CurrencyRates: CurrencyRateGenViewModel[];
        Id: number;
        Name: string;
        CurrencyCode: string;
    }

    export class CurrencyGenViewModel implements IGenCurrencyViewModel, ICurrency { 
    public CurrencyRates: CurrencyRateGenViewModel[];
    public Id: number;
    public Name: string;
    public CurrencyCode: string;

    public static FIELD_CurrencyRates: string = 'CurrencyRates';
    public static FIELD_Id: string = 'Id';
    public static FIELD_Name: string = 'Name';
    public static FIELD_CurrencyCode: string = 'CurrencyCode';

    constructor() {
    }

    public CloneFromModel(inputModel : Currency) {  
        //CurrencyRateViewModel[]
        this.Id = inputModel.Id;
        this.Name = inputModel.Name;
        this.CurrencyCode = inputModel.CurrencyCode;   
    }

    public CloneFromViewModel(inputViewModel : CurrencyViewModel) {  
        if (inputViewModel.CurrencyRates != null) { this.CurrencyRates = inputViewModel.CurrencyRates; }
        this.Id = inputViewModel.Id;
        this.Name = inputViewModel.Name;
        this.CurrencyCode = inputViewModel.CurrencyCode;   
    }

    public GetCurrency() : Currency {
        var model : Currency = { 
            //CurrencyRateViewModel[]
            Id: this.Id,
            Name: this.Name,
            CurrencyCode: this.CurrencyCode,    
        };

        return model;
    }
}
}

正在寻求建议,谢谢。

0 个答案:

没有答案