8

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

Dorad
  • 3,413
  • 2
  • 44
  • 71
  • 4
    Kinda sounds like you're on an older version of Typescript, so the compiler doesn't recognize the `unknown` keyword which was introduced in TS 3.0. Can you check your Typescript version [like so](https://stackoverflow.com/questions/23948348/where-can-i-find-the-typescript-version-installed-in-visual-studio) – pushkin Nov 28 '18 at 16:48
  • @pushkin - look at edited answer – Dorad Nov 28 '18 at 17:07
  • @AndyJ I have right clicked the project, then clicked properties, but there isn't a "TypeScript Build" tab... – Dorad Nov 28 '18 at 17:07
  • Checkout: https://github.com/Microsoft/TypeScript/issues/17951 – Dipen Shah Nov 29 '18 at 02:54
  • will check and let you know – Dorad Nov 29 '18 at 16:39
  • TypeScriptToolsVersion element value in .jsproj was indeed wrong (2.3). now it's 3.1. unknown is recognized but still not marked as keyword and stays "white". – Dorad Dec 07 '18 at 12:30

1 Answers1

2

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;
satanTime
  • 12,631
  • 1
  • 25
  • 73