简体   繁体   中英

Visual Studio 2015 giving "TS1110 Type expected." for numeric literal type union alias

My general setup is this:

Visual Studio 2015
.NET Framework 4.5.2

I would like to start refactoring some client-side code from javascript to typescript. To start this process, I:

  • Added a .ts file to the web project
  • Let Visual Studio configure itself to compile typescript
  • Installed the jquery.Typescript.DefinitelyTyped Nu-Get package v3.1.2
  • Copied my existing typescript code into the new file

All's good except one of my type alias declarations. I made a simple demonstration of the error at the top of my file to show the issue.

几个字符串之间的类型联合别名很好,但是几个整数之间的类型联合别名会产生错误。

Visual Studio has no problem with a string literal type alias , but doesn't like the numeric literal type alias .

Visual Studio is reporting the version of TypeScript installed as 1.8.36.0 .

In typescript 1.8, numeric literal type aliases aren't implemented yet, only string literal aliases .

Visual Studio 2015 will let you update your version of TypeScript tools to a newer one (though not the newest version, since the team has since moved on from supporting 2015).

  • Got to Tools > Extensions and Updates...
  • Click Online ,
  • Type typescript 3.1.1 into the search bar. That is the most recent version that Visual Studio 2015 supports as of this writing.
  • Clicking download will redirect you to your browser to download the installer.
  • Install away, then restart visual studio.

It should now be using the version of typescript that you installed. You can check what version it's using under Help > About Microsoft Visual Studio .

If it didn't install correctly, edit the relevant .csproj file and change the contents of the element TypeScriptToolsVersion from 1.8 to 3.1 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM