我将一个名为Auth.js的.js文件(因此不是.ts文件)导入到reactjs& typescript应用程序中,所以在我的组件中我有这个:
import * as Auth from '../Auth/Auth';
..
const auth = new Auth();
这是我的Auth.js的一部分:
export default class Auth {
auth0 = new auth0.WebAuth({
domain: AUTH_CONFIG.domain,
clientID: AUTH_CONFIG.clientId,
redirectUri: AUTH_CONFIG.callbackUrl,
audience: `https://${AUTH_CONFIG.domain}/userinfo`,
responseType: 'token id_token',
scope: 'openid'
});
constructor() {
this.login = this.login.bind(this);
this.logout = this.logout.bind(this);
this.handleAuthentication = this.handleAuthentication.bind(this);
this.isAuthenticated = this.isAuthenticated.bind(this);
}
..
当我运行webpack时,我收到以下错误消息:
ERROR in ./src/containers/main.tsx
(16,14): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
如何解决此TS错误?
答案 0 :(得分:27)
尝试删除* as
。您正在导出Auth
作为默认值。我们直接导入的默认导出属性没有任何*
或{}
。
import Auth from '../Auth/Auth';
..
const auth = new Auth();