【发布时间】:2016-02-09 05:29:11
【问题描述】:
我正在尝试使用 TypeScript 编写一个 Node 模块,这就是我的目标:
MysqlMapper.ts
export class MysqlMapper{
private _config: Mysql.IConnectionConfig;
private openConnection(): Mysql.IConnection{
...
}
private createSelectAllQuery(constructor): string{
...
}
public getAll<T>(constructor): Q.Promise<Array<T>>{
.....
}
constructor(config: Mysql.IConnectionConfig){
...
}
}
index.ts
export * from "./MysqlMapper";
package.json
{
"name": "mysql-metadata-orm",
"version": "1.0.0",
"description": "A Simple ORM using reflect-metadata",
"main": "build/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "..."
},
"author": "+",
"license": "MIT",
"dependencies": {
"mysql": "^2.9.0",
"q": "^1.4.1",
"reflect-metadata": "^0.1.2"
}
}
我在我的 tsconfig 文件中激活了声明生成,但我真的不明白如何获得一个允许像这样导入模块的声明文件:
import * as Mapper from "mysql-metadata-mapper"
我希望有人能帮我解决这个问题,因为这让我非常抓狂。
@Update
这些是生成的 .d.ts 文件:
index.d.ts
export * from "./MysqlMapper";
MysqlMapper.d.ts
import * as Q from "q";
import * as Mysql from "mysql";
export declare class MysqlMapper {
private _config;
private openConnection();
private createSelectAllQuery(constructor);
getAll<T>(constructor: any): Q.Promise<Array<T>>;
constructor(config: Mysql.IConnectionConfig);
}
如何获取声明文件?
【问题讨论】:
-
你可以在这里发布自动生成的声明为这个模块产生的内容吗?
-
我知道这是一个很老的问题,但对于后来遇到这个问题的其他人(就像我上周所做的那样),你可能会发现这个 typescript 样板项目很有帮助:github.com/bitjson/typescript-starter
标签: javascript node.js typescript commonjs