I am importing a .js file (so not a .ts-file) called Auth.js into my reactjs&typescript application, so in my component I have this:
import * as Auth from '../Auth/Auth';
..
const auth = new Auth();
This is part of my 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);
}
..
When I run webpack I get the following error message:
ERROR in ./src/containers/main.tsx
(16,14): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
How can I resolve this TS-error?
Try by removing * as
. You are exporting Auth
as default. Default export property we import directly without any *
or {}
.
import Auth from '../Auth/Auth';
..
const auth = new Auth();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With