[英]Error when mixing javascript and typescript in angular
我試圖在我的角度應用程序中使用打字稿。 我有一個描述類User的ts文件:
module App.Tools {
export class User {
name: string;
constructor(name: string) {
this.name = name;
}
}
}
在我的JS文件(es2015)中,我嘗試導入User類:
import {User} from 'User.ts';
export default class AuthFactory {
/**
* @param {[type]}
* @return {[type]}
*/
constructor($firebaseAuth) {
this.ref = new Firebase("...");
// create an instance of the authentication service
this.auth = $firebaseAuth(this.ref);
var authData = this.auth.$getAuth();
if (authData) {
this.currentUser = new User(authData.google.displayName, authData.provider);
} else {
this.currentUser = null;
}
}
}
由於我收到錯誤消息:“未定義用戶”,此方法不起作用。
我正在使用帶有瀏覽器,tsify和babel的gulp。
我認為您需要在“ User.ts”文件中使用“ 外部 ”打字稿模塊:
class User {
name: string;
constructor(name: string) {
this.name = name;
}
}
export = User;
使用內部模塊:
module App.Tools {
export class User {
name: string;
constructor(name: string) {
this.name = name;
}
}
}
export = App.Tools;
要在導入中使用它:
import { User } from 'User.ts';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.