0

I am following an example in this github repository

My code is

const TYPES = {
    UserService: Symbol("UserService")
};

export default TYPES;

Visual studio code intellisense gives the following error for the above code.

message: 'Cannot invoke an expression whose type lacks a call signature. Type 'SymbolConstructor' has no compatible call signatures.' at: '3,18' source: 'ts'

Symbol definition

interface SymbolConstructor {
    readonly iterator: symbol;
}
declare var Symbol: SymbolConstructor;

This symbol definition is defined in @types/node index.d.ts. When I navigate to the Symbol definition through visual studio code intellisense it took me to the file @types/node index.d.ts.

I just copy paste the code from the repository which I mentioned earlier. So there is no change. I also checked the packages which I installed just to make sure that I installed everything which is there in the repo. Everything looks same.

I am very new to typescript. I looked into some of these links

link 1 and link 2. But I am not able to understand that. Can anyone please clarify on this why this error is coming ?

shanmugharaj
  • 3,814
  • 7
  • 42
  • 70

2 Answers2

0

I found the mistake I did.

I looked into the repository here. The only change is lies in the tsconfig file

In my tsconfig I had this line

"types": ["reflect-metadata"]

So the compiler is able to look only the @types/node definitions. But when I remove this the compiler is able to find some other definitions from here lib.es2015.symbol.d.ts.

This file is present inside here

/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/lib.es2015.symbol.d.ts

Now that error is gone on the removal of "reflect-metadata" from types in my tsconfig file

shanmugharaj
  • 3,814
  • 7
  • 42
  • 70
0

When I had this issue, I found I had neglected to add "lib": ["es6"] to my tsconfig.json file.

There's a good description of this setting in this answer.

Jono Job
  • 2,732
  • 1
  • 23
  • 23