There is a small application on angular 6.0.7 / typescript 2.7.2. I connected the socket.io-client like this:

 import * as io from 'socket.io-client'; 

everything worked. So I decided to make it nice and updated to angular 6.1.0 / typescript 2.9.2. The build faylitsya, the editor in the line with the library connection gives the following hint: Import of the namespace style cannot be called or created and will lead to a crash at runtime. Console on the line

 private socket = io(); 

gives an error message: error TS2349: Cannot invoke an expression Type '{connect (uri: string, opts ?: ConnectOpts): Socket; connect (opts ?: ConnectOpts): Socket; protocol ... has no compatible call signatures. What do you advise to do?

  • Removed @ types / socket.io-client dependencies - it worked. But, damn, it's not cool ( - muturgan
  • one
    do you have somewhere in tsconfig.json or tsconfig.app.json property esModuleInterop: true ? - overthesanity
  • there is muturgan in tsconfig.json

1 answer 1

It has nothing to do with the typescript version. You can bring back the @types/socket.io-client definitions. This error can occur only with the esModuleInterop: true parameter. When you put esModuleInterop: true , it tells the compiler to wrap the require('any-module') into the generated __importStar function, which checks whether the module is es6 or commonjs . This parameter should not be used in angular projects, it was added by the Microsoft team (due to a large number of issues developers on React ) solely for the purposes that, for example, import * as React from 'react could be replaced by import React from 'react' , while the compiler did not swear.

  • According to your tip, I started digging documentation. Added the rule "allowSyntheticDefaultImports" to tsconfig.app.json: true - it worked. - muturgan