bie*_*ier 18 javascript typescript reactjs
我将一个名为Auth.js的.js文件(因此不是.ts文件)导入到reactjs和typescript应用程序中,所以在我的组件中我有这个:
import * as Auth from '../Auth/Auth';
..
const auth = new Auth();
Run Code Online (Sandbox Code Playgroud)
这是我的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);
}
..
Run Code Online (Sandbox Code Playgroud)
当我运行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.
Run Code Online (Sandbox Code Playgroud)
如何解决此TS错误?
Kis*_*dha 34
尝试删除* as.您正在导出Auth为默认值.我们直接导入的默认导出属性没有任何*或{}.
import Auth from '../Auth/Auth';
..
const auth = new Auth();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23310 次 |
| 最近记录: |