Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio 2017 | TS2304: Cannot find name 'unknown'

Tags:

typescript

I tried to load some new type definition files into my cordova/typescript project.

Now i receive the following error:

TS2304: Cannot find name 'unknown'.

In those definition files, the unknown type (keyword) isn't painted in blue like 'any' or 'string' etc.

Manually installing typescript extension also didn't solve it.

tsconfig.json:

{
  "compileOnSave": true,
  "compilerOptions": {
    "inlineSources": true,
    "module": "system",
    "noEmitOnError": true,
    "noImplicitAny": false,
    "out": "www/scripts/appBundle.js",
    "preserveConstEnums": true,
    "removeComments": true,
    "sourceMap": true,
    "target": "es2015"
  },
  "files": [ ... ]
}

VS2017 info:

Microsoft Visual Studio Community 2017 Version 15.9.2 VisualStudio.15.Release/15.9.2+28307.108 Microsoft .NET Framework Version 4.7.03056

Installed Version: Community

TypeScript Tools 15.9.20918.2001 TypeScript Tools for Microsoft Visual Studio

Visual Studio Tools for Apache Cordova 15.123.7408.1

Visual Studio Command Prompt output: enter image description here

like image 369
Dorad Avatar asked Nov 25 '18 19:11

Dorad


1 Answers

unknown was added in TS 3.0 and because you get this error it means that your project (package.json) has lower version, whereas VSC has 3.1.2 that supports it and doesn't show the error.

The best practise is to use the same version of TS in both your IDE and your project.

If it's critical for you to stay with TS < 3.0 you can add to declarations of your project, if you don't have them use index.ts.

declare type unknown = any;
like image 150
satanTime Avatar answered Nov 20 '22 14:11

satanTime