Dorad
Dorad

Reputation: 3713

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

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

Upvotes: 8

Views: 5227

Answers (1)

satanTime
satanTime

Reputation: 13539

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;

Upvotes: 2

Related Questions