Site icon Ryadel

Error TS2693 Build:'Map' only refers to a type and other Typescript compilation errors - How to Fix

Fixing TypeScript "Compile on Save" feature in Visual Studio 2015 ASP.NET 5 RC1

Within the past two weeks I received a lot of feedbacks from the readers who bought my ASP.NET Core and Angular 2 book for a rather nasty issue which is also affecting a lot of Typescript-based applications. This is hardly something new: Typescript is sadly full of compilation issues, expecially whithin Visual Studio 2015 and 2017. We already dealt with them a number of times in the past: TS5023TS2304 and even the "Compile on Save" feature, just to name a few.

However this one is different because it involves an internal issue within the DefinitelyTyped repository, which used by many developers to "normalize" the type definitions among different versions of Typescript, thus addressing the compilation errors themselves: in other words, more than a Typescript bug we're dealing with an internal issue of a useful workaround.

The compilation errors you can receive are the following:

Error TS2693 Build:'Map' only refers to a type, but is being used as a value here.
Error TS2693 Build:'Promise' only refers to a type, but is being used as a value here.
Error TS2693 Build:'Set' only refers to a type, but is being used as a value here.
Error TS2304 Build:Cannot find name 'Iterable'.
Error TS2304 Build:Cannot find name 'IterableIterator'.
Error TS2304 Build:Cannot find name 'MapConstructor'.
Error TS2304 Build:Cannot find name 'Iterator'.
Error TS2304 Build:Cannot find name 'PromiseConstructor'.
Error TS2304 Build:Cannot find name 'PropertyKey'.
Error TS2304 Build:Cannot find name 'SetConstructor'.
Error TS2304 Build:Cannot find name 'Symbol'.
Error TS2304 Build:Cannot find name 'WeakMapConstructor'.
Error TS2304 Build:Cannot find name 'WeakSetConstructor'.
Error TS2339 Build:Property 'for' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'hasInstance' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'isConcatSpreadable' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'iterator' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'keyFor' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'match' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'replace' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'search' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'species' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'split' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'toPrimitive' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'toStringTag' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'unscopables' does not exist on type 'SymbolConstructor'.

.. and so on.

As said, the problem is due to an internal issue within that third-party tool - specifically within the core-js definitions list. The problem is well-documented here and it can be fixed in a number of ways, maybe even by passively waiting for the developers to address it: however, if you're stuck with a project you cannot compile anymore - just like my book's readers - there's an easy workaround that we can use to quickly overcome it.

If you're using DefinitelyTyped, you'll probably have a package.json file within the root folder of your project containing something like the following:

 

Replace your existing code with the following one:

What we did that was pretty simple: we specified an explicit version+build for the core-js typings rather than let Visual Studio pick the latest/most recent one: the first one seems to be unaffected by the problem. However, is highly recommended to remove the explicit version+build reference as soon as the issue will be released.

That's it for now: happy coding!

 

Exit mobile version