【发布时间】:2016-02-27 16:56:37
【问题描述】:
我正在尝试使用 TypeScript ECMAScript6 使用 Visual Studio 2015 社区版创建一个简单的 Node.js 控制台应用程序,但无法使用 app.ts 中模块内定义的类。然而,Visual Studio 确实将模块“DataModels”显示为命名空间以及 intellisense 中的类,但是在 app.ts 中初始化它时会引发错误
错误:ReferenceError:未定义数据模型
尝试使用 AMD 和 CommonJs 作为模块系统的 VS 项目设置,但没有成功。
文件夹结构
/
app.ts
DataModels.ts
Scripts
Typings (dir)
Node (dir)
node.d.ts
app.ts
/// <reference path="DataModels.ts" />
var user: IUser = new DataModels.User();
user.Name = 'user1';
console.log(user.Name);
DataModels.ts
interface IUser {
Name: string;
Email: string;
UserName: string;
Password: string;
ProfilePicPath: URL;
}
module DataModels {
export class User implements IUser {
private _name: string;
private _email: string;
private _username: string;
private _password: string;
private _profilePicPath: URL;
public get Name() {
return this._name;
}
public set Name(value) {
this._name = value;
}
public get Email() {
return this._email;
}
public set Email(value) {
this._email = value;
}
public get UserName() {
return this._username;
}
public set UserName(value) {
this._username = value;
}
public get Password() {
return this._password;
}
public set Password(value) {
this._password = value;
}
public get ProfilePicPath() {
return this._profilePicPath;
}
public set ProfilePicPath(value) {
this._profilePicPath = value;
}
}
}
【问题讨论】:
标签: node.js typescript visual-studio-2015 ecmascript-6