打字稿npm库

时间:2018-05-31 18:15:56

标签: typescript npm

我在打字稿中有一堆基类。我还有一个使用typescript编写的web应用程序,我希望包含所有数据类型定义的'Plain Old Typescript objects'库。让我们称之为'domain.common'库。

从domain.commin我有一个小的npm构建任务,基本上使用typescript编译器和配置来创建实际的js代码。 tsconfig.json如下所示:

{
  "compilerOptions": {
    "target": "ES5",
    "module": "amd",
    "sourceMap": false,
    "declaration": true,
    "outFile": "npm_lib_template/bundle.js"
  },
  "include": [
    "./src/**/*.ts"
  ]
}

使用typescript编译器的这个代码段提供了一个捆绑文件: 'bundle.js'和'bundle.d.ts'。这很好,并且查看声明文件似乎遵循导出打字稿文件的标准。

declare module "BaseEntity" {
    /**
     * The BaseEntity class that contains an unique ID
     * @class
     */
    export abstract class BaseEntity {
        /**
         * The unique identifier for this entity
         */
        id: string;
        classType: string;
        equals(obj: any): boolean;
        constructor();
    }
}
declare module "BaseConnection" {
    import { BaseEntity } from "BaseEntity";
    /**
     * A base connection class that represent a link between two {@link BaseEntity} classes
     * @class
     * @extends BaseEntity
     */
    export abstract class BaseConnection extends BaseEntity {
        nodeFirstReference: string;
        nodeSecondReference: string;
        constructor();
    }
}
declare module "housing/HouseInformation" {
    import { BaseEntity } from "BaseEntity";
    export class HouseInformation extends BaseEntity {
        address: string;
        zipCode: string;
        city: string;
        country: string;
        constructor();
    }
}

我可以在webapplication中确认这一点,看到Visual Studio Code选择了类定义。

import {HouseInformation} from 'housing/HouseInformation'

但是当我启动应用程序时,我得到了:

未找到模块:无法解析'... \ src \ service \ data'中的'HouseInformation'

此外,我正在使用npm链接在开发期间将本地库链接到Web应用程序。我看不出我错过了什么。

提前致谢!

1 个答案:

答案 0 :(得分:0)