Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
119
rated 0 times [  121] [ 2]  / answers: 1 / hits: 40958  / 7 Years ago, wed, october 4, 2017, 12:00:00

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?


More From » reactjs

 Answers
127

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();

[#56315] Saturday, September 30, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anabeldaliad

Total Points: 552
Total Questions: 107
Total Answers: 120

Location: Hungary
Member since Mon, Feb 21, 2022
2 Years ago
;