microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.29k stars 12.39k forks source link

[Ts parser bugs] Type casting statement parser error #27183

Closed xieguigang closed 6 years ago

xieguigang commented 6 years ago

TypeScript Version: 3.1.0-dev.201xxxxx

Microsoft Visual Studio Community 2017 Preview Version 15.9.0 Preview 2.0 VisualStudio.15.Preview/15.9.0-pre.2.0+28107.0 Microsoft .NET Framework Version 4.7.03056

Installed Version: Community

Visual C++ 2017 00369-60000-00001-AA604 Microsoft Visual C++ 2017

Application Insights Tools for Visual Studio Package 8.14.10823.1 Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.9.02026.0 ASP.NET and Web Tools 2017

Azure App Service Tools v3.0.0 15.9.02003.0 Azure App Service Tools v3.0.0

C# Tools 2.10.0-beta2-63307-03 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

JavaScript Language Service 2.0 JavaScript Language Service

JavaScript Project System 2.0 JavaScript Project System

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards

Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package

Node.js Tools 1.4.20802.1 Commit Hash:97e1085d8b4b8e3e51c398e910177f87e86d135e Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager 4.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

TypeScript Tools 15.8.20801.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.10.0-beta2-63307-03 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Search Terms:

Type casting statement parser error

Code

return (IEnumerator<Map<string, string>>headers).ToArray();

The type casting statement show above should works, but parser thinks the code is a kind of numeric expression:

ts_parser_error

Expected behavior:

TypeScript parser parse the <type>variable as the type casting expression.

Actual behavior:

The latest typescript parser think it is a numeric math expression

Playground Link:

https://github.com/GCModeller-Cloud/data.ts/blame/3a78b978a32ce32a4a407ee26cd4bd2fed9f1b47/Linq.ts/Linq/DOM/Document.ts#L97

dhruvrajvanshi commented 6 years ago

You aren't using correct syntax for type casting. You did this.

IEnumerator<Map<string, string>>headers // typeheaders

You need to do this

<IEnumerator<Map<string, string>>>headers // <type>headers
xieguigang commented 6 years ago

Oh,yes, many thank for point out my problem.