Reputation: 23
I have just started learning Typescript today and when I run tsc app.ts I get 11 errors but I thought I would start with the first. Tried updating tsconfig.json problems seem to be with node_modules.Any help would be appreciated. Thanks.
error states - ../../../node_modules/@types/react/index.d.ts:411:23 - error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"declaration": true,
"outDir": "./lib",
"strict": false,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["./src"],
"exclude": ["node_modules"]
Upvotes: 1
Views: 2814
Reputation: 11
I also used npm install @types/node
and it worked.
By default, TypeScript doesn't have the type declarations for different libraries (for example lodash, or, in this case, Node.js) unless you explicitly install them.
So, the above command provides those type definitions for types specific to Node.js, including Set.
You can read more about it in the TypeScript documentation.
Upvotes: 1
Reputation: 19
In Visual Studio add the Microsoft.TypeScript.MSBuild package.
I also had this problem in a number of my SPAs in a .NET 5 core project. It seems like every time I added a Typescript file manually I would get these errors. I tried all of the different suggestions here on this site but nothing worked. So I paid attention the next time I added a typescript file maually. A pop up mentioned adding the Microsoft.TypeScript.MSBuild package. I did and all the errors went away.
Now, I don't use VSCode, so I don't know if it works the same or not but this worked in Visual Studio 2019.
Upvotes: 1