我正在将一个名为 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 错误?
尝试通过删除* as
。您正在导出Auth
作为默认值。默认导出属性我们直接导入,无需任何*
or {}
.
import Auth from '../Auth/Auth';
..
const auth = new Auth();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)