Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve ' error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.'?

Tags:

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?

like image 944
bier hier Avatar asked Oct 04 '17 06:10

bier hier


1 Answers

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();
like image 90
Kishan Mundha Avatar answered Sep 17 '22 15:09

Kishan Mundha