diff --git a/.gitignore b/.gitignore index a05a65c95c1..21d79becb15 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,5 @@ tests/*.d.ts scripts/debug.bat scripts/run.bat scripts/word2md.js +scripts/ior.js coverage/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a6ab80a408d..dfaba0c06ab 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,7 +9,7 @@ Design changes will not be accepted at this time. If you have a design change pr ## Legal You will need to complete a Contributor License Agreement (CLA). Briefly, this agreement testifies that you are granting us permission to use the submitted change according to the terms of the project's license, and that the work being submitted is under appropriate copyright. -Please submit a Contributor License Agreement (CLA) before submitting a pull request. Download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190)), sign, scan, and email it back to . Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. Please note that we're currently only accepting pull requests of bug fixes rather than new features. +Please submit a Contributor License Agreement (CLA) before submitting a pull request. Download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190) or [Microsoft Contribution License Agreement.pdf](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=921298)), sign, scan, and email it back to . Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. Please note that we're currently only accepting pull requests of bug fixes rather than new features. ## Housekeeping Your pull request should: diff --git a/Jakefile b/Jakefile index da91239d7a5..34879a56691 100644 --- a/Jakefile +++ b/Jakefile @@ -10,6 +10,7 @@ var servicesDirectory = "src/services/"; var harnessDirectory = "src/harness/"; var libraryDirectory = "src/lib/"; var scriptsDirectory = "scripts/"; +var unittestsDirectory = "tests/cases/unittests/"; var docDirectory = "doc/"; var builtDirectory = "built/"; @@ -74,13 +75,17 @@ var harnessSources = [ "typeWriter.ts", "fourslashRunner.ts", "projectsRunner.ts", - "unittestrunner.ts", "loggedIO.ts", "rwcRunner.ts", "runner.ts" ].map(function (f) { return path.join(harnessDirectory, f); -}); +}).concat([ + "services/colorization.ts", + "services/documentRegistry.ts" +].map(function (f) { + return path.join(unittestsDirectory, f); +})); var librarySourceMap = [ { target: "lib.core.d.ts", sources: ["core.d.ts"] }, @@ -279,7 +284,6 @@ var word2mdJs = path.join(scriptsDirectory, "word2md.js"); var word2mdTs = path.join(scriptsDirectory, "word2md.ts"); var specWord = path.join(docDirectory, "TypeScript Language Specification.docx"); var specMd = path.join(docDirectory, "spec.md"); -var headerMd = path.join(docDirectory, "header.md"); file(word2mdTs); @@ -292,9 +296,8 @@ compileFile(word2mdJs, // The generated spec.md; built for the 'generate-spec' task file(specMd, [word2mdJs, specWord], function () { - jake.cpR(headerMd, specMd, {silent: true}); var specWordFullPath = path.resolve(specWord); - var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" >>' + specMd; + var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + specMd; console.log(cmd); child_process.exec(cmd, function () { complete(); diff --git a/README.md b/README.md index 0d304cf0679..f7e55d2dffe 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +[![Build Status](https://travis-ci.org/Microsoft/TypeScript.svg?branch=master)](https://travis-ci.org/Microsoft/TypeScript) +[![Issue Stats](http://issuestats.com/github/Microsoft/TypeScript/badge/pr)](http://issuestats.com/github/microsoft/typescript) +[![Issue Stats](http://issuestats.com/github/Microsoft/TypeScript/badge/issue)](http://issuestats.com/github/microsoft/typescript) + # TypeScript [TypeScript](http://www.typescriptlang.org/) is a language for application-scale JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript supports tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the [playground](http://www.typescriptlang.org/Playground), and stay up to date via [our blog](http://blogs.msdn.com/typescript) and [twitter account](https://twitter.com/typescriptlang). diff --git a/doc/TypeScript Language Specification (Change Markup).docx b/doc/TypeScript Language Specification (Change Markup).docx index 5bc24af5ec8..bb4be4fac1c 100644 Binary files a/doc/TypeScript Language Specification (Change Markup).docx and b/doc/TypeScript Language Specification (Change Markup).docx differ diff --git a/doc/TypeScript Language Specification (Change Markup).pdf b/doc/TypeScript Language Specification (Change Markup).pdf index 52998e9ec79..0cffd20b7c7 100644 Binary files a/doc/TypeScript Language Specification (Change Markup).pdf and b/doc/TypeScript Language Specification (Change Markup).pdf differ diff --git a/doc/TypeScript Language Specification.docx b/doc/TypeScript Language Specification.docx index 381ac186a4b..3d2014252f2 100644 Binary files a/doc/TypeScript Language Specification.docx and b/doc/TypeScript Language Specification.docx differ diff --git a/doc/TypeScript Language Specification.pdf b/doc/TypeScript Language Specification.pdf index 049f7e06fb3..203269c3f24 100644 Binary files a/doc/TypeScript Language Specification.pdf and b/doc/TypeScript Language Specification.pdf differ diff --git a/doc/header.md b/doc/header.md deleted file mode 100644 index 3cf5b569800..00000000000 --- a/doc/header.md +++ /dev/null @@ -1,2 +0,0 @@ -# TypeScript Language Specification - diff --git a/doc/spec.md b/doc/spec.md index 5635c100a40..158c431c229 100644 --- a/doc/spec.md +++ b/doc/spec.md @@ -1,12 +1,12 @@ # TypeScript Language Specification -Version 1.3 +Version 1.4 -September, 2014 +October, 2014
-Microsoft is making this Specification available under the Open Web Foundation Final Specification Agreement Version 1.0 (“OWF 1.0”) as of October 1, 2012. The OWF 1.0 is available at http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0. +Microsoft is making this Specification available under the Open Web Foundation Final Specification Agreement Version 1.0 ("OWF 1.0") as of October 1, 2012. The OWF 1.0 is available at http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0. TypeScript is a trademark of Microsoft Corporation. @@ -45,9 +45,10 @@ TypeScript is a trademark of Microsoft Corporation. * [3.3.1 Named Type References](#3.3.1) * [3.3.2 Array Types](#3.3.2) * [3.3.3 Tuple Types](#3.3.3) - * [3.3.4 Function Types](#3.3.4) - * [3.3.5 Constructor Types](#3.3.5) - * [3.3.6 Members](#3.3.6) + * [3.3.4 Union Types](#3.3.4) + * [3.3.5 Function Types](#3.3.5) + * [3.3.6 Constructor Types](#3.3.6) + * [3.3.7 Members](#3.3.7) * [3.4 Type Parameters](#3.4) * [3.4.1 Type Parameter Lists](#3.4.1) * [3.4.2 Type Argument Lists](#3.4.2) @@ -59,9 +60,10 @@ TypeScript is a trademark of Microsoft Corporation. * [3.6.3 Object Type Literals](#3.6.3) * [3.6.4 Array Type Literals](#3.6.4) * [3.6.5 Tuple Type Literals](#3.6.5) - * [3.6.6 Function Type Literals](#3.6.6) - * [3.6.7 Constructor Type Literals](#3.6.7) - * [3.6.8 Type Queries](#3.6.8) + * [3.6.6 Union Type Literals](#3.6.6) + * [3.6.7 Function Type Literals](#3.6.7) + * [3.6.8 Constructor Type Literals](#3.6.8) + * [3.6.9 Type Queries](#3.6.9) * [3.7 Specifying Members](#3.7) * [3.7.1 Property Signatures](#3.7.1) * [3.7.2 Call Signatures](#3.7.2) @@ -77,7 +79,6 @@ TypeScript is a trademark of Microsoft Corporation. * [3.8.6 Type Inference](#3.8.6) * [3.8.7 Recursive Types](#3.8.7) * [3.9 Widened Types](#3.9) - * [3.10 Best Common Type](#3.10) * [4 Expressions](#4) * [4.1 Values and References](#4.1) * [4.2 The this Keyword](#4.2) @@ -102,13 +103,13 @@ TypeScript is a trademark of Microsoft Corporation. * [4.13 Type Assertions](#4.13) * [4.14 Unary Operators](#4.14) * [4.14.1 The ++ and -- operators](#4.14.1) - * [4.14.2 The +, –, and ~ operators](#4.14.2) + * [4.14.2 The +, –, and ~ operators](#4.14.2) * [4.14.3 The ! operator](#4.14.3) * [4.14.4 The delete Operator](#4.14.4) * [4.14.5 The void Operator](#4.14.5) * [4.14.6 The typeof Operator](#4.14.6) * [4.15 Binary Operators](#4.15) - * [4.15.1 The *, /, %, –, <<, >>, >>>, &, ^, and | operators](#4.15.1) + * [4.15.1 The *, /, %, –, <<, >>, >>>, &, ^, and | operators](#4.15.1) * [4.15.2 The + operator](#4.15.2) * [4.15.3 The <, >, <=, >=, ==, !=, ===, and !== operators](#4.15.3) * [4.15.4 The instanceof operator](#4.15.4) @@ -119,6 +120,7 @@ TypeScript is a trademark of Microsoft Corporation. * [4.17 Assignment Operators](#4.17) * [4.18 The Comma Operator](#4.18) * [4.19 Contextually Typed Expressions](#4.19) + * [4.20 Type Guards](#4.20) * [5 Statements](#5) * [5.1 Variable Statements](#5.1) * [5.2 If, Do, and While Statements](#5.2) @@ -210,7 +212,7 @@ TypeScript is a trademark of Microsoft Corporation. # 1 Introduction -JavaScript applications such as web e-mail, maps, document editing, and collaboration tools are becoming an increasingly important part of the everyday computing. We designed TypeScript to meet the needs of the JavaScript programming teams that build and maintain large JavaScript programs. TypeScript helps programming teams to define interfaces between software components and to gain insight into the behavior of existing JavaScript libraries. TypeScript also enables teams to reduce naming conflicts by organizing their code into dynamically-loadable modules. TypeScript’s optional type system enables JavaScript programmers to use highly-productive development tools and practices: static checking, symbol-based navigation, statement completion, and code re-factoring. +JavaScript applications such as web e-mail, maps, document editing, and collaboration tools are becoming an increasingly important part of the everyday computing. We designed TypeScript to meet the needs of the JavaScript programming teams that build and maintain large JavaScript programs. TypeScript helps programming teams to define interfaces between software components and to gain insight into the behavior of existing JavaScript libraries. TypeScript also enables teams to reduce naming conflicts by organizing their code into dynamically-loadable modules. TypeScript's optional type system enables JavaScript programmers to use highly-productive development tools and practices: static checking, symbol-based navigation, statement completion, and code re-factoring. TypeScript is a syntactic sugar for JavaScript. TypeScript syntax is a superset of Ecmascript 5 (ES5) syntax. Every JavaScript program is also a TypeScript program. The TypeScript compiler performs only file-local transformations on TypeScript programs and does not re-order variables declared in TypeScript. This leads to JavaScript output that closely matches the TypeScript input. TypeScript does not transform variable names, making tractable the direct debugging of emitted JavaScript. TypeScript optionally provides source maps, enabling source-level debugging. TypeScript tools typically emit JavaScript upon file save, preserving the test, edit, refresh cycle commonly used in JavaScript development. @@ -218,7 +220,7 @@ TypeScript syntax includes several proposed features of Ecmascript 6 (ES6), incl TypeScript also provides to JavaScript programmers a system of optional type annotations. These type annotations are like the JSDoc comments found in the Closure system, but in TypeScript they are integrated directly into the language syntax. This integration makes the code more readable and reduces the maintenance cost of synchronizing type annotations with their corresponding variables. -The TypeScript type system enables programmers to express limits on the capabilities of JavaScript objects, and to use tools that enforce these limits. To minimize the number of annotations needed for tools to become useful, the TypeScript type system makes extensive use of type inference. For example, from the following statement, TypeScript will infer that the variable ‘i’ has the type number. +The TypeScript type system enables programmers to express limits on the capabilities of JavaScript objects, and to use tools that enforce these limits. To minimize the number of annotations needed for tools to become useful, the TypeScript type system makes extensive use of type inference. For example, from the following statement, TypeScript will infer that the variable 'i' has the type number. ```TypeScript var i = 0; @@ -247,7 +249,7 @@ f({}); // Error f("hello"); // Ok ``` -This optional type annotation on the parameter ‘s’ lets the TypeScript type checker know that the programmer expects parameter ‘s’ to be of type ‘string’. Within the body of function ‘f’, tools can assume ‘s’ is of type ‘string’ and provide operator type checking and member completion consistent with this assumption. Tools can also signal an error on the first call to ‘f’, because ‘f’ expects a string, not an object, as its parameter. For the function ‘f’, the TypeScript compiler will emit the following JavaScript code: +This optional type annotation on the parameter 's' lets the TypeScript type checker know that the programmer expects parameter 's' to be of type 'string'. Within the body of function 'f', tools can assume 's' is of type 'string' and provide operator type checking and member completion consistent with this assumption. Tools can also signal an error on the first call to 'f', because 'f' expects a string, not an object, as its parameter. For the function 'f', the TypeScript compiler will emit the following JavaScript code: ```TypeScript function f(s) { @@ -259,14 +261,14 @@ In the JavaScript output, all type annotations have been erased. In general, Typ ## 1.1 Ambient Declarations -An ambient declaration introduces a variable into a TypeScript scope, but has zero impact on the emitted JavaScript program. Programmers can use ambient declarations to tell the TypeScript compiler that some other component will supply a variable. For example, by default the TypeScript compiler will print an error for uses of undefined variables. To add some of the common variables defined by browsers, a TypeScript programmer can use ambient declarations. The following example declares the ‘document’ object supplied by browsers. Because the declaration does not specify a type, the type ‘any’ is inferred. The type ‘any’ means that a tool can assume nothing about the shape or behavior of the document object. Some of the examples below will illustrate how programmers can use types to further characterize the expected behavior of an object. +An ambient declaration introduces a variable into a TypeScript scope, but has zero impact on the emitted JavaScript program. Programmers can use ambient declarations to tell the TypeScript compiler that some other component will supply a variable. For example, by default the TypeScript compiler will print an error for uses of undefined variables. To add some of the common variables defined by browsers, a TypeScript programmer can use ambient declarations. The following example declares the 'document' object supplied by browsers. Because the declaration does not specify a type, the type 'any' is inferred. The type 'any' means that a tool can assume nothing about the shape or behavior of the document object. Some of the examples below will illustrate how programmers can use types to further characterize the expected behavior of an object. ```TypeScript declare var document; document.title = "Hello"; // Ok because document has been declared ``` -In the case of ‘document’, the TypeScript compiler automatically supplies a declaration, because TypeScript by default includes a file ‘lib.d.ts’ that provides interface declarations for the built-in JavaScript library as well as the Document Object Model. +In the case of 'document', the TypeScript compiler automatically supplies a declaration, because TypeScript by default includes a file 'lib.d.ts' that provides interface declarations for the built-in JavaScript library as well as the Document Object Model. The TypeScript compiler does not include by default an interface for jQuery, so to use jQuery, a programmer could supply a declaration such as: @@ -278,7 +280,7 @@ Section [1.3](#1.3) provides a more extensive example of how a programmer can ad ## 1.2 Function Types -Function expressions are a powerful feature of JavaScript. They enable function definitions to create closures: functions that capture information from the lexical scope surrounding the function’s definition. Closures are currently JavaScript’s only way of enforcing data encapsulation. By capturing and using environment variables, a closure can retain information that cannot be accessed from outside the closure. JavaScript programmers often use closures to express event handlers and other asynchronous callbacks, in which another software component, such as the DOM, will call back into JavaScript through a handler function. +Function expressions are a powerful feature of JavaScript. They enable function definitions to create closures: functions that capture information from the lexical scope surrounding the function's definition. Closures are currently JavaScript's only way of enforcing data encapsulation. By capturing and using environment variables, a closure can retain information that cannot be accessed from outside the closure. JavaScript programmers often use closures to express event handlers and other asynchronous callbacks, in which another software component, such as the DOM, will call back into JavaScript through a handler function. TypeScript function types make it possible for programmers to express the expected *signature* of a function. A function signature is a sequence of parameter types plus a return type. The following example uses function types to express the callback signature requirements of an asynchronous voting mechanism. @@ -296,19 +298,19 @@ vote("BigPig", ); ``` -In this example, the second parameter to ‘vote’ has the function type +In this example, the second parameter to 'vote' has the function type ```TypeScript (result: string) => any ``` -which means the second parameter is a function returning type ‘any’ that has a single parameter of type ‘string’ named ‘result’. +which means the second parameter is a function returning type 'any' that has a single parameter of type 'string' named 'result'. Section [3.7.2](#3.7.2) provides additional information about function types. ## 1.3 Object Types -TypeScript programmers use *object types* to declare their expectations of object behavior. The following code uses an *object type literal* to specify the return type of the ‘MakePoint’ function. +TypeScript programmers use *object types* to declare their expectations of object behavior. The following code uses an *object type literal* to specify the return type of the 'MakePoint' function. ```TypeScript var MakePoint: () => { @@ -333,7 +335,7 @@ add({ favoriteColor: "blue" }); // Error, name required add({ name: "Jill", favoriteColor: "green" }); // Ok ``` -TypeScript object types model the diversity of behaviors that a JavaScript object can exhibit. For example, the jQuery library defines an object, ‘$’, that has methods, such as ‘get’ (which sends an Ajax message), and fields, such as ‘browser’ (which gives browser vendor information). However, jQuery clients can also call ‘$’ as a function. The behavior of this function depends on the type of parameters passed to the function. +TypeScript object types model the diversity of behaviors that a JavaScript object can exhibit. For example, the jQuery library defines an object, '$', that has methods, such as 'get' (which sends an Ajax message), and fields, such as 'browser' (which gives browser vendor information). However, jQuery clients can also call '$' as a function. The behavior of this function depends on the type of parameters passed to the function. The following code fragment captures a small subset of jQuery behavior, just enough to use jQuery in a simple way. @@ -356,9 +358,9 @@ $.get("http://mysite.org/divContent", ); ``` -The ‘JQueryStatic’ interface references another interface: ‘JQuery’. This interface represents a collection of one or more DOM elements. The jQuery library can perform many operations on such a collection, but in this example the jQuery client only needs to know that it can set the text content of each jQuery element in a collection by passing a string to the ‘text’ method. The ‘JQueryStatic’ interface also contains a method, ‘get’, that performs an Ajax get operation on the provided URL and arranges to invoke the provided callback upon receipt of a response. +The 'JQueryStatic' interface references another interface: 'JQuery'. This interface represents a collection of one or more DOM elements. The jQuery library can perform many operations on such a collection, but in this example the jQuery client only needs to know that it can set the text content of each jQuery element in a collection by passing a string to the 'text' method. The 'JQueryStatic' interface also contains a method, 'get', that performs an Ajax get operation on the provided URL and arranges to invoke the provided callback upon receipt of a response. -Finally, the ‘JQueryStatic’ interface contains a bare function signature +Finally, the 'JQueryStatic' interface contains a bare function signature ```TypeScript (query: string): JQuery; @@ -372,13 +374,13 @@ var sameType: () => string = f; // Ok var nope: () => number = sameType; // Error: type mismatch ``` -We mentioned above that the ‘$’ function behaves differently depending on the type of its parameter. So far, our jQuery typing only captures one of these behaviors: return an object of type ‘JQuery’ when passed a string. To specify multiple behaviors, TypeScript supports *overloading* of function signatures in object types. For example, we can add an additional call signature to the ‘JQueryStatic’ interface. +We mentioned above that the '$' function behaves differently depending on the type of its parameter. So far, our jQuery typing only captures one of these behaviors: return an object of type 'JQuery' when passed a string. To specify multiple behaviors, TypeScript supports *overloading* of function signatures in object types. For example, we can add an additional call signature to the 'JQueryStatic' interface. ```TypeScript (ready: () => any): any; ``` -This signature denotes that a function may be passed as the parameter of the ‘$’ function. When a function is passed to ‘$’, the jQuery library will invoke that function when a DOM document is ready. Because TypeScript supports overloading, tools can use TypeScript to show all available function signatures with their documentation tips and to give the correct documentation once a function has been called with a particular signature. +This signature denotes that a function may be passed as the parameter of the '$' function. When a function is passed to '$', the jQuery library will invoke that function when a DOM document is ready. Because TypeScript supports overloading, tools can use TypeScript to show all available function signatures with their documentation tips and to give the correct documentation once a function has been called with a particular signature. A typical client would not need to add any additional typing but could just use a community-supplied typing to discover (through statement completion with documentation tips) and verify (through static checking) correct use of the library, as in the following screen shot. @@ -388,7 +390,7 @@ Section [3.3](#3.3) provides additional information about object types. ## 1.4 Structural Subtyping -Object types are compared *structurally*. For example, in the code fragment below, class ‘CPoint’ matches interface ‘Point’ because ‘CPoint’ has all of the required members of ‘Point’. A class may optionally declare that it implements an interface, so that the compiler will check the declaration for structural compatibility. The example also illustrates that an object type can match the type inferred from an object literal, as long as the object literal supplies all of the required members. +Object types are compared *structurally*. For example, in the code fragment below, class 'CPoint' matches interface 'Point' because 'CPoint' has all of the required members of 'Point'. A class may optionally declare that it implements an interface, so that the compiler will check the declaration for structural compatibility. The example also illustrates that an object type can match the type inferred from an object literal, as long as the object literal supplies all of the required members. ```TypeScript interface Point { @@ -420,7 +422,7 @@ See section [3.8](#3.8) for more information about type comparisons. ## 1.5 Contextual Typing -Ordinarily, TypeScript type inference proceeds “bottom-up”: from the leaves of an expression tree to its root. In the following example, TypeScript infers ‘number’ as the return type of the function ‘mul’ by flowing type information bottom up in the return expression. +Ordinarily, TypeScript type inference proceeds "bottom-up": from the leaves of an expression tree to its root. In the following example, TypeScript infers 'number' as the return type of the function 'mul' by flowing type information bottom up in the return expression. ```TypeScript function mul(a: number, b: number) { @@ -428,9 +430,9 @@ function mul(a: number, b: number) { } ``` -For variables and parameters without a type annotation or a default value, TypeScript infers type ‘any’, ensuring that compilers do not need non-local information about a function’s call sites to infer the function’s return type. Generally, this bottom-up approach provides programmers with a clear intuition about the flow of type information. +For variables and parameters without a type annotation or a default value, TypeScript infers type 'any', ensuring that compilers do not need non-local information about a function's call sites to infer the function's return type. Generally, this bottom-up approach provides programmers with a clear intuition about the flow of type information. -However, in some limited contexts, inference proceeds “top-down” from the context of an expression. Where this happens, it is called contextual typing. Contextual typing helps tools provide excellent information when a programmer is using a type but may not know all of the details of the type. For example, in the jQuery example, above, the programmer supplies a function expression as the second parameter to the ‘get’ method. During typing of that expression, tools can assume that the type of the function expression is as given in the ‘get’ signature and can provide a template that includes parameter names and types. +However, in some limited contexts, inference proceeds "top-down" from the context of an expression. Where this happens, it is called contextual typing. Contextual typing helps tools provide excellent information when a programmer is using a type but may not know all of the details of the type. For example, in the jQuery example, above, the programmer supplies a function expression as the second parameter to the 'get' method. During typing of that expression, tools can assume that the type of the function expression is as given in the 'get' signature and can provide a template that includes parameter names and types. ```TypeScript $.get("http://mysite.org/divContent", @@ -446,9 +448,9 @@ Section [4.19](#4.19) provides additional information about contextually typed e ## 1.6 Classes -JavaScript practice has at least two common design patterns: the module pattern and the class pattern. Roughly speaking, the module pattern uses closures to hide names and to encapsulate private data, while the class pattern uses prototype chains to implement many variations on object-oriented inheritance mechanisms. Libraries such as ‘prototype.js’ are typical of this practice. +JavaScript practice has at least two common design patterns: the module pattern and the class pattern. Roughly speaking, the module pattern uses closures to hide names and to encapsulate private data, while the class pattern uses prototype chains to implement many variations on object-oriented inheritance mechanisms. Libraries such as 'prototype.js' are typical of this practice. -This section and the module section below will show how TypeScript emits consistent, idiomatic JavaScript code to implement classes and modules that are closely aligned with the current ES6 proposal. The goal of TypeScript’s translation is to emit exactly what a programmer would type when implementing a class or module unaided by a tool. This section will also describe how TypeScript infers a type for each class declaration. We’ll start with a simple BankAccount class. +This section and the module section below will show how TypeScript emits consistent, idiomatic JavaScript code to implement classes and modules that are closely aligned with the current ES6 proposal. The goal of TypeScript's translation is to emit exactly what a programmer would type when implementing a class or module unaided by a tool. This section will also describe how TypeScript infers a type for each class declaration. We'll start with a simple BankAccount class. ```TypeScript class BankAccount { @@ -475,7 +477,7 @@ var BankAccount = (function () { })(); ``` -This TypeScript class declaration creates a variable named ‘BankAccount’ whose value is the constructor function for ‘BankAccount’ instances. This declaration also creates an instance type of the same name. If we were to write this type as an interface it would look like the following. +This TypeScript class declaration creates a variable named 'BankAccount' whose value is the constructor function for 'BankAccount' instances. This declaration also creates an instance type of the same name. If we were to write this type as an interface it would look like the following. ```TypeScript interface BankAccount { @@ -484,15 +486,15 @@ interface BankAccount { } ``` -If we were to write out the function type declaration for the ‘BankAccount’ constructor variable, it would have the following form. +If we were to write out the function type declaration for the 'BankAccount' constructor variable, it would have the following form. ```TypeScript var BankAccount: new() => BankAccount; ``` -The function signature is prefixed with the keyword ‘new’ indicating that the ‘BankAccount’ function must be called as a constructor. It is possible for a function’s type to have both call and constructor signatures. For example, the type of the built-in JavaScript Date object includes both kinds of signatures. +The function signature is prefixed with the keyword 'new' indicating that the 'BankAccount' function must be called as a constructor. It is possible for a function's type to have both call and constructor signatures. For example, the type of the built-in JavaScript Date object includes both kinds of signatures. -If we want to start our bank account with an initial balance, we can add to the ‘BankAccount’ class a constructor declaration. +If we want to start our bank account with an initial balance, we can add to the 'BankAccount' class a constructor declaration. ```TypeScript class BankAccount { @@ -507,7 +509,7 @@ class BankAccount { } ``` -This version of the ‘BankAccount’ class requires us to introduce a constructor parameter and then assign it to the ‘balance’ field. To simplify this common case, TypeScript accepts the following shorthand syntax. +This version of the 'BankAccount' class requires us to introduce a constructor parameter and then assign it to the 'balance' field. To simplify this common case, TypeScript accepts the following shorthand syntax. ```TypeScript class BankAccount { @@ -520,7 +522,7 @@ class BankAccount { } ``` -The ‘public’ keyword denotes that the constructor parameter is to be retained as a field. Public is the default accessibility for class members, but a programmer can also specify private or protected accessibility for a class member. Accessibility is a design-time construct; it is enforced during static type checking but does not imply any runtime enforcement. +The 'public' keyword denotes that the constructor parameter is to be retained as a field. Public is the default accessibility for class members, but a programmer can also specify private or protected accessibility for a class member. Accessibility is a design-time construct; it is enforced during static type checking but does not imply any runtime enforcement. TypeScript classes also support inheritance, as in the following example.* * @@ -535,7 +537,7 @@ class CheckingAccount extends BankAccount { } ``` -In this example, the class ‘CheckingAccount’ *derives* from class ‘BankAccount’. The constructor for ‘CheckingAccount’ calls the constructor for class ‘BankAccount’ using the ‘super’ keyword. In the emitted JavaScript code, the prototype of ‘CheckingAccount’ will chain to the prototype of ‘BankingAccount’. +In this example, the class 'CheckingAccount' *derives* from class 'BankAccount'. The constructor for 'CheckingAccount' calls the constructor for class 'BankAccount' using the 'super' keyword. In the emitted JavaScript code, the prototype of 'CheckingAccount' will chain to the prototype of 'BankingAccount'. TypeScript classes may also specify static members. Static class members become properties of the class constructor. @@ -559,11 +561,11 @@ function compute(op: Operator, a: number, b: number) { } ``` -In this example, the compute function logs the operator ‘op’ using a feature of enum types: reverse mapping from the enum value (‘op’) to the string corresponding to that value. For example, the declaration of ‘Operator’ automatically assigns integers, starting from zero, to the listed enum members. Section [9](#9) describes how programmers can also explicitly assign integers to enum members, and can use any string to name an enum member. +In this example, the compute function logs the operator 'op' using a feature of enum types: reverse mapping from the enum value ('op') to the string corresponding to that value. For example, the declaration of 'Operator' automatically assigns integers, starting from zero, to the listed enum members. Section [9](#9) describes how programmers can also explicitly assign integers to enum members, and can use any string to name an enum member. -If all enum members have explicitly assigned literal integers, or if an enum has all members automatically assigned, the TypeScript compiler will emit for an enum member a JavaScript constant corresponding to that member’s assigned value (annotated with a comment). This improves performance on many JavaScript engines. +If all enum members have explicitly assigned literal integers, or if an enum has all members automatically assigned, the TypeScript compiler will emit for an enum member a JavaScript constant corresponding to that member's assigned value (annotated with a comment). This improves performance on many JavaScript engines. -For example, the ‘compute’ function could contain a switch statement like the following. +For example, the 'compute' function could contain a switch statement like the following. ```TypeScript switch (op) { @@ -597,18 +599,18 @@ JavaScript implementations can use these explicit constants to generate efficien An important goal of TypeScript is to provide accurate and straightforward types for existing JavaScript programming patterns. To that end, TypeScript includes generic types, discussed in the next section, and *overloading on string parameters*, the topic of this section. -JavaScript programming interfaces often include functions whose behavior is discriminated by a string constant passed to the function. The Document Object Model makes heavy use of this pattern. For example, the following screen shot shows that the ‘createElement’ method of the ‘document’ object has multiple signatures, some of which identify the types returned when specific strings are passed into the method. +JavaScript programming interfaces often include functions whose behavior is discriminated by a string constant passed to the function. The Document Object Model makes heavy use of this pattern. For example, the following screen shot shows that the 'createElement' method of the 'document' object has multiple signatures, some of which identify the types returned when specific strings are passed into the method. / -The following code fragment uses this feature. Because the ‘span’ variable is inferred to have the type ‘HTMLSpanElement’, the code can reference without static error the ‘isMultiline’ property of ‘span’. +The following code fragment uses this feature. Because the 'span' variable is inferred to have the type 'HTMLSpanElement', the code can reference without static error the 'isMultiline' property of 'span'. ```TypeScript var span = document.createElement("span"); span.isMultiLine = false; // OK: HTMLSpanElement has isMultiline property ``` -In the following screen shot, a programming tool combines information from overloading on string parameters with contextual typing to infer that the type of the variable ‘e’ is ‘MouseEvent’ and that therefore ‘e’ has a ‘clientX’ property. +In the following screen shot, a programming tool combines information from overloading on string parameters with contextual typing to infer that the type of the variable 'e' is 'MouseEvent' and that therefore 'e' has a 'clientX' property. / @@ -618,7 +620,7 @@ Section [3.7.2.4](#3.7.2.4) provides details on how to use string literals in fu Like overloading on string parameters, *generic types* make it easier for TypeScript to accurately capture the behavior of JavaScript libraries. Because they enable type information to flow from client code, through library code, and back into client code, generic types may do more than any other TypeScript feature to support detailed API descriptions. -To illustrate this, let’s take a look at part of the TypeScript interface for the built-in JavaScript array type. You can find this interface in the ‘lib.d.ts’ file that accompanies a TypeScript distribution. +To illustrate this, let's take a look at part of the TypeScript interface for the built-in JavaScript array type. You can find this interface in the 'lib.d.ts' file that accompanies a TypeScript distribution. ```TypeScript interface Array { @@ -628,17 +630,17 @@ interface Array { } ``` -Interface definitions, like the one above, can have one or more *type parameters*. In this case the ‘Array’ interface has a single parameter, ‘T’, that defines the element type for the array. The ‘reverse’ method returns an array with the same element type. The sort method takes an optional parameter, ‘compareFn’, whose type is a function that takes two parameters of type ‘T’ and returns a number. Finally, sort returns an array with element type ‘T’. +Interface definitions, like the one above, can have one or more *type parameters*. In this case the 'Array' interface has a single parameter, 'T', that defines the element type for the array. The 'reverse' method returns an array with the same element type. The sort method takes an optional parameter, 'compareFn', whose type is a function that takes two parameters of type 'T' and returns a number. Finally, sort returns an array with element type 'T'. -Functions can also have generic parameters. For example, the array interface contains a ‘map’ method, defined as follows: +Functions can also have generic parameters. For example, the array interface contains a 'map' method, defined as follows: ```TypeScript map(func: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; ``` -The map method, invoked on an array ‘a’ with element type ‘T’, will apply function ‘func’ to each element of ‘a’, returning a value of type ‘U’. +The map method, invoked on an array 'a' with element type 'T', will apply function 'func' to each element of 'a', returning a value of type 'U'. -The TypeScript compiler can often infer generic method parameters, making it unnecessary for the programmer to explicitly provide them. In the following example, the compiler infers that parameter ‘U’ of the map method has type ‘string’, because the function passed to map returns a string. +The TypeScript compiler can often infer generic method parameters, making it unnecessary for the programmer to explicitly provide them. In the following example, the compiler infers that parameter 'U' of the map method has type 'string', because the function passed to map returns a string. ```TypeScript function numberToString(a: number[]) { @@ -647,9 +649,9 @@ function numberToString(a: number[]) { } ``` -The compiler infers in this example that the ‘numberToString’ function returns an array of strings. +The compiler infers in this example that the 'numberToString' function returns an array of strings. -In TypeScript, classes can also have type parameters. The following code declares a class that implements a linked list of items of type ‘T’. This code illustrates how programmers can *constrain* type parameters to extend a specific type. In this case, the items on the list must extend the type ‘NamedItem’. This enables the programmer to implement the ‘log’ function, which logs the name of the item. +In TypeScript, classes can also have type parameters. The following code declares a class that implements a linked list of items of type 'T'. This code illustrates how programmers can *constrain* type parameters to extend a specific type. In this case, the items on the list must extend the type 'NamedItem'. This enables the programmer to implement the 'log' function, which logs the name of the item. ```TypeScript interface NamedItem { @@ -680,7 +682,7 @@ Section [3.5](#3.5) provides further information about generic types. ## 1.10 Modules -Classes and interfaces support large-scale JavaScript development by providing a mechanism for describing how to use a software component that can be separated from that component’s implementation. TypeScript enforces *encapsulation* of implementation in classes at design time (by restricting use of private and protected members), but cannot enforce encapsulation at runtime because all object properties are accessible at runtime. Future versions of JavaScript may provide *private names* which would enable runtime enforcement of private and protected members. +Classes and interfaces support large-scale JavaScript development by providing a mechanism for describing how to use a software component that can be separated from that component's implementation. TypeScript enforces *encapsulation* of implementation in classes at design time (by restricting use of private and protected members), but cannot enforce encapsulation at runtime because all object properties are accessible at runtime. Future versions of JavaScript may provide *private names* which would enable runtime enforcement of private and protected members. In the current version of JavaScript, the only way to enforce encapsulation at runtime is to use the module pattern: encapsulate private fields and methods using closure variables. The module pattern is a natural way to provide organizational structure and dynamic loading options by drawing a boundary around a software component. A module can also provide the ability to introduce namespaces, avoiding use of the global namespace for most software components. @@ -696,9 +698,9 @@ The following example illustrates the JavaScript module pattern. })(MessageModule); ``` -This example illustrates the two essential elements of the module pattern: a *module closure* and a *module* *object*. The module closure is a function that encapsulates the module’s implementation, in this case the variable ‘key’ and the function ‘sendMessage’. The module object contains the exported variables and functions of the module. Simple modules may create and return the module object. The module above takes the module object as a parameter, ‘exports’, and adds the ‘sendMessage’ property to the module object. This *augmentation* approach simplifies dynamic loading of modules and also supports separation of module code into multiple files. +This example illustrates the two essential elements of the module pattern: a *module closure* and a *module* *object*. The module closure is a function that encapsulates the module's implementation, in this case the variable 'key' and the function 'sendMessage'. The module object contains the exported variables and functions of the module. Simple modules may create and return the module object. The module above takes the module object as a parameter, 'exports', and adds the 'sendMessage' property to the module object. This *augmentation* approach simplifies dynamic loading of modules and also supports separation of module code into multiple files. -The example assumes that an outer lexical scope defines the functions ‘generateSecretKey’ and ‘sendSecureMessage’; it also assumes that the outer scope has assigned the module object to the variable ‘MessageModule’. +The example assumes that an outer lexical scope defines the functions 'generateSecretKey' and 'sendSecureMessage'; it also assumes that the outer scope has assigned the module object to the variable 'MessageModule'. TypeScript modules provide a mechanism for succinctly expressing the module pattern. In TypeScript, programmers can combine the module pattern with the class pattern by nesting modules and classes within an outer module. @@ -716,7 +718,7 @@ M.f(); M.s; // Error, s is not exported ``` -In this example, variable ‘s’ is a private feature of the module, but function ‘f’ is exported from the module and accessible to code outside of the module. If we were to describe the effect of module ‘M’ in terms of interfaces and variables, we would write +In this example, variable 's' is a private feature of the module, but function 'f' is exported from the module and accessible to code outside of the module. If we were to describe the effect of module 'M' in terms of interfaces and variables, we would write ```TypeScript interface M { @@ -726,9 +728,9 @@ interface M { var M: M; ``` -The interface ‘M’ summarizes the externally visible behavior of module ‘M’. In this example, we can use the same name for the interface as for the initialized variable because in TypeScript type names and variable names do not conflict: each lexical scope contains a variable declaration space and type declaration space (see section [2.3](#2.3) for more details). +The interface 'M' summarizes the externally visible behavior of module 'M'. In this example, we can use the same name for the interface as for the initialized variable because in TypeScript type names and variable names do not conflict: each lexical scope contains a variable declaration space and type declaration space (see section [2.3](#2.3) for more details). -Module ‘M’ is an example of an *internal* module, because it is nested within the *global* module (see section [10](#10) for more details). The TypeScript compiler emits the following JavaScript code for this module. +Module 'M' is an example of an *internal* module, because it is nested within the *global* module (see section [10](#10) for more details). The TypeScript compiler emits the following JavaScript code for this module. ```TypeScript var M; @@ -741,7 +743,7 @@ var M; })(M || (M = {})); ``` -In this case, the compiler assumes that the module object resides in global variable ‘M’, which may or may not have been initialized to the desired module object. +In this case, the compiler assumes that the module object resides in global variable 'M', which may or may not have been initialized to the desired module object. TypeScript also supports *external* modules, which are files that contain top-level *export* and *import *directives. For this type of module the TypeScript compiler will emit code whose module closure and module object implementation vary according to the specified dynamic loading system, for example, the Asynchronous Module Definition system. @@ -756,13 +758,13 @@ The remainder of this document is the formal specification of the TypeScript pro The syntactic grammar added by TypeScript language is specified throughout this document using the existing conventions and production names of the ECMAScript grammar. In places where TypeScript augments an existing grammar production it is so noted. For example:   *CallExpression:* *( Modified )* -   … +   …    `super` `(` *ArgumentListopt* `)`    `super` `.` *IdentifierName* -The ‘*( Modified )*’ annotation indicates that an existing grammar production is being replaced, and the ‘…’ references the contents of the original grammar production. +The '*( Modified )*' annotation indicates that an existing grammar production is being replaced, and the '…' references the contents of the original grammar production. -Similar to the ECMAScript grammar, if the phrase “*[no LineTerminator here]*” appears in the right-hand side of a production of the syntactic grammar, it indicates that the production is not a match if a *LineTerminator* occurs in the input stream at the indicated position. +Similar to the ECMAScript grammar, if the phrase "*[no LineTerminator here]*" appears in the right-hand side of a production of the syntactic grammar, it indicates that the production is not a match if a *LineTerminator* occurs in the input stream at the indicated position. ## 2.2 Namespaces and Named Types @@ -777,7 +779,7 @@ module X { } ``` -declares two interface types with the qualified names ‘X.Y.Z’ and ‘X.Y’ relative to the root module in which ‘X’ is declared. +declares two interface types with the qualified names 'X.Y.Z' and 'X.Y' relative to the root module in which 'X' is declared. In a qualified type name all identifiers but the last one refer to namespaces and the last identifier refers to a named type. Named type and namespace names are in separate declaration spaces and it is therefore possible for a named type and a namespace to have the same name, as in the example above. @@ -791,23 +793,23 @@ module A { } ``` -introduces a named type with the qualified name ‘A.B.C’ and also introduces a constructor function that can be accessed using the expression ‘A.B.C’. Thus, in the example +introduces a named type with the qualified name 'A.B.C' and also introduces a constructor function that can be accessed using the expression 'A.B.C'. Thus, in the example ```TypeScript var c: A.B.C = new A.B.C(); ``` -the two occurrences of ‘A.B.C’ in fact refer to different entities. It is the context of the occurrences that determines whether ‘A.B.C’ is processed as a type name or an expression. +the two occurrences of 'A.B.C' in fact refer to different entities. It is the context of the occurrences that determines whether 'A.B.C' is processed as a type name or an expression. ## 2.3 Declarations Declarations introduce names in the ***declaration spaces*** to which they belong. It is an error to have two names with same spelling in the same declaration space. Declaration spaces exist as follows: * The global module and each external or internal module has a declaration space for variables (including functions, modules, class constructor functions, and enum objects), a declaration space for named types (classes, interfaces, and enums), and a declaration space for namespaces (containers of named types). Every declaration (whether local or exported) in a module contributes to one or more of these declaration spaces. -* Each external or internal module has a declaration space for exported members, a declaration space for exported named types, and a declaration space for exported namespaces. All export declarations in the module contribute to these declaration spaces. Each internal module’s export declaration spaces are shared with other internal modules that have the same root module and the same qualified name starting from that root module. +* Each external or internal module has a declaration space for exported members, a declaration space for exported named types, and a declaration space for exported namespaces. All export declarations in the module contribute to these declaration spaces. Each internal module's export declaration spaces are shared with other internal modules that have the same root module and the same qualified name starting from that root module. * Each class declaration has a declaration space for instance members, a declaration space for static members, and a declaration space for type parameters. -* Each interface declaration has a declaration space for members and a declaration space for type parameters. An interface’s declaration space is shared with other interfaces that have the same root module and the same qualified name starting from that root module. -* Each enum declaration has a declaration space for its enum members. An enum’s declaration space is shared with other enums that have the same root module and the same qualified name starting from that root module. +* Each interface declaration has a declaration space for members and a declaration space for type parameters. An interface's declaration space is shared with other interfaces that have the same root module and the same qualified name starting from that root module. +* Each enum declaration has a declaration space for its enum members. An enum's declaration space is shared with other enums that have the same root module and the same qualified name starting from that root module. * Each function declaration (including constructor, member function, and member accessor declarations) and each function expression has a declaration space for variables (parameters, local variables, and local functions) and a declaration space for type parameters. * Each object literal has a declaration space for its properties. * Each object type literal has a declaration space for its members. @@ -825,14 +827,14 @@ The ***parent module*** of an entity is defined as follows: The ***root module*** of an entity is defined as follows: -* The root module of a non-exported entity is the entity’s parent module. -* The root module of an exported entity is the root module of the entity’s parent module. +* The root module of a non-exported entity is the entity's parent module. +* The root module of an exported entity is the root module of the entity's parent module. Intuitively, the root module of an entity is the outermost module body from within which the entity is reachable. -Interfaces, enums, and internal modules are “open ended,” meaning that interface, enum, and internal module declarations with the same qualified name relative to a common root are automatically merged. For further details, see sections [7.2](#7.2), [9.3](#9.3), and [10.5](#10.5). +Interfaces, enums, and internal modules are "open ended," meaning that interface, enum, and internal module declarations with the same qualified name relative to a common root are automatically merged. For further details, see sections [7.2](#7.2), [9.3](#9.3), and [10.5](#10.5). -Namespace, type, and member names exist in separate declaration spaces. Furthermore, declarations of non-instantiated modules (modules that contain only interfaces or modules at all levels of nesting) do not introduce a member name in their containing declaration space. This means that the following is permitted, provided module ‘X’ contains only interface or module declarations at all levels of nesting: +Namespace, type, and member names exist in separate declaration spaces. Furthermore, declarations of non-instantiated modules (modules that contain only interfaces or modules at all levels of nesting) do not introduce a member name in their containing declaration space. This means that the following is permitted, provided module 'X' contains only interface or module declarations at all levels of nesting: ```TypeScript module M { @@ -842,7 +844,7 @@ module M { } ``` -If module ‘X’ above was an instantiated module (section [10.1](#10.1)) it would cause a member ‘X’ to be introduced in ‘M’. This member would conflict with the variable ‘X’ and thus cause an error. +If module 'X' above was an instantiated module (section [10.1](#10.1)) it would cause a member 'X' to be introduced in 'M'. This member would conflict with the variable 'X' and thus cause an error. Instance and static members in a class are likewise in separate declaration spaces. Thus the following is permitted: @@ -874,7 +876,7 @@ When an identifier is resolved as a *ModuleName* (section [3.6.2](#3.6.2)), only When an identifier is resolved as a *PrimaryExpression* (section [4.3](#4.3)), only instantiated modules (section [10.1](#10.1)), classes, enums, functions, variables, and parameters are considered and other entities in scope are ignored. -Note that class and enum members are never directly in scope—they can only be accessed by applying the dot (‘.’) operator to a class instance or enum object. This even includes members of the current instance in a constructor or member function, which are accessed by applying the dot operator to `this`. +Note that class and enum members are never directly in scope—they can only be accessed by applying the dot ('.') operator to a class instance or enum object. This even includes members of the current instance in a constructor or member function, which are accessed by applying the dot operator to `this`. As the rules above imply, locally declared entities in an internal module are closer in scope than exported entities declared in other module declarations for the same internal module. For example: @@ -897,11 +899,11 @@ module M { # 3 Types -TypeScript adds optional static types to JavaScript. Types are used to place static constraints on program entities such as functions, variables, and properties so that compilers and development tools can offer better verification and assistance during software development. TypeScript’s *static* compile-time type system closely models the *dynamic* run-time type system of JavaScript, allowing programmers to accurately express the type relationships that are expected to exist when their programs run and have those assumptions pre-validated by the TypeScript compiler. TypeScript’s type analysis occurs entirely at compile-time and adds no run-time overhead to program execution. +TypeScript adds optional static types to JavaScript. Types are used to place static constraints on program entities such as functions, variables, and properties so that compilers and development tools can offer better verification and assistance during software development. TypeScript's *static* compile-time type system closely models the *dynamic* run-time type system of JavaScript, allowing programmers to accurately express the type relationships that are expected to exist when their programs run and have those assumptions pre-validated by the TypeScript compiler. TypeScript's type analysis occurs entirely at compile-time and adds no run-time overhead to program execution. All types in TypeScript are subtypes of a single top type called the Any type. The `any` keyword references this type. The Any type is the one type that can represent *any* JavaScript value with no constraints. All other types are categorized as ***primitive types***, ***object types***, or ***type parameters***. These types introduce various static constraints on their values. -The primitive types are the Number, Boolean, String, Void, Null, and Undefined types along with user defined enum types. The `number`, `boolean`, `string`, and `void` keywords reference the Number, Boolean, String, and Void primitive types respectively. The Void type exists purely to indicate the absence of a value, such as in a function with no return value. It is not possible to explicitly reference the Null and Undefined types—only *values* of those types can be referenced, using the `null` and `undefined` literals. +The primitive types are the Number, Boolean, String, Void, Null, and Undefined types along with user defined enum types. The `number`, `boolean`, `string`, and `void` keywords reference the Number, Boolean, String, and Void primitive types respectively. The Void type exists purely to indicate the absence of a value, such as in a function with no return value. It is not possible to explicitly reference the Null and Undefined types—only *values* of those types can be referenced, using the `null` and `undefined` literals. The object types are all class, interface, array, and literal types. Class and interface types are introduced through class and interface declarations and are referenced by the name given to them in their declarations. Class and interface types may be ***generic types*** which have one or more type parameters. Literal types are written as object, array, function, or constructor type literals and are used to compose new types from other types. @@ -917,7 +919,7 @@ or through implicit ***type inference***, as in var x = 1; ``` -which infers the type of ‘x’ to be the Number primitive type because that is the type of the value used to initialize ‘x’. +which infers the type of 'x' to be the Number primitive type because that is the type of the value used to initialize 'x'. ## 3.1 The Any Type @@ -949,7 +951,7 @@ The Number primitive type corresponds to the similarly named JavaScript primitiv The `number` keyword references the Number primitive type and numeric literals may be used to write values of the Number primitive type. -For purposes of determining type relationships (section [3.8](#3.8)) and accessing properties (section [4.10](#4.10)), the Number primitive type behaves as an object type with the same properties as the global interface type ‘Number’. +For purposes of determining type relationships (section [3.8](#3.8)) and accessing properties (section [4.10](#4.10)), the Number primitive type behaves as an object type with the same properties as the global interface type 'Number'. Some examples: @@ -966,7 +968,7 @@ The Boolean primitive type corresponds to the similarly named JavaScript primiti The `boolean` keyword references the Boolean primitive type and the `true` and `false` literals reference the two Boolean truth values. -For purposes of determining type relationships (section [3.8](#3.8)) and accessing properties (section [4.10](#4.10)), the Boolean primitive type behaves as an object type with the same properties as the global interface type ‘Boolean’. +For purposes of determining type relationships (section [3.8](#3.8)) and accessing properties (section [4.10](#4.10)), the Boolean primitive type behaves as an object type with the same properties as the global interface type 'Boolean'. Some examples: @@ -982,7 +984,7 @@ The String primitive type corresponds to the similarly named JavaScript primitiv The `string` keyword references the String primitive type and string literals may be used to write values of the String primitive type. -For purposes of determining type relationships (section [3.8](#3.8)) and accessing properties (section [4.10](#4.10)), the String primitive type behaves as an object type with the same properties as the global interface type ‘String’. +For purposes of determining type relationships (section [3.8](#3.8)) and accessing properties (section [4.10](#4.10)), the String primitive type behaves as an object type with the same properties as the global interface type 'String'. Some examples: @@ -1049,13 +1051,14 @@ All string literal types are subtypes of the String primitive type. Object types are composed from properties, call signatures, construct signatures, and index signatures, collectively called members. -Class and interface type references, array types, tuple types, function types, and constructor types are all classified as object types. Multiple constructs in the TypeScript language create object types, including: +Class and interface type references, array types, tuple types, union types, function types, and constructor types are all classified as object types. Multiple constructs in the TypeScript language create object types, including: * Object type literals (section [3.6.3](#3.6.3)). * Array type literals (section [3.6.4](#3.6.4)). * Tuple type literals (section [3.6.5](#3.6.5)). -* Function type literals (section [3.6.6](#3.6.6)). -* Constructor type literals (section [3.6.7](#3.6.7)). +* Union type literals (section [3.6.6](#3.6.6)). +* Function type literals (section [3.6.7](#3.6.7)). +* Constructor type literals (section [3.6.8](#3.6.8)). * Object literals (section [4.5](#4.5)). * Array literals (section [4.6](#4.6)). * Function expressions (section [4.9](#4.9)) and function declarations ([6.1](#6.1)). @@ -1068,9 +1071,9 @@ Type references (section [3.6.2](#3.6.2)) to class and interface types are class ### 3.3.2 Array Types -***Array types*** represent JavaScript arrays with a common element type. Array types are named type references created from the generic interface type ‘Array’ in the global module with the array element type as a type argument. Array type literals (section [3.6.4](#3.6.4)) provide a shorthand notation for creating such references. +***Array types*** represent JavaScript arrays with a common element type. Array types are named type references created from the generic interface type 'Array' in the global module with the array element type as a type argument. Array type literals (section [3.6.4](#3.6.4)) provide a shorthand notation for creating such references. -The declaration of the ‘Array’ interface includes a property ‘length’ and a numeric index signature for the element type, along with other members: +The declaration of the 'Array' interface includes a property 'length' and a numeric index signature for the element type, along with other members: ```TypeScript interface Array { @@ -1105,23 +1108,111 @@ combines the set of properties } ``` -with the members of an array type whose element type is the best common type (section [3.10](#3.10)) of the tuple element types. +with the members of an array type whose element type is the union type (section [3.3.4](#3.3.4)) of the tuple element types. -Array literals (section [4.6](#4.6)) may be used to create values of tuple types. For example +Array literals (section [4.6](#4.6)) may be used to create values of tuple types. + +An example: ```TypeScript -var t: [number, string] = [1, "one"]; +var t: [number, string] = [3, "three"]; +var n = t[0]; // Type of n is number +var s = t[1]; // Type of s is string +var i: number; +var x = t[i]; // Type of x is number | string ``` -### 3.3.4 Function Types +### 3.3.4 Union Types -An object type containing one or more call signatures is said to be a ***function type***. Function types may be written using function type literals (section [3.6.6](#3.6.6)) or by including call signatures in object type literals. +***Union types*** represent values that may have one of several disjoint representations. A value of a union type *A* | *B* is a value that is *either* of type *A* or type *B*. Union types are written using union type literals (section [3.6.6](#3.6.6)). -### 3.3.5 Constructor Types +A union type encompasses an unordered set of unrelated types (that is, types that aren't subtypes of each other). The following rules govern union types: -An object type containing one or more construct signatures is said to be a ***constructor type***. Constructor types may be written using constructor type literals (section [3.6.7](#3.6.7)) or by including construct signatures in object type literals. +* *A* | *B* is equivalent to *A* if *B* is a subtype of *A*. +* *A* | *B* is equivalent to *B* | *A*. +* *AB* | *C* is equivalent to *A* | *BC*, where *AB* is *A* | *B* and *BC* is *B* | *C*. -### 3.3.6 Members +Union types are reduced to the smallest possible set of constituent types using these rules. + +Union types have the following subtype relationships: + +* A union type *U* is a subtype of a type *T* if each type in *U* is a subtype of *T*. +* A type *T* is a subtype of a union type *U* if *T* is a subtype of any type in *U*. + +Similarly, union types have the following assignability relationships: + +* A union type *U* is assignable to a type *T* if each type in *U* is assignable to *T*. +* A type *T* is assignable to a union type *U* if *T* is assignable to any type in *U*. + +For purposes of property access (section [4.10](#4.10)) and function calls ([4.12](#4.12)), a union type *U* has those members that are present in every one of its constituent types, with types that are unions of the respective members in the constituent types. Specifically: + +* If each type in *U* has a property *P*, *U* has a property *P* of a union type of the types of *P* from each type in *U*. +* If each type in *U* has call signatures and the sets of call signatures are identical ignoring return types, *U* has the same set of call signatures, but with return types that are unions of the return types of the respective call signatures from each type in *U*. +* If each type in *U* has construct signatures and the sets of construct signatures are identical ignoring return types, *U* has the same set of construct signatures, but with return types that are unions of the return types of the respective construct signatures from each type in *U*. +* If each type in *U* has a string index signature, *U* has a string index signature of a union type of the types of the string index signatures from each type in *U*. +* If each type in *U* has a numeric index signature, *U* has a numeric index signature of a union type of the types of the numeric index signatures from each type in *U*. + +When used as a contextual type (section [4.19](#4.19)), a union type *U* has those members that are present in any of its constituent types, with types that are unions of the respective members in the constituent types. Specifically: + +* Let *S* be the set of types in *U* that has a property *P*. If *S* is not empty, *U* has a property *P* of a union type of the types of *P* from each type in *S*. +* Let *S* be the set of types in *U* that have call signatures. If *S* is not empty and the sets of call signatures of the types in *S* are identical ignoring return types, *U* has the same set of call signatures, but with return types that are unions of the return types of the respective call signatures from each type in *S*. +* Let *S* be the set of types in *U* that have construct signatures. If *S* is not empty and the sets of construct signatures of the types in *S* are identical ignoring return types, *U* has the same set of construct signatures, but with return types that are unions of the return types of the respective construct signatures from each type in *S*. +* Let *S* be the set of types in *U* that has a string index signature. If *S* is not empty, *U* has a string index signature of a union type of the types of the string index signatures from each type in *S*. +* Let *S* be the set of types in *U* that has a numeric index signature. If *S* is not empty, *U* has a numeric index signature of a union type of the types of the numeric index signatures from each type in *S*. + +The || and conditional operators (section [4.15.7](#4.15.7) and [4.16](#4.16)) may produce values of union types, and array literals (section [4.6](#4.6)) may produce array values that have union types as their element types. + +Type guards (section [4.20](#4.20)) may be used to narrow a union type to a more specific type. In particular, type guards are useful for narrowing union type values to a non-union type values. + +In the example + +```TypeScript +var x: string | number; +var test: boolean; +x = "hello"; // Ok +x = 42; // Ok +x = test; // Error, boolean not assignable +x = test ? 5 : "five"; // Ok +x = test ? 0 : false; // Error, number | boolean not asssignable +``` + +it is possible to assign 'x' a value of type string, number, or the union type string | number, but not any other type. To access a value in 'x', a type guard can be used to first narrow the type of 'x' to either string or number: + +```TypeScript +var n = typeof x === "string" ? x.length : x; // Type of n is number +``` + +The following example illustrates the merging of member types that occurs when union types are created from object types. + +```TypeScript +interface A { + a: string; + b: number; +} + +interface B { + a: number; + b: number; + c: number; +} + +var x: A | B; +var a = x.a; // a has type string | number +var b = x.b; // b has type number +var c = x.c; // Error, no property c in union type +``` + +Note that 'x.a' has a union type because the type of 'a' is different in 'A' and 'B', whereas 'x.b' simply has type number because that is the type of 'b' in both 'A' and 'B'. Also note that there is no property 'x.c' because only 'A' has a property 'c'. + +### 3.3.5 Function Types + +An object type containing one or more call signatures is said to be a ***function type***. Function types may be written using function type literals (section [3.6.7](#3.6.7)) or by including call signatures in object type literals. + +### 3.3.6 Constructor Types + +An object type containing one or more construct signatures is said to be a ***constructor type***. Constructor types may be written using constructor type literals (section [3.6.8](#3.6.8)) or by including construct signatures in object type literals. + +### 3.3.7 Members Every object type is composed from zero or more of the following kinds of members: @@ -1168,9 +1259,9 @@ Each type parameter has an associated type parameter ***constraint*** that estab The ***base constraint*** of a type parameter *T* is defined as follows: -* If *T* has no declared constraint, *T*’s base constraint is the empty object type `{}`. -* If *T*’s declared constraint is a type parameter, *T*’s base constraint is that of the type parameter. -* Otherwise, *T*’s base constraint is *T*’s declared constraint. +* If *T* has no declared constraint, *T*'s base constraint is the empty object type `{}`. +* If *T*'s declared constraint is a type parameter, *T*'s base constraint is that of the type parameter. +* Otherwise, *T*'s base constraint is *T*'s declared constraint. In the example @@ -1180,7 +1271,7 @@ interface G { } ``` -the base constraint of ‘T’ is the empty object type, and the base constraint of ‘U’ and ‘V’ is ‘Function’. +the base constraint of 'T' is the empty object type, and the base constraint of 'U' and 'V' is 'Function'. For purposes of determining type relationships (section [3.8](#3.8)), type parameters appear to be subtypes of their base constraint. Likewise, in property accesses (section [4.10](#4.10)), `new` operations (section [4.11](#4.11)), and function calls (section [4.12](#4.12)), type parameters appear to have the members of their base constraint, but no other members. @@ -1206,7 +1297,7 @@ Given the declaration interface G { } ``` -a type reference of the form ‘G<A, B>’ places no requirements on ‘A’ but requires ‘B’ to be assignable to ‘Function’. +a type reference of the form 'G<A, B>' places no requirements on 'A' but requires 'B' to be assignable to 'Function'. The process of substituting type arguments for type parameters in a generic type or generic signature is known as ***instantiating*** the generic type or signature. Instantiation of a generic type or signature can fail if the supplied type arguments do not satisfy the constraints of their corresponding type parameters. @@ -1214,11 +1305,11 @@ The process of substituting type arguments for type parameters in a generic type Class, interface, and enum types are ***named types*** that are introduced through class declarations (section [8.1](#8.1)), interface declarations (section [7.1](#7.1)), and enum declarations ([9.1](#9.1)). Class and interface types may have type parameters and are then called ***generic types***. Conversely, named types without type parameters are called ***non-generic types***. -Interface declarations only introduce named types, whereas class declarations introduce named types *and* constructor functions that create instances of implementations of those named types. The named types introduced by class and interface declarations have only minor differences (classes can’t declare optional members and interfaces can’t declare private or protected members) and are in most contexts interchangeable. In particular, class declarations with only public members introduce named types that function exactly like those created by interface declarations. +Interface declarations only introduce named types, whereas class declarations introduce named types *and* constructor functions that create instances of implementations of those named types. The named types introduced by class and interface declarations have only minor differences (classes can't declare optional members and interfaces can't declare private or protected members) and are in most contexts interchangeable. In particular, class declarations with only public members introduce named types that function exactly like those created by interface declarations. Named types are referenced through ***type references*** (section [3.6.2](#3.6.2)) that specify a type name and, if applicable, the type arguments to be substituted for the type parameters of the named type. -Named types are technically not types—only *references* to named types are. This distinction is particularly evident with generic types: Generic types are “templates” from which multiple *actual* types can be created by writing type references that supply type arguments to substitute in place of the generic type’s type parameters. This substitution process is known as ***instantiating*** a generic type. Only once a generic type is instantiated does it denote an actual type. +Named types are technically not types—only *references* to named types are. This distinction is particularly evident with generic types: Generic types are "templates" from which multiple *actual* types can be created by writing type references that supply type arguments to substitute in place of the generic type's type parameters. This substitution process is known as ***instantiating*** a generic type. Only once a generic type is instantiated does it denote an actual type. TypeScript has a structural type system, and therefore an instantiation of a generic type is indistinguishable from an equivalent manually written expansion. For example, given the declaration @@ -1240,7 +1331,7 @@ is indistinguishable from the type ### 3.5.1 Instance Types -Each named type has an associated actual type known as the ***instance type***. For a non-generic type, the instance type is simply a type reference to the non-generic type. For a generic type, the instance type is an instantiation of the generic type where each of the type arguments is the corresponding type parameter. Since the instance type uses the type parameters it can be used only where the type parameters are in scope—that is, inside the declaration of the generic type. Within the constructor and instance member functions of a class, the type of `this` is the instance type of the class. +Each named type has an associated actual type known as the ***instance type***. For a non-generic type, the instance type is simply a type reference to the non-generic type. For a generic type, the instance type is an instantiation of the generic type where each of the type arguments is the corresponding type parameter. Since the instance type uses the type parameters it can be used only where the type parameters are in scope—that is, inside the declaration of the generic type. Within the constructor and instance member functions of a class, the type of `this` is the instance type of the class. The following example illustrates the concept of an instance type: @@ -1258,15 +1349,33 @@ class G { // Introduce type parameter T Types are specified either by referencing their keyword or name, or by writing object type literals, array type literals, tuple type literals, function type literals, constructor type literals, or type queries.   *Type:* +   *PrimaryOrUnionType* +   *FunctionType* +   *ConstructorType* + +  *PrimaryOrUnionType:* +   *PrimaryType* +   *UnionType* + +  *PrimaryType:* +   *ParenthesizedType*    *PredefinedType*    *TypeReference*    *ObjectType*    *ArrayType*    *TupleType* -   *FunctionType* -   *ConstructorType*    *TypeQuery* +  *ParenthesizedType:* +   `(` *Type* `)` + +Parentheses are required around union, function, or constructor types when they are used as array element types, and parentheses are required around function or constructor types in union types. For example: + +```TypeScript +(string | number)[] +((x: string) => string) | (x: number) => number) +``` + The different forms of type notations are described in the following sections. ### 3.6.1 Predefined Types @@ -1330,9 +1439,9 @@ var v6: G; // Error, wrong number of arguments var v7: G; // Error, no arguments ``` -A type argument is simply a *Type* and may itself be a type reference to a generic type, as demonstrated by ‘v4’ in the example above. +A type argument is simply a *Type* and may itself be a type reference to a generic type, as demonstrated by 'v4' in the example above. -As described in section [3.5](#3.5), a type reference to a generic type *G* designates a type wherein all occurrences of *G*’s type parameters have been replaced with the actual type arguments supplied in the type reference. For example, the declaration of ‘v1’ above is equivalent to: +As described in section [3.5](#3.5), a type reference to a generic type *G* designates a type wherein all occurrences of *G*'s type parameters have been replaced with the actual type arguments supplied in the type reference. For example, the declaration of 'v1' above is equivalent to: ```TypeScript var v1: { @@ -1369,36 +1478,24 @@ The members of an object type literal are specified as a combination of property An array type literal is written as an element type followed by an open and close square bracket.   *ArrayType:* -   *ElementType* *[no LineTerminator here]* `[` `]` +   *PrimaryType* *[no LineTerminator here]* `[` `]` -  *ElementType:* -   *PredefinedType* -   *TypeReference* -   *ObjectType* -   *ArrayType* -   *TupleType* -   *TypeQuery* +An array type literal references an array type (section [3.3.2](#3.3.2)) with the given element type. An array type literal is simply shorthand notation for a reference to the generic interface type 'Array' in the global module with the element type as a type argument. -An array type literal references an array type (section [3.3.2](#3.3.2)) with the given element type. An array type literal is simply shorthand notation for a reference to the generic interface type ‘Array’ in the global module with the element type as a type argument. - -In order to avoid grammar ambiguities, array type literals permit only a restricted set of notations for the element type. Specifically, an *ArrayType* cannot start with a *FunctionType* or *ConstructorType*. To use one of those forms for the element type, an array type must be written using the ‘Array<T>’ notation. For example, the type +When union, function, or constructor types are used as array element types they must be enclosed in parentheses. For example: ```TypeScript -() => string[] +(string | number)[] +(() => string))[] ``` -denotes a function returning a string array, not an array of functions returning string. The latter can be expressed using ‘Array<T>’ notation +Alternatively, array types can be written using the 'Array<T>' notation. For example, the types above are equivalent to ```TypeScript +Array Array<() => string> ``` -or by writing the element type as an object type literal - -```TypeScript -{ (): string }[] -``` - ### 3.6.5 Tuple Type Literals A tuple type literal is written as a sequence of element types, separated by commas and enclosed in square brackets. @@ -1415,7 +1512,28 @@ A tuple type literal is written as a sequence of element types, separated by com A tuple type literal references a tuple type (section [3.3.3](#3.3.3)). -### 3.6.6 Function Type Literals +### 3.6.6 Union Type Literals + +A union type literal is written as a sequence of types separated by vertical bars. + +  *UnionType:* +   *PrimaryOrUnionType* `|` *PrimaryType* + +A union typle literal references a union type (section [3.3.4](#3.3.4)). + +When function or constructor types are included in union types they must be enclosed in parentheses. For example: + +```TypeScript +((x: string) => string) | ((x: number) => number) +``` + +Alternatively, function or constructor types in union types can be written using object literals: + +```TypeScript +{ (x: string): string } | { (x: number): number } +``` + +### 3.6.7 Function Type Literals A function type literal specifies the type parameters, regular parameters, and return type of a call signature. @@ -1436,7 +1554,7 @@ is exactly equivalent to the object type literal Note that function types with multiple call or construct signatures cannot be written as function type literals but must instead be written as object type literals. -### 3.6.7 Constructor Type Literals +### 3.6.8 Constructor Type Literals A constructor type literal specifies the type parameters, regular parameters, and return type of a construct signature. @@ -1457,7 +1575,7 @@ is exactly equivalent to the object type literal Note that constructor types with multiple construct signatures cannot be written as constructor type literals but must instead be written as object type literals. -### 3.6.8 Type Queries +### 3.6.9 Type Queries A type query obtains the type of an expression. @@ -1477,7 +1595,7 @@ var a = { x: 10, y: 20 }; var b: typeof a; ``` -Above, ‘b’ is given the same type as ‘a’, namely ‘{ x: number; y: number; }’. +Above, 'b' is given the same type as 'a', namely '{ x: number; y: number; }'. If a declaration includes a type annotation that references the entity being declared through a circular path of type queries or type references containing type queries, the resulting type is the Any type. For example, all of the following variables are given the type Any: @@ -1495,7 +1613,7 @@ var g: { x: typeof g; }; var h: () => typeof h; ``` -Here, ‘g’ and ‘g.x’ have the same recursive type, and likewise ‘h’ and ‘h()’ have the same recursive type. +Here, 'g' and 'g.x' have the same recursive type, and likewise 'h' and 'h()' have the same recursive type. ## 3.7 Specifying Members @@ -1554,7 +1672,7 @@ A function taking two values of the same type, returning an array of that type: (x: T, y: T): T[] ``` -A function taking two arguments of different types, returning an object with properties ‘x’ and ‘y’ of those types: +A function taking two arguments of different types, returning an object with properties 'x' and 'y' of those types: ```TypeScript (x: T, y: U): { x: T; y: U; } @@ -1568,7 +1686,7 @@ A function taking an array of one type and a function argument, returning an arr #### 3.7.2.2 Parameter List -A signature’s parameter list consists of zero or more required parameters, followed by zero or more optional parameters, finally followed by an optional rest parameter. +A signature's parameter list consists of zero or more required parameters, followed by zero or more optional parameters, finally followed by an optional rest parameter.   *ParameterList:*    *RequiredParameterList* @@ -1618,7 +1736,7 @@ A parameter can be marked optional by following its name with a question mark (` #### 3.7.2.3 Return Type -If present, a call signature’s return type annotation specifies the type of the value computed and returned by a call operation. A `void` return type annotation is used to indicate that a function has no return value. +If present, a call signature's return type annotation specifies the type of the value computed and returned by a call operation. A `void` return type annotation is used to indicate that a function has no return value. When a call signature with no return type annotation occurs in a context without a function body, the return type is assumed to be the Any type. @@ -1637,11 +1755,11 @@ interface Document { } ``` -states that calls to ‘createElement’ with the string literals “div”, “span”, and “canvas” return values of type ‘HTMLDivElement’, ‘HTMLSpanElement’, and ‘HTMLCanvasElement’ respectively, and that calls with all other string expressions return values of type ‘HTMLElement’. +states that calls to 'createElement' with the string literals "div", "span", and "canvas" return values of type 'HTMLDivElement', 'HTMLSpanElement', and 'HTMLCanvasElement' respectively, and that calls with all other string expressions return values of type 'HTMLElement'. When writing overloaded declarations such as the one above it is important to list the non-specialized signature last. This is because overload resolution (section [4.12.1](#4.12.1)) processes the candidates in declaration order and picks the first one that matches. -Every specialized call or construct signature in an object type must be assignable to at least one non-specialized call or construct signature in the same object type (where a call signature *A* is considered assignable to another call signature *B* if an object type containing only *A* would be assignable to an object type containing only *B*). For example, the ‘createElement’ property in the example above is of a type that contains three specialized signatures, all of which are assignable to the non-specialized signature in the type. +Every specialized call or construct signature in an object type must be assignable to at least one non-specialized call or construct signature in the same object type (where a call signature *A* is considered assignable to another call signature *B* if an object type containing only *A* would be assignable to an object type containing only *B*). For example, the 'createElement' property in the example above is of a type that contains three specialized signatures, all of which are assignable to the non-specialized signature in the type. ### 3.7.3 Construct Signatures @@ -1722,7 +1840,7 @@ In the following example of an object type } ``` -the properties ‘func1’, ‘func2’, and ‘func3’ are all of the same type, namely an object type with a single call signature taking a number and returning a number. Likewise, in the object type +the properties 'func1', 'func2', and 'func3' are all of the same type, namely an object type with a single call signature taking a number and returning a number. Likewise, in the object type ```TypeScript { @@ -1735,29 +1853,29 @@ the properties } ``` -the properties ‘func4’ and ‘func5’ are of the same type, namely an object type with two call signatures taking and returning number and string respectively. +the properties 'func4' and 'func5' are of the same type, namely an object type with two call signatures taking and returning number and string respectively. ## 3.8 Type Relationships Types in TypeScript have identity, subtype, supertype, and assignment compatibility relationships as defined in the following sections. -For purposes of determining type relationships, all object types appear to have the members of the ‘Object’ interface unless those members are hidden by members with the same name in the object types, and object types with one or more call or construct signatures appear to have the members of the ‘Function’ interface unless those members are hidden by members with the same name in the object types. Apparent types (section [3.8.1](#3.8.1)) that are object types appear to have these extra members as well. +For purposes of determining type relationships, all object types appear to have the members of the 'Object' interface unless those members are hidden by members with the same name in the object types, and object types with one or more call or construct signatures appear to have the members of the 'Function' interface unless those members are hidden by members with the same name in the object types. Apparent types (section [3.8.1](#3.8.1)) that are object types appear to have these extra members as well. ### 3.8.1 Apparent Type -In certain contexts a type appears to have the characteristics of a related type called the type’s ***apparent type***. Specifically, a type’s apparent type is used when determining subtype, supertype, and assignment compatibility relationships, as well as in the type checking of property accesses (section [4.10](#4.10)), `new` operations (section [4.11](#4.11)), and function calls (section [4.12](#4.12)). +In certain contexts a type appears to have the characteristics of a related type called the type's ***apparent type***. Specifically, a type's apparent type is used when determining subtype, supertype, and assignment compatibility relationships, as well as in the type checking of property accesses (section [4.10](#4.10)), `new` operations (section [4.11](#4.11)), and function calls (section [4.12](#4.12)). The apparent type of a type *T* is defined as follows: -* If *T* is the primitive type Number, Boolean, or String, the apparent type of *T* is the augmented form (as defined below) of the global interface type ‘Number’, ‘Boolean’, or ‘String’. -* if *T* is an enum type, the apparent type of *T* is the augmented form of the global interface type ‘Number’. +* If *T* is the primitive type Number, Boolean, or String, the apparent type of *T* is the augmented form (as defined below) of the global interface type 'Number', 'Boolean', or 'String'. +* if *T* is an enum type, the apparent type of *T* is the augmented form of the global interface type 'Number'. * If *T* is an object type, the apparent type of *T* is the augmented form of *T*. -* If *T* is a type parameter, the apparent type of *T* is the apparent type of *T*’s base constraint (section [3.4.1](#3.4.1)). +* If *T* is a type parameter, the apparent type of *T* is the apparent type of *T*'s base constraint (section [3.4.1](#3.4.1)). * Otherwise, the apparent type of *T* is *T* itself. -The augmented form of an object type *T* adds to *T* those properties of the global interface type ‘Object’ that aren’t hidden by properties in *T*. Furthermore, if *T* has one or more call or construct signatures, the augmented form of *T* adds to *T* the properties of the global interface type ‘Function’ that aren’t hidden by properties in *T*. Properties in *T* hide ‘Object’ or ‘Function’ interface properties with the same name. +The augmented form of an object type *T* adds to *T* those properties of the global interface type 'Object' that aren't hidden by properties in *T*. Furthermore, if *T* has one or more call or construct signatures, the augmented form of *T* adds to *T* the properties of the global interface type 'Function' that aren't hidden by properties in *T*. Properties in *T* hide 'Object' or 'Function' interface properties with the same name. -In effect, a type’s apparent type is a subtype of the ‘Object’ or ‘Function’ interface unless the type defines members that are incompatible with those of the ‘Object’ or ‘Function’ interface—which, for example, occurs if the type defines a property with the same name as a property in the ‘Object’ or ‘Function’ interface but with a type that isn’t a subtype of that in the ‘Object’ or ‘Function’ interface. +In effect, a type's apparent type is a subtype of the 'Object' or 'Function' interface unless the type defines members that are incompatible with those of the 'Object' or 'Function' interface—which, for example, occurs if the type defines a property with the same name as a property in the 'Object' or 'Function' interface but with a type that isn't a subtype of that in the 'Object' or 'Function' interface. Some examples: @@ -1767,7 +1885,7 @@ var f: Function = (x: number) => x * x; // Ok var err: Object = { toString: 0 }; // Error ``` -The last assignment is an error because the apparent type of the object literal has a ‘toString’ method that isn’t compatible with that of ‘Object’. +The last assignment is an error because the apparent type of the object literal has a 'toString' method that isn't compatible with that of 'Object'. ### 3.8.2 Type and Member Identity @@ -1775,8 +1893,9 @@ Two types are considered ***identical*** when * they are both the Any type, * they are the same primitive type, -* they are the same type parameter, or -* they are object types with identical sets of members. +* they are the same type parameter, +* they are union types with identical sets of constituent types, or +* they are non-union object types with identical sets of members. Two members are considered identical when @@ -1803,11 +1922,11 @@ var a: C; var b: C; ``` -the variables ‘a’ and ‘b’ are of identical types because the two type references to ‘C’ create types with a private member ‘x’ that originates in the same declaration, and because the two private ‘x’ members have types with identical sets of members once the type arguments ‘X’ and ‘Y’ are substituted. +the variables 'a' and 'b' are of identical types because the two type references to 'C' create types with a private member 'x' that originates in the same declaration, and because the two private 'x' members have types with identical sets of members once the type arguments 'X' and 'Y' are substituted. ### 3.8.3 Subtypes and Supertypes -*S* is a ***subtype*** of a type *T*, and *T* is a ***supertype*** of *S*, if one of the following is true, where *S*’ denotes the apparent type (section [3.8.1](#3.8.1)) of *S*: +*S* is a ***subtype*** of a type *T*, and *T* is a ***supertype*** of *S*, if one of the following is true, where *S*' denotes the apparent type (section [3.8.1](#3.8.1)) of *S*: * *S* and *T* are identical types. * *T* is the Any type. @@ -1816,20 +1935,22 @@ the variables * *S* is an enum type and *T* is the primitive type Number. * *S* is a string literal type and *T* is the primitive type String. * *S* and *T* are type parameters, and *S* is directly or indirectly constrained to *T*. -* *S’* and *T* are object types and, for each member *M* in *T*, one of the following is true: - * *M* is a property and *S’* contains a property *N* where +* *S* is a union type and each constituent type of *S* is a subtype of *T*. +* *T* is a union type and *S* is a subtype of at least one constituent type of *T*. +* *S'* and *T* are object types and, for each member *M* in *T*, one of the following is true: + * *M* is a property and *S'* contains a property *N* where * *M* and *N* have the same name, * the type of *N* is a subtype of that of *M*, * if *M* is a required property, *N* is also a required property, and * *M* and *N* are both public, *M* and *N* are both private and originate in the same declaration, *M* and *N* are both protected and originate in the same declaration, or *M* is protected and *N* is declared in a class derived from the class in which *M* is declared. - * *M* is an optional property and *S’* contains no property of the same name as *M*. - * *M* is a non-specialized call or construct signature and *S*’ contains a call or construct signature *N* where, when *M* and *N* are instantiated using type Any as the type argument for all type parameters declared by *M* and *N* (if any), + * *M* is an optional property and *S'* contains no property of the same name as *M*. + * *M* is a non-specialized call or construct signature and *S*' contains a call or construct signature *N* where, when *M* and *N* are instantiated using type Any as the type argument for all type parameters declared by *M* and *N* (if any), * the signatures are of the same kind (call or construct), * *M* has a rest parameter or the number of non-optional parameters in *N* is less than or equal to the total number of parameters in *M*, * for parameter positions that are present in both signatures, each parameter type in *N* is a subtype or supertype of the corresponding parameter type in *M*, and * the result type of *M* is Void, or the result type of *N* is a subtype of that of *M*. - * *M* is a string index signature of type *U* and *S’* contains a string index signature of a type that is a subtype of *U*. - * *M* is a numeric index signature of type *U* and *S’* contains a string or numeric index signature of a type that is a subtype of *U*. + * *M* is a string index signature of type *U* and *S'* contains a string index signature of a type that is a subtype of *U*. + * *M* is a numeric index signature of type *U* and *S'* contains a string or numeric index signature of a type that is a subtype of *U*. When comparing call or construct signatures, parameter names are ignored and rest parameters correspond to an unbounded expansion of optional parameters of the rest parameter element type. @@ -1841,7 +1962,7 @@ Also note that type parameters are not considered object types. Thus, the only s Types are required to be assignment compatible in certain circumstances, such as expression and variable types in assignment statements and argument and parameter types in function calls. -*S* is ***assignable to*** a type *T*, and *T* is ***assignable from*** *S*, if one of the following is true, where *S*’ denotes the apparent type (section [3.8.1](#3.8.1)) of *S*: +*S* is ***assignable to*** a type *T*, and *T* is ***assignable from*** *S*, if one of the following is true, where *S*' denotes the apparent type (section [3.8.1](#3.8.1)) of *S*: * *S* and *T* are identical types. * *S* or *T* is the Any type. @@ -1850,20 +1971,22 @@ Types are required to be assignment compatible in certain circumstances, such as * *S* or *T* is an enum type and* *the other is the primitive type Number. * *S* is a string literal type and *T* is the primitive type String. * *S* and *T* are type parameters, and *S* is directly or indirectly constrained to *T*. -* *S’* and *T* are object types and, for each member *M* in *T*, one of the following is true: - * *M* is a property and *S’* contains a property *N* where +* *S* is a union type and each constituent type of *S* is assignable to *T*. +* *T* is a union type and *S* is assignable to at least one constituent type of *T*. +* *S'* and *T* are object types and, for each member *M* in *T*, one of the following is true: + * *M* is a property and *S'* contains a property *N* where * *M* and *N* have the same name, * the type of *N* is assignable to that of *M*, * if *M* is a required property, *N* is also a required property, and * *M* and *N* are both public, *M* and *N* are both private and originate in the same declaration, *M* and *N* are both protected and originate in the same declaration, or *M* is protected and *N* is declared in a class derived from the class in which *M* is declared. - * *M* is an optional property and *S’* contains no property of the same name as *M*. - * *M* is a non-specialized call or construct signature and *S*’ contains a call or construct signature *N* where, when *M* and *N* are instantiated using type Any as the type argument for all type parameters declared by *M* and *N* (if any), + * *M* is an optional property and *S'* contains no property of the same name as *M*. + * *M* is a non-specialized call or construct signature and *S*' contains a call or construct signature *N* where, when *M* and *N* are instantiated using type Any as the type argument for all type parameters declared by *M* and *N* (if any), * the signatures are of the same kind (call or construct), * *M* has a rest parameter or the number of non-optional parameters in *N* is less than or equal to the total number of parameters in *M*, * for parameter positions that are present in both signatures, each parameter type in *N* is assignable to or from the corresponding parameter type in *M*, and * the result type of *M* is Void, or the result type of *N* is assignable to that of *M*. - * *M* is a string index signature of type *U* and *S’* contains a string index signature of a type that is assignable to *U*. - * *M* is a numeric index signature of type *U* and *S’* contains a string or numeric index signature of a type that is assignable to *U*. + * *M* is a string index signature of type *U* and *S'* contains a string index signature of a type that is assignable to *U*. + * *M* is a numeric index signature of type *U* and *S'* contains a string or numeric index signature of a type that is assignable to *U*. When comparing call or construct signatures, parameter names are ignored and rest parameters correspond to an unbounded expansion of optional parameters of the rest parameter element type. @@ -1889,14 +2012,19 @@ foo({ name: "hello" }); // Error, id required but missing During type argument inference in a function call (section [4.12.2](#4.12.2)) it is in certain circumstances necessary to instantiate a generic call signature of an argument expression in the context of a non-generic call signature of a parameter such that further inferences can be made. A generic call signature *A* is ***instantiated in the context of*** non-generic call signature *B* as follows: -* Using the process described in [3.8.6](#3.8.6), inferences for *A*’s type parameters are made from each parameter type in *B* to the corresponding parameter type in *A* for those parameter positions that are present in both signatures, where rest parameters correspond to an unbounded expansion of optional parameters of the rest parameter element type. -* The inferred type argument for each type parameter is the best common type (section [3.10](#3.10)) of the set of inferences made for that type parameter. However, if the best common type does not satisfy the constraint of the type parameter, the inferred type argument is instead the constraint. +* Using the process described in [3.8.6](#3.8.6), inferences for *A*'s type parameters are made from each parameter type in *B* to the corresponding parameter type in *A* for those parameter positions that are present in both signatures, where rest parameters correspond to an unbounded expansion of optional parameters of the rest parameter element type. +* The inferred type argument for each type parameter is the union type of the set of inferences made for that type parameter. However, if the union type does not satisfy the constraint of the type parameter, the inferred type argument is instead the constraint. ### 3.8.6 Type Inference In certain contexts, inferences for a given set of type parameters are made *from* a type *S*, in which those type parameters do not occur, *to* another type *T*, in which those type parameters do occur. Inferences consist of a set of candidate type arguments collected for each of the type parameters. The inference process recursively relates *S* and *T* to gather as many inferences as possible: * If *T* is one of the type parameters for which inferences are being made, *S* is added to the set of inferences for that type parameter. +* Otherwise, if *S* and *T* are references to the same generic type, inferences are made from each type argument in *S* to each corresponding type argument in *T*. +* Otherwise, if *T* is a union type: + * First, inferences are made from *S* to each constituent type in *T* that isn't simply one of the type parameters for which inferences are being made. + * If the first step produced no inferences and exactly one constituent type in *T* is simply a type parameter for which inferences are being made, inferences are made from *S* to that type parameter. +* Otherwise, if *S* is a union type, inferences are made from each constituent type in *S* to *T*. * Otherwise, if *S* and *T* are object types, then for each member *M* in *T*: * If *M* is a property and *S* contains a property *N* with the same name as *M*, inferences are made from the type of *N* to the type of *M*. * If *M* is a call signature and a corresponding call signature *N* exists in *S*, *N* is instantiated with the Any type as an argument for each type parameter (if any) and inferences are made from parameter types in *N* to the corresponding parameter types in *M* for positions that are present in both signatures, and from the return type of *N* to the return type of *M*. @@ -1915,7 +2043,7 @@ Classes and interfaces can reference themselves in their internal structure, in interface A { next: A; } ``` -contains an infinitely nested sequence of ‘next’ properties. Types such as this are perfectly valid but require special treatment when determining type relationships. Specifically, when comparing types *S* and *T* for a given relationship (identity, subtype, or assignability), the relationship in question is assumed to be true for every directly or indirectly nested occurrence of the same *S* and the same *T* (where same means originating in the same declaration and, if applicable, having identical type arguments). For example, consider the identity relationship between ‘A’ above and ‘B’ below: +contains an infinitely nested sequence of 'next' properties. Types such as this are perfectly valid but require special treatment when determining type relationships. Specifically, when comparing types *S* and *T* for a given relationship (identity, subtype, or assignability), the relationship in question is assumed to be true for every directly or indirectly nested occurrence of the same *S* and the same *T* (where same means originating in the same declaration and, if applicable, having identical type arguments). For example, consider the identity relationship between 'A' above and 'B' below: ```TypeScript interface B { next: C; } @@ -1925,7 +2053,7 @@ interface C { next: D; } interface D { next: B; } ``` -To determine whether ‘A’ and ‘B’ are identical, first the ‘next’ properties of type ‘A’ and ‘C’ are compared. That leads to comparing the ‘next’ properties of type ‘A’ and ‘D’, which leads to comparing the ‘next’ properties of type ‘A’ and ‘B’. Since ‘A’ and ‘B’ are already being compared this relationship is by definition true. That in turn causes the other comparisons to be true, and therefore the final result is true. +To determine whether 'A' and 'B' are identical, first the 'next' properties of type 'A' and 'C' are compared. That leads to comparing the 'next' properties of type 'A' and 'D', which leads to comparing the 'next' properties of type 'A' and 'B'. Since 'A' and 'B' are already being compared this relationship is by definition true. That in turn causes the other comparisons to be true, and therefore the final result is true. When this same technique is used to compare generic type references, two type references are considered the same when they originate in the same declaration and have identical type arguments. @@ -1939,7 +2067,7 @@ interface List { } ``` -‘List<T>’ has a member ‘owner’ of type ‘List<List<T>>’, which has a member ‘owner’ of type ‘List<List<List<T>>>’, which has a member ‘owner’ of type ‘List<List<List<List<T>>>>’ and so on, ad infinitum. Since type relationships are determined structurally, possibly exploring the constituent types to their full depth, in order to determine type relationships involving infinitely expanding generic types it may be necessary for the compiler to terminate the recursion at some point with the assumption that no further exploration will change the outcome. +'List<T>' has a member 'owner' of type 'List<List<T>>', which has a member 'owner' of type 'List<List<List<T>>>', which has a member 'owner' of type 'List<List<List<List<T>>>>' and so on, ad infinitum. Since type relationships are determined structurally, possibly exploring the constituent types to their full depth, in order to determine type relationships involving infinitely expanding generic types it may be necessary for the compiler to terminate the recursion at some point with the assumption that no further exploration will change the outcome. ## 3.9 Widened Types @@ -1949,41 +2077,24 @@ In several situations TypeScript infers types from context, alleviating the need var name = "Steve"; ``` -infers the type of ‘name’ to be the String primitive type since that is the type of the value used to initialize it. When inferring the type of a variable, property or function result from an expression, the ***widened*** form of the source type is used as the inferred type of the target. The widened form of a type is the type in which all occurrences of the Null and Undefined types have been replaced with the type `any`. +infers the type of 'name' to be the String primitive type since that is the type of the value used to initialize it. When inferring the type of a variable, property or function result from an expression, the ***widened*** form of the source type is used as the inferred type of the target. The widened form of a type is the type in which all occurrences of the Null and Undefined types have been replaced with the type `any`. The following example shows the results of widening types to produce inferred variable types. ```TypeScript -var a = null; // var a: any -var b = undefined; // var b: any -var c = { x: 0, y: null }; // var c: { x: number, y: any } -var d = [ null, undefined ]; // var d: any[] +var a = null; // var a: any +var b = undefined; // var b: any +var c = { x: 0, y: null }; // var c: { x: number, y: any } +var d = [ null, undefined ]; // var d: any[] ``` -## 3.10 Best Common Type - -In several situations a ***best common type*** needs to be inferred from a set of types. In particular, return types of functions with multiple return statements and element types of array literals are found this way. The determination of a best common type may in some cases factor in a contextual type. - -Given a set of types { *T1*, *T2*, …, *Tn* } and a contextual type *C*, the best common type is determined as follows: - -* If the set of types is empty, the best common type is *C*. -* Otherwise, if C is a supertype of every *Tn*, the best common type is C. -* Otherwise, if one exists, the first *Tx* that is a supertype of every *Tn* is the best common type. -* Otherwise, the best common type is an empty object type (the type `{}`). - -Given a set of types { *T1*, *T2*, …, *Tn* } and no contextual type, the best common type is determined as follows: - -* If the set of types is empty, the best common type is an empty object type. -* Otherwise, if one exists, the first *Tx* that is a supertype of every *Tn* is the best common type. -* Otherwise, the best common type is an empty object type (the type `{}`). -
#
4 Expressions -This chapter describes the manner in which TypeScript provides type inference and type checking for JavaScript expressions. TypeScript’s type analysis occurs entirely at compile-time and adds no run-time overhead to expression evaluation. +This chapter describes the manner in which TypeScript provides type inference and type checking for JavaScript expressions. TypeScript's type analysis occurs entirely at compile-time and adds no run-time overhead to expression evaluation. -TypeScript’s typing rules define a type for every expression construct. For example, the type of the literal 123 is the Number primitive type, and the type of the object literal { a: 10, b: "hello" } is { a: number; b: string; }. The sections in this chapter describe these rules in detail. +TypeScript's typing rules define a type for every expression construct. For example, the type of the literal 123 is the Number primitive type, and the type of the object literal { a: 10, b: "hello" } is { a: number; b: string; }. The sections in this chapter describe these rules in detail. In addition to type inference and type checking, TypeScript augments JavaScript expressions with the following constructs: @@ -2033,7 +2144,7 @@ Literals are typed as follows: * The type of the literals `true` and `false` is the Boolean primitive type. * The type of numeric literals is the Number primitive type. * The type of string literals is the String primitive type. -* The type of regular expression literals is the global interface type ‘RegExp’. +* The type of regular expression literals is the global interface type 'RegExp'. ## 4.5 Object Literals @@ -2068,7 +2179,7 @@ f : function ( ... ) { ... } Each property assignment in an object literal is processed as follows: * If the object literal is contextually typed and the contextual type contains a property with a matching name, the property assignment is contextually typed by the type of that property. -* Otherwise, if the object literal is contextually typed, the contextual type contains a numeric index signature, and the property assignment specifies a numeric property name, the property assignment is contextually typed by the type of the numeric index signature. +* Otherwise, if the object literal is contextually typed, if the contextual type contains a numeric index signature, and if the property assignment specifies a numeric property name, the property assignment is contextually typed by the type of the numeric index signature. * Otherwise, if the object literal is contextually typed and the contextual type contains a string index signature, the property assignment is contextually typed by the type of the string index signature. * Otherwise, the property assignment is processed without a contextual type. @@ -2082,14 +2193,14 @@ A get accessor declaration is processed in the same manner as an ordinary functi If a get accessor is declared for a property, the return type of the get accessor becomes the type of the property. If only a set accessor is declared for a property, the parameter type (which may be type Any if no type annotation is present) of the set accessor becomes the type of the property. -When an object literal is contextually typed by a type that includes a string index signature of type *T*, the resulting type of the object literal includes a string index signature with the widened form of the best common type of the contextual type *T* and the types of the properties declared in the object literal. Likewise, when an object literal is contextually typed by a type that includes a numeric index signature of type *T*, the resulting type of the object literal includes a numeric index signature with the widened form of the best common type of the contextual type *T* and the types of the numerically named properties (section [3.7.4](#3.7.4)) declared in the object literal. +When an object literal is contextually typed by a type that includes a string index signature, the resulting type of the object literal includes a string index signature with the union type of the types of the properties declared in the object literal, or the Undefined type if the object literal is empty. Likewise, when an object literal is contextually typed by a type that includes a numeric index signature, the resulting type of the object literal includes a numeric index signature with the union type of the types of the numerically named properties (section [3.7.4](#3.7.4)) declared in the object literal, or the Undefined type if the object literal declares no numerically named properties. ## 4.6 Array Literals An array literal ```TypeScript -[expr1, expr2, ..., exprN] +[ expr1, expr2, ..., exprN ] ``` denotes a value of an array type (section [3.3.2](#3.3.2)) or a tuple type (section [3.3.3](#3.3.3)) depending on context. @@ -2100,22 +2211,17 @@ Each element expression in a non-empty array literal is processed as follows: * Otherwise, if the array literal is contextually typed by a type *T* with a numeric index signature, the element expression is contextually typed by the type of the numeric index signature. * Otherwise, the element expression is not contextually typed. -The resulting type of a non-empty array literal expression is determined as follows: +The resulting type an array literal expression is determined as follows: -* If the array literal is contextually typed by a type *T* and *T* has at least one property with a numeric name that matches the index of an element expression in the array literal, the resulting type is a tuple type constructed from the types of the element expressions. -* Otherwise, if the array literal is contextually typed by a type T with a numeric index signature of type *S*, the resulting type is an array type where the element type is the best common type of the contextual type *S* and the types of the element expressions. -* Otherwise, if the array literal is not contextually typed, the resulting type is an array type where the element type is the best common type of the types of the element expressions. - -The resulting type of an empty array literal expression is determined as follows: - -* If the array literal is contextually typed by a type *T* with a numeric index signature of type *S*, the resulting type is an array type with element type *S*. -* Otherwise, the resulting type is an array type with the element type Undefined. +* If the array literal is empty, the resulting type is an array type with the element type Undefined. +* Otherwise, if the array literal is contextually typed by a type that has a property with the numeric name '0', the resulting type is a tuple type constructed from the types of the element expressions. +* Otherwise, the resulting type is an array type with an element type that is the union of the types of the element expressions. The rules above mean that an array literal is always of an array type, unless it is contextually typed by a type with numerically named properties (such as a tuple type). For example ```TypeScript var a = [1, 2]; // number[] -var b = ["hello", true]; // {}[] +var b = ["hello", true]; // (string | boolean)[] var c: [number, string] = [3, "three"]; // [number, string] ``` @@ -2134,7 +2240,7 @@ has the same type and classification as the contained expression itself. Specifi The `super` keyword can be used in expressions to reference base class properties and the base class constructor.   *CallExpression:* *( Modified )* -   … +   …    `super` `(` *ArgumentListopt* `)`    `super` `.` *IdentifierName* @@ -2169,7 +2275,7 @@ Function expressions are extended from JavaScript to optionally include paramete    `function` *Identifieropt* *CallSignature* `{` *FunctionBody* `}`   *AssignmentExpression:* *( Modified )* -   … +   …    *ArrowFunctionExpression*   *ArrowFunctionExpression:* @@ -2182,7 +2288,7 @@ Function expressions are extended from JavaScript to optionally include paramete The terms ***standard function expression*** and ***arrow function expression*** are used to refer to the *FunctionExpression* and *ArrowFunctionExpression* forms respectively. When referring to either, the generic term ***function expression*** is used. -The type of a function expression is an object type containing a single call signature with parameter and return types inferred from the function expression’s signature and body. +The type of a function expression is an object type containing a single call signature with parameter and return types inferred from the function expression's signature and body. The descriptions of function declarations provided in section [6.1](#6.1) apply to function expressions as well, except that function expressions do not support overloading. @@ -2247,7 +2353,7 @@ var messenger = new Messenger(); messenger.start(); ``` -the use of an arrow function expression causes the callback to have the same `this` as the surrounding ‘start’ method. Writing the callback as a standard function expression it becomes necessary to manually arrange access to the surrounding `this`, for example by copying it into a local variable: +the use of an arrow function expression causes the callback to have the same `this` as the surrounding 'start' method. Writing the callback as a standard function expression it becomes necessary to manually arrange access to the surrounding `this`, for example by copying it into a local variable: ```TypeScript class Messenger { @@ -2282,13 +2388,13 @@ Function expressions with no type parameters and no parameter type annotations ( When a function expression is contextually typed by a function type *T*, the function expression is processed as if it had explicitly specified parameter type annotations as they exist in *T*. Parameters are matched by position and need not have matching names. If the function expression has fewer parameters than *T*, the additional parameters in *T* are ignored. If the function expression has more parameters than *T*, the additional parameters are all considered to have type Any. -Furthermore, when a function expression has no return type annotation and is contextually typed by a function type *T*, expressions in contained return statements (section [5.7](#5.7)) are contextually typed by *T*’s return type. +Furthermore, when a function expression has no return type annotation and is contextually typed by a function type *T*, expressions in contained return statements (section [5.7](#5.7)) are contextually typed by *T*'s return type. ## 4.10 Property Access A property access uses either dot notation or bracket notation. A property access expression is always classified as a reference. -A property access uses an object’s apparent type (section [3.8.1](#3.8.1)) to determine its properties. Furthermore, in a property access, an object’s apparent type includes the properties that originate in the ‘Object’ or ‘Function’ global interface types, as described in section [3.3](#3.3). +A property access uses an object's apparent type (section [3.8.1](#3.8.1)) to determine its properties. Furthermore, in a property access, an object's apparent type includes the properties that originate in the 'Object' or 'Function' global interface types, as described in section [3.3](#3.3). A dot notation property access of the form @@ -2310,9 +2416,9 @@ object [ index ] where *object* and *index* are expressions, is used to access the property with the name computed by the index expression on the given object. A bracket notation property access is processed as follows at compile-time: -* If *index* is a string literal or a numeric literal and *object*’s apparent type has a property with the name given by that literal (converted to its string representation in the case of a numeric literal), the property access is of the type of that property. -* Otherwise, if *object*’s apparent type has a numeric index signature and *index* is of type Any, the Number primitive type, or an enum type, the property access is of the type of that index signature. -* Otherwise, if *object*’s apparent type has a string index signature and *index* is of type Any, the String or Number primitive type, or an enum type, the property access is of the type of that index signature. +* If *index* is a string literal or a numeric literal and *object*'s apparent type has a property with the name given by that literal (converted to its string representation in the case of a numeric literal), the property access is of the type of that property. +* Otherwise, if *object*'s apparent type has a numeric index signature and *index* is of type Any, the Number primitive type, or an enum type, the property access is of the type of that index signature. +* Otherwise, if *object*'s apparent type has a string index signature and *index* is of type Any, the String or Number primitive type, or an enum type, the property access is of the type of that index signature. * Otherwise, if *index* is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any. * Otherwise, the property access is invalid and a compile-time error occurs. @@ -2336,7 +2442,7 @@ var s = data[0]; // string var n = data[1]; // number ``` -## 4.11 The new Operator +## 4.11 The new Operator A `new` operation has one of the following forms: @@ -2349,8 +2455,8 @@ new C < ... > ( ... ) where *C* is an expression. The first form is equivalent to supplying an empty argument list. *C* must be of type Any or of an object type with one or more construct or call signatures. The operation is processed as follows at compile-time: * If *C* is of type Any, any argument list is permitted and the result of the operation is of type Any. -* If *C*’s apparent type (section [3.8.1](#3.8.1)) is an object type with one or more construct signatures, the expression is processed in the same manner as a function call, but using the construct signatures as the initial set of candidate signatures for overload resolution. The result type of the function call becomes the result type of the operation. -* If *C*’s apparent type is an object type with no construct signatures but one or more call signatures, the expression is processed as a function call. A compile-time error occurs if the result of the function call is not Void. The type of the result of the operation is Any. +* If *C*'s apparent type (section [3.8.1](#3.8.1)) is an object type with one or more construct signatures, the expression is processed in the same manner as a function call, but using the construct signatures as the initial set of candidate signatures for overload resolution. The result type of the function call becomes the result type of the operation. +* If *C*'s apparent type is an object type with no construct signatures but one or more call signatures, the expression is processed as a function call. A compile-time error occurs if the result of the function call is not Void. The type of the result of the operation is Any. ## 4.12 Function Calls @@ -2370,11 +2476,11 @@ where *func* is an expression of a function type or of type Any. The function ex If *func* is of type Any, or of an object type that has no call or construct signatures but is a subtype of the Function interface, the call is an ***untyped function call***. In an untyped function call no type arguments are permitted, argument expressions can be of any type and number, no contextual types are provided for the argument expressions, and the result is always of type Any. -If *func*’s apparent type (section [3.8.1](#3.8.1)) is a function type, the call is a ***typed function call***. TypeScript employs ***overload resolution*** in typed function calls in order to support functions with multiple call signatures. Furthermore, TypeScript may perform ***type argument inference*** to automatically determine type arguments in generic function calls. +If *func*'s apparent type (section [3.8.1](#3.8.1)) is a function type, the call is a ***typed function call***. TypeScript employs ***overload resolution*** in typed function calls in order to support functions with multiple call signatures. Furthermore, TypeScript may perform ***type argument inference*** to automatically determine type arguments in generic function calls. ### 4.12.1 Overload Resolution -The purpose of overload resolution in a function call is to ensure that at least one signature is applicable, to provide contextual types for the arguments, and to determine the result type of the function call, which could differ between the multiple applicable signatures. Overload resolution has no impact on the run-time behavior of a function call. Since JavaScript doesn’t support function overloading, all that matters at run-time is the name of the function. +The purpose of overload resolution in a function call is to ensure that at least one signature is applicable, to provide contextual types for the arguments, and to determine the result type of the function call, which could differ between the multiple applicable signatures. Overload resolution has no impact on the run-time behavior of a function call. Since JavaScript doesn't support function overloading, all that matters at run-time is the name of the function. The compile-time processing of a typed function call consists of the following steps: @@ -2383,8 +2489,7 @@ The compile-time processing of a typed function call consists of the following s * the function call has no type arguments, and * the signature is applicable with respect to the argument list of the function call. * A generic signature is a candidate in a function call without type arguments when - * type inference (section [4.12.2](#4.12.2)) succeeds in inferring a list of type arguments, - * the inferred type arguments satisfy their constraints, and + * type inference (section [4.12.2](#4.12.2)) succeeds for each type parameter, * once the inferred type arguments are substituted for their associated type parameters, the signature is applicable with respect to the argument list of the function call. * A generic signature is a candidate in a function call with type arguments when * The signature has the same number of type parameters as were supplied in the type argument list, @@ -2402,12 +2507,13 @@ A signature is said to be an ***applicable signature*** with respect to an argum ### 4.12.2 Type Argument Inference -Given a signature < *T1* , *T2* , … , *Tn* > ( *p1* : *P1* , *p2* : *P2* , … , *pm* : *Pm* ), where each parameter type *P* references zero or more of the type parameters *T*, and an argument list ( *e1* , *e2* , … , *em* ), the task of type argument inference is to find a set of type arguments *A1*…*An* to substitute for *T1*…*Tn* such that the argument list becomes an applicable signature. +Given a signature < *T1* , *T2* , … , *Tn* > ( *p1* : *P1* , *p2* : *P2* , … , *pm* : *Pm* ), where each parameter type *P* references zero or more of the type parameters *T*, and an argument list ( *e1* , *e2* , … , *em* ), the task of type argument inference is to find a set of type arguments *A1*…*An* to substitute for *T1*…*Tn* such that the argument list becomes an applicable signature. -The inferred type argument for a particular type parameter is determined from a set of candidate types. Given a type parameter *T*, let *C* denote the widened form (section [3.9](#3.9)) of the best common type (section [3.10](#3.10)) of the set of candidate types *T*. Then, +Type argument inference produces a set of candidate types for each type parameter. Given a type parameter *T* and set of candidate types, the actual inferred type argument is determined as follows: -* If *C* satisfies *T*’s constraint, the inferred type argument for *T* is *C*. -* Otherwise, the inferred type argument for *T* is *T*’s constraint. +* If the set of candidate argument types is empty, the inferred type argument for *T* is *T*'s constraint. +* Otherwise, if at least one of the candidate types is a supertype of all of the other candidate types, let *C* denote the first such candidate type. If *C* satisfies *T*'s constraint, the inferred type argument for *T* is *C*. Otherwise, the inferred type argument for *T* is *T*'s constraint. +* Otherwise, if no candidate type is a supertype of all of the other candidate types, type inference has fails and no type argument is inferred for *T*. In order to compute candidate types, the argument list is processed as follows: @@ -2417,27 +2523,27 @@ In order to compute candidate types, the argument list is processed as follows: The process of inferentially typing an expression *e* by a type *T* is the same as that of contextually typing *e* by *T*, with the following exceptions: * Where expressions contained within *e* would be contextually typed, they are instead inferentially typed. -* Where a contextual type would be included in a best common type determination (such as when inferentially typing an object or array literal), an inferential type is not. * When a function expression is inferentially typed (section [4.9.3](#4.9.3)) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, the corresponding inferred type arguments to become ***fixed*** and no further candidate inferences are made for them. -* If *e* is an expression of a function type that contains exactly one generic call signature and no other members, and *T* is a function type with exactly one non-generic call signature and no other members, then any inferences made for type parameters referenced by the parameters of *T*’s call signature are ***fixed***, and *e*’s type is changed to a function type with *e*’s call signature instantiated in the context of *T*’s call signature (section [3.8.5](#3.8.5)). +* If *e* is an expression of a function type that contains exactly one generic call signature and no other members, and *T* is a function type with exactly one non-generic call signature and no other members, then any inferences made for type parameters referenced by the parameters of *T*'s call signature are ***fixed***, and *e*'s type is changed to a function type with *e*'s call signature instantiated in the context of *T*'s call signature (section [3.8.5](#3.8.5)). -In the example +An example: ```TypeScript function choose(x: T, y: T): T { return Math.random() < 0.5 ? x : y; } -var x = choose("Five", 5); +var x = choose(10, 20); // Ok, x of type number +var y = choose("Five", 5); // Error ``` -inferences for ‘T’ in the call to ‘choose’ are made as follows: For the first parameter, an inference is made from type ‘string’ to ‘T’. For the second parameter, an inference is made from type ‘number’ to ‘T’. Since the best common type (section [3.10](#3.10)) of ‘string’ and ‘number’ is the empty object type, the call to ‘choose’ is equivalent to +In the first call to 'choose', two inferences are made from 'number' to 'T', one for each parameter. Thus, 'number' is inferred for 'T' and the call is equivalent to ```TypeScript -var x = choose<{}>("Five", 5); +var x = choose(10, 20); ``` -and the resulting type of ‘x’ is therefore the empty object type. Note that had both arguments been of type ‘string’ or ‘number’, ‘x’ would have been of that type. +In the second call to 'choose', an inference is made from type 'string' to 'T' for the first parameter and an inference is made from type 'number' to 'T' for the second parameter. Since neither 'string' nor 'number' is a supertype of the other, type inference fails. That in turn means there are no applicable signatures and the function call is an error. In the example @@ -2452,13 +2558,13 @@ var names = ["Peter", "Paul", "Mary"]; var lengths = map(names, s => s.length); ``` -inferences for ‘T’ and ‘U’ in the call to ‘map’ are made as follows: For the first parameter, inferences are made from the type ‘string[]’ (the type of ‘names’) to the type ‘T[]’, inferring ‘string’ for ‘T’. For the second parameter, inferential typing of the arrow expression ‘s => s.length’ causes ‘T’ to become fixed such that the inferred type ‘string’ can be used for the parameter ‘s’. The return type of the arrow expression can then be determined, and inferences are made from the type ‘(s: string) => number’ to the type ‘(x: T) => U’, inferring ‘number’ for ‘U’. Thus the call to ‘map’ is equivalent to +inferences for 'T' and 'U' in the call to 'map' are made as follows: For the first parameter, inferences are made from the type 'string[]' (the type of 'names') to the type 'T[]', inferring 'string' for 'T'. For the second parameter, inferential typing of the arrow expression 's => s.length' causes 'T' to become fixed such that the inferred type 'string' can be used for the parameter 's'. The return type of the arrow expression can then be determined, and inferences are made from the type '(s: string) => number' to the type '(x: T) => U', inferring 'number' for 'U'. Thus the call to 'map' is equivalent to ```TypeScript var lengths = map(names, s => s.length); ``` -and the resulting type of ‘lengths’ is therefore ‘number[]’. +and the resulting type of 'lengths' is therefore 'number[]'. In the example @@ -2475,14 +2581,14 @@ var ages = [7, 9, 12]; var pairs = zip(names, ages, s => n => ({ name: s, age: n })); ``` -inferences for ‘S’, ‘T’ and ‘U’ in the call to ‘zip’ are made as follows: Using the first two parameters, inferences of ‘string’ for ‘S’ and ‘number’ for ‘T’ are made. For the third parameter, inferential typing of the outer arrow expression causes ‘S’ to become fixed such that the inferred type ‘string’ can be used for the parameter ‘s’. When a function expression is inferentially typed, its return expression(s) are also inferentially typed. Thus, the inner arrow function is inferentially typed, causing ‘T’ to become fixed such that the inferred type ‘number’ can be used for the parameter ‘n’. The return type of the inner arrow function can then be determined, which in turn determines the return type of the function returned from the outer arrow function, and inferences are made from the type ‘(s: string) => (n: number) => { name: string; age: number }’ to the type ‘(x: S) => (y: T) => R’, inferring ‘{ name: string; age: number }’ for ‘R’. Thus the call to ‘zip’ is equivalent to +inferences for 'S', 'T' and 'U' in the call to 'zip' are made as follows: Using the first two parameters, inferences of 'string' for 'S' and 'number' for 'T' are made. For the third parameter, inferential typing of the outer arrow expression causes 'S' to become fixed such that the inferred type 'string' can be used for the parameter 's'. When a function expression is inferentially typed, its return expression(s) are also inferentially typed. Thus, the inner arrow function is inferentially typed, causing 'T' to become fixed such that the inferred type 'number' can be used for the parameter 'n'. The return type of the inner arrow function can then be determined, which in turn determines the return type of the function returned from the outer arrow function, and inferences are made from the type '(s: string) => (n: number) => { name: string; age: number }' to the type '(x: S) => (y: T) => R', inferring '{ name: string; age: number }' for 'R'. Thus the call to 'zip' is equivalent to ```TypeScript var pairs = zip( names, ages, s => n => ({ name: s, age: n })); ``` -and the resulting type of ‘pairs’ is therefore ‘{ name: string; age: number }[]’. +and the resulting type of 'pairs' is therefore '{ name: string; age: number }[]'. ### 4.12.3 Grammar Ambiguities @@ -2492,32 +2598,32 @@ The inclusion of type arguments in the *Arguments* production (section [4.12](#4 f(g(7)); ``` -could be interpreted as a call to ‘f’ with two arguments, ‘g < A’ and ‘B > (7)’. Alternatively, it could be interpreted as a call to ‘f’ with one argument, which is a call to a generic function ‘g’ with two type arguments and one regular argument. +could be interpreted as a call to 'f' with two arguments, 'g < A' and 'B > (7)'. Alternatively, it could be interpreted as a call to 'f' with one argument, which is a call to a generic function 'g' with two type arguments and one regular argument. -The grammar ambiguity is resolved as follows: In a context where one possible interpretation of a sequence of tokens is an *Arguments* production, if the initial sequence of tokens forms a syntactically correct *TypeArguments* production and is followed by a ‘`(`‘ token, then the sequence of tokens is processed an *Arguments* production, and any other possible interpretation is discarded. Otherwise, the sequence of tokens is not considered an *Arguments* production. +The grammar ambiguity is resolved as follows: In a context where one possible interpretation of a sequence of tokens is an *Arguments* production, if the initial sequence of tokens forms a syntactically correct *TypeArguments* production and is followed by a '`(`' token, then the sequence of tokens is processed an *Arguments* production, and any other possible interpretation is discarded. Otherwise, the sequence of tokens is not considered an *Arguments* production. -This rule means that the call to ‘f’ above is interpreted as a call with one argument, which is a call to a generic function ‘g’ with two type arguments and one regular argument. However, the statements +This rule means that the call to 'f' above is interpreted as a call with one argument, which is a call to a generic function 'g' with two type arguments and one regular argument. However, the statements ```TypeScript f(g < A, B > 7); f(g < A, B > +(7)); ``` -are both interpreted as calls to ‘f’ with two arguments. +are both interpreted as calls to 'f' with two arguments. ## 4.13 Type Assertions TypeScript extends the JavaScript expression grammar with the ability to assert a type for an expression:   *UnaryExpression:* *( Modified )* -   … +   …    `<` *Type* `>` *UnaryExpression* A type assertion expression consists of a type enclosed in `<` and `>` followed by a unary expression. Type assertion expressions are purely a compile-time construct. Type assertions are *not* checked at run-time and have no impact on the emitted JavaScript (and therefore no run-time cost). The type and the enclosing `<` and `>` are simply removed from the generated code. In a type assertion expression of the form `<` *T* `>` *e*, *e* is contextually typed (section [4.19](#4.19)) by *T* and the resulting type of* e* is required to be assignable to *T*, or *T* is required to be assignable to the widened form of the resulting type of *e*, or otherwise a compile-time error occurs. The type of the result is *T*. -Type assertions check for assignment compatibility in both directions. Thus, type assertions allow type conversions that *might* be correct, but aren’t *known* to be correct. In the example +Type assertions check for assignment compatibility in both directions. Thus, type assertions allow type conversions that *might* be correct, but aren't *known* to be correct. In the example ```TypeScript class Shape { ... } @@ -2532,7 +2638,7 @@ function createShape(kind: string): Shape { var circle = createShape("circle"); ``` -the type annotations indicate that the ‘createShape’ function *might* return a ‘Circle’ (because ‘Circle’ is a subtype of ‘Shape’), but isn’t *known* to do so (because its return type is ‘Shape’). Therefore, a type assertion is needed to treat the result as a ‘Circle’. +the type annotations indicate that the 'createShape' function *might* return a 'Circle' (because 'Circle' is a subtype of 'Shape'), but isn't *known* to do so (because its return type is 'Shape'). Therefore, a type assertion is needed to treat the result as a 'Circle'. As mentioned above, type assertions are not checked at run-time and it is up to the programmer to guard against errors, for example using the `instanceof` operator: @@ -2552,7 +2658,7 @@ The subsections that follow specify the compile-time processing rules of the una These operators, in prefix or postfix form, require their operand to be of type Any, the Number primitive type, or an enum type, and classified as a reference (section [4.1](#4.1)). They produce a result of the Number primitive type. -### 4.14.2 The +, –, and ~ operators +### 4.14.2 The +, –, and ~ operators These operators permit their operand to be of any type and produce a result of the Number primitive type. @@ -2564,7 +2670,7 @@ function getValue() { ... } var n = +getValue(); ``` -The example above converts the result of ‘getValue()’ to a number if it isn’t a number already. The type inferred for ‘n’ is the Number primitive type regardless of the return type of ‘getValue’. +The example above converts the result of 'getValue()' to a number if it isn't a number already. The type inferred for 'n' is the Number primitive type regardless of the return type of 'getValue'. ### 4.14.3 The ! operator @@ -2578,19 +2684,19 @@ function getValue() { ... } var b = !!getValue(); ``` -The example above converts the result of ‘getValue()’ to a Boolean if it isn’t a Boolean already. The type inferred for ‘b’ is the Boolean primitive type regardless of the return type of ‘getValue’. +The example above converts the result of 'getValue()' to a Boolean if it isn't a Boolean already. The type inferred for 'b' is the Boolean primitive type regardless of the return type of 'getValue'. ### 4.14.4 The delete Operator -The ‘delete’ operator takes an operand of any type and produces a result of the Boolean primitive type. +The 'delete' operator takes an operand of any type and produces a result of the Boolean primitive type. ### 4.14.5 The void Operator -The ‘void’ operator takes an operand of any type and produces the value ‘undefined’. The type of the result is the Undefined type ([3.2.6](#3.2.6)). +The 'void' operator takes an operand of any type and produces the value 'undefined'. The type of the result is the Undefined type ([3.2.6](#3.2.6)). ### 4.14.6 The typeof Operator -The ‘typeof’ operator takes an operand of any type and produces a value of the String primitive type. In positions where a type is expected, ‘typeof’ can also be used in a type query (section [3.6.8](#3.6.8)) to produce the type of an expression. +The 'typeof' operator takes an operand of any type and produces a value of the String primitive type. In positions where a type is expected, 'typeof' can also be used in a type query (section [3.6.9](#3.6.9)) to produce the type of an expression. ```TypeScript var x = 5; @@ -2598,13 +2704,13 @@ var y = typeof x; // Use in an expression var z: typeof x; // Use in a type query ``` -In the example above, ‘x’ is of type ‘number’, ‘y’ is of type ‘string’ because when used in an expression, ‘typeof’ produces a value of type string (in this case the string “number”), and ‘z’ is of type ‘number’ because when used in a type query, ‘typeof’ obtains the type of an expression. +In the example above, 'x' is of type 'number', 'y' is of type 'string' because when used in an expression, 'typeof' produces a value of type string (in this case the string "number"), and 'z' is of type 'number' because when used in a type query, 'typeof' obtains the type of an expression. ## 4.15 Binary Operators The subsections that follow specify the compile-time processing rules of the binary operators. In general, if the operands of a binary operator do not meet the stated requirements, a compile-time error occurs and the result of the operation defaults to type any in further processing. Tables that summarize the compile-time processing rules for operands of the Any type, the Boolean, Number, and String primitive types, and all object types and type parameters (the Object column in the tables) are provided. -### 4.15.1 The *, /, %, –, <<, >>, >>>, &, ^, and | operators +### 4.15.1 The *, /, %, –, <<, >>, >>>, &, ^, and | operators These operators require their operands to be of type Any, the Number primitive type, or an enum type. Operands of an enum type are treated as having the primitive type Number. If one operand is the `null` or `undefined` value, it is treated as having the type of the other operand. The result is always of the Number primitive type. @@ -2636,7 +2742,7 @@ function getValue() { ... } var s = getValue() + ""; ``` -The example above converts the result of ‘getValue()’ to a string if it isn’t a string already. The type inferred for ‘s’ is the String primitive type regardless of the return type of ‘getValue’. +The example above converts the result of 'getValue()' to a string if it isn't a string already. The type inferred for 's' is the String primitive type regardless of the return type of 'getValue'. ### 4.15.3 The <, >, <=, >=, ==, !=, ===, and !== operators @@ -2652,9 +2758,9 @@ These operators require one operand type to be identical to or a subtype of the ### 4.15.4 The instanceof operator -The `instanceof` operator requires the left operand to be of type Any, an object type, or a type parameter type, and the right operand to be of type Any or a subtype of the ‘Function’ interface type. The result is always of the Boolean primitive type. +The `instanceof` operator requires the left operand to be of type Any, an object type, or a type parameter type, and the right operand to be of type Any or a subtype of the 'Function' interface type. The result is always of the Boolean primitive type. -Note that object types containing one or more call or construct signatures are automatically subtypes of the ‘Function’ interface type, as described in section [3.3](#3.3). +Note that object types containing one or more call or construct signatures are automatically subtypes of the 'Function' interface type, as described in section [3.3](#3.3). ### 4.15.5 The in operator @@ -2676,9 +2782,9 @@ The && operator permits the operands to be of any type and produces a result of The || operator permits the operands to be of any type. -If the || expression is contextually typed (section [4.19](#4.19)), the operands are contextually typed by the same type and the result is of the best common type (section [3.10](#3.10)) of the contextual type and the two operand types. +If the || expression is contextually typed (section [4.19](#4.19)), the operands are contextually typed by the same type. Otherwise, the left operand is not contextually typed and the right operand is contextually typed by the type of the left operand. -If the || expression is not contextually typed, the right operand is contextually typed by the type of the left operand and the result is of the best common type of the two operand types. +The type of the result is the union type of the two operand types. ||Any|Boolean|Number|String|Object| |:---:|:---:|:---:|:---:|:---:|:---:| @@ -2698,9 +2804,9 @@ test ? expr1 : expr2 the *test* expression may be of any type. -If the conditional expression is contextually typed (section [4.19](#4.19)), *expr1* and *expr2* are contextually typed by the same type and the result is of the best common type (section [3.10](#3.10)) of the contextual type and the types of *expr1* and *expr2*. An error occurs if the best common type is not identical to at least one of the three candidate types. +If the conditional expression is contextually typed (section [4.19](#4.19)), *expr1* and *expr2* are contextually typed by the same type. Otherwise, *expr1* and *expr2* are not contextually typed. -If the conditional expression is not contextually typed, the result is of the best common type of the types of *Expr1* and *Expr2*. An error occurs if the best common type is not identical to at least one of the two candidate types. +The type of the result is the union type of the types of *expr1* and *expr2*. ## 4.17 Assignment Operators @@ -2744,10 +2850,10 @@ the assignment f = function(s) { return s.toLowerCase(); } ``` -infers the type of the ‘s’ parameter to be the String primitive type even though there is no type annotation to that effect. The function expression is said to be ***contextually typed*** by the variable to which it is being assigned. Contextual typing occurs in the following situations: +infers the type of the 's' parameter to be the String primitive type even though there is no type annotation to that effect. The function expression is said to be ***contextually typed*** by the variable to which it is being assigned. Contextual typing occurs in the following situations: * In variable, parameter, and member declarations with a type annotation and an initializer, the initializer expression is contextually typed by the type of the variable, parameter, or property. -* In return statements, if the containing function includes a return type annotation, return expressions are contextually typed by that return type. Otherwise, if the containing function is contextually typed by a type *T*, return expressions are contextually typed by *T*’s return type. +* In return statements, if the containing function includes a return type annotation, return expressions are contextually typed by that return type. Otherwise, if the containing function is contextually typed by a type *T*, return expressions are contextually typed by *T*'s return type. * In typed function calls, argument expressions are contextually typed by their parameter types. * In type assertions, the expression is contextually typed by the indicated type. * In || operator expressions without a contextual type, the right hand expression is contextually typed by the type of the left hand expression. @@ -2761,24 +2867,24 @@ Contextual typing of an expression *e* by a type *T* proceeds as follows: * If *e* is an *ObjectLiteral* and *T* is an object type, *e* is processed with the contextual type *T*, as described in section [4.5](#4.5). * If *e* is an *ArrayLiteral* and *T* is an object type with a numeric index signature, *e* is processed with the contextual type *T*, as described in section [4.6](#4.6). -* If *e* is a *FunctionExpression* or *ArrowFunctionExpression* with no type parameters and no parameter type annotations, *T* is a function type with exactly one call signature and *T*’s call signature is non-generic, then any inferences made for type parameters referenced by the parameters of *T*’s call signature are fixed (section [4.12.2](#4.12.2)) and *e* is processed with the contextual type *T*, as described in section [4.9.3](#4.9.3). +* If *e* is a *FunctionExpression* or *ArrowFunctionExpression* with no type parameters and no parameter type annotations, *T* is a function type with exactly one call signature and *T*'s call signature is non-generic, then any inferences made for type parameters referenced by the parameters of *T*'s call signature are fixed (section [4.12.2](#4.12.2)) and *e* is processed with the contextual type *T*, as described in section [4.9.3](#4.9.3). * If *e* is a || operator expression and *T* is an object type, *e* is processed with the contextual type *T*, as described in section [4.15.7](#4.15.7). * If *e* is a conditional operator expression and *T* is an object type, *e* is processed with the contextual type *T*, as described in section [4.16](#4.16). * Otherwise, *e* is processed without a contextual type. -The rules above require expressions be of the exact syntactic forms specified in order to be processed as contextually typed constructs. For example, given the declaration of the variable ‘f’ above, the assignment +The rules above require expressions be of the exact syntactic forms specified in order to be processed as contextually typed constructs. For example, given the declaration of the variable 'f' above, the assignment ```TypeScript f = s => s.toLowerCase(); ``` -causes the function expression to be contextually typed, inferring the String primitive type for ‘s’. However, simply enclosing the construct in parentheses +causes the function expression to be contextually typed, inferring the String primitive type for 's'. However, simply enclosing the construct in parentheses ```TypeScript f = (s => s.toLowerCase()); ``` -causes the function expression to be processed without a contextual type, now inferring ‘s’ and the result of the function to be of type Any as no type annotations are present. +causes the function expression to be processed without a contextual type, now inferring 's' and the result of the function to be of type Any as no type annotations are present. In the following example @@ -2802,7 +2908,113 @@ setEventHandlers({ }); ``` -the object literal passed to ‘setEventHandlers’ is contextually typed to the ‘EventHandlers’ type. This causes the two property assignments to be contextually typed to the unnamed function type ‘(event: EventObject) => void’, which in turn causes the ‘e’ parameters in the arrow function expressions to automatically be typed as ‘EventObject’. +the object literal passed to 'setEventHandlers' is contextually typed to the 'EventHandlers' type. This causes the two property assignments to be contextually typed to the unnamed function type '(event: EventObject) => void', which in turn causes the 'e' parameters in the arrow function expressions to automatically be typed as 'EventObject'. + +## 4.20 Type Guards + +Type guards are particular expression patterns involving the 'typeof' and 'instanceof' operators that cause the types of variables or parameters to be ***narrowed*** to more specific types. For example, in the code below, knowledge of the static type of 'x' in combination with a 'typeof' check makes it safe to narrow the type of 'x' to string in the first branch of the 'if' statement and number in the second branch of the 'if' statement. + +```TypeScript +function foo(x: number | string) { + if (typeof x === "string") { + return x.length; // x has type string here + } + else { + return x + 1; // x has type number here + } +} +``` + +The type of a variable or parameter is narrowed in the following situations: + +* In the true branch statement of an 'if' statement, the type of a variable or parameter is *narrowed* by any type guard in the 'if' condition *when true*, provided the true branch statement contains no assignments to the variable or parameter. +* In the false branch statement of an 'if' statement, the type of a variable or parameter is *narrowed* by any type guard in the 'if' condition *when false*, provided the false branch statement contains no assignments to the variable or parameter. +* In the true expression of a conditional expression, the type of a variable or parameter is *narrowed* by any type guard in the condition *when true*, provided the true expression contains no assignments to the variable or parameter. +* In the false expression of a conditional expression, the type of a variable or parameter is *narrowed* by any type guard in the condition *when false*, provided the false expression contains no assignments to the variable or parameter. +* In the right operand of a && operation, the type of a variable or parameter is *narrowed* by any type guard in the left operand *when true*, provided the right operand contains no assignments to the variable or parameter. +* In the right operand of a || operation, the type of a variable or parameter is *narrowed* by any type guard in the left operand *when false*, provided the right operand contains no assignments to the variable or parameter. + +A type guard is simply an expression that follows a particular pattern. The process of narrowing the type of a variable *x* by a type guard *when true* or *when false* depends on the type guard as follows: + +* A type guard of the form `x instanceof C`, where *C* is of a subtype of the global type 'Function' and *C* has a property named 'prototype' + * *when true*, narrows the type of *x* to the type of the 'prototype' property in *C* provided it is a subtype of the type of *x*, or + * *when false*, has no effect on the type of *x*. +* A type guard of the form `typeof x === s`, where *s* is a string literal with the value 'string', 'number', or 'boolean', + * *when true*, narrows the type of *x* to the given primitive type, or + * *when false*, removes the primitive type from the type of *x*. +* A type guard of the form `typeof x === s`, where *s* is a string literal with any value but 'string', 'number', or 'boolean', + * *when true*, removes the primitive types string, number, and boolean from the type of *x*, or + * *when false*, has no effect on the type of *x*. +* A type guard of the form `typeof x !== s`, where *s* is a string literal, + * *when true*, narrows the type of x by `typeof x === s` *when false*, or + * *when false*, narrows the type of x by `typeof x === s` *when true*. +* A type guard of the form `!expr` + * *when true*, narrows the type of *x* by *expr* *when false*, or + * *when false*, narrows the type of *x* by *expr* *when true*. +* A type guard of the form `expr1 && expr2` + * *when true*, narrows the type of *x* by *expr1* *when true* and then by *expr2* *when true*, or + * *when false*, narrows the type of *x* to *T1* | *T2*, where *T1* is the type of *x* narrowed by *expr1* *when false*, and *T2* is the type of *x* narrowed by *expr1* *when true* and then by *expr2* *when false*. +* A type guard of the form `expr1 || expr2` + * *when true*, narrows the type of *x* to *T1* | *T2*, where *T1* is the type of *x* narrowed by *expr1* *when true*, and *T2* is the type of *x* narrowed by *expr1* *when false* and then by *expr2* *when true*, or + * *when false*, narrows the type of *x* by *expr1* *when false* and then by *expr2* *when false*. +* A type guard of any other form has no effect on the type of *x*. + +A primitive type *P* is removed from a type *T* as follows: + +* If *T* is a union type *P* | *T1* | *T2* | … | *Tn*, the result is the type *T1* | *T2* | … | *Tn*. +* Otherwise, the result is *T*. + +Note that type guards affect types of variables and parameters only and have no effect on members of objects such as properties. Also note that it is possible to defeat a type guard by calling a function that changes the type of the guarded variable. + +In the example + +```TypeScript +function isLongString(obj: any) { + return typeof obj === "string" && obj.length > 100; +} +``` + +the 'obj' parameter has type string in the right operand of the && operator. + +In the example + +```TypeScript +function f(x: string | number | boolean) { + if (typeof x === "string" || typeof x === "number") { + var y = x; // Type of y is string | number + } + else { + var z = x; // Type of z is boolean + } +} +``` + +the type of 'x' is string | number | boolean in left operand of the || operator, number | boolean in the right operand of the || operator, string | number in the first branch of the 'if' statement, and boolean in the second branch of the 'if' statement. + +In the example + +```TypeScript +function processData(data: string | { (): string }) { + var d = typeof data !== "string" ? data() : data; + // Process string in d +} +``` + +the inferred type of 'd' is string. + +In the example + +```TypeScript +class NamedItem { + name: string; +} + +function getName(obj: any) { + return obj instanceof NamedItem ? obj.name : "unknown"; +} +``` + +the inferred type of the 'getName' function is string.
@@ -2826,7 +3038,7 @@ Variable statements are extended to include optional type annotations. A variable declaration introduces a variable with the given name in the containing declaration space. The type associated with a variable is determined as follows: * If the declaration includes a type annotation, the stated type becomes the type of the variable. If an initializer is present, the initializer expression is contextually typed (section [4.19](#4.19)) by the stated type and must be assignable to the stated type, or otherwise a compile-time error occurs. -* If the declaration includes an initializer but no type annotation, and if the initializer doesn’t directly or indirectly reference the variable, the widened type (section [3.9](#3.9)) of the initializer expression becomes the type of the variable. If the initializer directly or indirectly references the variable, the type of the variable becomes the Any type. +* If the declaration includes an initializer but no type annotation, and if the initializer doesn't directly or indirectly reference the variable, the widened type (section [3.9](#3.9)) of the initializer expression becomes the type of the variable. If the initializer directly or indirectly references the variable, the type of the variable becomes the Any type. * If the declaration includes neither a type annotation nor an initializer, the type of the variable becomes the Any type. Multiple declarations for the same variable name in the same declaration space are permitted, provided that each declaration associates the same type with the variable. @@ -2841,7 +3053,7 @@ var d = { x: 1, y: "hello" }; // { x: number; y: string; } var e: any = "test"; // any ``` -The following is permitted because all declarations of the single variable ‘x’ associate the same type (Number) with ‘x’. +The following is permitted because all declarations of the single variable 'x' associate the same type (Number) with 'x'. ```TypeScript var x = 1; @@ -2851,7 +3063,7 @@ if (x == 1) { } ``` -In the following example, all five variables are of the same type, ‘{ x: number; y: number; }’. +In the following example, all five variables are of the same type, '{ x: number; y: number; }'. ```TypeScript interface Point { x: number; y: number; } @@ -2865,15 +3077,15 @@ var e = <{ x: number; y: number; }> { x: 0, y: undefined }; ##
5.2 If, Do, and While Statements -Expressions controlling ‘if’, ‘do’, and ‘while’ statements can be of any type (and not just type Boolean). +Expressions controlling 'if', 'do', and 'while' statements can be of any type (and not just type Boolean). ## 5.3 For Statements -Variable declarations in ‘for’ statements are extended in the same manner as variable declarations in variable statements (section [5.1](#5.1)). +Variable declarations in 'for' statements are extended in the same manner as variable declarations in variable statements (section [5.1](#5.1)). ## 5.4 For-In Statements -In a ‘for-in’ statement of the form +In a 'for-in' statement of the form ```TypeScript for (v in expr) statement @@ -2881,7 +3093,7 @@ for (v in expr) statement *v* must be an expression classified as a reference of type Any or the String primitive type, and *expr* must be an expression of type Any, an object type, or a type parameter type. -In a ‘for-in’ statement of the form +In a 'for-in' statement of the form ```TypeScript for (var v in expr) statement @@ -2891,21 +3103,21 @@ for (var v in expr) statement ## 5.5 Continue Statements -A ‘continue’ statement is required to be nested, directly or indirectly (but not crossing function boundaries), within an iteration (‘do’, ‘while’, ‘for’, or ‘for-in’) statement. When a ‘continue’ statement includes a target label, that target label must appear in the label set of an enclosing (but not crossing function boundaries) iteration statement. +A 'continue' statement is required to be nested, directly or indirectly (but not crossing function boundaries), within an iteration ('do', 'while', 'for', or 'for-in') statement. When a 'continue' statement includes a target label, that target label must appear in the label set of an enclosing (but not crossing function boundaries) iteration statement. ## 5.6 Break Statements -A ‘break’ statement is required to be nested, directly or indirectly (but not crossing function boundaries), within an iteration (‘do’, ‘while’, ‘for’, or ‘for-in’) or ‘switch’ statement. When a ‘break’ statement includes a target label, that target label must appear in the label set of an enclosing (but not crossing function boundaries) statement. +A 'break' statement is required to be nested, directly or indirectly (but not crossing function boundaries), within an iteration ('do', 'while', 'for', or 'for-in') or 'switch' statement. When a 'break' statement includes a target label, that target label must appear in the label set of an enclosing (but not crossing function boundaries) statement. ## 5.7 Return Statements -It is an error for a ‘return’ statement to occur outside a function body. Specifically, ‘return’ statements are not permitted at the global level or in module bodies. +It is an error for a 'return' statement to occur outside a function body. Specifically, 'return' statements are not permitted at the global level or in module bodies. -A ‘return’ statement without an expression returns the value ‘undefined’ and is permitted in the body of any function, regardless of the return type of the function. +A 'return' statement without an expression returns the value 'undefined' and is permitted in the body of any function, regardless of the return type of the function. -When a ‘return’ statement includes an expression, if the containing function includes a return type annotation, the return expression is contextually typed (section [4.19](#4.19)) by that return type and must be of a type that is assignable to the return type. Otherwise, if the containing function is contextually typed by a type *T*, *Expr* is contextually typed by *T*’s return type. +When a 'return' statement includes an expression, if the containing function includes a return type annotation, the return expression is contextually typed (section [4.19](#4.19)) by that return type and must be of a type that is assignable to the return type. Otherwise, if the containing function is contextually typed by a type *T*, *Expr* is contextually typed by *T*'s return type. -In a function implementation without a return type annotation, the return type is inferred from the ‘return’ statements in the function body, as described in section [6.3](#6.3). +In a function implementation without a return type annotation, the return type is inferred from the 'return' statements in the function body, as described in section [6.3](#6.3). In the example @@ -2915,23 +3127,23 @@ function f(): (x: string) => number { } ``` -the arrow expression in the ‘return’ statement is contextually typed by the return type of ‘f’, thus giving type ‘string’ to ‘s’. +the arrow expression in the 'return' statement is contextually typed by the return type of 'f', thus giving type 'string' to 's'. ## 5.8 With Statements -Use of the ‘with’ statement in TypeScript is an error, as is the case in ECMAScript 5’s strict mode. Furthermore, within the body of a ‘with’ statement, TypeScript considers every identifier occurring in an expression (section [4.3](#4.3)) to be of the Any type regardless of its declared type. Because the ‘with’ statement puts a statically unknown set of identifiers in scope in front of those that are statically known, it is not possible to meaningfully assign a static type to any identifier. +Use of the 'with' statement in TypeScript is an error, as is the case in ECMAScript 5's strict mode. Furthermore, within the body of a 'with' statement, TypeScript considers every identifier occurring in an expression (section [4.3](#4.3)) to be of the Any type regardless of its declared type. Because the 'with' statement puts a statically unknown set of identifiers in scope in front of those that are statically known, it is not possible to meaningfully assign a static type to any identifier. ## 5.9 Switch Statements -In a ‘switch’ statement, each ‘case’ expression must be of a type that is assignable to or from (section [3.8.4](#3.8.4)) the type of the ‘switch’ expression. +In a 'switch' statement, each 'case' expression must be of a type that is assignable to or from (section [3.8.4](#3.8.4)) the type of the 'switch' expression. ## 5.10 Throw Statements -The expression specified in a ‘throw’ statement can be of any type. +The expression specified in a 'throw' statement can be of any type. ## 5.11 Try Statements -The variable introduced by a ‘catch’ clause of a ‘try’ statement is always of type Any. It is not possible to include a type annotation in a ‘catch’ clause. +The variable introduced by a 'catch' clause of a 'try' statement is always of type Any. It is not possible to include a type annotation in a 'catch' clause.
@@ -2960,7 +3172,7 @@ A function declaration introduces a function with the given name in the containi ##
6.2 Function Overloads -Function overloads allow a more accurate specification of the patterns of invocation supported by a function than is possible with a single signature. The compile-time processing of a call to an overloaded function chooses the best candidate overload for the particular arguments and the return type of that overload becomes the result type the function call expression. Thus, using overloads it is possible to statically describe the manner in which a function’s return type varies based on its arguments. Overload resolution in function calls is described further in section [4.12](#4.12). +Function overloads allow a more accurate specification of the patterns of invocation supported by a function than is possible with a single signature. The compile-time processing of a call to an overloaded function chooses the best candidate overload for the particular arguments and the return type of that overload becomes the result type the function call expression. Thus, using overloads it is possible to statically describe the manner in which a function's return type varies based on its arguments. Overload resolution in function calls is described further in section [4.12](#4.12). Function overloads are purely a compile-time construct. They have no impact on the emitted JavaScript and thus no run-time cost. @@ -2982,7 +3194,7 @@ function attr(nameOrMap: any, value?: string): any { } ``` -Note that each overload and the final implementation specify the same identifier. The type of the local variable ‘attr’ introduced by this declaration is +Note that each overload and the final implementation specify the same identifier. The type of the local variable 'attr' introduced by this declaration is ```TypeScript var attr: { @@ -2998,9 +3210,10 @@ Note that the signature of the actual function implementation is not included in A function implementation without a return type annotation is said to be an ***implicitly typed function***. The return type of an implicitly typed function *f* is inferred from its function body as follows: -* If there are no return statements with expressions in *f*’s function body, the inferred return type is Void. -* Otherwise, if *f*’s function body directly references *f* or references any implicitly typed functions that through this same analysis reference *f*, the inferred return type is Any. -* Otherwise, the inferred return type is the widened form (section [3.9](#3.9)) of the best common type (section [3.10](#3.10)) of the types of the return statement expression in the function body, ignoring return statements with no expressions. A compile-time error occurs if the best common type isn’t one of the return statement expression types (i.e. if the best common type is an empty type). +* If there are no return statements with expressions in *f*'s function body, the inferred return type is Void. +* Otherwise, if *f*'s function body directly references *f* or references any implicitly typed functions that through this same analysis reference *f*, the inferred return type is Any. +* Otherwise, if *f* is a contextually typed function expression (section [4.9.3](#4.9.3)), the inferred return type is the union type (section [3.3.4](#3.3.4)) of the types of the return statement expressions in the function body, ignoring return statements with no expressions. +* Otherwise, the inferred return type is the first of the types of the return statement expressions in the function body that is a supertype (section [3.8.3](#3.8.3)) of each of the others, ignoring return statements with no expressions. A compile-time error occurs if no return statement expression has a type that is a supertype of each of the others. In the example @@ -3015,11 +3228,11 @@ function g(x: number) { } ``` -the inferred return type for ‘f’ and ‘g’ is Any because the functions reference themselves through a cycle with no return type annotations. Adding an explicit return type ‘number’ to either breaks the cycle and causes the return type ‘number’ to be inferred for the other. +the inferred return type for 'f' and 'g' is Any because the functions reference themselves through a cycle with no return type annotations. Adding an explicit return type 'number' to either breaks the cycle and causes the return type 'number' to be inferred for the other. -An explicitly typed function whose return type isn’t the Void or the Any type must have at least one return statement somewhere in its body. An exception to this rule is if the function implementation consists of a single ‘throw’ statement. +An explicitly typed function whose return type isn't the Void or the Any type must have at least one return statement somewhere in its body. An exception to this rule is if the function implementation consists of a single 'throw' statement. -The type of ‘this’ in a function implementation is the Any type. +The type of 'this' in a function implementation is the Any type. In the signature of a function implementation, a parameter can be marked optional by following it with an initializer. When a parameter declaration includes both a type annotation and an initializer, the initializer expression is contextually typed (section [4.19](#4.19)) by the stated type and must be assignable to the stated type, or otherwise a compile-time error occurs. When a parameter declaration has no type annotation but includes an initializer, the type of the parameter is the widened form (section [3.9](#3.9)) of the type of the initializer expression. @@ -3052,11 +3265,11 @@ function f(a = x) { } ``` -the local variable ‘x’ is in scope in the parameter initializer (thus hiding the outer ‘x’), but it is an error to reference it because it will always be uninitialized at the time the parameter initializer is evaluated. +the local variable 'x' is in scope in the parameter initializer (thus hiding the outer 'x'), but it is an error to reference it because it will always be uninitialized at the time the parameter initializer is evaluated. ## 6.4 Generic Functions -A function implementation may include type parameters in its signature (section [3.7.2.1](#3.7.2.1)) and is then called a ***generic function***. Type parameters provide a mechanism for expressing relationships between parameter and return types in call operations. Type parameters have no run-time representation—they are purely a compile-time construct. +A function implementation may include type parameters in its signature (section [3.7.2.1](#3.7.2.1)) and is then called a ***generic function***. Type parameters provide a mechanism for expressing relationships between parameter and return types in call operations. Type parameters have no run-time representation—they are purely a compile-time construct. Type parameters declared in the signature of a function implementation are in scope in the signature and body of that function implementation. @@ -3074,7 +3287,7 @@ function compare(x: T, y: T): number { } ``` -Note that the ‘x’ and ‘y’ parameters are known to be subtypes of the constraint ‘Comparable’ and therefore have a ‘compareTo’ member. This is described further in section [3.4.1](#3.4.1). +Note that the 'x' and 'y' parameters are known to be subtypes of the constraint 'Comparable' and therefore have a 'compareTo' member. This is described further in section [3.4.1](#3.4.1). The type arguments of a call to a generic function may be explicitly specified in a call operation or may, when possible, be inferred (section [4.12.2](#4.12.2)) from the types of the regular arguments in the call. In the example @@ -3087,7 +3300,7 @@ class Person { } ``` -the type argument to ‘compare’ is automatically inferred to be the String type because the two arguments are strings. +the type argument to 'compare' is automatically inferred to be the String type because the two arguments are strings. ## 6.5 Code Generation @@ -3102,7 +3315,7 @@ function () { *FunctionName* is the name of the function (or nothing in the case of a function expression). -*FunctionParameters* is a comma separated list of the function’s parameter names. +*FunctionParameters* is a comma separated list of the function's parameter names. *DefaultValueAssignments* is a sequence of default property value assignments, one for each parameter with a default value, in the order they are declared, of the form @@ -3120,7 +3333,7 @@ where *Parameter* is the parameter name and *Default* is the default value expre Interfaces provide the ability to name and parameterize object types and to compose existing named object types into new ones. -Interfaces have no run-time representation—they are purely a compile-time construct. Interfaces are particularly useful for documenting and validating the required shape of properties, objects passed as parameters, and objects returned from functions. +Interfaces have no run-time representation—they are purely a compile-time construct. Interfaces are particularly useful for documenting and validating the required shape of properties, objects passed as parameters, and objects returned from functions. Because TypeScript has a structural type system, an interface type with a particular set of members is considered identical to, and can be substituted for, another interface type or object type literal with an identical set of members (see section [3.8.2](#3.8.2)). @@ -3149,7 +3362,7 @@ An interface may optionally have type parameters (section [3.4.1](#3.4.1)) that An interface can inherit from zero or more ***base types*** which are specified in the *InterfaceExtendsClause*. The base types must be type references to class or interface types. -An interface has the members specified in the *ObjectType* of its declaration and furthermore inherits all base type members that aren’t hidden by declarations in the interface: +An interface has the members specified in the *ObjectType* of its declaration and furthermore inherits all base type members that aren't hidden by declarations in the interface: * A property declaration hides a public base type property with the same name. * A string index signature declaration hides a base type string index signature. @@ -3179,7 +3392,7 @@ interface Shaker { } ``` -An interface that extends ‘Mover’ and ‘Shaker’ must declare a new ‘getStatus’ property as it would otherwise inherit two ‘getStatus’ properties with different types. The new ‘getStatus’ property must be declared such that the resulting ‘MoverShaker’ is a subtype of both ‘Mover’ and ‘Shaker’: +An interface that extends 'Mover' and 'Shaker' must declare a new 'getStatus' property as it would otherwise inherit two 'getStatus' properties with different types. The new 'getStatus' property must be declared such that the resulting 'MoverShaker' is a subtype of both 'Mover' and 'Shaker': ```TypeScript interface MoverShaker extends Mover, Shaker { @@ -3193,11 +3406,11 @@ Since function and constructor types are just object types containing call and c interface StringComparer { (a: string, b: string): number; } ``` -This declares type ‘StringComparer’ to be a function type taking two strings and returning a number. +This declares type 'StringComparer' to be a function type taking two strings and returning a number. ## 7.2 Declaration Merging -Interfaces are “open-ended” and interface declarations with the same qualified name relative to a common root (as defined in section [2.3](#2.3)) contribute to a single interface. +Interfaces are "open-ended" and interface declarations with the same qualified name relative to a common root (as defined in section [2.3](#2.3)) contribute to a single interface. When a generic interface has multiple declarations, all declarations must have identical type parameter lists, i.e. identical type parameter names with identical constraints in identical order. @@ -3264,13 +3477,13 @@ class Location { } ``` -In the above example, ‘SelectableControl’ contains all of the members of ‘Control’, including the private ‘state’ property. Since ‘state’ is a private member it is only possible for descendants of ‘Control’ to implement ‘SelectableControl’. This is because only descendants of ‘Control’ will have a ‘state’ private member that originates in the same declaration, which is a requirement for private members to be compatible (section [3.8](#3.8)). +In the above example, 'SelectableControl' contains all of the members of 'Control', including the private 'state' property. Since 'state' is a private member it is only possible for descendants of 'Control' to implement 'SelectableControl'. This is because only descendants of 'Control' will have a 'state' private member that originates in the same declaration, which is a requirement for private members to be compatible (section [3.8](#3.8)). -Within the ‘Control’ class it is possible to access the ‘state’ private member through an instance of ‘SelectableControl’. Effectively, a ‘SelectableControl’ acts like a ‘Control’ that is known to have a ‘select’ method. The ‘Button’ and ‘TextBox’ classes are subtypes of ‘SelectableControl’ (because they both inherit from ‘Control’ and have a ‘select’ method), but the ‘Image’ and ‘Location’ classes are not. +Within the 'Control' class it is possible to access the 'state' private member through an instance of 'SelectableControl'. Effectively, a 'SelectableControl' acts like a 'Control' that is known to have a 'select' method. The 'Button' and 'TextBox' classes are subtypes of 'SelectableControl' (because they both inherit from 'Control' and have a 'select' method), but the 'Image' and 'Location' classes are not. ## 7.4 Dynamic Type Checks -TypeScript does not provide a direct mechanism for dynamically testing whether an object implements a particular interface. Instead, TypeScript code can use the JavaScript technique of checking whether an appropriate set of members are present on the object. For example, given the declarations in section [7.1](#7.1), the following is a dynamic check for the ‘MoverShaker’ interface: +TypeScript does not provide a direct mechanism for dynamically testing whether an object implements a particular interface. Instead, TypeScript code can use the JavaScript technique of checking whether an appropriate set of members are present on the object. For example, given the declarations in section [7.1](#7.1), the following is a dynamic check for the 'MoverShaker' interface: ```TypeScript var obj: any = getSomeObject(); @@ -3294,7 +3507,7 @@ function asMoverShaker(obj: any): MoverShaker { TypeScript supports classes that are closely aligned with those proposed for ECMAScript 6, and includes extensions for instance and static member declarations and properties declared and initialized from constructor parameters. -*NOTE: TypeScript currently doesn’t support class expressions or nested class declarations from the ECMAScript 6 proposal*. +*NOTE: TypeScript currently doesn't support class expressions or nested class declarations from the ECMAScript 6 proposal*. ## 8.1 Class Declarations @@ -3309,7 +3522,7 @@ The *Identifier* of a class declaration may not be one of the predefined type na A class may optionally have type parameters (section [3.4.1](#3.4.1)) that serve as placeholders for actual types to be provided when the class is referenced in type references. A class with type parameters is called a ***generic class***. The type parameters of a generic class declaration are in scope in the entire declaration and may be referenced in the *ClassHeritage* and *ClassBody*. -The following example introduces both a named type called ‘Point’ (the class type) and a member called ‘Point’ (the constructor function) in the containing module. +The following example introduces both a named type called 'Point' (the class type) and a member called 'Point' (the constructor function) in the containing module. ```TypeScript class Point { @@ -3319,7 +3532,7 @@ class Point { } ``` -The ‘Point’ type is exactly equivalent to +The 'Point' type is exactly equivalent to ```TypeScript interface Point { @@ -3329,7 +3542,7 @@ interface Point { } ``` -The ‘Point’ member is a constructor function whose type corresponds to the declaration +The 'Point' member is a constructor function whose type corresponds to the declaration ```TypeScript var Point: { @@ -3344,7 +3557,7 @@ The context in which a class is referenced distinguishes between the class insta var p: Point = new Point(10, 20); ``` -the identifier ‘Point’ in the type annotation refers to the class instance type, whereas the identifier ‘Point’ in the `new` expression refers to the constructor function object. +the identifier 'Point' in the type annotation refers to the class instance type, whereas the identifier 'Point' in the `new` expression refers to the constructor function object. ### 8.1.1 Class Heritage Specification @@ -3362,7 +3575,7 @@ The heritage specification of a class consists of optional `extends` and `implem   *ImplementsClause:*    `implements` *ClassOrInterfaceTypeList* -A class that includes an `extends` clause is called a ***derived class***, and the class specified in the `extends` clause is called the ***base class*** of the derived class. When a class heritage specification omits the `extends` clause, the class does not have a base class. However, as is the case with every object type, type references (section [3.3.1](#3.3.1)) to the class will appear to have the members of the global interface type named ‘Object’ unless those members are hidden by members with the same name in the class. +A class that includes an `extends` clause is called a ***derived class***, and the class specified in the `extends` clause is called the ***base class*** of the derived class. When a class heritage specification omits the `extends` clause, the class does not have a base class. However, as is the case with every object type, type references (section [3.3.1](#3.3.1)) to the class will appear to have the members of the global interface type named 'Object' unless those members are hidden by members with the same name in the class. The following constraints must be satisfied by the class heritage specification or otherwise a compile-time error occurs: @@ -3382,15 +3595,15 @@ module Foo { } ``` -When evaluated as an expression, the type reference ‘A’ in the `extends` clause doesn’t reference the class constructor function of ‘A’ (instead it references the local variable ‘A’). +When evaluated as an expression, the type reference 'A' in the `extends` clause doesn't reference the class constructor function of 'A' (instead it references the local variable 'A'). The only situation in which the last two constraints above are violated is when a class overrides one or more base class members with incompatible new members. -Note that because TypeScript has a structural type system, a class doesn’t need to explicitly state that it implements an interface—it suffices for the class to simply contain the appropriate set of instance members. The `implements` clause of a class provides a mechanism to assert and validate that the class contains the appropriate sets of instance members, but otherwise it has no effect on the class type. +Note that because TypeScript has a structural type system, a class doesn't need to explicitly state that it implements an interface—it suffices for the class to simply contain the appropriate set of instance members. The `implements` clause of a class provides a mechanism to assert and validate that the class contains the appropriate sets of instance members, but otherwise it has no effect on the class type. ### 8.1.2 Class Body -The class body consists of zero or more constructor or member declarations. Statements are not allowed in the body of a class—they must be placed in the constructor or in members. +The class body consists of zero or more constructor or member declarations. Statements are not allowed in the body of a class—they must be placed in the constructor or in members.   *ClassBody:*    *ClassElementsopt* @@ -3432,7 +3645,7 @@ Private property members can be accessed only within their declaring class. Spec Protected property members can be accessed only within their declaring class and classes derived from their declaring class, and a protected instance property member must be accessed *through* an instance of the enclosing class. Specifically, a protected member *M* declared in a class *C* can be accessed only within the class body of *C* or the class body of a class derived from *C*. Furthermore, when a protected instance member *M* is accessed in a property access *E*`.`*M* within the body of a class *D*, the type of *E* is required to be *D* or a type that directly or indirectly has *D* as a base type, regardless of type arguments. -Private and protected accessibility is enforced only at compile-time and serves as no more than an *indication of intent*. Since JavaScript provides no mechanism to create private and protected properties on an object, it is not possible to enforce the private and protected modifiers in dynamic code at run-time. For example, private and protected accessibility can be defeated by changing an object’s static type to Any and accessing the member dynamically. +Private and protected accessibility is enforced only at compile-time and serves as no more than an *indication of intent*. Since JavaScript provides no mechanism to create private and protected properties on an object, it is not possible to enforce the private and protected modifiers in dynamic code at run-time. For example, private and protected accessibility can be defeated by changing an object's static type to Any and accessing the member dynamically. The following example demonstrates private and protected accessibility: @@ -3458,11 +3671,11 @@ class B extends A { } ``` -In class ‘A’, the accesses to ‘x’ are permitted because ‘x’ is declared in ‘A’, and the accesses to ‘y’ are permitted because both take place through an instance of ‘A’ or a type derived from ‘A’. In class ‘B’, access to ‘x’ is not permitted, and the first access to ‘y’ is an error because it takes place through an instance of ‘A’, which is not derived from the enclosing class ‘B’. +In class 'A', the accesses to 'x' are permitted because 'x' is declared in 'A', and the accesses to 'y' are permitted because both take place through an instance of 'A' or a type derived from 'A'. In class 'B', access to 'x' is not permitted, and the first access to 'y' is an error because it takes place through an instance of 'A', which is not derived from the enclosing class 'B'. ### 8.2.3 Inheritance and Overriding -A derived class ***inherits*** all members from its base class it doesn’t ***override***. Inheritance means that a derived class implicitly contains all non-overridden members of the base class. Only public and protected property members can be overridden. +A derived class ***inherits*** all members from its base class it doesn't ***override***. Inheritance means that a derived class implicitly contains all non-overridden members of the base class. Only public and protected property members can be overridden. A property member in a derived class is said to override a property member in a base class when the derived class property member has the same name and kind (instance or static) as the base class property member. The type of an overriding property member must be assignable (section [3.8.4](#3.8.4)) to the type of the overridden property member, or otherwise a compile-time error occurs. @@ -3503,7 +3716,7 @@ class B extends A { } ``` -the instance type of ‘A’ is +the instance type of 'A' is ```TypeScript interface A { @@ -3513,7 +3726,7 @@ interface A { } ``` -and the instance type of ‘B’ is +and the instance type of 'B' is ```TypeScript interface B { @@ -3524,7 +3737,7 @@ interface B { } ``` -Note that static declarations in a class do not contribute to the class type and its instance type—rather, static declarations introduce properties on the constructor function object. Also note that the declaration of ‘g’ in ‘B’ overrides the member inherited from ‘A’. +Note that static declarations in a class do not contribute to the class type and its instance type—rather, static declarations introduce properties on the constructor function object. Also note that the declaration of 'g' in 'B' overrides the member inherited from 'A'. ### 8.2.5 Constructor Function Types @@ -3537,10 +3750,10 @@ The type of the constructor function introduced by a class declaration is called * A property for each static member variable declaration in the class body. * A property of a function type for each static member function declaration in the class body. * A property for each uniquely named static member accessor declaration in the class body. -* A property named ‘prototype’, the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter. +* A property named 'prototype', the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter. * All base class constructor function type properties that are not overridden in the class. -Every class automatically contains a static property member named ‘prototype’, the type of which is the containing class with type Any substituted for each type parameter. +Every class automatically contains a static property member named 'prototype', the type of which is the containing class with type Any substituted for each type parameter. The example @@ -3578,7 +3791,7 @@ var TwoArrays: { } ``` -Note that the construct signatures in the constructor function types have the same type parameters as their class and return the instance type of their class. Also note that when a derived class doesn’t declare a constructor, type arguments from the base class reference are substituted before construct signatures are propagated from the base constructor function type to the derived constructor function type. +Note that the construct signatures in the constructor function types have the same type parameters as their class and return the instance type of their class. Also note that when a derived class doesn't declare a constructor, type arguments from the base class reference are substituted before construct signatures are propagated from the base constructor function type to the derived constructor function type. ## 8.3 Constructor Declarations @@ -3689,7 +3902,7 @@ Note that the declaration spaces of instance and static property members are sep Except for overrides, as described in section [8.2.3](#8.2.3), it is an error for a derived class to declare a property member with the same name and kind (instance or static) as a base class member. -Every class automatically contains a static property member named ‘prototype’, the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter. It is an error to explicitly declare a static property member with the name ‘prototype’. +Every class automatically contains a static property member named 'prototype', the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter. It is an error to explicitly declare a static property member with the name 'prototype'. Below is an example of a class containing both instance and static property member declarations: @@ -3706,7 +3919,7 @@ class Point { } ``` -The class instance type ‘Point’ has the members: +The class instance type 'Point' has the members: ```TypeScript interface Point { @@ -3716,7 +3929,7 @@ interface Point { } ``` -and the constructor function ‘Point’ has a type corresponding to the declaration: +and the constructor function 'Point' has a type corresponding to the declaration: ```TypeScript var Point: { @@ -3815,7 +4028,7 @@ class ColoredPoint extends Point { } ``` -In a static member function, `this` represents the constructor function object on which the static member function was invoked. Thus, a call to ‘new this()’ may actually invoke a derived class constructor: +In a static member function, `this` represents the constructor function object on which the static member function was invoked. Thus, a call to 'new this()' may actually invoke a derived class constructor: ```TypeScript class A { @@ -3833,7 +4046,7 @@ var x = A.create(); // new A() var y = B.create(); // new B() ``` -Note that TypeScript doesn’t require or verify that derived constructor functions are subtypes of base constructor functions. In other words, changing the declaration of ‘B’ to +Note that TypeScript doesn't require or verify that derived constructor functions are subtypes of base constructor functions. In other words, changing the declaration of 'B' to ```TypeScript class B extends A { @@ -3843,7 +4056,7 @@ class B extends A { } ``` -does not cause errors in the example, even though the call to the constructor from the ‘create’ function doesn’t specify an argument (thus giving the value ‘undefined’ to ‘b’). +does not cause errors in the example, even though the call to the constructor from the 'create' function doesn't specify an argument (thus giving the value 'undefined' to 'b'). ### 8.4.3 Member Accessor Declarations @@ -3861,7 +4074,7 @@ An instance member accessor declaration declares a property in the class instanc A static member accessor declaration declares a property in the constructor function type and defines a property on the constructor function object of the class with a get or set accessor. In the body of a static member accessor declaration, the type of `this` is the constructor function type. -Get and set accessors are emitted as calls to ‘Object.defineProperty’ in the generated JavaScript, as described in section [8.6.1](#8.6.1). +Get and set accessors are emitted as calls to 'Object.defineProperty' in the generated JavaScript, as described in section [8.6.1](#8.6.1). ## 8.5 Index Member Declarations @@ -3902,7 +4115,7 @@ var = (function () { *ClassName* is the name of the class. -*ConstructorParameters* is a comma separated list of the constructor’s parameter names. +*ConstructorParameters* is a comma separated list of the constructor's parameter names. *DefaultValueAssignments* is a sequence of default property value assignments corresponding to those generated for a regular function declaration, as described in section [6.5](#6.5). @@ -3976,7 +4189,7 @@ Object.defineProperty(, "", { }; ``` -where *MemberName* is the name of the member accessor, *GetAccessorStatements* is the code generated for the statements in the get acessor’s function body, *ParameterName* is the name of the set accessor parameter, and *SetAccessorStatements* is the code generated for the statements in the set accessor’s function body. The ‘get’ property is included only if a get accessor is declared and the ‘set’ property is included only if a set accessor is declared. +where *MemberName* is the name of the member accessor, *GetAccessorStatements* is the code generated for the statements in the get acessor's function body, *ParameterName* is the name of the set accessor parameter, and *SetAccessorStatements* is the code generated for the statements in the set accessor's function body. The 'get' property is included only if a get accessor is declared and the 'set' property is included only if a set accessor is declared. *StaticVariableAssignments* is a sequence of statements, one for each static member variable declaration with an initializer, in the order they are declared, of the form @@ -4006,7 +4219,7 @@ var = (function (_super) { })(); ``` -In addition, the ‘__extends’ function below is emitted at the beginning of the JavaScript source file. It copies all properties from the base constructor function object to the derived constructor function object (in order to inherit static members), and appropriately establishes the ‘prototype’ property of the derived constructor function object. +In addition, the '__extends' function below is emitted at the beginning of the JavaScript source file. It copies all properties from the base constructor function object to the derived constructor function object (in order to inherit static members), and appropriately establishes the 'prototype' property of the derived constructor function object. ```TypeScript var __extends = this.__extends || function(d, b) { @@ -4074,7 +4287,7 @@ An enum declaration declares an ***enum type*** and an ***enum object*** in the   *EnumDeclaration:*    `enum` *Identifier* `{` *EnumBodyopt* `}` -The enum type and enum object declared by an *EnumDeclaration* both have the name given by the *Identifier* of the declaration. The enum type is a distinct subtype of the Number primitive type. The enum object is a variable of an anonymous object type containing a set of properties, all of the enum type, corresponding to the values declared for the enum type in the body of the declaration. The enum object’s type furthermore includes a numeric index signature with the signature ‘[x: number]: string’. +The enum type and enum object declared by an *EnumDeclaration* both have the name given by the *Identifier* of the declaration. The enum type is a distinct subtype of the Number primitive type. The enum object is a variable of an anonymous object type containing a set of properties, all of the enum type, corresponding to the values declared for the enum type in the body of the declaration. The enum object's type furthermore includes a numeric index signature with the signature '[x: number]: string'. The *Identifier* of an enum declaration may not be one of the predefined type names (section [3.6.1](#3.6.1)). @@ -4084,7 +4297,7 @@ The example enum Color { Red, Green, Blue } ``` -declares a subtype of the Number primitive type called ‘Color’ and introduces a variable ‘Color’ with a type that corresponds to the declaration +declares a subtype of the Number primitive type called 'Color' and introduces a variable 'Color' with a type that corresponds to the declaration ```TypeScript var Color: { @@ -4095,7 +4308,7 @@ var Color: { }; ``` -The numeric index signature reflects a “reverse mapping” that is automatically generated in every enum object, as described in section [9.4](#9.4). The reverse mapping provides a convenient way to obtain the string representation of an enum value. For example +The numeric index signature reflects a "reverse mapping" that is automatically generated in every enum object, as described in section [9.4](#9.4). The reverse mapping provides a convenient way to obtain the string representation of an enum value. For example ```TypeScript var c = Color.Red; @@ -4156,7 +4369,7 @@ enum Test { } ``` -‘A’, ‘B’, ‘D’, and ‘E’ are constant members with values 0, 1, 10, and 11 respectively, and ‘C’ is a computed member. +'A', 'B', 'D', and 'E' are constant members with values 0, 1, 10, and 11 respectively, and 'C' is a computed member. In the example @@ -4175,9 +4388,9 @@ the first four members are constant members and the last two are computed member ## 9.3 Declaration Merging -Enums are “open-ended” and enum declarations with the same qualified name relative to a common root (as defined in section [2.3](#2.3)) define a single enum type and contribute to a single enum object. +Enums are "open-ended" and enum declarations with the same qualified name relative to a common root (as defined in section [2.3](#2.3)) define a single enum type and contribute to a single enum object. -It isn’t possible for one enum declaration to continue the automatic numbering sequence of another, and when an enum type has multiple declarations, only one declaration is permitted to omit a value for the first member. +It isn't possible for one enum declaration to continue the automatic numbering sequence of another, and when an enum type has multiple declarations, only one declaration is permitted to omit a value for the first member. ## 9.4 Code Generation @@ -4200,7 +4413,7 @@ var ; where *MemberName* is the name of the enum member and *Value* is the assigned constant value or the code generated for the computed value expression. -For example, the ‘Color’ enum example from section [9.1](#9.1) generates the following JavaScript: +For example, the 'Color' enum example from section [9.1](#9.1) generates the following JavaScript: ```TypeScript var Color; @@ -4215,7 +4428,7 @@ var Color; # 10 Internal Modules -An internal module is a named container of statements and declarations. An internal module represents both a namespace and a singleton module instance. The namespace contains named types and other namespaces, and the singleton module instance contains properties for the module’s exported members. The body of an internal module corresponds to a function that is executed once, thereby providing a mechanism for maintaining local state with assured isolation. +An internal module is a named container of statements and declarations. An internal module represents both a namespace and a singleton module instance. The namespace contains named types and other namespaces, and the singleton module instance contains properties for the module's exported members. The body of an internal module corresponds to a function that is executed once, thereby providing a mechanism for maintaining local state with assured isolation. ## 10.1 Module Declarations @@ -4228,7 +4441,7 @@ An internal module declaration declares a namespace name and, in the case of an    *Identifier*    *IdentifierPath* `.` *Identifier* -Internal modules are either ***instantiated*** or ***non-instantiated***. A non-instantiated module is an internal module containing only interface types and other non-instantiated modules. An instantiated module is an internal module that doesn’t meet this definition. In intuitive terms, an instantiated module is one for which a module object instance is created, whereas a non-instantiated module is one for which no code is generated. +Internal modules are either ***instantiated*** or ***non-instantiated***. A non-instantiated module is an internal module containing only interface types and other non-instantiated modules. An instantiated module is an internal module that doesn't meet this definition. In intuitive terms, an instantiated module is one for which a module object instance is created, whereas a non-instantiated module is one for which no code is generated. When a module identifier is referenced as a *ModuleName* (section [3.6.2](#3.6.2)) it denotes a container of module and type names, and when a module identifier is referenced as a *PrimaryExpression* (section [4.3](#4.3)) it denotes the singleton module instance. For example: @@ -4245,9 +4458,9 @@ var x2 = m.a; // Same as M.a var q: m.P; // Error ``` -Above, when ‘M’ is used as a *PrimaryExpression* it denotes an object instance with a single member ‘a’ and when ‘M’ is used as a *ModuleName* it denotes a container with a single type member ‘P’. The final line in the example is an error because ‘m’ is a variable which cannot be referenced in a type name. +Above, when 'M' is used as a *PrimaryExpression* it denotes an object instance with a single member 'a' and when 'M' is used as a *ModuleName* it denotes a container with a single type member 'P'. The final line in the example is an error because 'm' is a variable which cannot be referenced in a type name. -If the declaration of ‘M’ above had excluded the exported variable ‘a’, ‘M’ would be a non-instantiated module and it would be an error to reference ‘M’ as a *PrimaryExpression*. +If the declaration of 'M' above had excluded the exported variable 'a', 'M' would be a non-instantiated module and it would be an error to reference 'M' as a *PrimaryExpression*. An internal module declaration that specifies an *IdentifierPath* with more than one identifier is equivalent to a series of nested single-identifier internal module declarations where all but the outermost are automatically exported. For example: @@ -4306,7 +4519,7 @@ Import declarations are used to create local aliases for entities in other modul An *EntityName* consisting of a single identifier is resolved as a *ModuleName* and is thus required to reference an internal module. The resulting local alias references the given internal module and is itself classified as an internal module. -An *EntityName* consisting of more than one identifier is resolved as a *ModuleName* followed by an identifier that names one or more exported entities in the given module. The resulting local alias has all the meanings and classifications of the referenced entity or entities. (As many as three distinct meanings are possible for an entity name—namespace, type, and member.) In effect, it is as if the imported entity or entities were declared locally with the local alias name. +An *EntityName* consisting of more than one identifier is resolved as a *ModuleName* followed by an identifier that names one or more exported entities in the given module. The resulting local alias has all the meanings and classifications of the referenced entity or entities. (As many as three distinct meanings are possible for an entity name—namespace, type, and member.) In effect, it is as if the imported entity or entities were declared locally with the local alias name. In the example @@ -4324,7 +4537,7 @@ module B { } ``` -within ‘B’, ‘Y’ is an alias only for module ‘A’ and not the local interface ‘A’, whereas ‘Z’ is an alias for all exported meanings of ‘A.X’, thus denoting both an interface type and a variable. +within 'B', 'Y' is an alias only for module 'A' and not the local interface 'A', whereas 'Z' is an alias for all exported meanings of 'A.X', thus denoting both an interface type and a variable. If the *ModuleName* portion of an *EntityName* references an instantiated module, the *ModuleName* is required to reference the module instance when evaluated as an expression. In the example @@ -4339,7 +4552,7 @@ module B { } ``` -‘Y’ is a local alias for the non-instantiated module ‘A’. If the declaration of ‘A’ is changed such that ‘A’ becomes an instantiated module, for example by including a variable declaration in ‘A’, the import statement in ‘B’ above would be an error because the expression ‘A’ doesn’t reference the module instance of module ‘A’. +'Y' is a local alias for the non-instantiated module 'A'. If the declaration of 'A' is changed such that 'A' becomes an instantiated module, for example by including a variable declaration in 'A', the import statement in 'B' above would be an error because the expression 'A' doesn't reference the module instance of module 'A'. When an import statement includes an export modifier, all meanings of the local alias are exported. @@ -4349,7 +4562,7 @@ An export declaration declares an externally accessible module member. An export Exported class, interface, and enum types can be accessed as a *TypeName* (section [3.6.2](#3.6.2)) of the form *M.T*, where *M* is a reference to the containing module and *T* is the exported type name. Likewise, as part of a *TypeName*, exported modules can be accessed as a *ModuleName* of the form *M.N*, where *M* is a reference to the containing module and *N* is the exported module. -Exported variable, function, class, enum, module, and import alias declarations become properties on the module instance and together establish the module’s ***instance type***. This unnamed type has the following members: +Exported variable, function, class, enum, module, and import alias declarations become properties on the module instance and together establish the module's ***instance type***. This unnamed type has the following members: * A property for each exported variable declaration. * A property of a function type for each exported function declaration. @@ -4383,15 +4596,15 @@ interface A { x: string; } module M { export interface B { x: A; } export interface C { x: B; } - export function foo(c: C) { … } + export function foo(c: C) { … } } ``` -the ‘foo’ function depends upon the named types ‘A’, ‘B’, and ‘C’. In order to export ‘foo’ it is necessary to also export ‘B’ and ‘C’ as they otherwise would not be at least as accessible as ‘foo’. The ‘A’ interface is already at least as accessible as ‘foo’ because it is declared in a parent module of foo’s module. +the 'foo' function depends upon the named types 'A', 'B', and 'C'. In order to export 'foo' it is necessary to also export 'B' and 'C' as they otherwise would not be at least as accessible as 'foo'. The 'A' interface is already at least as accessible as 'foo' because it is declared in a parent module of foo's module. ## 10.5 Declaration Merging -Internal modules are “open-ended” and internal module declarations with the same qualified name relative to a common root (as defined in section [2.3](#2.3)) contribute to a single module. For example, the following two declarations of a module outer might be located in separate source files. +Internal modules are "open-ended" and internal module declarations with the same qualified name relative to a common root (as defined in section [2.3](#2.3)) contribute to a single module. For example, the following two declarations of a module outer might be located in separate source files. File a.ts: @@ -4438,7 +4651,7 @@ Declaration merging also extends to internal module declarations with the same q * When merging a class and an internal module, the type of the constructor function object is merged with the instance type of the module. In effect, the overloads or implementation of the class constructor provide the construct signatures, and the static members of the class and exported members of the module provide the properties of the combined type. It is an error to have static class members and exported module members with the same name. * When merging an enum and an internal module, the type of the enum object is merged with the instance type of the module. In effect, the members of the enum and the exported members of the module provide the properties of the combined type. It is an error to have enum members and exported module members with the same name. -When merging a non-ambient function or class declaration and a non-ambient internal module declaration, the function or class declaration must be located prior to the internal module declaration in the same source file. This ensures that the shared object instance is created as a function object. (While it is possible to add properties to an object after its creation, it is not possible to make an object “callable” after the fact.) +When merging a non-ambient function or class declaration and a non-ambient internal module declaration, the function or class declaration must be located prior to the internal module declaration in the same source file. This ensures that the shared object instance is created as a function object. (While it is possible to add properties to an object after its creation, it is not possible to make an object "callable" after the fact.) The example @@ -4464,7 +4677,7 @@ var p2 = point.origin; var b = point.equals(p1, p2); ``` -declares ‘point’ as a function object with two properties, ‘origin’ and ‘equals’. Note that the module declaration for ‘point’ is located after the function declaration. +declares 'point' as a function object with two properties, 'origin' and 'equals'. Note that the module declaration for 'point' is located after the function declaration. ## 10.6 Code Generation @@ -4477,7 +4690,7 @@ var ; })(||(={})); ``` -where *ModuleName* is the name of the module and *ModuleStatements* is the code generated for the statements in the module body. The *ModuleName* function parameter may be prefixed with one or more underscore characters to ensure the name is unique within the function body. Note that the entire module is emitted as an anonymous function that is immediately executed. This ensures that local variables are in their own lexical environment isolated from the surrounding context. Also note that the generated function doesn’t create and return a module instance, but rather it extends the existing instance (which may have just been created in the function call). This ensures that internal modules can extend each other. +where *ModuleName* is the name of the module and *ModuleStatements* is the code generated for the statements in the module body. The *ModuleName* function parameter may be prefixed with one or more underscore characters to ensure the name is unique within the function body. Note that the entire module is emitted as an anonymous function that is immediately executed. This ensures that local variables are in their own lexical environment isolated from the surrounding context. Also note that the generated function doesn't create and return a module instance, but rather it extends the existing instance (which may have just been created in the function call). This ensures that internal modules can extend each other. An import statement generates code of the form @@ -4509,11 +4722,11 @@ This copies a reference to the entity into a property on the module instance. TypeScript implements external modules that are closely aligned with those proposed for ECMAScript 6 and supports code generation targeting CommonJS and AMD module systems. -*NOTE: TypeScript currently doesn’t support the full proposed capabilities of the ECMAScript 6 import and export syntax. We expect to align more closely on the syntax as the ECMAScript 6 specification evolves*. +*NOTE: TypeScript currently doesn't support the full proposed capabilities of the ECMAScript 6 import and export syntax. We expect to align more closely on the syntax as the ECMAScript 6 specification evolves*. ## 11.1 Source Files -A TypeScript ***program*** consists of one or more source files that are either ***implementation source files*** or ***declaration source files***. Source files with extension ‘.ts’ are *ImplementationSourceFiles* containing statements and declarations. Source files with extension ‘.d.ts’ are *DeclarationSourceFiles* containing declarations only. Declaration source files are a strict subset of implementation source files. +A TypeScript ***program*** consists of one or more source files that are either ***implementation source files*** or ***declaration source files***. Source files with extension '.ts' are *ImplementationSourceFiles* containing statements and declarations. Source files with extension '.d.ts' are *DeclarationSourceFiles* containing declarations only. Declaration source files are a strict subset of implementation source files.   *SourceFile:*    *ImplementationSourceFile* @@ -4547,9 +4760,9 @@ A TypeScript ***program*** consists of one or more source files that are either    `export`*opt* *AmbientDeclaration*    `export`*opt* *ExternalImportDeclaration* -When a TypeScript program is compiled, all of the program’s source files are processed together. Statements and declarations in different source files can depend on each other, possibly in a circular fashion. By default, a JavaScript output file is generated for each implementation source file in a compilation, but no output is generated from declaration source files. +When a TypeScript program is compiled, all of the program's source files are processed together. Statements and declarations in different source files can depend on each other, possibly in a circular fashion. By default, a JavaScript output file is generated for each implementation source file in a compilation, but no output is generated from declaration source files. -The source elements permitted in a TypeScript implementation source file are a superset of those supported by JavaScript. Specifically, TypeScript extends the JavaScript grammar’s existing *VariableDeclaration* (section [5.1](#5.1)) and *FunctionDeclaration* (section [6.1](#6.1)) productions, and adds *InterfaceDeclaration* (section [7.1](#7.1)), *ClassDeclaration* (section [8.1](#8.1)), *EnumDeclaration* (section [9.1](#9.1)), *ModuleDeclaration* (section [10.1](#10.1)), *ImportDeclaration* (section [10.3](#10.3)), *ExternalImportDeclaration* (section [11.2.2](#11.2.2)), *ExportAssignment* (section [11.2.4](#11.2.4)), *AmbientDeclaration* (section [12.1](#12.1)), and *AmbientExternalModuleDeclaration* (section [12.2](#12.2)) productions. +The source elements permitted in a TypeScript implementation source file are a superset of those supported by JavaScript. Specifically, TypeScript extends the JavaScript grammar's existing *VariableDeclaration* (section [5.1](#5.1)) and *FunctionDeclaration* (section [6.1](#6.1)) productions, and adds *InterfaceDeclaration* (section [7.1](#7.1)), *ClassDeclaration* (section [8.1](#8.1)), *EnumDeclaration* (section [9.1](#9.1)), *ModuleDeclaration* (section [10.1](#10.1)), *ImportDeclaration* (section [10.3](#10.3)), *ExternalImportDeclaration* (section [11.2.2](#11.2.2)), *ExportAssignment* (section [11.2.4](#11.2.4)), *AmbientDeclaration* (section [12.1](#12.1)), and *AmbientExternalModuleDeclaration* (section [12.2](#12.2)) productions. Declaration source files are restricted to contain declarations only. Declaration source files can be used to declare the static type information associated with existing JavaScript code in an adjunct manner. They are entirely optional but enable the TypeScript compiler and tools to provide better verification and assistance when integrating existing JavaScript code and libraries in a TypeScript application. @@ -4561,11 +4774,11 @@ External modules can additionally be declared using *AmbientExternalModuleDeclar ### 11.1.1 Source Files Dependencies -The TypeScript compiler automatically determines a source file’s dependencies and includes those dependencies in the program being compiled. The determination is made from “reference comments” and external import declarations as follows: +The TypeScript compiler automatically determines a source file's dependencies and includes those dependencies in the program being compiled. The determination is made from "reference comments" and external import declarations as follows: -* A comment of the form /// <reference path="…"/> adds a dependency on the source file specified in the path argument. The path is resolved relative to the directory of the containing source file. -* An external import declaration that specifies a relative external module name (section [11.2.1](#11.2.1)) resolves the name relative to the directory of the containing source file. If a source file with the resulting path and file extension ‘.ts’ exists, that file is added as a dependency. Otherwise, if a source file with the resulting path and file extension ‘.d.ts’ exists, that file is added as a dependency. -* An external import declaration that specifies a top-level external module name (section [11.2.1](#11.2.1)) resolves the name in a host dependent manner (typically by resolving the name relative to a module name space root or searching for the name in a series of directories). If a source file with extension ‘.ts’ or ‘.d.ts’ corresponding to the reference is located, that file is added as a dependency. +* A comment of the form /// <reference path="…"/> adds a dependency on the source file specified in the path argument. The path is resolved relative to the directory of the containing source file. +* An external import declaration that specifies a relative external module name (section [11.2.1](#11.2.1)) resolves the name relative to the directory of the containing source file. If a source file with the resulting path and file extension '.ts' exists, that file is added as a dependency. Otherwise, if a source file with the resulting path and file extension '.d.ts' exists, that file is added as a dependency. +* An external import declaration that specifies a top-level external module name (section [11.2.1](#11.2.1)) resolves the name in a host dependent manner (typically by resolving the name relative to a module name space root or searching for the name in a series of directories). If a source file with extension '.ts' or '.d.ts' corresponding to the reference is located, that file is added as a dependency. Any files included as dependencies in turn have their references analyzed in a transitive manner until all dependencies have been determined. @@ -4605,7 +4818,7 @@ export function message(s: string) { } ``` -The import declaration in the ‘main’ module references the ‘log’ module and compiling the ‘main.ts’ file causes the ‘log.ts’ file to also be compiled as part of the program. At run-time, the import declaration loads the ‘log’ module and produces a reference to its module instance through which it is possible to reference the exported function. +The import declaration in the 'main' module references the 'log' module and compiling the 'main.ts' file causes the 'log.ts' file to also be compiled as part of the program. At run-time, the import declaration loads the 'log' module and produces a reference to its module instance through which it is possible to reference the exported function. TypeScript supports two patterns of JavaScript code generation for external modules: The CommonJS Modules pattern (section [11.2.5](#11.2.5)), typically used by server frameworks such as node.js, and the Asynchronous Module Definition (AMD) pattern (section [11.2.6](#11.2.6)), an extension to CommonJS Modules that permits asynchronous module loading, as is typical in browsers. The desired module code generation pattern is selected through a compiler option and does not affect the TypeScript source code. Indeed, it is possible to author external modules that can be compiled for use both on the server side (e.g. using node.js) and on the client side (using an AMD compliant loader) with no changes to the TypeScript source code. @@ -4614,16 +4827,16 @@ TypeScript supports two patterns of JavaScript code generation for external modu External modules are identified and referenced using external module names. The following definition is aligned with that provided in the CommonJS Modules 1.0 specification. * An external module name is a string of terms delimited by forward slashes. -* External module names may not have file-name extensions like “.js”. -* External module names may be relative or top-level. An external module name is relative if the first term is “.” or “..”. +* External module names may not have file-name extensions like ".js". +* External module names may be relative or top-level. An external module name is relative if the first term is "." or "..". * Top-level names are resolved off the conceptual module name space root. * Relative names are resolved relative to the name of the module in which they occur. -For purposes of resolving external module references, TypeScript associates a file path with every external module. The file path is simply the path of the module’s source file without the file extension. For example, an external module contained in the source file ‘C:\src\lib\io.ts’ has the file path ‘C:/src/lib/io’ and an external module contained in the source file ‘C:\src\ui\editor.d.ts’ has the file path ‘C:/src/ui/editor’. +For purposes of resolving external module references, TypeScript associates a file path with every external module. The file path is simply the path of the module's source file without the file extension. For example, an external module contained in the source file 'C:\src\lib\io.ts' has the file path 'C:/src/lib/io' and an external module contained in the source file 'C:\src\ui\editor.d.ts' has the file path 'C:/src/ui/editor'. An external module name in an import declaration is resolved as follows: -* If the import declaration specifies a relative external module name, the name is resolved relative to the directory of the referencing module’s file path. The program must contain a module with the resulting file path or otherwise an error occurs. For example, in a module with the file path ‘C:/src/ui/main’, the external module names ‘./editor’ and ‘../lib/io’ reference modules with the file paths ‘C:/src/ui/editor’ and ‘C:/src/lib/io’. +* If the import declaration specifies a relative external module name, the name is resolved relative to the directory of the referencing module's file path. The program must contain a module with the resulting file path or otherwise an error occurs. For example, in a module with the file path 'C:/src/ui/main', the external module names './editor' and '../lib/io' reference modules with the file paths 'C:/src/ui/editor' and 'C:/src/lib/io'. * If the import declaration specifies a top-level external module name and the program contains an *AmbientExternalModuleDeclaration* (section [12.2](#12.2)) with a string literal that specifies that exact name, then the import declaration references that ambient external module. * If the import declaration specifies a top-level external module name and the program contains no *AmbientExternalModuleDeclaration* (section [12.2](#12.2)) with a string literal that specifies that exact name, the name is resolved in a host dependent manner (for example by considering the name relative to a module name space root). If a matching module cannot be found an error occurs. @@ -4660,7 +4873,7 @@ When an external module containing an export assignment is imported, the local a It is an error for an external module to contain more than one export assignment. -Assume the following example resides in the file ‘point.ts’: +Assume the following example resides in the file 'point.ts': ```TypeScript export = Point; @@ -4671,7 +4884,7 @@ class Point { } ``` -When ‘point.ts’ is imported in another external module, the import alias references the exported class and can be used both as a type and as a constructor function: +When 'point.ts' is imported in another external module, the import alias references the exported class and can be used both as a type and as a constructor function: ```TypeScript import Pt = require("./point"); @@ -4684,9 +4897,9 @@ Note that there is no requirement that the import alias use the same name as the ### 11.2.5 CommonJS Modules -The CommonJS Modules definition specifies a methodology for writing JavaScript modules with implied privacy, the ability to import other modules, and the ability to explicitly export members. A CommonJS compliant system provides a ‘require’ function that can be used to synchronously load other external modules to obtain their singleton module instance, as well as an ‘exports’ variable to which a module can add properties to define its external API. +The CommonJS Modules definition specifies a methodology for writing JavaScript modules with implied privacy, the ability to import other modules, and the ability to explicitly export members. A CommonJS compliant system provides a 'require' function that can be used to synchronously load other external modules to obtain their singleton module instance, as well as an 'exports' variable to which a module can add properties to define its external API. -The ‘main’ and ‘log’ example from section [11.2](#11.2) above generates the following JavaScript code when compiled for the CommonJS Modules pattern: +The 'main' and 'log' example from section [11.2](#11.2) above generates the following JavaScript code when compiled for the CommonJS Modules pattern: File main.js: @@ -4703,7 +4916,7 @@ exports.message = function(s) { } ``` -An external import declaration is represented in the generated JavaScript as a variable initialized by a call to the ‘require’ function provided by the module system host. A variable declaration and ‘require’ call is emitted for a particular imported module only if the imported module, or a local alias (section [10.3](#10.3)) that references the imported module, is referenced as a *PrimaryExpression* somewhere in the body of the importing module. If an imported module is referenced only as a *ModuleName* or *TypeQueryExpression*, nothing is emitted. +An external import declaration is represented in the generated JavaScript as a variable initialized by a call to the 'require' function provided by the module system host. A variable declaration and 'require' call is emitted for a particular imported module only if the imported module, or a local alias (section [10.3](#10.3)) that references the imported module, is referenced as a *PrimaryExpression* somewhere in the body of the importing module. If an imported module is referenced only as a *ModuleName* or *TypeQueryExpression*, nothing is emitted. An example: @@ -4724,21 +4937,21 @@ import g = require("./geometry"); var p = g.point(10, 20); ``` -The ‘game’ module references the imported ‘geometry’ module in an expression (through its alias ‘g’) and a ‘require’ call is therefore included in the emitted JavaScript: +The 'game' module references the imported 'geometry' module in an expression (through its alias 'g') and a 'require' call is therefore included in the emitted JavaScript: ```TypeScript var g = require("./geometry"); var p = g.point(10, 20); ``` -Had the ‘game’ module instead been written to only reference ‘geometry’ in a type position +Had the 'game' module instead been written to only reference 'geometry' in a type position ```TypeScript import g = require("./geometry"); var p: g.Point = { x: 10, y: 20 }; ``` -the emitted JavaScript would have no dependency on the ‘geometry’ module and would simply be +the emitted JavaScript would have no dependency on the 'geometry' module and would simply be ```TypeScript var p = { x: 10, y: 20 }; @@ -4746,9 +4959,9 @@ var p = { x: 10, y: 20 }; ### 11.2.6 AMD Modules -The Asynchronous Module Definition (AMD) specification extends the CommonJS Modules specification with a pattern for authoring asynchronously loadable modules with associated dependencies. Using the AMD pattern, modules are emitted as calls to a global ‘define’ function taking an array of dependencies, specified as external module names, and a callback function containing the module body. The global ‘define’ function is provided by including an AMD compliant loader in the application. The loader arranges to asynchronously load the module’s dependencies and, upon completion, calls the callback function passing resolved module instances as arguments in the order they were listed in the dependency array. +The Asynchronous Module Definition (AMD) specification extends the CommonJS Modules specification with a pattern for authoring asynchronously loadable modules with associated dependencies. Using the AMD pattern, modules are emitted as calls to a global 'define' function taking an array of dependencies, specified as external module names, and a callback function containing the module body. The global 'define' function is provided by including an AMD compliant loader in the application. The loader arranges to asynchronously load the module's dependencies and, upon completion, calls the callback function passing resolved module instances as arguments in the order they were listed in the dependency array. -The “main” and “log” example from above generates the following JavaScript code when compiled for the AMD pattern. +The "main" and "log" example from above generates the following JavaScript code when compiled for the AMD pattern. File main.js: @@ -4768,13 +4981,13 @@ define(["require", "exports"], function(require, exports) { } ``` -The special ‘require’ and ‘exports’ dependencies are always present. Additional entries are added to the dependencies array and the parameter list as required to represent imported external modules. Similar to the code generation for CommonJS Modules, a dependency entry is generated for a particular imported module only if the imported module is referenced as a *PrimaryExpression* somewhere in the body of the importing module. If an imported module is referenced only as a *ModuleName*, no dependency is generated for that module. +The special 'require' and 'exports' dependencies are always present. Additional entries are added to the dependencies array and the parameter list as required to represent imported external modules. Similar to the code generation for CommonJS Modules, a dependency entry is generated for a particular imported module only if the imported module is referenced as a *PrimaryExpression* somewhere in the body of the importing module. If an imported module is referenced only as a *ModuleName*, no dependency is generated for that module.
#
12 Ambients -Ambient declarations are used to provide static typing over existing JavaScript code. Ambient declarations differ from regular declarations in that no JavaScript code is emitted for them. Instead of introducing new variables, functions, classes, enums, or modules, ambient declarations provide type information for entities that exist “ambiently” and are included in a program by external means, for example by referencing a JavaScript library in a <script/> tag. +Ambient declarations are used to provide static typing over existing JavaScript code. Ambient declarations differ from regular declarations in that no JavaScript code is emitted for them. Instead of introducing new variables, functions, classes, enums, or modules, ambient declarations provide type information for entities that exist "ambiently" and are included in a program by external means, for example by referencing a JavaScript library in a <script/> tag. ## 12.1 Ambient Declarations @@ -4903,7 +5116,7 @@ An *ExternalImportDeclaration* in an *AmbientExternalModuleDeclaration* may refe If an ambient external module declaration includes an export assignment, it is an error for any of the declarations within the module to specify an `export` modifier. If an ambient external module declaration contains no export assignment, entities declared in the module are exported regardless of whether their declarations include the optional `export` modifier. -Ambient external modules are “open-ended” and ambient external module declarations with the same string literal name contribute to a single external module. For example, the following two declarations of an external module ‘io’ might be located in separate source files. +Ambient external modules are "open-ended" and ambient external module declarations with the same string literal name contribute to a single external module. For example, the following two declarations of an external module 'io' might be located in separate source files. ```TypeScript declare module "io" { @@ -4956,15 +5169,26 @@ This appendix contains a summary of the grammar found in the main document. As d    *Type*   *Type:* +   *PrimaryOrUnionType* +   *FunctionType* +   *ConstructorType* + +  *PrimaryOrUnionType:* +   *PrimaryType* +   *UnionType* + +  *PrimaryType:* +   *ParenthesizedType*    *PredefinedType*    *TypeReference*    *ObjectType*    *ArrayType*    *TupleType* -   *FunctionType* -   *ConstructorType*    *TypeQuery* +  *ParenthesizedType:* +   `(` *Type* `)` +   *PredefinedType:*    `any`    `number` @@ -5001,15 +5225,7 @@ This appendix contains a summary of the grammar found in the main document. As d    *MethodSignature*   *ArrayType:* -   *ElementType* *[no LineTerminator here]* `[` `]` - -  *ElementType:* -   *PredefinedType* -   *TypeReference* -   *ObjectType* -   *ArrayType* -   *TupleType* -   *TypeQuery* +   *PrimaryType* *[no LineTerminator here]* `[` `]`   *TupleType:*    `[` *TupleElementTypes* `]` @@ -5021,6 +5237,9 @@ This appendix contains a summary of the grammar found in the main document. As d   *TupleElementType:*    *Type* +  *UnionType:* +   *PrimaryOrUnionType* `|` *PrimaryType* +   *FunctionType:*    *TypeParametersopt* `(` *ParameterListopt* `)` `=>` *Type* @@ -5104,7 +5323,7 @@ This appendix contains a summary of the grammar found in the main document. As d    `set` *PropertyName* `(` *Identifier* *TypeAnnotationopt* `)` `{` *FunctionBody* `}`   *CallExpression:* *( Modified )* -   … +   …    `super` `(` *ArgumentListopt* `)`    `super` `.` *IdentifierName* @@ -5112,7 +5331,7 @@ This appendix contains a summary of the grammar found in the main document. As d    `function` *Identifieropt* *CallSignature* `{` *FunctionBody* `}`   *AssignmentExpression:* *( Modified )* -   … +   …    *ArrowFunctionExpression*   *ArrowFunctionExpression:* @@ -5127,7 +5346,7 @@ This appendix contains a summary of the grammar found in the main document. As d    *TypeArgumentsopt* `(` *ArgumentListopt* `)`   *UnaryExpression:* *( Modified )* -   … +   …    `<` *Type* `>` *UnaryExpression* ## A.3 Statements diff --git a/scripts/ior.ts b/scripts/ior.ts new file mode 100644 index 00000000000..f0c142a266c --- /dev/null +++ b/scripts/ior.ts @@ -0,0 +1,123 @@ +/// + +import fs = require('fs'); +import path = require('path'); + +interface IOLog { + filesRead: { + path: string; + result: { contents: string; }; + }[]; + arguments: string[]; +} + +module Commands { + export function dir(obj: IOLog) { + obj.filesRead.filter(f => f.result !== undefined).forEach(f => { + console.log(f.path); + }); + } + dir['description'] = ': displays a list of files'; + + export function find(obj: IOLog, str: string) { + obj.filesRead.filter(f => f.result !== undefined).forEach(f => { + var lines = f.result.contents.split('\n'); + var printedHeader = false; + lines.forEach(line => { + if (line.indexOf(str) >= 0) { + if (!printedHeader) { + console.log(' === ' + f.path + ' ==='); + printedHeader = true; + } + console.log(line); + } + }); + }); + } + find['description'] = ' string: finds text in files'; + + export function grab(obj: IOLog, filename: string) { + obj.filesRead.filter(f => f.result !== undefined).forEach(f => { + if (path.basename(f.path) === filename) { + fs.writeFile(filename, f.result.contents); + } + }); + } + grab['description'] = ' filename.ts: writes out the specified file to disk'; + + export function extract(obj: IOLog, outputFolder: string) { + var directorySeparator = "/"; + function directoryExists(path: string): boolean { + return fs.existsSync(path) && fs.statSync(path).isDirectory(); + } + function getDirectoryPath(path: string) { + return path.substr(0, Math.max(getRootLength(path), path.lastIndexOf(directorySeparator))); + } + function getRootLength(path: string): number { + if (path.charAt(0) === directorySeparator) { + if (path.charAt(1) !== directorySeparator) return 1; + var p1 = path.indexOf(directorySeparator, 2); + if (p1 < 0) return 2; + var p2 = path.indexOf(directorySeparator, p1 + 1); + if (p2 < 0) return p1 + 1; + return p2 + 1; + } + if (path.charAt(1) === ":") { + if (path.charAt(2) === directorySeparator) return 3; + return 2; + } + return 0; + } + function ensureDirectoriesExist(directoryPath: string) { + if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) { + var parentDirectory = getDirectoryPath(directoryPath); + ensureDirectoriesExist(parentDirectory); + console.log("creating directory: " + directoryPath); + fs.mkdirSync(directoryPath); + } + } + function transalatePath(outputFolder:string, path: string): string { + return outputFolder + directorySeparator + path.replace(":", ""); + } + function fileExists(path: string): boolean { + return fs.existsSync(path); + } + obj.filesRead.forEach(f => { + var filename = transalatePath(outputFolder, f.path); + ensureDirectoriesExist(getDirectoryPath(filename)); + console.log("writing filename: " + filename); + fs.writeFile(filename, f.result.contents, (err) => { }); + }); + + console.log("Command: tsc "); + obj.arguments.forEach(a => { + if (getRootLength(a) > 0) { + console.log(transalatePath(outputFolder, a)); + } + else { + console.log(a); + } + console.log(" "); + }); + } + extract['description'] = ' outputFolder: extract all input files to '; +} + +var args = process.argv.slice(2); +if (args.length < 2) { + console.log('Usage: node ior.js path_to_file.json [command]'); + console.log('List of commands: '); + Object.keys(Commands).forEach(k => console.log(' ' + k + Commands[k]['description'])); +} else { + var cmd: Function = Commands[args[1]]; + if (cmd === undefined) { + console.log('Unknown command ' + args[1]); + } else { + fs.readFile(args[0], 'utf-8', (err, data) => { + if (err) throw err; + var json = JSON.parse(data); + cmd.apply(undefined, [json].concat(args.slice(2))); + }); + } +} + diff --git a/scripts/word2md.js b/scripts/word2md.js index 8f9cd276f95..0645acbb143 100644 --- a/scripts/word2md.js +++ b/scripts/word2md.js @@ -1,4 +1,8 @@ var sys = (function () { + var fileStream = new ActiveXObject("ADODB.Stream"); + fileStream.Type = 2; + var binaryStream = new ActiveXObject("ADODB.Stream"); + binaryStream.Type = 1; var args = []; for (var i = 0; i < WScript.Arguments.length; i++) { args[i] = WScript.Arguments.Item(i); @@ -6,7 +10,24 @@ var sys = (function () { return { args: args, createObject: function (typeName) { return new ActiveXObject(typeName); }, - write: function (s) { return WScript.StdOut.Write(s); } + write: function (s) { + WScript.StdOut.Write(s); + }, + writeFile: function (fileName, data) { + fileStream.Open(); + binaryStream.Open(); + try { + fileStream.Charset = "utf-8"; + fileStream.WriteText(data); + fileStream.Position = 3; + fileStream.CopyTo(binaryStream); + binaryStream.SaveToFile(fileName, 2); + } + finally { + binaryStream.Close(); + fileStream.Close(); + } + } }; })(); function convertDocumentToMarkdown(doc) { @@ -149,6 +170,10 @@ function convertDocumentToMarkdown(doc) { lastInTable = inTable; } function writeDocument() { + var title = doc.builtInDocumentProperties.item(1) + ""; + if (title.length) { + write("# " + title + "\n\n"); + } for (var p = doc.paragraphs.first; p; p = p.next()) { writeParagraph(p); } @@ -168,16 +193,19 @@ function convertDocumentToMarkdown(doc) { findReplace("^19 REF", {}, "[^&](#^&)", {}); doc.fields.toggleShowCodes(); writeDocument(); + result = result.replace(/\x85/g, "\u2026"); + result = result.replace(/\x96/g, "\u2013"); + result = result.replace(/\x97/g, "\u2014"); return result; } function main(args) { - if (args.length !== 1) { - sys.write("Syntax: word2md \n"); + if (args.length !== 2) { + sys.write("Syntax: word2md \n"); return; } var app = sys.createObject("Word.Application"); var doc = app.documents.open(args[0]); - sys.write(convertDocumentToMarkdown(doc)); + sys.writeFile(args[1], convertDocumentToMarkdown(doc)); doc.close(false); app.quit(); } diff --git a/scripts/word2md.ts b/scripts/word2md.ts index b1bc50b0cb9..65b39d6e4f6 100644 --- a/scripts/word2md.ts +++ b/scripts/word2md.ts @@ -103,6 +103,7 @@ module Word { export interface Document { fields: Fields; paragraphs: Paragraphs; + builtInDocumentProperties: Collection; close(saveChanges: boolean): void; range(): Range; } @@ -118,6 +119,10 @@ module Word { } var sys = (function () { + var fileStream = new ActiveXObject("ADODB.Stream"); + fileStream.Type = 2 /*text*/; + var binaryStream = new ActiveXObject("ADODB.Stream"); + binaryStream.Type = 1 /*binary*/; var args: string[] = []; for (var i = 0; i < WScript.Arguments.length; i++) { args[i] = WScript.Arguments.Item(i); @@ -125,7 +130,26 @@ var sys = (function () { return { args: args, createObject: (typeName: string) => new ActiveXObject(typeName), - write: (s: string) => WScript.StdOut.Write(s) + write(s: string): void { + WScript.StdOut.Write(s); + }, + writeFile: (fileName: string, data: string): void => { + fileStream.Open(); + binaryStream.Open(); + try { + // Write characters in UTF-8 encoding + fileStream.Charset = "utf-8"; + fileStream.WriteText(data); + // We don't want the BOM, skip it by setting the starting location to 3 (size of BOM). + fileStream.Position = 3; + fileStream.CopyTo(binaryStream); + binaryStream.SaveToFile(fileName, 2 /*overwrite*/); + } + finally { + binaryStream.Close(); + fileStream.Close(); + } + } }; })(); @@ -298,6 +322,10 @@ function convertDocumentToMarkdown(doc: Word.Document): string { } function writeDocument() { + var title = doc.builtInDocumentProperties.item(1) + ""; + if (title.length) { + write("# " + title + "\n\n"); + } for (var p = doc.paragraphs.first; p; p = p.next()) { writeParagraph(p); } @@ -321,17 +349,21 @@ function convertDocumentToMarkdown(doc: Word.Document): string { writeDocument(); + result = result.replace(/\x85/g, "\u2026"); + result = result.replace(/\x96/g, "\u2013"); + result = result.replace(/\x97/g, "\u2014"); + return result; } function main(args: string[]) { - if (args.length !== 1) { - sys.write("Syntax: word2md \n"); + if (args.length !== 2) { + sys.write("Syntax: word2md \n"); return; } var app: Word.Application = sys.createObject("Word.Application"); var doc = app.documents.open(args[0]); - sys.write(convertDocumentToMarkdown(doc)); + sys.writeFile(args[1], convertDocumentToMarkdown(doc)); doc.close(false); app.quit(); } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 952600b6017..229fcf51f17 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -33,10 +33,16 @@ module ts { if (stringWriters.length == 0) { var str = ""; + var writeText: (text: string) => void = text => str += text; return { string: () => str, - writeKind: text => str += text, - writeSymbol: text => str += text, + writeKeyword: writeText, + writeOperator: writeText, + writePunctuation: writeText, + writeSpace: writeText, + writeStringLiteral: writeText, + writeParameter: writeText, + writeSymbol: writeText, // Completely ignore indentation for string writers. And map newlines to // a single space. @@ -88,27 +94,24 @@ module ts { getSymbolsInScope: getSymbolsInScope, getSymbolInfo: getSymbolInfo, getTypeOfNode: getTypeOfNode, - getApparentType: getApparentType, typeToString: typeToString, - writeType: writeType, + getSymbolDisplayBuilder: getSymbolDisplayBuilder, symbolToString: symbolToString, - writeSymbol: writeSymbol, - getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType, - getRootSymbol: getRootSymbol, + getAugmentedPropertiesOfType: getAugmentedPropertiesOfType, + getRootSymbols: getRootSymbols, getContextualType: getContextualType, getFullyQualifiedName: getFullyQualifiedName, getResolvedSignature: getResolvedSignature, getEnumMemberValue: getEnumMemberValue, isValidPropertyAccess: isValidPropertyAccess, getSignatureFromDeclaration: getSignatureFromDeclaration, - writeSignature: writeSignature, - writeTypeParameter: writeTypeParameter, - writeTypeParametersOfSymbol: writeTypeParametersOfSymbol, isImplementationOfOverload: isImplementationOfOverload, - getAliasedSymbol: resolveImport + getAliasedSymbol: resolveImport, + isUndefinedSymbol: symbol => symbol === undefinedSymbol, + isArgumentsSymbol: symbol => symbol === argumentsSymbol }; - var undefinedSymbol = createSymbol(SymbolFlags.Undefined | SymbolFlags.Property | SymbolFlags.Transient, "undefined"); + var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined"); var argumentsSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "arguments"); var unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown"); var resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__"); @@ -143,6 +146,7 @@ module ts { var globalRegExpType: ObjectType; var tupleTypes: Map = {}; + var unionTypes: Map = {}; var stringLiteralTypes: Map = {}; var emitExtends = false; @@ -606,6 +610,12 @@ module ts { } function symbolIsValue(symbol: Symbol): boolean { + // If it is an instantiated symbol, then it is a value if the symbol it is an + // instantiation of is a value. + if (symbol.flags & SymbolFlags.Instantiated) { + return symbolIsValue(getSymbolLinks(symbol).target); + } + // If the symbol has the value flag, it is trivially a value. if (symbol.flags & SymbolFlags.Value) { return true; @@ -616,12 +626,6 @@ module ts { return (resolveImport(symbol).flags & SymbolFlags.Value) !== 0; } - // If it is an instantiated symbol, then it is a value if the symbol it is an - // instantiation of is a value. - if (symbol.flags & SymbolFlags.Instantiated) { - return (getSymbolLinks(symbol).target.flags & SymbolFlags.Value) !== 0; - } - return false; } @@ -674,17 +678,17 @@ module ts { return result || emptyArray; } - function setObjectTypeMembers(type: ObjectType, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexType: Type, numberIndexType: Type): ResolvedObjectType { - (type).members = members; - (type).properties = getNamedMembers(members); - (type).callSignatures = callSignatures; - (type).constructSignatures = constructSignatures; - if (stringIndexType) (type).stringIndexType = stringIndexType; - if (numberIndexType) (type).numberIndexType = numberIndexType; - return type; + function setObjectTypeMembers(type: ObjectType, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexType: Type, numberIndexType: Type): ResolvedType { + (type).members = members; + (type).properties = getNamedMembers(members); + (type).callSignatures = callSignatures; + (type).constructSignatures = constructSignatures; + if (stringIndexType) (type).stringIndexType = stringIndexType; + if (numberIndexType) (type).numberIndexType = numberIndexType; + return type; } - function createAnonymousType(symbol: Symbol, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexType: Type, numberIndexType: Type): ResolvedObjectType { + function createAnonymousType(symbol: Symbol, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexType: Type, numberIndexType: Type): ResolvedType { return setObjectTypeMembers(createObjectType(TypeFlags.Anonymous, symbol), members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } @@ -736,7 +740,7 @@ module ts { return rightMeaning === SymbolFlags.Value ? SymbolFlags.Value : SymbolFlags.Namespace; } - function getAccessibleSymbolChain(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): Symbol[] { + function getAccessibleSymbolChain(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags, useOnlyExternalAliasing: boolean): Symbol[] { function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable): Symbol[] { function canQualifySymbol(symbolFromSymbolTable: Symbol, meaning: SymbolFlags) { // If the symbol is equivalent and doesn't need further qualification, this symbol is accessible @@ -745,7 +749,7 @@ module ts { } // If symbol needs qualification, make sure that parent is accessible, if it is then this symbol is accessible too - var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning)); + var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing); return !!accessibleParent; } @@ -767,16 +771,21 @@ module ts { // Check if symbol is any of the alias return forEachValue(symbols, symbolFromSymbolTable => { if (symbolFromSymbolTable.flags & SymbolFlags.Import) { - var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); - if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { - return [symbolFromSymbolTable]; - } + if (!useOnlyExternalAliasing || // We can use any type of alias to get the name + // Is this external alias, then use it to name + ts.forEach(symbolFromSymbolTable.declarations, declaration => + declaration.kind === SyntaxKind.ImportDeclaration && (declaration).externalModuleName)) { + var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); + if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { + return [symbolFromSymbolTable]; + } - // Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain - // but only if the symbolFromSymbolTable can be qualified - var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; - if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { - return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); + // Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain + // but only if the symbolFromSymbolTable can be qualified + var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined; + if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) { + return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports); + } } } }); @@ -822,7 +831,7 @@ module ts { var meaningToLook = meaning; while (symbol) { // Symbol is accessible if it by itself is accessible - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook); + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, /*useOnlyExternalAliasing*/ false); if (accessibleSymbolChain) { var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]); if (!hasAccessibleDeclarations) { @@ -940,24 +949,24 @@ module ts { } function writeKeyword(writer: SymbolWriter, kind: SyntaxKind) { - writer.writeKind(tokenToString(kind), SymbolDisplayPartKind.keyword); + writer.writeKeyword(tokenToString(kind)); } function writePunctuation(writer: SymbolWriter, kind: SyntaxKind) { - writer.writeKind(tokenToString(kind), SymbolDisplayPartKind.punctuation); + writer.writePunctuation(tokenToString(kind)); } function writeOperator(writer: SymbolWriter, kind: SyntaxKind) { - writer.writeKind(tokenToString(kind), SymbolDisplayPartKind.operator); + writer.writeOperator(tokenToString(kind)); } function writeSpace(writer: SymbolWriter) { - writer.writeKind(" ", SymbolDisplayPartKind.space); + writer.writeSpace(" "); } function symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string { var writer = getSingleLineStringWriter(); - writeSymbol(symbol, writer, enclosingDeclaration, meaning); + getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning); var result = writer.string(); releaseStringWriter(writer); @@ -965,93 +974,9 @@ module ts { return result; } - // Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope - // Meaning needs to be specified if the enclosing declaration is given - function writeSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void { - var parentSymbol: Symbol; - function writeSymbolName(symbol: Symbol): void { - if (parentSymbol) { - // Write type arguments of instantiated class/interface here - if (flags & SymbolFormatFlags.WriteTypeParametersOrArguments) { - if (symbol.flags & SymbolFlags.Instantiated) { - writeTypeArguments(getTypeParametersOfClassOrInterface(parentSymbol), - (symbol).mapper, writer, enclosingDeclaration); - } - else { - writeTypeParametersOfSymbol(parentSymbol, writer, enclosingDeclaration); - } - } - writePunctuation(writer, SyntaxKind.DotToken); - } - parentSymbol = symbol; - if (symbol.declarations && symbol.declarations.length > 0) { - var declaration = symbol.declarations[0]; - if (declaration.name) { - writer.writeSymbol(identifierToString(declaration.name), symbol); - return; - } - } - - writer.writeSymbol(symbol.name, symbol); - } - - // Let the writer know we just wrote out a symbol. The declaration emitter writer uses - // this to determine if an import it has previously seen (and not written out) needs - // to be written to the file once the walk of the tree is complete. - // - // NOTE(cyrusn): This approach feels somewhat unfortunate. A simple pass over the tree - // up front (for example, during checking) could determine if we need to emit the imports - // and we could then access that data during declaration emit. - writer.trackSymbol(symbol, enclosingDeclaration, meaning); - function walkSymbol(symbol: Symbol, meaning: SymbolFlags): void { - if (symbol) { - var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning); - - if (!accessibleSymbolChain || - needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { - - // Go up and add our parent. - walkSymbol( - getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), - getQualifiedLeftMeaning(meaning)); - } - - if (accessibleSymbolChain) { - for (var i = 0, n = accessibleSymbolChain.length; i < n; i++) { - writeSymbolName(accessibleSymbolChain[i]); - } - } - else { - // If we didn't find accessible symbol chain for this symbol, break if this is external module - if (!parentSymbol && ts.forEach(symbol.declarations, declaration => hasExternalModuleSymbol(declaration))) { - return; - } - - // if this is anonymous type break - if (symbol.flags & SymbolFlags.TypeLiteral || symbol.flags & SymbolFlags.ObjectLiteral) { - return; - } - - writeSymbolName(symbol); - } - } - } - - // Get qualified name - if (enclosingDeclaration && - // TypeParameters do not need qualification - !(symbol.flags & SymbolFlags.TypeParameter)) { - - walkSymbol(symbol, meaning); - return; - } - - return writeSymbolName(symbol); - } - function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string { var writer = getSingleLineStringWriter(); - writeType(type, writer, enclosingDeclaration, flags); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); var result = writer.string(); releaseStringWriter(writer); @@ -1064,304 +989,453 @@ module ts { return result; } - function writeType(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { - return writeType(type, flags | TypeFormatFlags.WriteArrowStyleSignature); - - function writeType(type: Type, flags: TypeFormatFlags) { - // Write undefined/null type as any - if (type.flags & TypeFlags.Intrinsic) { - // Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving - writer.writeKind(!(flags & TypeFormatFlags.WriteOwnNameForAnyLike) && - (type.flags & TypeFlags.Any) ? "any" : (type).intrinsicName, SymbolDisplayPartKind.keyword); - } - else if (type.flags & TypeFlags.Reference) { - writeTypeReference(type); - } - else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) { - writeSymbol(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type); - } - else if (type.flags & TypeFlags.Tuple) { - writeTupleType(type); - } - else if (type.flags & TypeFlags.Anonymous) { - writeAnonymousType(type, flags); - } - else if (type.flags & TypeFlags.StringLiteral) { - writer.writeKind((type).text, SymbolDisplayPartKind.stringLiteral); - } - else { - // Should never get here - // { ... } - writePunctuation(writer, SyntaxKind.OpenBraceToken); - writeSpace(writer); - writePunctuation(writer, SyntaxKind.DotDotDotToken); - writeSpace(writer); - writePunctuation(writer, SyntaxKind.CloseBraceToken); - } - } - - function writeTypeList(types: Type[]) { - for (var i = 0; i < types.length; i++) { - if (i > 0) { - writePunctuation(writer, SyntaxKind.CommaToken); - writeSpace(writer); + // This is for caching the result of getSymbolDisplayBuilder. Do not access directly. + var _displayBuilder: SymbolDisplayBuilder; + function getSymbolDisplayBuilder(): SymbolDisplayBuilder { + /** + * Writes only the name of the symbol out to the writer. Uses the original source text + * for the name of the symbol if it is available to match how the user inputted the name. + */ + function appendSymbolNameOnly(symbol: Symbol, writer: SymbolWriter): void { + if (symbol.declarations && symbol.declarations.length > 0) { + var declaration = symbol.declarations[0]; + if (declaration.name) { + writer.writeSymbol(identifierToString(declaration.name), symbol); + return; } - writeType(types[i], flags | TypeFormatFlags.WriteArrowStyleSignature); } + + writer.writeSymbol(symbol.name, symbol); } - function writeTypeReference(type: TypeReference) { - if (type.target === globalArrayType && !(flags & TypeFormatFlags.WriteArrayAsGenericType)) { - // If we are writing array element type the arrow style signatures are not allowed as - // we need to surround it by curlies, e.g. { (): T; }[]; as () => T[] would mean something different - writeType(type.typeArguments[0], flags & ~TypeFormatFlags.WriteArrowStyleSignature); - writePunctuation(writer, SyntaxKind.OpenBracketToken); - writePunctuation(writer, SyntaxKind.CloseBracketToken); - } - else { - writeSymbol(type.target.symbol, writer, enclosingDeclaration, SymbolFlags.Type); - writePunctuation(writer, SyntaxKind.LessThanToken); - writeTypeList(type.typeArguments); - writePunctuation(writer, SyntaxKind.GreaterThanToken); - } - } - - function writeTupleType(type: TupleType) { - writePunctuation(writer, SyntaxKind.OpenBracketToken); - writeTypeList(type.elementTypes); - writePunctuation(writer, SyntaxKind.CloseBracketToken); - } - - function writeAnonymousType(type: ObjectType, flags: TypeFormatFlags) { - // Always use 'typeof T' for type of class, enum, and module objects - if (type.symbol && type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) { - writeTypeofSymbol(type); - } - // Use 'typeof T' for types of functions and methods that circularly reference themselves - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type); - } - else if (typeStack && contains(typeStack, type)) { - // Recursive usage, use any - writeKeyword(writer, SyntaxKind.AnyKeyword); - } - else { - if (!typeStack) { - typeStack = []; + /** + * Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope + * Meaning needs to be specified if the enclosing declaration is given + */ + function buildSymbolDisplay(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void { + var parentSymbol: Symbol; + function appendParentTypeArgumentsAndSymbolName(symbol: Symbol): void { + if (parentSymbol) { + // Write type arguments of instantiated class/interface here + if (flags & SymbolFormatFlags.WriteTypeParametersOrArguments) { + if (symbol.flags & SymbolFlags.Instantiated) { + buildDisplayForTypeArgumentsAndDelimiters(getTypeParametersOfClassOrInterface(parentSymbol), + (symbol).mapper, writer, enclosingDeclaration); + } + else { + buildTypeParameterDisplayFromSymbol(parentSymbol, writer, enclosingDeclaration); + } + } + writePunctuation(writer, SyntaxKind.DotToken); } - typeStack.push(type); - writeLiteralType(type, flags); - typeStack.pop(); + parentSymbol = symbol; + appendSymbolNameOnly(symbol, writer); } - function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - var isStaticMethodSymbol = !!(type.symbol.flags & SymbolFlags.Method && // typeof static method - ts.forEach(type.symbol.declarations, declaration => declaration.flags & NodeFlags.Static)); - var isNonLocalFunctionSymbol = !!(type.symbol.flags & SymbolFlags.Function) && - (type.symbol.parent || // is exported function symbol - ts.forEach(type.symbol.declarations, declaration => - declaration.parent.kind === SyntaxKind.SourceFile || declaration.parent.kind === SyntaxKind.ModuleBlock)); + // Let the writer know we just wrote out a symbol. The declaration emitter writer uses + // this to determine if an import it has previously seen (and not written out) needs + // to be written to the file once the walk of the tree is complete. + // + // NOTE(cyrusn): This approach feels somewhat unfortunate. A simple pass over the tree + // up front (for example, during checking) could determine if we need to emit the imports + // and we could then access that data during declaration emit. + writer.trackSymbol(symbol, enclosingDeclaration, meaning); + function walkSymbol(symbol: Symbol, meaning: SymbolFlags): void { + if (symbol) { + var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning, !!(flags & SymbolFormatFlags.UseOnlyExternalAliasing)); - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - // typeof is allowed only for static/non local functions - return !!(flags & TypeFormatFlags.UseTypeOfFunction) || // use typeof if format flags specify it - (typeStack && contains(typeStack, type)); // it is type of the symbol uses itself recursively + if (!accessibleSymbolChain || + needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { + + // Go up and add our parent. + walkSymbol( + getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol), + getQualifiedLeftMeaning(meaning)); + } + + if (accessibleSymbolChain) { + for (var i = 0, n = accessibleSymbolChain.length; i < n; i++) { + appendParentTypeArgumentsAndSymbolName(accessibleSymbolChain[i]); + } + } + else { + // If we didn't find accessible symbol chain for this symbol, break if this is external module + if (!parentSymbol && ts.forEach(symbol.declarations, declaration => hasExternalModuleSymbol(declaration))) { + return; + } + + // if this is anonymous type break + if (symbol.flags & SymbolFlags.TypeLiteral || symbol.flags & SymbolFlags.ObjectLiteral) { + return; + } + + appendParentTypeArgumentsAndSymbolName(symbol); } } } + + // Get qualified name + if (enclosingDeclaration && + // TypeParameters do not need qualification + !(symbol.flags & SymbolFlags.TypeParameter)) { + + walkSymbol(symbol, meaning); + return; + } + + return appendParentTypeArgumentsAndSymbolName(symbol); } - function writeTypeofSymbol(type: ObjectType) { - writeKeyword(writer, SyntaxKind.TypeOfKeyword); - writeSpace(writer); - writeSymbol(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value); - } + function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, typeStack?: Type[]) { + var globalFlagsToPass = globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike; + return writeType(type, globalFlags); - function writeLiteralType(type: ObjectType, flags: TypeFormatFlags) { - var resolved = resolveObjectTypeMembers(type); - if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) { - if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { + function writeType(type: Type, flags: TypeFormatFlags) { + // Write undefined/null type as any + if (type.flags & TypeFlags.Intrinsic) { + // Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving + writer.writeKeyword(!(globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike) && + (type.flags & TypeFlags.Any) ? "any" : (type).intrinsicName); + } + else if (type.flags & TypeFlags.Reference) { + writeTypeReference(type, flags); + } + else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) { + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type); + } + else if (type.flags & TypeFlags.Tuple) { + writeTupleType(type); + } + else if (type.flags & TypeFlags.Union) { + writeUnionType(type, flags); + } + else if (type.flags & TypeFlags.Anonymous) { + writeAnonymousType(type, flags); + } + else if (type.flags & TypeFlags.StringLiteral) { + writer.writeStringLiteral((type).text); + } + else { + // Should never get here + // { ... } writePunctuation(writer, SyntaxKind.OpenBraceToken); + writeSpace(writer); + writePunctuation(writer, SyntaxKind.DotDotDotToken); + writeSpace(writer); writePunctuation(writer, SyntaxKind.CloseBraceToken); - return; + } + } + + function writeTypeList(types: Type[], union: boolean) { + for (var i = 0; i < types.length; i++) { + if (i > 0) { + if (union) { + writeSpace(writer); + } + writePunctuation(writer, union ? SyntaxKind.BarToken : SyntaxKind.CommaToken); + writeSpace(writer); + } + writeType(types[i], union ? TypeFormatFlags.InElementType : TypeFormatFlags.None); + } + } + + function writeTypeReference(type: TypeReference, flags: TypeFormatFlags) { + if (type.target === globalArrayType && !(flags & TypeFormatFlags.WriteArrayAsGenericType)) { + writeType(type.typeArguments[0], TypeFormatFlags.InElementType); + writePunctuation(writer, SyntaxKind.OpenBracketToken); + writePunctuation(writer, SyntaxKind.CloseBracketToken); + } + else { + buildSymbolDisplay(type.target.symbol, writer, enclosingDeclaration, SymbolFlags.Type); + writePunctuation(writer, SyntaxKind.LessThanToken); + writeTypeList(type.typeArguments, /*union*/ false); + writePunctuation(writer, SyntaxKind.GreaterThanToken); + } + } + + function writeTupleType(type: TupleType) { + writePunctuation(writer, SyntaxKind.OpenBracketToken); + writeTypeList(type.elementTypes, /*union*/ false); + writePunctuation(writer, SyntaxKind.CloseBracketToken); + } + + function writeUnionType(type: UnionType, flags: TypeFormatFlags) { + if (flags & TypeFormatFlags.InElementType) { + writePunctuation(writer, SyntaxKind.OpenParenToken); + } + writeTypeList(type.types, /*union*/ true); + if (flags & TypeFormatFlags.InElementType) { + writePunctuation(writer, SyntaxKind.CloseParenToken); + } + } + + function writeAnonymousType(type: ObjectType, flags: TypeFormatFlags) { + // Always use 'typeof T' for type of class, enum, and module objects + if (type.symbol && type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) { + writeTypeofSymbol(type); + } + // Use 'typeof T' for types of functions and methods that circularly reference themselves + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type); + } + else if (typeStack && contains(typeStack, type)) { + // Recursive usage, use any + writeKeyword(writer, SyntaxKind.AnyKeyword); + } + else { + if (!typeStack) { + typeStack = []; + } + typeStack.push(type); + writeLiteralType(type, flags); + typeStack.pop(); } - if (flags & TypeFormatFlags.WriteArrowStyleSignature) { + function shouldWriteTypeOfFunctionSymbol() { + if (type.symbol) { + var isStaticMethodSymbol = !!(type.symbol.flags & SymbolFlags.Method && // typeof static method + ts.forEach(type.symbol.declarations, declaration => declaration.flags & NodeFlags.Static)); + var isNonLocalFunctionSymbol = !!(type.symbol.flags & SymbolFlags.Function) && + (type.symbol.parent || // is exported function symbol + ts.forEach(type.symbol.declarations, declaration => + declaration.parent.kind === SyntaxKind.SourceFile || declaration.parent.kind === SyntaxKind.ModuleBlock)); + + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + // typeof is allowed only for static/non local functions + return !!(flags & TypeFormatFlags.UseTypeOfFunction) || // use typeof if format flags specify it + (typeStack && contains(typeStack, type)); // it is type of the symbol uses itself recursively + } + } + } + } + + function writeTypeofSymbol(type: ObjectType) { + writeKeyword(writer, SyntaxKind.TypeOfKeyword); + writeSpace(writer); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value); + } + + function writeLiteralType(type: ObjectType, flags: TypeFormatFlags) { + var resolved = resolveObjectOrUnionTypeMembers(type); + if (!resolved.properties.length && !resolved.stringIndexType && !resolved.numberIndexType) { + if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { + writePunctuation(writer, SyntaxKind.OpenBraceToken); + writePunctuation(writer, SyntaxKind.CloseBraceToken); + return; + } + if (resolved.callSignatures.length === 1 && !resolved.constructSignatures.length) { - writeSignature(resolved.callSignatures[0], writer, enclosingDeclaration, flags, typeStack); + if (flags & TypeFormatFlags.InElementType) { + writePunctuation(writer, SyntaxKind.OpenParenToken); + } + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature , typeStack); + if (flags & TypeFormatFlags.InElementType) { + writePunctuation(writer, SyntaxKind.CloseParenToken); + } return; } if (resolved.constructSignatures.length === 1 && !resolved.callSignatures.length) { + if (flags & TypeFormatFlags.InElementType) { + writePunctuation(writer, SyntaxKind.OpenParenToken); + } writeKeyword(writer, SyntaxKind.NewKeyword); writeSpace(writer); - writeSignature(resolved.constructSignatures[0], writer, enclosingDeclaration, flags, typeStack); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, typeStack); + if (flags & TypeFormatFlags.InElementType) { + writePunctuation(writer, SyntaxKind.CloseParenToken); + } return; } } - } - writePunctuation(writer, SyntaxKind.OpenBraceToken); - writer.writeLine(); - writer.increaseIndent(); - for (var i = 0; i < resolved.callSignatures.length; i++) { - writeSignature(resolved.callSignatures[i], writer, enclosingDeclaration, flags & ~TypeFormatFlags.WriteArrowStyleSignature, typeStack); - writePunctuation(writer, SyntaxKind.SemicolonToken); + writePunctuation(writer, SyntaxKind.OpenBraceToken); writer.writeLine(); - } - for (var i = 0; i < resolved.constructSignatures.length; i++) { - writeKeyword(writer, SyntaxKind.NewKeyword); - writeSpace(writer); + writer.increaseIndent(); + for (var i = 0; i < resolved.callSignatures.length; i++) { + buildSignatureDisplay(resolved.callSignatures[i], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, SyntaxKind.SemicolonToken); + writer.writeLine(); + } + for (var i = 0; i < resolved.constructSignatures.length; i++) { + writeKeyword(writer, SyntaxKind.NewKeyword); + writeSpace(writer); - writeSignature(resolved.constructSignatures[i], writer, enclosingDeclaration, flags & ~TypeFormatFlags.WriteArrowStyleSignature, typeStack); - writePunctuation(writer, SyntaxKind.SemicolonToken); - writer.writeLine(); - } - if (resolved.stringIndexType) { - // [x: string]: - writePunctuation(writer, SyntaxKind.OpenBracketToken); - writer.writeKind("x", SymbolDisplayPartKind.parameterName); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeKeyword(writer, SyntaxKind.StringKeyword); - writePunctuation(writer, SyntaxKind.CloseBracketToken); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeType(resolved.stringIndexType, flags | TypeFormatFlags.WriteArrowStyleSignature); - writePunctuation(writer, SyntaxKind.SemicolonToken); - writer.writeLine(); - } - if (resolved.numberIndexType) { - // [x: number]: - writePunctuation(writer, SyntaxKind.OpenBracketToken); - writer.writeKind("x", SymbolDisplayPartKind.parameterName); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeKeyword(writer, SyntaxKind.NumberKeyword); - writePunctuation(writer, SyntaxKind.CloseBracketToken); - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeType(resolved.numberIndexType, flags | TypeFormatFlags.WriteArrowStyleSignature); - writePunctuation(writer, SyntaxKind.SemicolonToken); - writer.writeLine(); - } - for (var i = 0; i < resolved.properties.length; i++) { - var p = resolved.properties[i]; - var t = getTypeOfSymbol(p); - if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfType(t).length) { - var signatures = getSignaturesOfType(t, SignatureKind.Call); - for (var j = 0; j < signatures.length; j++) { - writeSymbol(p, writer); + buildSignatureDisplay(resolved.constructSignatures[i], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, SyntaxKind.SemicolonToken); + writer.writeLine(); + } + if (resolved.stringIndexType) { + // [x: string]: + writePunctuation(writer, SyntaxKind.OpenBracketToken); + writer.writeParameter("x"); + writePunctuation(writer, SyntaxKind.ColonToken); + writeSpace(writer); + writeKeyword(writer, SyntaxKind.StringKeyword); + writePunctuation(writer, SyntaxKind.CloseBracketToken); + writePunctuation(writer, SyntaxKind.ColonToken); + writeSpace(writer); + writeType(resolved.stringIndexType, TypeFormatFlags.None); + writePunctuation(writer, SyntaxKind.SemicolonToken); + writer.writeLine(); + } + if (resolved.numberIndexType) { + // [x: number]: + writePunctuation(writer, SyntaxKind.OpenBracketToken); + writer.writeParameter("x"); + writePunctuation(writer, SyntaxKind.ColonToken); + writeSpace(writer); + writeKeyword(writer, SyntaxKind.NumberKeyword); + writePunctuation(writer, SyntaxKind.CloseBracketToken); + writePunctuation(writer, SyntaxKind.ColonToken); + writeSpace(writer); + writeType(resolved.numberIndexType, TypeFormatFlags.None); + writePunctuation(writer, SyntaxKind.SemicolonToken); + writer.writeLine(); + } + for (var i = 0; i < resolved.properties.length; i++) { + var p = resolved.properties[i]; + var t = getTypeOfSymbol(p); + if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(t).length) { + var signatures = getSignaturesOfType(t, SignatureKind.Call); + for (var j = 0; j < signatures.length; j++) { + buildSymbolDisplay(p, writer); + if (isOptionalProperty(p)) { + writePunctuation(writer, SyntaxKind.QuestionToken); + } + buildSignatureDisplay(signatures[j], writer, enclosingDeclaration, globalFlagsToPass, typeStack); + writePunctuation(writer, SyntaxKind.SemicolonToken); + writer.writeLine(); + } + } + else { + buildSymbolDisplay(p, writer); if (isOptionalProperty(p)) { writePunctuation(writer, SyntaxKind.QuestionToken); } - writeSignature(signatures[j], writer, enclosingDeclaration, flags & ~TypeFormatFlags.WriteArrowStyleSignature, typeStack); + writePunctuation(writer, SyntaxKind.ColonToken); + writeSpace(writer); + writeType(t, TypeFormatFlags.None); writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } } - else { - writeSymbol(p, writer); - if (isOptionalProperty(p)) { - writePunctuation(writer, SyntaxKind.QuestionToken); - } - writePunctuation(writer, SyntaxKind.ColonToken); - writeSpace(writer); - writeType(t, flags | TypeFormatFlags.WriteArrowStyleSignature); - writePunctuation(writer, SyntaxKind.SemicolonToken); - writer.writeLine(); - } + writer.decreaseIndent(); + writePunctuation(writer, SyntaxKind.CloseBraceToken); } - writer.decreaseIndent(); - writePunctuation(writer, SyntaxKind.CloseBraceToken); } - } - function writeTypeParameter(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { - writeSymbol(tp.symbol, writer); - var constraint = getConstraintOfTypeParameter(tp); - if (constraint) { - writeSpace(writer); - writeKeyword(writer, SyntaxKind.ExtendsKeyword); - writeSpace(writer); - writeType(constraint, writer, enclosingDeclaration, flags, typeStack); - } - } - - function writeTypeParameters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { - if (typeParameters && typeParameters.length) { - writePunctuation(writer, SyntaxKind.LessThanToken); - for (var i = 0; i < typeParameters.length; i++) { - if (i > 0) { - writePunctuation(writer, SyntaxKind.CommaToken); - writeSpace(writer); - } - writeTypeParameter(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + function buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags) { + var targetSymbol = getTargetSymbol(symbol); + if (targetSymbol.flags & SymbolFlags.Class || targetSymbol.flags & SymbolFlags.Interface) { + buildDisplayForTypeParametersAndDelimiters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } - writePunctuation(writer, SyntaxKind.GreaterThanToken); } - } - function writeTypeArguments(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { - if (typeParameters && typeParameters.length) { - writePunctuation(writer, SyntaxKind.LessThanToken); - for (var i = 0; i < typeParameters.length; i++) { - if (i > 0) { - writePunctuation(writer, SyntaxKind.CommaToken); - writeSpace(writer); - } - writeType(mapper(typeParameters[i]), writer, enclosingDeclaration, TypeFormatFlags.WriteArrowStyleSignature); - } - writePunctuation(writer, SyntaxKind.GreaterThanToken); - } - } - - function writeTypeParametersOfSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags) { - var rootSymbol = getRootSymbol(symbol); - if (rootSymbol.flags & SymbolFlags.Class || rootSymbol.flags & SymbolFlags.Interface) { - writeTypeParameters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); - } - } - - function writeSignature(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { - if (signature.target && (flags & TypeFormatFlags.WriteTypeArgumentsOfSignature)) { - // Instantiated signature, write type arguments instead - writeTypeArguments(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); - } - else { - writeTypeParameters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); - } - writePunctuation(writer, SyntaxKind.OpenParenToken); - for (var i = 0; i < signature.parameters.length; i++) { - if (i > 0) { - writePunctuation(writer, SyntaxKind.CommaToken); + function buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + appendSymbolNameOnly(tp.symbol, writer); + var constraint = getConstraintOfTypeParameter(tp); + if (constraint) { writeSpace(writer); + writeKeyword(writer, SyntaxKind.ExtendsKeyword); + writeSpace(writer); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); } - var p = signature.parameters[i]; + } + + function buildParameterDisplay(p: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { if (getDeclarationFlagsFromSymbol(p) & NodeFlags.Rest) { writePunctuation(writer, SyntaxKind.DotDotDotToken); } - writeSymbol(p, writer); + appendSymbolNameOnly(p, writer); if (p.valueDeclaration.flags & NodeFlags.QuestionMark || (p.valueDeclaration).initializer) { writePunctuation(writer, SyntaxKind.QuestionToken); } writePunctuation(writer, SyntaxKind.ColonToken); writeSpace(writer); - writeType(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); } - writePunctuation(writer, SyntaxKind.CloseParenToken); - if (flags & TypeFormatFlags.WriteArrowStyleSignature) { + function buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + if (typeParameters && typeParameters.length) { + writePunctuation(writer, SyntaxKind.LessThanToken); + for (var i = 0; i < typeParameters.length; i++) { + if (i > 0) { + writePunctuation(writer, SyntaxKind.CommaToken); + writeSpace(writer); + } + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + } + writePunctuation(writer, SyntaxKind.GreaterThanToken); + } + } + + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + if (typeParameters && typeParameters.length) { + writePunctuation(writer, SyntaxKind.LessThanToken); + for (var i = 0; i < typeParameters.length; i++) { + if (i > 0) { + writePunctuation(writer, SyntaxKind.CommaToken); + writeSpace(writer); + } + buildTypeDisplay(mapper(typeParameters[i]), writer, enclosingDeclaration, TypeFormatFlags.None); + } + writePunctuation(writer, SyntaxKind.GreaterThanToken); + } + } + + function buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + writePunctuation(writer, SyntaxKind.OpenParenToken); + for (var i = 0; i < parameters.length; i++) { + if (i > 0) { + writePunctuation(writer, SyntaxKind.CommaToken); + writeSpace(writer); + } + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + } + writePunctuation(writer, SyntaxKind.CloseParenToken); + } + + function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + if (flags & TypeFormatFlags.WriteArrowStyleSignature) { + writeSpace(writer); + writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken); + } + else { + writePunctuation(writer, SyntaxKind.ColonToken); + } writeSpace(writer); - writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); } - else { - writePunctuation(writer, SyntaxKind.ColonToken); - } - writeSpace(writer); + + function buildSignatureDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + if (signature.target && (flags & TypeFormatFlags.WriteTypeArgumentsOfSignature)) { + // Instantiated signature, write type arguments instead + // This is achieved by passing in the mapper separately + buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); + } + else { + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + } - writeType(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + } + + return _displayBuilder || (_displayBuilder = { + symbolToString: symbolToString, + typeToString: typeToString, + buildSymbolDisplay: buildSymbolDisplay, + buildTypeDisplay: buildTypeDisplay, + buildTypeParameterDisplay: buildTypeParameterDisplay, + buildParameterDisplay: buildParameterDisplay, + buildDisplayForParametersAndDelimiters: buildDisplayForParametersAndDelimiters, + buildDisplayForTypeParametersAndDelimiters: buildDisplayForTypeParametersAndDelimiters, + buildDisplayForTypeArgumentsAndDelimiters: buildDisplayForTypeArgumentsAndDelimiters, + buildTypeParameterDisplayFromSymbol: buildTypeParameterDisplayFromSymbol, + buildSignatureDisplay: buildSignatureDisplay, + buildReturnTypeDisplay: buildReturnTypeDisplay + }); } function isDeclarationVisible(node: Declaration): boolean { @@ -1477,25 +1551,6 @@ module ts { } } - function getApparentType(type: Type): ApparentType { - if (type.flags & TypeFlags.TypeParameter) { - do { - type = getConstraintOfTypeParameter(type); - } while (type && type.flags & TypeFlags.TypeParameter); - if (!type) type = emptyObjectType; - } - if (type.flags & TypeFlags.StringLike) { - type = globalStringType; - } - else if (type.flags & TypeFlags.NumberLike) { - type = globalNumberType; - } - else if (type.flags & TypeFlags.Boolean) { - type = globalBooleanType; - } - return type; - } - function getTypeOfPrototypeProperty(prototype: Symbol): Type { // TypeScript 1.0 spec (April 2014): 8.4 // Every class automatically contains a static property member named 'prototype', @@ -1712,6 +1767,9 @@ module ts { } function getTypeOfSymbol(symbol: Symbol): Type { + if (symbol.flags & SymbolFlags.Instantiated) { + return getTypeOfInstantiatedSymbol(symbol); + } if (symbol.flags & (SymbolFlags.Variable | SymbolFlags.Property)) { return getTypeOfVariableOrParameterOrProperty(symbol); } @@ -1727,9 +1785,6 @@ module ts { if (symbol.flags & SymbolFlags.Import) { return getTypeOfImport(symbol); } - if (symbol.flags & SymbolFlags.Instantiated) { - return getTypeOfInstantiatedSymbol(symbol); - } return unknownType; } @@ -1884,6 +1939,7 @@ module ts { } function getDeclaredTypeOfSymbol(symbol: Symbol): Type { + Debug.assert((symbol.flags & SymbolFlags.Instantiated) === 0); if (symbol.flags & SymbolFlags.Class) { return getDeclaredTypeOfClass(symbol); } @@ -1899,7 +1955,6 @@ module ts { if (symbol.flags & SymbolFlags.Import) { return getDeclaredTypeOfImport(symbol); } - Debug.assert((symbol.flags & SymbolFlags.Instantiated) === 0); return unknownType; } @@ -1947,7 +2002,7 @@ module ts { if (type.baseTypes.length) { members = createSymbolTable(type.declaredProperties); forEach(type.baseTypes, baseType => { - addInheritedMembers(members, getPropertiesOfType(baseType)); + addInheritedMembers(members, getPropertiesOfObjectType(baseType)); callSignatures = concatenate(callSignatures, getSignaturesOfType(baseType, SignatureKind.Call)); constructSignatures = concatenate(constructSignatures, getSignaturesOfType(baseType, SignatureKind.Construct)); stringIndexType = stringIndexType || getIndexTypeOfType(baseType, IndexKind.String); @@ -1967,7 +2022,7 @@ module ts { var numberIndexType = target.declaredNumberIndexType ? instantiateType(target.declaredNumberIndexType, mapper) : undefined; forEach(target.baseTypes, baseType => { var instantiatedBaseType = instantiateType(baseType, mapper); - addInheritedMembers(members, getPropertiesOfType(instantiatedBaseType)); + addInheritedMembers(members, getPropertiesOfObjectType(instantiatedBaseType)); callSignatures = concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Call)); constructSignatures = concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Construct)); stringIndexType = stringIndexType || getIndexTypeOfType(instantiatedBaseType, IndexKind.String); @@ -2020,12 +2075,72 @@ module ts { } function resolveTupleTypeMembers(type: TupleType) { - var arrayType = resolveObjectTypeMembers(createArrayType(getBestCommonType(type.elementTypes))); + var arrayType = resolveObjectOrUnionTypeMembers(createArrayType(getUnionType(type.elementTypes))); var members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); } + function signatureListsIdentical(s: Signature[], t: Signature[]): boolean { + if (s.length !== t.length) { + return false; + } + for (var i = 0; i < s.length; i++) { + if (!compareSignatures(s[i], t[i], /*compareReturnTypes*/ false, isTypeIdenticalTo)) { + return false; + } + } + return true; + } + + // If the lists of call or construct signatures in the given types are all identical except for return types, + // and if none of the signatures are generic, return a list of signatures that has substitutes a union of the + // return types of the corresponding signatures in each resulting signature. + function getUnionSignatures(types: Type[], kind: SignatureKind): Signature[] { + var signatureLists = map(types, t => getSignaturesOfType(t, kind)); + var signatures = signatureLists[0]; + for (var i = 0; i < signatures.length; i++) { + if (signatures[i].typeParameters) { + return emptyArray; + } + } + for (var i = 1; i < signatureLists.length; i++) { + if (!signatureListsIdentical(signatures, signatureLists[i])) { + return emptyArray; + } + } + var result = map(signatures, cloneSignature); + for (var i = 0; i < result.length; i++) { + var s = result[i]; + // Clear resolved return type we possibly got from cloneSignature + s.resolvedReturnType = undefined; + s.unionSignatures = map(signatureLists, signatures => signatures[i]); + } + return result; + } + + function getUnionIndexType(types: Type[], kind: IndexKind): Type { + var indexTypes: Type[] = []; + for (var i = 0; i < types.length; i++) { + var indexType = getIndexTypeOfType(types[i], kind); + if (!indexType) { + return undefined; + } + indexTypes.push(indexType); + } + return getUnionType(indexTypes); + } + + function resolveUnionTypeMembers(type: UnionType) { + // The members and properties collections are empty for union types. To get all properties of a union + // type use getPropertiesOfType (only the language service uses this). + var callSignatures = getUnionSignatures(type.types, SignatureKind.Call); + var constructSignatures = getUnionSignatures(type.types, SignatureKind.Construct); + var stringIndexType = getUnionIndexType(type.types, IndexKind.String); + var numberIndexType = getUnionIndexType(type.types, IndexKind.Number); + setObjectTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexType, numberIndexType); + } + function resolveAnonymousTypeMembers(type: ObjectType) { var symbol = type.symbol; if (symbol.flags & SymbolFlags.TypeLiteral) { @@ -2054,7 +2169,7 @@ module ts { } if (classType.baseTypes.length) { members = createSymbolTable(getNamedMembers(members)); - addInheritedMembers(members, getPropertiesOfType(getTypeOfSymbol(classType.baseTypes[0].symbol))); + addInheritedMembers(members, getPropertiesOfObjectType(getTypeOfSymbol(classType.baseTypes[0].symbol))); } } var stringIndexType: Type = undefined; @@ -2063,8 +2178,8 @@ module ts { setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType); } - function resolveObjectTypeMembers(type: ObjectType): ResolvedObjectType { - if (!(type).members) { + function resolveObjectOrUnionTypeMembers(type: ObjectType): ResolvedType { + if (!(type).members) { if (type.flags & (TypeFlags.Class | TypeFlags.Interface)) { resolveClassOrInterfaceMembers(type); } @@ -2074,64 +2189,180 @@ module ts { else if (type.flags & TypeFlags.Tuple) { resolveTupleTypeMembers(type); } + else if (type.flags & TypeFlags.Union) { + resolveUnionTypeMembers(type); + } else { resolveTypeReferenceMembers(type); } } - return type; + return type; } - function getPropertiesOfType(type: Type): Symbol[] { + // Return properties of an object type or an empty array for other types + function getPropertiesOfObjectType(type: Type): Symbol[] { if (type.flags & TypeFlags.ObjectType) { - return resolveObjectTypeMembers(type).properties; + return resolveObjectOrUnionTypeMembers(type).properties; } return emptyArray; } + // If the given type is an object type and that type has a property by the given name, return + // the symbol for that property. Otherwise return undefined. + function getPropertyOfObjectType(type: Type, name: string): Symbol { + if (type.flags & TypeFlags.ObjectType) { + var resolved = resolveObjectOrUnionTypeMembers(type); + if (hasProperty(resolved.members, name)) { + var symbol = resolved.members[name]; + if (symbolIsValue(symbol)) { + return symbol; + } + } + } + } + + function getPropertiesOfUnionType(type: UnionType): Symbol[] { + var result: Symbol[] = []; + forEach(getPropertiesOfType(type.types[0]), prop => { + var unionProp = getPropertyOfUnionType(type, prop.name); + if (unionProp) { + result.push(unionProp); + } + }); + return result; + } + + function getPropertiesOfType(type: Type): Symbol[] { + if (type.flags & TypeFlags.Union) { + return getPropertiesOfUnionType(type); + } + return getPropertiesOfObjectType(getApparentType(type)); + } + + // For a type parameter, return the base constraint of the type parameter. For the string, number, and + // boolean primitive types, return the corresponding object types.Otherwise return the type itself. + // Note that the apparent type of a union type is the union type itself. + function getApparentType(type: Type): Type { + if (type.flags & TypeFlags.TypeParameter) { + do { + type = getConstraintOfTypeParameter(type); + } while (type && type.flags & TypeFlags.TypeParameter); + if (!type) { + type = emptyObjectType; + } + } + if (type.flags & TypeFlags.StringLike) { + type = globalStringType; + } + else if (type.flags & TypeFlags.NumberLike) { + type = globalNumberType; + } + else if (type.flags & TypeFlags.Boolean) { + type = globalBooleanType; + } + return type; + } + + function createUnionProperty(unionType: UnionType, name: string): Symbol { + var types = unionType.types; + var props: Symbol[]; + for (var i = 0; i < types.length; i++) { + var type = getApparentType(types[i]); + if (type !== unknownType) { + var prop = getPropertyOfType(type, name); + if (!prop) { + return undefined; + } + if (!props) { + props = [prop]; + } + else { + props.push(prop); + } + } + } + var propTypes: Type[] = []; + var declarations: Declaration[] = []; + for (var i = 0; i < props.length; i++) { + var prop = props[i]; + if (prop.declarations) { + declarations.push.apply(declarations, prop.declarations); + } + propTypes.push(getTypeOfSymbol(prop)); + } + var result = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | SymbolFlags.UnionProperty, name); + result.unionType = unionType; + result.declarations = declarations; + result.type = getUnionType(propTypes); + return result; + } + + function getPropertyOfUnionType(type: UnionType, name: string): Symbol { + var properties = type.resolvedProperties || (type.resolvedProperties = {}); + if (hasProperty(properties, name)) { + return properties[name]; + } + var property = createUnionProperty(type, name); + if (property) { + properties[name] = property; + } + return property; + } + + // Return the symbol for the property with the given name in the given type. Creates synthetic union properties when + // necessary, maps primtive types and type parameters are to their apparent types, and augments with properties from + // Object and Function as appropriate. function getPropertyOfType(type: Type, name: string): Symbol { - if (type.flags & TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); - if (hasProperty(resolved.members, name)) { - var symbol = resolved.members[name]; - if (symbolIsValue(symbol)) { - return symbol; - } + if (type.flags & TypeFlags.Union) { + return getPropertyOfUnionType(type, name); + } + if (!(type.flags & TypeFlags.ObjectType)) { + type = getApparentType(type); + if (!(type.flags & TypeFlags.ObjectType)) { + return undefined; } } - } - - function getPropertyOfApparentType(type: ApparentType, name: string): Symbol { - if (type.flags & TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); - if (hasProperty(resolved.members, name)) { - var symbol = resolved.members[name]; - if (symbolIsValue(symbol)) { - return symbol; - } + var resolved = resolveObjectOrUnionTypeMembers(type); + if (hasProperty(resolved.members, name)) { + var symbol = resolved.members[name]; + if (symbolIsValue(symbol)) { + return symbol; } - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - var symbol = getPropertyOfType(globalFunctionType, name); - if (symbol) return symbol; - } - return getPropertyOfType(globalObjectType, name); } + if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { + var symbol = getPropertyOfObjectType(globalFunctionType, name); + if (symbol) return symbol; + } + return getPropertyOfObjectType(globalObjectType, name); } - function getSignaturesOfType(type: Type, kind: SignatureKind): Signature[] { - if (type.flags & TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + function getSignaturesOfObjectOrUnionType(type: Type, kind: SignatureKind): Signature[] { + if (type.flags & (TypeFlags.ObjectType | TypeFlags.Union)) { + var resolved = resolveObjectOrUnionTypeMembers(type); return kind === SignatureKind.Call ? resolved.callSignatures : resolved.constructSignatures; } return emptyArray; } - function getIndexTypeOfType(type: Type, kind: IndexKind): Type { - if (type.flags & TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + // Return the signatures of the given kind in the given type. Creates synthetic union signatures when necessary and + // maps primtive types and type parameters are to their apparent types. + function getSignaturesOfType(type: Type, kind: SignatureKind): Signature[] { + return getSignaturesOfObjectOrUnionType(getApparentType(type), kind); + } + + function getIndexTypeOfObjectOrUnionType(type: Type, kind: IndexKind): Type { + if (type.flags & (TypeFlags.ObjectType | TypeFlags.Union)) { + var resolved = resolveObjectOrUnionTypeMembers(type); return kind === IndexKind.String ? resolved.stringIndexType : resolved.numberIndexType; } } + // Return the index type of the given kind in the given type. Creates synthetic union index types when necessary and + // maps primtive types and type parameters are to their apparent types. + function getIndexTypeOfType(type: Type, kind: IndexKind): Type { + return getIndexTypeOfObjectOrUnionType(getApparentType(type), kind); + } + // Return list of type parameters with duplicates removed (duplicate identifier errors are generated in the actual // type checking functions). function getTypeParametersFromDeclaration(typeParameterDeclarations: TypeParameterDeclaration[]): TypeParameter[] { @@ -2234,6 +2465,9 @@ module ts { if (signature.target) { var type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper); } + else if (signature.unionSignatures) { + var type = getUnionType(map(signature.unionSignatures, getReturnTypeOfSignature)); + } else { var type = getReturnTypeFromBody(signature.declaration); } @@ -2290,7 +2524,7 @@ module ts { // will result in a different declaration kind. if (!signature.isolatedSignatureType) { var isConstructor = signature.declaration.kind === SyntaxKind.Constructor || signature.declaration.kind === SyntaxKind.ConstructSignature; - var type = createObjectType(TypeFlags.Anonymous | TypeFlags.FromSignature); + var type = createObjectType(TypeFlags.Anonymous | TypeFlags.FromSignature); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -2542,6 +2776,102 @@ module ts { return links.resolvedType; } + function addTypeToSortedSet(sortedSet: Type[], type: Type) { + if (type.flags & TypeFlags.Union) { + addTypesToSortedSet(sortedSet, (type).types); + } + else { + var i = 0; + var id = type.id; + while (i < sortedSet.length && sortedSet[i].id < id) { + i++; + } + if (i === sortedSet.length || sortedSet[i].id !== id) { + sortedSet.splice(i, 0, type); + } + } + } + + function addTypesToSortedSet(sortedTypes: Type[], types: Type[]) { + for (var i = 0, len = types.length; i < len; i++) { + addTypeToSortedSet(sortedTypes, types[i]); + } + } + + function isSubtypeOfAny(candidate: Type, types: Type[]): boolean { + for (var i = 0, len = types.length; i < len; i++) { + if (candidate !== types[i] && isTypeSubtypeOf(candidate, types[i])) { + return true; + } + } + return false; + } + + function removeSubtypes(types: Type[]) { + var i = types.length; + while (i > 0) { + i--; + if (isSubtypeOfAny(types[i], types)) { + types.splice(i, 1); + } + } + } + + function containsAnyType(types: Type[]) { + for (var i = 0; i < types.length; i++) { + if (types[i].flags & TypeFlags.Any) { + return true; + } + } + return false; + } + + function removeAllButLast(types: Type[], typeToRemove: Type) { + var i = types.length; + while (i > 0 && types.length > 1) { + i--; + if (types[i] === typeToRemove) { + types.splice(i, 1); + } + } + } + + function getUnionType(types: Type[], noSubtypeReduction?: boolean): Type { + if (types.length === 0) { + return emptyObjectType; + } + var sortedTypes: Type[] = []; + addTypesToSortedSet(sortedTypes, types); + if (noSubtypeReduction) { + if (containsAnyType(sortedTypes)) { + return anyType; + } + removeAllButLast(sortedTypes, undefinedType); + removeAllButLast(sortedTypes, nullType); + } + else { + removeSubtypes(sortedTypes); + } + if (sortedTypes.length === 1) { + return sortedTypes[0]; + } + var id = getTypeListId(sortedTypes); + var type = unionTypes[id]; + if (!type) { + type = unionTypes[id] = createObjectType(TypeFlags.Union); + type.types = sortedTypes; + } + return type; + } + + function getTypeFromUnionTypeNode(node: UnionTypeNode): Type { + var links = getNodeLinks(node); + if (!links.resolvedType) { + links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode), /*noSubtypeReduction*/ true); + } + return links.resolvedType; + } + function getTypeFromTypeLiteralNode(node: TypeLiteralNode): Type { var links = getNodeLinks(node); if (!links.resolvedType) { @@ -2588,6 +2918,10 @@ module ts { return getTypeFromArrayTypeNode(node); case SyntaxKind.TupleType: return getTypeFromTupleTypeNode(node); + case SyntaxKind.UnionType: + return getTypeFromUnionTypeNode(node); + case SyntaxKind.ParenType: + return getTypeFromTypeNode((node).type); case SyntaxKind.TypeLiteral: return getTypeFromTypeLiteralNode(node); // This function assumes that an identifier or qualified name is a type expression @@ -2712,7 +3046,7 @@ module ts { // Keep the flags from the symbol we're instantiating. Mark that is instantiated, and // also transient so that we can just store data on it directly. - var result = createSymbol(SymbolFlags.Instantiated | SymbolFlags.Transient, symbol.name); + var result = createSymbol(SymbolFlags.Instantiated | SymbolFlags.Transient | symbol.flags, symbol.name); result.declarations = symbol.declarations; result.parent = symbol.parent; result.target = symbol; @@ -2725,8 +3059,8 @@ module ts { } function instantiateAnonymousType(type: ObjectType, mapper: TypeMapper): ObjectType { - var result = createObjectType(TypeFlags.Anonymous, type.symbol); - result.properties = instantiateList(getPropertiesOfType(type), mapper, instantiateSymbol); + var result = createObjectType(TypeFlags.Anonymous, type.symbol); + result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, SignatureKind.Call), mapper, instantiateSignature); result.constructSignatures = instantiateList(getSignaturesOfType(type, SignatureKind.Construct), mapper, instantiateSignature); @@ -2752,6 +3086,9 @@ module ts { if (type.flags & TypeFlags.Tuple) { return createTupleType(instantiateList((type).elementTypes, mapper, instantiateType)); } + if (type.flags & TypeFlags.Union) { + return getUnionType(instantiateList((type).types, mapper, instantiateType), /*noSubtypeReduction*/ true); + } } return type; } @@ -2780,9 +3117,9 @@ module ts { function getTypeWithoutConstructors(type: Type): Type { if (type.flags & TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + var resolved = resolveObjectOrUnionTypeMembers(type); if (resolved.constructSignatures.length) { - var result = createObjectType(TypeFlags.Anonymous, type.symbol); + var result = createObjectType(TypeFlags.Anonymous, type.symbol); result.members = resolved.members; result.properties = resolved.properties; result.callSignatures = resolved.callSignatures; @@ -2844,7 +3181,7 @@ module ts { for (var i = 0, len = type.baseTypes.length; i < len; ++i) { var base = type.baseTypes[i]; - var properties = getPropertiesOfType(base); + var properties = getPropertiesOfObjectType(base); for (var j = 0, proplen = properties.length; j < proplen; ++j) { var prop = properties[j]; if (!hasProperty(seen, prop.name)) { @@ -2913,7 +3250,7 @@ module ts { errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); } - function isRelatedTo(source: Type, target: Type, reportErrors: boolean): boolean { + function isRelatedTo(source: Type, target: Type, reportErrors?: boolean): boolean { return isRelatedToWithCustomErrors(source, target, reportErrors, /*chainedMessage*/ undefined, /*terminalMessage*/ undefined); } @@ -2934,8 +3271,17 @@ module ts { if (source === numberType && target.flags & TypeFlags.Enum) return true; } } - - if (source.flags & TypeFlags.TypeParameter && target.flags & TypeFlags.TypeParameter) { + if (source.flags & TypeFlags.Union) { + if (unionTypeRelatedToType(source, target, reportErrors)) { + return true; + } + } + else if (target.flags & TypeFlags.Union) { + if (typeRelatedToUnionType(source, target, reportErrors)) { + return true; + } + } + else if (source.flags & TypeFlags.TypeParameter && target.flags & TypeFlags.TypeParameter) { if (typeParameterRelatedTo(source, target, reportErrors)) { return true; } @@ -2952,7 +3298,7 @@ module ts { // Report structural errors only if we haven't reported any errors yet var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo; // identity relation does not use apparent type - var sourceOrApparentType = relation === identityRelation ? source : getApparentType(source); + var sourceOrApparentType = relation === identityRelation ? source : getApparentType(source); if (sourceOrApparentType.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType && objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors)) { errorInfo = saveErrorInfo; @@ -2973,6 +3319,26 @@ module ts { return false; } + function typeRelatedToUnionType(source: Type, target: UnionType, reportErrors: boolean): boolean { + var targetTypes = target.types; + for (var i = 0, len = targetTypes.length; i < len; i++) { + if (isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1)) { + return true; + } + } + return false; + } + + function unionTypeRelatedToType(source: UnionType, target: Type, reportErrors: boolean): boolean { + var sourceTypes = source.types; + for (var i = 0, len = sourceTypes.length; i < len; i++) { + if (!isRelatedTo(sourceTypes[i], target, reportErrors)) { + return false; + } + } + return true; + } + function typesRelatedTo(sources: Type[], targets: Type[], reportErrors: boolean): boolean { for (var i = 0, len = sources.length; i < len; i++) { if (!isRelatedTo(sources[i], targets[i], reportErrors)) return false; @@ -3074,37 +3440,15 @@ module ts { function propertiesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { if (relation === identityRelation) { - return propertiesAreIdenticalTo(source, target, reportErrors); + return propertiesIdenticalTo(source, target, reportErrors); } - else { - return propertiesAreSubtypeOrAssignableTo(source, target, reportErrors); - } - } - - function propertiesAreIdenticalTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { - var sourceProperties = getPropertiesOfType(source); - var targetProperties = getPropertiesOfType(target); - if (sourceProperties.length !== targetProperties.length) { - return false; - } - for (var i = 0, len = sourceProperties.length; i < len; ++i) { - var sourceProp = sourceProperties[i]; - var targetProp = getPropertyOfType(target, sourceProp.name); - if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { - return false; - } - } - return true; - } - - function propertiesAreSubtypeOrAssignableTo(source: ApparentType, target: ObjectType, reportErrors: boolean): boolean { - var properties = getPropertiesOfType(target); + var properties = getPropertiesOfObjectType(target); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; - var sourceProp = getPropertyOfApparentType(source, targetProp.name); + var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { - if (!isOptionalProperty(targetProp)) { + if (relation === subtypeRelation || !isOptionalProperty(targetProp)) { if (reportErrors) { reportError(Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } @@ -3174,80 +3518,26 @@ module ts { return true; } - function signaturesRelatedTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): boolean { - if (relation === identityRelation) { - return areSignaturesIdenticalTo(source, target, kind, reportErrors); - } - else { - return areSignaturesSubtypeOrAssignableTo(source, target, kind, reportErrors); - } - } - - function areSignaturesIdenticalTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): boolean { - var sourceSignatures = getSignaturesOfType(source, kind); - var targetSignatures = getSignaturesOfType(target, kind); - if (sourceSignatures.length !== targetSignatures.length) { + function propertiesIdenticalTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { + var sourceProperties = getPropertiesOfObjectType(source); + var targetProperties = getPropertiesOfObjectType(target); + if (sourceProperties.length !== targetProperties.length) { return false; } - - for (var i = 0, len = sourceSignatures.length; i < len; ++i) { - if (!isSignatureIdenticalTo(sourceSignatures[i], targetSignatures[i], reportErrors)) { + for (var i = 0, len = sourceProperties.length; i < len; ++i) { + var sourceProp = sourceProperties[i]; + var targetProp = getPropertyOfObjectType(target, sourceProp.name); + if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { return false; } } - return true; } - function isSignatureIdenticalTo(source: Signature, target: Signature, reportErrors: boolean): boolean { - if (source === target) { - return true; + function signaturesRelatedTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): boolean { + if (relation === identityRelation) { + return signaturesIdenticalTo(source, target, kind, reportErrors); } - - if (source.hasRestParameter !== target.hasRestParameter) { - return false; - } - - if (source.parameters.length !== target.parameters.length) { - return false; - } - - if (source.minArgumentCount !== target.minArgumentCount) { - return false; - } - - if (source.typeParameters && target.typeParameters) { - if (source.typeParameters.length !== target.typeParameters.length) { - return false; - } - - for (var i = 0, len = source.typeParameters.length; i < len; ++i) { - if (!isRelatedTo(source.typeParameters[i], target.typeParameters[i], reportErrors)) { - return false; - } - } - } - else if (source.typeParameters || source.typeParameters) { - return false; - } - - // Spec 1.0 Section 3.8.3 & 3.8.4: - // M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N - source = getErasedSignature(source); - target = getErasedSignature(target); - for (var i = 0, len = source.parameters.length; i < len; i++) { - var s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]); - var t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]); - if (!isRelatedTo(s, t, reportErrors)) { - return false; - } - } - var t = getReturnTypeOfSignature(target); - var s = getReturnTypeOfSignature(source); - return isRelatedTo(s, t, reportErrors); - } - - function areSignaturesSubtypeOrAssignableTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): boolean { if (target === anyFunctionType || source === anyFunctionType) return true; var sourceSignatures = getSignaturesOfType(source, kind); var targetSignatures = getSignaturesOfType(target, kind); @@ -3259,7 +3549,7 @@ module ts { for (var j = 0; j < sourceSignatures.length; j++) { var s = sourceSignatures[j]; if (!s.hasStringLiterals || source.flags & TypeFlags.FromSignature) { - if (isSignatureSubtypeOrAssignableTo(s, t, localErrors)) { + if (signatureRelatedTo(s, t, localErrors)) { errorInfo = saveErrorInfo; continue outer; } @@ -3273,15 +3563,13 @@ module ts { return true; } - function isSignatureSubtypeOrAssignableTo(source: Signature, target: Signature, reportErrors: boolean): boolean { + function signatureRelatedTo(source: Signature, target: Signature, reportErrors: boolean): boolean { if (source === target) { return true; } - if (!target.hasRestParameter && source.minArgumentCount > target.parameters.length) { return false; } - var sourceMax = source.parameters.length; var targetMax = target.parameters.length; var checkCount: number; @@ -3327,71 +3615,117 @@ module ts { return isRelatedTo(s, t, reportErrors); } + function signaturesIdenticalTo(source: ObjectType, target: ObjectType, kind: SignatureKind, reportErrors: boolean): boolean { + var sourceSignatures = getSignaturesOfType(source, kind); + var targetSignatures = getSignaturesOfType(target, kind); + if (sourceSignatures.length !== targetSignatures.length) { + return false; + } + for (var i = 0, len = sourceSignatures.length; i < len; ++i) { + if (!compareSignatures(sourceSignatures[i], targetSignatures[i], /*compareReturnTypes*/ true, isRelatedTo)) { + return false; + } + } + return true; + } + function stringIndexTypesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { if (relation === identityRelation) { - return areIndexTypesIdenticalTo(IndexKind.String, source, target, reportErrors); + return indexTypesIdenticalTo(IndexKind.String, source, target, reportErrors); } - else { - var targetType = getIndexTypeOfType(target, IndexKind.String); - if (targetType) { - var sourceType = getIndexTypeOfType(source, IndexKind.String); - if (!sourceType) { - if (reportErrors) { - reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return false; - } - if (!isRelatedTo(sourceType, targetType, reportErrors)) { - if (reportErrors) { - reportError(Diagnostics.Index_signatures_are_incompatible_Colon); - } - return false; + var targetType = getIndexTypeOfType(target, IndexKind.String); + if (targetType) { + var sourceType = getIndexTypeOfType(source, IndexKind.String); + if (!sourceType) { + if (reportErrors) { + reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } + return false; + } + if (!isRelatedTo(sourceType, targetType, reportErrors)) { + if (reportErrors) { + reportError(Diagnostics.Index_signatures_are_incompatible_Colon); + } + return false; } - return true; } + return true; } function numberIndexTypesRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { if (relation === identityRelation) { - return areIndexTypesIdenticalTo(IndexKind.Number, source, target, reportErrors); + return indexTypesIdenticalTo(IndexKind.Number, source, target, reportErrors); } - else { - var targetType = getIndexTypeOfType(target, IndexKind.Number); - if (targetType) { - var sourceStringType = getIndexTypeOfType(source, IndexKind.String); - var sourceNumberType = getIndexTypeOfType(source, IndexKind.Number); - if (!(sourceStringType || sourceNumberType)) { - if (reportErrors) { - reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); - } - return false; - } - if (sourceStringType && sourceNumberType) { - // If we know for sure we're testing both string and numeric index types then only report errors from the second one - var compatible = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors); - } - else { - var compatible = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); - } - if (!compatible) { - if (reportErrors) { - reportError(Diagnostics.Index_signatures_are_incompatible_Colon); - } - return false; + var targetType = getIndexTypeOfType(target, IndexKind.Number); + if (targetType) { + var sourceStringType = getIndexTypeOfType(source, IndexKind.String); + var sourceNumberType = getIndexTypeOfType(source, IndexKind.Number); + if (!(sourceStringType || sourceNumberType)) { + if (reportErrors) { + reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } + return false; + } + if (sourceStringType && sourceNumberType) { + // If we know for sure we're testing both string and numeric index types then only report errors from the second one + var compatible = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors); + } + else { + var compatible = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); + } + if (!compatible) { + if (reportErrors) { + reportError(Diagnostics.Index_signatures_are_incompatible_Colon); + } + return false; } - return true; } + return true; } - function areIndexTypesIdenticalTo(indexKind: IndexKind, source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { + function indexTypesIdenticalTo(indexKind: IndexKind, source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { var targetType = getIndexTypeOfType(target, indexKind); var sourceType = getIndexTypeOfType(source, indexKind); return (!sourceType && !targetType) || (sourceType && targetType && isRelatedTo(sourceType, targetType, reportErrors)); } } + function compareSignatures(source: Signature, target: Signature, compareReturnTypes: boolean, compareTypes: (s: Type, t: Type) => boolean): boolean { + if (source === target) { + return true; + } + if (source.parameters.length !== target.parameters.length || + source.minArgumentCount !== target.minArgumentCount || + source.hasRestParameter !== target.hasRestParameter) { + return false; + } + if (source.typeParameters && target.typeParameters) { + if (source.typeParameters.length !== target.typeParameters.length) { + return false; + } + for (var i = 0, len = source.typeParameters.length; i < len; ++i) { + if (!compareTypes(source.typeParameters[i], target.typeParameters[i])) { + return false; + } + } + } + else if (source.typeParameters || source.typeParameters) { + return false; + } + // Spec 1.0 Section 3.8.3 & 3.8.4: + // M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N + source = getErasedSignature(source); + target = getErasedSignature(target); + for (var i = 0, len = source.parameters.length; i < len; i++) { + var s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]); + var t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]); + if (!compareTypes(s, t)) { + return false; + } + } + return !compareReturnTypes || compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); + } + function isSupertypeOfEach(candidate: Type, types: Type[]): boolean { for (var i = 0, len = types.length; i < len; i++) { if (candidate !== types[i] && !isTypeSubtypeOf(types[i], candidate)) return false; @@ -3399,9 +3733,8 @@ module ts { return true; } - function getBestCommonType(types: Type[], contextualType?: Type, candidatesOnly?: boolean): Type { - if (contextualType && isSupertypeOfEach(contextualType, types)) return contextualType; - return forEach(types, t => isSupertypeOfEach(t, types) ? t : undefined) || (candidatesOnly ? undefined : emptyObjectType); + function getCommonSupertype(types: Type[]): Type { + return forEach(types, t => isSupertypeOfEach(t, types) ? t : undefined); } function isTypeOfObjectLiteral(type: Type): boolean { @@ -3420,10 +3753,13 @@ module ts { } /* If we are widening on a literal, then we may need to the 'node' parameter for reporting purposes */ - function getWidenedType(type: Type, supressNoImplicitAnyErrors?: boolean): Type { + function getWidenedType(type: Type, suppressNoImplicitAnyErrors?: boolean): Type { if (type.flags & (TypeFlags.Undefined | TypeFlags.Null)) { return anyType; } + if (type.flags & TypeFlags.Union) { + return getWidenedTypeOfUnion(type); + } if (isTypeOfObjectLiteral(type)) { return getWidenedTypeOfObjectLiteral(type); } @@ -3432,8 +3768,12 @@ module ts { } return type; + function getWidenedTypeOfUnion(type: Type): Type { + return getUnionType(map((type).types, t => getWidenedType(t, suppressNoImplicitAnyErrors))); + } + function getWidenedTypeOfObjectLiteral(type: Type): Type { - var properties = getPropertiesOfType(type); + var properties = getPropertiesOfObjectType(type); if (properties.length) { var widenedTypes: Type[] = []; var propTypeWasWidened: boolean = false; @@ -3442,8 +3782,7 @@ module ts { var widenedType = getWidenedType(propType); if (propType !== widenedType) { propTypeWasWidened = true; - - if (!supressNoImplicitAnyErrors && program.getCompilerOptions().noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (!suppressNoImplicitAnyErrors && compilerOptions.noImplicitAny && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(widenedType)); } } @@ -3453,7 +3792,7 @@ module ts { var members: SymbolTable = {}; var index = 0; forEach(properties, p => { - var symbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, p.name); + var symbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | p.flags, p.name); symbol.declarations = p.declarations; symbol.parent = p.parent; symbol.type = widenedTypes[index++]; @@ -3473,10 +3812,8 @@ module ts { function getWidenedTypeOfArrayLiteral(type: Type): Type { var elementType = (type).typeArguments[0]; - var widenedType = getWidenedType(elementType, supressNoImplicitAnyErrors); - + var widenedType = getWidenedType(elementType, suppressNoImplicitAnyErrors); type = elementType !== widenedType ? createArrayType(widenedType) : type; - return type; } } @@ -3508,11 +3845,13 @@ module ts { } } - function createInferenceContext(typeParameters: TypeParameter[]): InferenceContext { + function createInferenceContext(typeParameters: TypeParameter[], inferUnionTypes: boolean): InferenceContext { var inferences: Type[][] = []; for (var i = 0; i < typeParameters.length; i++) inferences.push([]); return { typeParameters: typeParameters, + inferUnionTypes: inferUnionTypes, + inferenceCount: 0, inferences: inferences, inferredTypes: new Array(typeParameters.length), }; @@ -3550,6 +3889,7 @@ module ts { var typeParameters = context.typeParameters; for (var i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { + context.inferenceCount++; var inferences = context.inferences[i]; if (!contains(inferences, source)) inferences.push(source); break; @@ -3564,6 +3904,34 @@ module ts { inferFromTypes(sourceTypes[i], targetTypes[i]); } } + else if (target.flags & TypeFlags.Union) { + var targetTypes = (target).types; + var startCount = context.inferenceCount; + var typeParameterCount = 0; + var typeParameter: TypeParameter; + // First infer to each type in union that isn't a type parameter + for (var i = 0; i < targetTypes.length; i++) { + var t = targetTypes[i]; + if (t.flags & TypeFlags.TypeParameter && contains(context.typeParameters, t)) { + typeParameter = t; + typeParameterCount++; + } + else { + inferFromTypes(source, t); + } + } + // If no inferences were produced above and union contains a single naked type parameter, infer to that type parameter + if (context.inferenceCount === startCount && typeParameterCount === 1) { + inferFromTypes(source, typeParameter); + } + } + else if (source.flags & TypeFlags.Union) { + // Source is a union type, infer from each consituent type + var sourceTypes = (source).types; + for (var i = 0; i < sourceTypes.length; i++) { + inferFromTypes(sourceTypes[i], target); + } + } else if (source.flags & TypeFlags.ObjectType && (target.flags & (TypeFlags.Reference | TypeFlags.Tuple) || (target.flags & TypeFlags.Anonymous) && target.symbol && target.symbol.flags & (SymbolFlags.Method | SymbolFlags.TypeLiteral))) { // If source is an object type, and target is a type reference, a tuple type, the type of a method, or a type literal, infer from members @@ -3587,10 +3955,10 @@ module ts { } function inferFromProperties(source: Type, target: Type) { - var properties = getPropertiesOfType(target); + var properties = getPropertiesOfObjectType(target); for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; - var sourceProp = getPropertyOfType(source, targetProp.name); + var sourceProp = getPropertyOfObjectType(source, targetProp.name); if (sourceProp) { inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } @@ -3627,9 +3995,18 @@ module ts { function getInferredType(context: InferenceContext, index: number): Type { var result = context.inferredTypes[index]; if (!result) { - var commonType = getWidenedType(getBestCommonType(context.inferences[index])); + var inferences = context.inferences[index]; + if (inferences.length) { + // Infer widened union or supertype, or the undefined type for no common supertype + var unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences); + var inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : undefinedType; + } + else { + // Infer the empty object type when no inferences were made + inferredType = emptyObjectType; + } var constraint = getConstraintOfTypeParameter(context.typeParameters[index]); - var result = constraint && !isTypeAssignableTo(commonType, constraint) ? constraint : commonType; + var result = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType; context.inferredTypes[index] = result; } return result; @@ -3649,44 +4026,288 @@ module ts { // EXPRESSION TYPE CHECKING - function checkIdentifier(node: Identifier): Type { - function isInTypeQuery(node: Node): boolean { - // TypeScript 1.0 spec (April 2014): 3.6.3 - // A type query consists of the keyword typeof followed by an expression. - // The expression is restricted to a single identifier or a sequence of identifiers separated by periods - while (node) { - switch (node.kind) { - case SyntaxKind.TypeQuery: - return true; - case SyntaxKind.Identifier: - case SyntaxKind.QualifiedName: - node = node.parent; - continue; - default: - return false; + function getResolvedSymbol(node: Identifier): Symbol { + var links = getNodeLinks(node); + if (!links.resolvedSymbol) { + links.resolvedSymbol = resolveName(node, node.text, SymbolFlags.Value | SymbolFlags.ExportValue, Diagnostics.Cannot_find_name_0, identifierToString(node)) || unknownSymbol; + } + return links.resolvedSymbol; + } + + function isInTypeQuery(node: Node): boolean { + // TypeScript 1.0 spec (April 2014): 3.6.3 + // A type query consists of the keyword typeof followed by an expression. + // The expression is restricted to a single identifier or a sequence of identifiers separated by periods + while (node) { + switch (node.kind) { + case SyntaxKind.TypeQuery: + return true; + case SyntaxKind.Identifier: + case SyntaxKind.QualifiedName: + node = node.parent; + continue; + default: + return false; + } + } + Debug.fail("should not get here"); + } + + // Remove one or more primitive types from a union type + function subtractPrimitiveTypes(type: Type, subtractMask: TypeFlags): Type { + if (type.flags & TypeFlags.Union) { + var types = (type).types; + if (forEach(types, t => t.flags & subtractMask)) { + return getUnionType(filter(types, t => !(t.flags & subtractMask))); + } + } + return type; + } + + // Check if a given variable is assigned within a given syntax node + function isVariableAssignedWithin(symbol: Symbol, node: Node): boolean { + var links = getNodeLinks(node); + if (links.assignmentChecks) { + var cachedResult = links.assignmentChecks[symbol.id]; + if (cachedResult !== undefined) { + return cachedResult; + } + } + else { + links.assignmentChecks = {}; + } + return links.assignmentChecks[symbol.id] = isAssignedIn(node); + + function isAssignedInBinaryExpression(node: BinaryExpression) { + if (node.operator >= SyntaxKind.FirstAssignment && node.operator <= SyntaxKind.LastAssignment) { + var n = node.left; + while (n.kind === SyntaxKind.ParenExpression) { + n = (n).expression; + } + if (n.kind === SyntaxKind.Identifier && getResolvedSymbol(n) === symbol) { + return true; } } - Debug.fail("should not get here"); + return forEachChild(node, isAssignedIn); } - var symbol = resolveName(node, node.text, SymbolFlags.Value | SymbolFlags.ExportValue, Diagnostics.Cannot_find_name_0, identifierToString(node)); - if (!symbol) { - symbol = unknownSymbol; + function isAssignedInVariableDeclaration(node: VariableDeclaration) { + if (getSymbolOfNode(node) === symbol && node.initializer) { + return true; + } + return forEachChild(node, isAssignedIn); } + function isAssignedIn(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.BinaryExpression: + return isAssignedInBinaryExpression(node); + case SyntaxKind.VariableDeclaration: + return isAssignedInVariableDeclaration(node); + case SyntaxKind.ArrayLiteral: + case SyntaxKind.ObjectLiteral: + case SyntaxKind.PropertyAccess: + case SyntaxKind.IndexedAccess: + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.TypeAssertion: + case SyntaxKind.ParenExpression: + case SyntaxKind.PrefixOperator: + case SyntaxKind.PostfixOperator: + case SyntaxKind.ConditionalExpression: + case SyntaxKind.Block: + case SyntaxKind.VariableStatement: + case SyntaxKind.ExpressionStatement: + case SyntaxKind.IfStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.WhileStatement: + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ReturnStatement: + case SyntaxKind.WithStatement: + case SyntaxKind.SwitchStatement: + case SyntaxKind.CaseClause: + case SyntaxKind.DefaultClause: + case SyntaxKind.LabeledStatement: + case SyntaxKind.ThrowStatement: + case SyntaxKind.TryStatement: + case SyntaxKind.TryBlock: + case SyntaxKind.CatchBlock: + case SyntaxKind.FinallyBlock: + return forEachChild(node, isAssignedIn); + } + return false; + } + } + + // Get the narrowed type of a given symbol at a given location + function getNarrowedTypeOfSymbol(symbol: Symbol, node: Node) { + var type = getTypeOfSymbol(symbol); + // Only narrow when symbol is variable of a non-primitive type + if (symbol.flags & SymbolFlags.Variable && isTypeAnyOrObjectOrTypeParameter(type)) { + while (true) { + var child = node; + node = node.parent; + // Stop at containing function or module block + if (!node || node.kind === SyntaxKind.FunctionBlock || node.kind === SyntaxKind.ModuleBlock) { + break; + } + var narrowedType = type; + switch (node.kind) { + case SyntaxKind.IfStatement: + // In a branch of an if statement, narrow based on controlling expression + if (child !== (node).expression) { + narrowedType = narrowType(type, (node).expression, /*assumeTrue*/ child === (node).thenStatement); + } + break; + case SyntaxKind.ConditionalExpression: + // In a branch of a conditional expression, narrow based on controlling condition + if (child !== (node).condition) { + narrowedType = narrowType(type, (node).condition, /*assumeTrue*/ child === (node).whenTrue); + } + break; + case SyntaxKind.BinaryExpression: + // In the right operand of an && or ||, narrow based on left operand + if (child === (node).right) { + if ((node).operator === SyntaxKind.AmpersandAmpersandToken) { + narrowedType = narrowType(type, (node).left, /*assumeTrue*/ true); + } + else if ((node).operator === SyntaxKind.BarBarToken) { + narrowedType = narrowType(type, (node).left, /*assumeTrue*/ false); + } + } + break; + } + // Only use narrowed type if construct contains no assignments to variable + if (narrowedType !== type) { + if (isVariableAssignedWithin(symbol, node)) { + break; + } + type = narrowedType; + } + } + } + return type; + + function narrowTypeByEquality(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { + var left = expr.left; + var right = expr.right; + // Check that we have 'typeof ' on the left and string literal on the right + if (left.kind !== SyntaxKind.PrefixOperator || left.operator !== SyntaxKind.TypeOfKeyword || + left.operand.kind !== SyntaxKind.Identifier || right.kind !== SyntaxKind.StringLiteral || + getResolvedSymbol(left.operand) !== symbol) { + return type; + } + var t = right.text; + var checkType: Type = t === "string" ? stringType : t === "number" ? numberType : t === "boolean" ? booleanType : emptyObjectType; + if (expr.operator === SyntaxKind.ExclamationEqualsEqualsToken) { + assumeTrue = !assumeTrue; + } + if (assumeTrue) { + // The assumed result is true. If check was for a primitive type, that type is the narrowed type. Otherwise we can + // remove the primitive types from the narrowed type. + return checkType === emptyObjectType ? subtractPrimitiveTypes(type, TypeFlags.String | TypeFlags.Number | TypeFlags.Boolean) : checkType; + } + else { + // The assumed result is false. If check was for a primitive type we can remove that type from the narrowed type. + // Otherwise we don't have enough information to do anything. + return checkType === emptyObjectType ? type : subtractPrimitiveTypes(type, checkType.flags); + } + } + + function narrowTypeByAnd(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { + if (assumeTrue) { + // The assumed result is true, therefore we narrow assuming each operand to be true. + return narrowType(narrowType(type, expr.left, /*assumeTrue*/ true), expr.right, /*assumeTrue*/ true); + } + else { + // The assumed result is false. This means either the first operand was false, or the first operand was true + // and the second operand was false. We narrow with those assumptions and union the two resulting types. + return getUnionType([ + narrowType(type, expr.left, /*assumeTrue*/ false), + narrowType(narrowType(type, expr.left, /*assumeTrue*/ true), expr.right, /*assumeTrue*/ false) + ]); + } + } + + function narrowTypeByOr(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { + if (assumeTrue) { + // The assumed result is true. This means either the first operand was true, or the first operand was false + // and the second operand was true. We narrow with those assumptions and union the two resulting types. + return getUnionType([ + narrowType(type, expr.left, /*assumeTrue*/ true), + narrowType(narrowType(type, expr.left, /*assumeTrue*/ false), expr.right, /*assumeTrue*/ true) + ]); + } + else { + // The assumed result is false, therefore we narrow assuming each operand to be false. + return narrowType(narrowType(type, expr.left, /*assumeTrue*/ false), expr.right, /*assumeTrue*/ false); + } + } + + function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { + // Check that assumed result is true and we have variable symbol on the left + if (!assumeTrue || expr.left.kind !== SyntaxKind.Identifier || getResolvedSymbol(expr.left) !== symbol) { + return type; + } + // Check that right operand is a function type with a prototype property + var rightType = checkExpression(expr.right); + if (!isTypeSubtypeOf(rightType, globalFunctionType)) { + return type; + } + var prototypeProperty = getPropertyOfType(rightType, "prototype"); + if (!prototypeProperty) { + return type; + } + var prototypeType = getTypeOfSymbol(prototypeProperty); + // Narrow to type of prototype property if it is a subtype of current type + return isTypeSubtypeOf(prototypeType, type) ? prototypeType : type; + } + + // Narrow the given type based on the given expression having the assumed boolean value + function narrowType(type: Type, expr: Expression, assumeTrue: boolean): Type { + switch (expr.kind) { + case SyntaxKind.ParenExpression: + return narrowType(type, (expr).expression, assumeTrue); + case SyntaxKind.BinaryExpression: + var operator = (expr).operator; + if (operator === SyntaxKind.EqualsEqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken) { + return narrowTypeByEquality(type, expr, assumeTrue); + } + else if (operator === SyntaxKind.AmpersandAmpersandToken) { + return narrowTypeByAnd(type, expr, assumeTrue); + } + else if (operator === SyntaxKind.BarBarToken) { + return narrowTypeByOr(type, expr, assumeTrue); + } + else if (operator === SyntaxKind.InstanceOfKeyword) { + return narrowTypeByInstanceof(type, expr, assumeTrue); + } + break; + case SyntaxKind.PrefixOperator: + if ((expr).operator === SyntaxKind.ExclamationToken) { + return narrowType(type, (expr).operand, !assumeTrue); + } + break; + } + return type; + } + } + + function checkIdentifier(node: Identifier): Type { + var symbol = getResolvedSymbol(node); + if (symbol.flags & SymbolFlags.Import) { // Mark the import as referenced so that we emit it in the final .js file. // exception: identifiers that appear in type queries getSymbolLinks(symbol).referenced = !isInTypeQuery(node); } - getNodeLinks(node).resolvedSymbol = symbol; - checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); checkCollisionWithIndexVariableInGeneratedCode(node, node); - return getTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol)); + return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); } function captureLexicalThis(node: Node, container: Node): void { @@ -3961,6 +4582,54 @@ module ts { return undefined; } + // Apply a mapping function to a contextual type and return the resulting type. If the contextual type + // is a union type, the mapping function is applied to each constituent type and a union of the resulting + // types is returned. + function applyToContextualType(type: Type, mapper: (t: Type) => Type): Type { + if (!(type.flags & TypeFlags.Union)) { + return mapper(type); + } + var types = (type).types; + var mappedType: Type; + var mappedTypes: Type[]; + for (var i = 0; i < types.length; i++) { + var t = mapper(types[i]); + if (t) { + if (!mappedType) { + mappedType = t; + } + else if (!mappedTypes) { + mappedTypes = [mappedType, t]; + } + else { + mappedTypes.push(t); + } + } + } + return mappedTypes ? getUnionType(mappedTypes) : mappedType; + } + + function getTypeOfPropertyOfContextualType(type: Type, name: string) { + return applyToContextualType(type, t => { + var prop = getPropertyOfObjectType(t, name); + return prop ? getTypeOfSymbol(prop) : undefined; + }); + } + + function getIndexTypeOfContextualType(type: Type, kind: IndexKind) { + return applyToContextualType(type, t => getIndexTypeOfObjectOrUnionType(t, kind)); + } + + // Return true if the given contextual type is a tuple-like type + function contextualTypeIsTupleType(type: Type): boolean { + return !!(type.flags & TypeFlags.Union ? forEach((type).types, t => getPropertyOfObjectType(t, "0")) : getPropertyOfObjectType(type, "0")); + } + + // Return true if the given contextual type provides an index signature of the given kind + function contextualTypeHasIndexSignature(type: Type, kind: IndexKind): boolean { + return !!(type.flags & TypeFlags.Union ? forEach((type).types, t => getIndexTypeOfObjectOrUnionType(t, kind)) : getIndexTypeOfObjectOrUnionType(type, kind)); + } + // In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of // the matching property in T, if one exists. Otherwise, it is the type of the numeric index signature in T, if one // exists. Otherwise, it is the type of the string index signature in T, if one exists. @@ -3970,11 +4639,9 @@ module ts { var type = getContextualType(objectLiteral); var name = declaration.name.text; if (type && name) { - var prop = getPropertyOfType(type, name); - if (prop) { - return getTypeOfSymbol(prop); - } - return isNumericName(name) && getIndexTypeOfType(type, IndexKind.Number) || getIndexTypeOfType(type, IndexKind.String); + return getTypeOfPropertyOfContextualType(type, name) || + isNumericName(name) && getIndexTypeOfContextualType(type, IndexKind.Number) || + getIndexTypeOfContextualType(type, IndexKind.String); } return undefined; } @@ -3987,11 +4654,7 @@ module ts { var type = getContextualType(arrayLiteral); if (type) { var index = indexOf(arrayLiteral.elements, node); - var prop = getPropertyOfType(type, "" + index); - if (prop) { - return getTypeOfSymbol(prop); - } - return getIndexTypeOfType(type, IndexKind.Number); + return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, IndexKind.Number); } return undefined; } @@ -4009,7 +4672,6 @@ module ts { // We cannot answer semantic questions within a with block, do not proceed any further return undefined; } - if (node.contextualType) { return node.contextualType; } @@ -4039,18 +4701,44 @@ module ts { return undefined; } + // If the given type is an object or union type, if that type has a single signature, and if + // that signature is non-generic, return the signature. Otherwise return undefined. + function getNonGenericSignature(type: Type): Signature { + var signatures = getSignaturesOfObjectOrUnionType(type, SignatureKind.Call); + if (signatures.length === 1) { + var signature = signatures[0]; + if (!signature.typeParameters) { + return signature; + } + } + } + + // Return the contextual signature for a given expression node. A contextual type provides a + // contextual signature if it has a single call signature and if that call signature is non-generic. + // If the contextual type is a union type and each constituent type that has a contextual signature + // provides the same contextual signature, then the union type provides that contextual signature. function getContextualSignature(node: Expression): Signature { var type = getContextualType(node); - if (type) { - var signatures = getSignaturesOfType(type, SignatureKind.Call); - if (signatures.length === 1) { - var signature = signatures[0]; - if (!signature.typeParameters) { - return signature; + if (!type) { + return undefined; + } + if (!(type.flags & TypeFlags.Union)) { + return getNonGenericSignature(type); + } + var result: Signature; + var types = (type).types; + for (var i = 0; i < types.length; i++) { + var signature = getNonGenericSignature(types[i]); + if (signature) { + if (!result) { + result = signature; + } + else if (!compareSignatures(result, signature, /*compareReturnTypes*/ true, isTypeIdenticalTo)) { + return undefined; } } } - return undefined; + return result; } // Presence of a contextual type mapper indicates inferential typing, except the identityMapper object is @@ -4060,44 +4748,53 @@ module ts { } function checkArrayLiteral(node: ArrayLiteral, contextualMapper?: TypeMapper): Type { - var contextualType = getContextualType(node); var elements = node.elements; - var elementTypes: Type[] = []; - var isTupleLiteral: boolean = false; - for (var i = 0; i < elements.length; i++) { - if (contextualType && getPropertyOfType(contextualType, "" + i)) { - isTupleLiteral = true; - } - var element = elements[i]; - var type = element.kind !== SyntaxKind.OmittedExpression ? checkExpression(element, contextualMapper) : undefinedType; - elementTypes.push(type); + if (!elements.length) { + return createArrayType(undefinedType); } - if (isTupleLiteral) { + var elementTypes = map(elements, e => checkExpression(e, contextualMapper)); + var contextualType = getContextualType(node); + if (contextualType && contextualTypeIsTupleType(contextualType)) { return createTupleType(elementTypes); } - var contextualElementType = contextualType && !isInferentialContext(contextualMapper) ? getIndexTypeOfType(contextualType, IndexKind.Number) : undefined; - var elementType = getBestCommonType(uniqueElements(elementTypes), contextualElementType, true); - if (!elementType) { - elementType = elements.length ? emptyObjectType : undefinedType; - } - return createArrayType(elementType); + return createArrayType(getUnionType(elementTypes)); } function isNumericName(name: string) { - return !isNaN(name); + // The intent of numeric names is that + // - they are names with text in a numeric form, and that + // - setting properties/indexing with them is always equivalent to doing so with the numeric literal 'numLit', + // acquired by applying the abstract 'ToNumber' operation on the name's text. + // + // The subtlety is in the latter portion, as we cannot reliably say that anything that looks like a numeric literal is a numeric name. + // In fact, it is the case that the text of the name must be equal to 'ToString(numLit)' for this to hold. + // + // Consider the property name '"0xF00D"'. When one indexes with '0xF00D', they are actually indexing with the value of 'ToString(0xF00D)' + // according to the ECMAScript specification, so it is actually as if the user indexed with the string '"61453"'. + // Thus, the text of all numeric literals equivalent to '61543' such as '0xF00D', '0xf00D', '0170015', etc. are not valid numeric names + // because their 'ToString' representation is not equal to their original text. + // This is motivated by ECMA-262 sections 9.3.1, 9.8.1, 11.1.5, and 11.2.1. + // + // Here, we test whether 'ToString(ToNumber(name))' is exactly equal to 'name'. + // The '+' prefix operator is equivalent here to applying the abstract ToNumber operation. + // Applying the 'toString()' method on a number gives us the abstract ToString operation on a number. + // + // Note that this accepts the values 'Infinity', '-Infinity', and 'NaN', and that this is intentional. + // This is desired behavior, because when indexing with them as numeric entities, you are indexing + // with the strings '"Infinity"', '"-Infinity"', and '"NaN"' respectively. + return (+name).toString() === name; } function checkObjectLiteral(node: ObjectLiteral, contextualMapper?: TypeMapper): Type { var members = node.symbol.members; var properties: SymbolTable = {}; var contextualType = getContextualType(node); - for (var id in members) { if (hasProperty(members, id)) { var member = members[id]; if (member.flags & SymbolFlags.Property) { var type = checkExpression((member.declarations[0]).initializer, contextualMapper); - var prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, member.name); + var prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name); prop.declarations = member.declarations; prop.parent = member.parent; if (member.valueDeclaration) prop.valueDeclaration = member.valueDeclaration; @@ -4129,21 +4826,21 @@ module ts { return createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType); function getIndexType(kind: IndexKind) { - if (contextualType) { - var indexType = getIndexTypeOfType(contextualType, kind); - if (indexType) { - var propTypes: Type[] = []; - for (var id in properties) { - if (hasProperty(properties, id)) { - if (kind === IndexKind.String || isNumericName(id)) { - var type = getTypeOfSymbol(properties[id]); - if (!contains(propTypes, type)) propTypes.push(type); + if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { + var propTypes: Type[] = []; + for (var id in properties) { + if (hasProperty(properties, id)) { + if (kind === IndexKind.String || isNumericName(id)) { + var type = getTypeOfSymbol(properties[id]); + if (!contains(propTypes, type)) { + propTypes.push(type); } } } - return getBestCommonType(propTypes, isInferentialContext(contextualMapper) ? undefined : indexType); } + return propTypes.length ? getUnionType(propTypes) : undefinedType; } + return undefined; } } @@ -4200,11 +4897,11 @@ module ts { if (type === unknownType) return type; if (type !== anyType) { var apparentType = getApparentType(getWidenedType(type)); - if (apparentType === unknownType) { + if (apparentType === unknownType) { // handle cases when type is Type parameter with invalid constraint return unknownType; } - var prop = getPropertyOfApparentType(apparentType, node.right.text); + var prop = getPropertyOfType(apparentType, node.right.text); if (!prop) { if (node.right.text) { error(node.right, Diagnostics.Property_0_does_not_exist_on_type_1, identifierToString(node.right), typeToString(type)); @@ -4235,8 +4932,7 @@ module ts { function isValidPropertyAccess(node: PropertyAccess, propertyName: string): boolean { var type = checkExpression(node.left); if (type !== unknownType && type !== anyType) { - var apparentType = getApparentType(getWidenedType(type)); - var prop = getPropertyOfApparentType(apparentType, propertyName); + var prop = getPropertyOfType(getWidenedType(type), propertyName); if (prop && prop.parent && prop.parent.flags & SymbolFlags.Class) { if (node.left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) { return false; @@ -4252,8 +4948,10 @@ module ts { } function checkIndexedAccess(node: IndexedAccess): Type { - var objectType = checkExpression(node.object); + // Obtain base constraint such that we can bail out if the constraint is an unknown type + var objectType = getApparentType(checkExpression(node.object)); var indexType = checkExpression(node.index); + if (objectType === unknownType) return unknownType; // TypeScript 1.0 spec (April 2014): 4.10 Property Access @@ -4266,14 +4964,9 @@ module ts { // - Otherwise, if IndexExpr is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any. // See if we can index as a property. - var apparentType = getApparentType(objectType); - if (apparentType === unknownType) { - // handle cases when objectType is type parameter with invalid type - return unknownType; - } if (node.index.kind === SyntaxKind.StringLiteral || node.index.kind === SyntaxKind.NumericLiteral) { var name = (node.index).text; - var prop = getPropertyOfApparentType(apparentType, name); + var prop = getPropertyOfType(objectType, name); if (prop) { return getTypeOfSymbol(prop); } @@ -4284,14 +4977,14 @@ module ts { // Try to use a number indexer. if (indexType.flags & (TypeFlags.Any | TypeFlags.NumberLike)) { - var numberIndexType = getIndexTypeOfType(apparentType, IndexKind.Number); + var numberIndexType = getIndexTypeOfType(objectType, IndexKind.Number); if (numberIndexType) { return numberIndexType; } } // Try to use string indexing. - var stringIndexType = getIndexTypeOfType(apparentType, IndexKind.String); + var stringIndexType = getIndexTypeOfType(objectType, IndexKind.String); if (stringIndexType) { return stringIndexType; } @@ -4354,7 +5047,7 @@ module ts { // If type has a single call signature and no other members, return that signature. Otherwise, return undefined. function getSingleCallSignature(type: Type): Signature { if (type.flags & TypeFlags.ObjectType) { - var resolved = resolveObjectTypeMembers(type); + var resolved = resolveObjectOrUnionTypeMembers(type); if (resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0 && resolved.properties.length === 0 && !resolved.stringIndexType && !resolved.numberIndexType) { return resolved.callSignatures[0]; @@ -4365,7 +5058,7 @@ module ts { // Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec) function instantiateSignatureInContextOf(signature: Signature, contextualSignature: Signature, contextualMapper: TypeMapper): Signature { - var context = createInferenceContext(signature.typeParameters); + var context = createInferenceContext(signature.typeParameters, /*inferUnionTypes*/ true); forEachMatchingParameterType(contextualSignature, signature, (source, target) => { // Type parameters from outer context referenced by source type are fixed by instantiation of the source type inferTypes(context, instantiateType(source, contextualMapper), target); @@ -4375,7 +5068,7 @@ module ts { function inferTypeArguments(signature: Signature, args: Expression[], excludeArgument?: boolean[]): Type[] { var typeParameters = signature.typeParameters; - var context = createInferenceContext(typeParameters); + var context = createInferenceContext(typeParameters, /*inferUnionTypes*/ false); var mapper = createInferenceMapper(context); // First infer from arguments that are not context sensitive for (var i = 0; i < args.length; i++) { @@ -4399,7 +5092,9 @@ module ts { } } } - return getInferredTypes(context); + var inferredTypes = getInferredTypes(context); + // Inference has failed if the undefined type is in list of inferences + return contains(inferredTypes, undefinedType) ? undefined : inferredTypes; } function checkTypeArguments(signature: Signature, typeArguments: TypeNode[]): Type[] { @@ -4424,7 +5119,6 @@ module ts { if (arg.kind === SyntaxKind.OmittedExpression) { continue; } - var paramType = getTypeAtPosition(signature, i); // String literals get string literal types unless we're reporting errors var argType = arg.kind === SyntaxKind.StringLiteral && !reportErrors ? @@ -4460,26 +5154,30 @@ module ts { } } var relation = candidates.length === 1 ? assignableRelation : subtypeRelation; + var lastCandidate: Signature; while (true) { for (var i = 0; i < candidates.length; i++) { if (!signatureHasCorrectArity(node, candidates[i])) { continue; } - while (true) { - var candidateWithCorrectArity = candidates[i]; - if (candidateWithCorrectArity.typeParameters) { + var candidate = candidates[i]; + if (candidate.typeParameters) { var typeArguments = node.typeArguments ? - checkTypeArguments(candidateWithCorrectArity, node.typeArguments) : - inferTypeArguments(candidateWithCorrectArity, args, excludeArgument); - candidateWithCorrectArity = getSignatureInstantiation(candidateWithCorrectArity, typeArguments); + checkTypeArguments(candidate, node.typeArguments) : + inferTypeArguments(candidate, args, excludeArgument); + if (!typeArguments) { + break; + } + candidate = getSignatureInstantiation(candidate, typeArguments); } - if (!checkApplicableSignature(node, candidateWithCorrectArity, relation, excludeArgument, /*reportErrors*/ false)) { + lastCandidate = candidate; + if (!checkApplicableSignature(node, candidate, relation, excludeArgument, /*reportErrors*/ false)) { break; } var index = excludeArgument ? indexOf(excludeArgument, true) : -1; if (index < 0) { - return candidateWithCorrectArity; + return candidate; } excludeArgument[index] = false; } @@ -4494,8 +5192,8 @@ module ts { // no arguments excluded from assignability checks. // If candidate is undefined, it means that no candidates had a suitable arity. In that case, // skip the checkApplicableSignature check. - if (candidateWithCorrectArity) { - checkApplicableSignature(node, candidateWithCorrectArity, relation, /*excludeArgument*/ undefined, /*reportErrors*/ true); + if (lastCandidate) { + checkApplicableSignature(node, lastCandidate, relation, /*excludeArgument*/ undefined, /*reportErrors*/ true); } else { error(node, Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target); @@ -4571,18 +5269,13 @@ module ts { } var funcType = checkExpression(node.func); - if (funcType === unknownType) { + var apparentType = getApparentType(funcType); + + if (apparentType === unknownType) { // Another error has already been reported return resolveErrorCall(node); } - var apparentType = getApparentType(funcType); - if (apparentType === unknownType) { - // handler cases when funcType is type parameter with invalid constraint - // Another error was already reported - return resolveErrorCall(node); - } - // Technically, this signatures list may be incomplete. We are taking the apparent type, // but we are not including call signatures that may have been added to the Object or // Function interface, since they have none by default. This is a bit of a leap of faith @@ -4595,7 +5288,9 @@ module ts { // but is a subtype of the Function interface, the call is an untyped function call. In an // untyped function call no TypeArgs are permitted, Args can be any argument list, no contextual // types are provided for the argument expressions, and the result is always of type Any. - if ((funcType === anyType) || (!callSignatures.length && !constructSignatures.length && isTypeAssignableTo(funcType, globalFunctionType))) { + // We exclude union types because we may have a union of function types that happen to have + // no common signatures. + if (funcType === anyType || (!callSignatures.length && !constructSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) { if (node.typeArguments) { error(node, Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } @@ -4618,10 +5313,7 @@ module ts { function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature { var expressionType = checkExpression(node.func); - if (expressionType === unknownType) { - // Another error has already been reported - return resolveErrorCall(node); - } + // TS 1.0 spec: 4.11 // If ConstructExpr is of type Any, Args can be any argument // list and the result of the operation is of type Any. @@ -4629,7 +5321,6 @@ module ts { if (node.typeArguments) { error(node, Diagnostics.Untyped_function_calls_may_not_accept_type_arguments); } - return resolveUntypedCall(node); } @@ -4639,9 +5330,8 @@ module ts { // signatures for overload resolution.The result type of the function call becomes // the result type of the operation. expressionType = getApparentType(expressionType); - if (expressionType === unknownType) { - // handler cases when original expressionType is a type parameter with invalid constraint - // another error has already been reported + if (expressionType === unknownType) { + // Another error has already been reported return resolveErrorCall(node); } @@ -4739,11 +5429,12 @@ module ts { } function getReturnTypeFromBody(func: FunctionDeclaration, contextualMapper?: TypeMapper): Type { + var contextualSignature = getContextualSignature(func); if (func.body.kind !== SyntaxKind.FunctionBlock) { var unwidenedType = checkAndMarkExpression(func.body, contextualMapper); var widenedType = getWidenedType(unwidenedType); - if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { error(func, Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeToString(widenedType)); } @@ -4755,7 +5446,9 @@ module ts { // Try to return the best common type if we have any return expressions. if (types.length > 0) { - var commonType = getBestCommonType(types, /*contextualType:*/ undefined, /*candidatesOnly:*/ true); + // When return statements are contextually typed we allow the return type to be a union type. Otherwise we require the + // return expressions to have a best common supertype. + var commonType = contextualSignature ? getUnionType(types) : getCommonSupertype(types); if (!commonType) { error(func, Diagnostics.No_best_common_type_exists_among_return_expressions); @@ -4765,7 +5458,7 @@ module ts { var widenedType = getWidenedType(commonType); // Check and report for noImplicitAny if the best common type implicitly gets widened to an 'any'/arrays-of-'any' type. - if (fullTypeCheck && compilerOptions.noImplicitAny && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { + if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== commonType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) { var typeName = typeToString(widenedType); if (func.name) { @@ -4986,8 +5679,8 @@ module ts { return numberType; } - function isTypeAnyTypeObjectTypeOrTypeParameter(type: Type): boolean { - return type === anyType || ((type.flags & (TypeFlags.ObjectType | TypeFlags.TypeParameter)) !== 0); + function isTypeAnyOrObjectOrTypeParameter(type: Type): boolean { + return (type.flags & (TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) !== 0; } function checkInstanceOfExpression(node: BinaryExpression, leftType: Type, rightType: Type): Type { @@ -4996,7 +5689,7 @@ module ts { // and the right operand to be of type Any or a subtype of the 'Function' interface type. // The result is always of the Boolean primitive type. // NOTE: do not raise error if leftType is unknown as related error was already reported - if (leftType !== unknownType && !isTypeAnyTypeObjectTypeOrTypeParameter(leftType)) { + if (leftType !== unknownType && !isTypeAnyOrObjectOrTypeParameter(leftType)) { error(node.left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } // NOTE: do not raise error if right is unknown as related error was already reported @@ -5014,7 +5707,7 @@ module ts { if (leftType !== anyType && leftType !== stringType && leftType !== numberType) { error(node.left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number); } - if (!isTypeAnyTypeObjectTypeOrTypeParameter(rightType)) { + if (!isTypeAnyOrObjectOrTypeParameter(rightType)) { error(node.right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter); } return booleanType; @@ -5115,7 +5808,7 @@ module ts { case SyntaxKind.GreaterThanToken: case SyntaxKind.LessThanEqualsToken: case SyntaxKind.GreaterThanEqualsToken: - if (!isTypeSubtypeOf(leftType, rightType) && !isTypeSubtypeOf(rightType, leftType)) { + if (!isTypeAssignableTo(leftType, rightType) && !isTypeAssignableTo(rightType, leftType)) { reportOperatorError(); } return booleanType; @@ -5126,7 +5819,7 @@ module ts { case SyntaxKind.AmpersandAmpersandToken: return rightType; case SyntaxKind.BarBarToken: - return getBestCommonType([leftType, rightType], isInferentialContext(contextualMapper) ? undefined : getContextualType(node)); + return getUnionType([leftType, rightType]); case SyntaxKind.EqualsToken: checkAssignmentOperator(rightType); return rightType; @@ -5176,18 +5869,7 @@ module ts { checkExpression(node.condition); var type1 = checkExpression(node.whenTrue, contextualMapper); var type2 = checkExpression(node.whenFalse, contextualMapper); - var contextualType = isInferentialContext(contextualMapper) ? undefined : getContextualType(node); - var resultType = getBestCommonType([type1, type2], contextualType, true); - if (!resultType) { - if (contextualType) { - error(node, Diagnostics.No_best_common_type_exists_between_0_1_and_2, typeToString(contextualType), typeToString(type1), typeToString(type2)); - } - else { - error(node, Diagnostics.No_best_common_type_exists_between_0_and_1, typeToString(type1), typeToString(type2)); - } - resultType = emptyObjectType; - } - return resultType; + return getUnionType([type1, type2]); } function checkExpressionWithContextualType(node: Expression, contextualType: Type, contextualMapper?: TypeMapper): Type { @@ -5275,6 +5957,8 @@ module ts { return checkBinaryExpression(node, contextualMapper); case SyntaxKind.ConditionalExpression: return checkConditionalExpression(node, contextualMapper); + case SyntaxKind.OmittedExpression: + return undefinedType; } return unknownType; } @@ -5579,6 +6263,10 @@ module ts { forEach(node.elementTypes, checkSourceElement); } + function checkUnionType(node: UnionTypeNode) { + forEach(node.types, checkSourceElement); + } + function isPrivateWithinAmbient(node: Node): boolean { return (node.flags & NodeFlags.Private) && isInAmbientContext(node); } @@ -6240,7 +6928,7 @@ module ts { var exprType = checkExpression(node.expression); // unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved // in this case error about missing name is already reported - do not report extra one - if (!isTypeAnyTypeObjectTypeOrTypeParameter(exprType) && exprType !== unknownType) { + if (!isTypeAnyOrObjectOrTypeParameter(exprType) && exprType !== unknownType) { error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } @@ -6345,7 +7033,7 @@ module ts { // for interfaces property and indexer might be inherited from different bases // check if any base class already has both property and indexer. // check should be performed only if 'type' is the first type that brings property\indexer together - var someBaseClassHasBothPropertyAndIndexer = forEach((type).baseTypes, base => getPropertyOfType(base, prop.name) && getIndexTypeOfType(base, indexKind)); + var someBaseClassHasBothPropertyAndIndexer = forEach((type).baseTypes, base => getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind)); errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : type.symbol.declarations[0]; } @@ -6365,7 +7053,7 @@ module ts { var numberIndexType = getIndexTypeOfType(type, IndexKind.Number); if (stringIndexType || numberIndexType) { - forEach(getPropertiesOfType(type), prop => { + forEach(getPropertiesOfObjectType(type), prop => { var propType = getTypeOfSymbol(prop); checkIndexConstraintForProperty(prop, propType, declaredStringIndexer, stringIndexType, IndexKind.String); checkIndexConstraintForProperty(prop, propType, declaredNumberIndexer, numberIndexType, IndexKind.Number); @@ -6497,7 +7185,7 @@ module ts { // derived class instance member variables and accessors, but not by other kinds of members. // NOTE: assignability is checked in checkClassDeclaration - var baseProperties = getPropertiesOfType(baseType); + var baseProperties = getPropertiesOfObjectType(baseType); for (var i = 0, len = baseProperties.length; i < len; ++i) { var base = getTargetSymbol(baseProperties[i]); @@ -6505,7 +7193,7 @@ module ts { continue; } - var derived = getTargetSymbol(getPropertyOfType(type, base.name)); + var derived = getTargetSymbol(getPropertyOfObjectType(type, base.name)); if (derived) { var baseDeclarationFlags = getDeclarationFlagsFromSymbol(base); var derivedDeclarationFlags = getDeclarationFlagsFromSymbol(derived); @@ -6643,6 +7331,9 @@ module ts { var ambient = isInAmbientContext(node); forEach(node.members, member => { + if(isNumericName(member.name.text)) { + error(member.name, Diagnostics.An_enum_member_cannot_have_a_numeric_name); + } var initializer = member.initializer; if (initializer) { autoValue = getConstantValueForExpression(initializer); @@ -6859,6 +7550,10 @@ module ts { return checkArrayType(node); case SyntaxKind.TupleType: return checkTupleType(node); + case SyntaxKind.UnionType: + return checkUnionType(node); + case SyntaxKind.ParenType: + return checkSourceElement((node).type); case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(node); case SyntaxKind.Block: @@ -7421,8 +8116,8 @@ module ts { var objectType = checkExpression((node.parent).object); if (objectType === unknownType) return undefined; var apparentType = getApparentType(objectType); - if (apparentType === unknownType) return undefined; - return getPropertyOfApparentType(apparentType, (node).text); + if (apparentType === unknownType) return undefined; + return getPropertyOfType(apparentType, (node).text); } break; } @@ -7481,45 +8176,37 @@ module ts { return checkExpression(expr); } - function getAugmentedPropertiesOfApparentType(type: Type): Symbol[]{ - var apparentType = getApparentType(type); - - if (apparentType.flags & TypeFlags.ObjectType) { - // Augment the apparent type with Function and Object members as applicable - var propertiesByName: Map = {}; - var results: Symbol[] = []; - - forEach(getPropertiesOfType(apparentType), s => { - propertiesByName[s.name] = s; - results.push(s); - }); - - var resolved = resolveObjectTypeMembers(type); - forEachValue(resolved.members, s => { - if (symbolIsValue(s) && !propertiesByName[s.name]) { - propertiesByName[s.name] = s; - results.push(s); + // Return the list of properties of the given type, augmented with properties from Function + // if the type has call or construct signatures + function getAugmentedPropertiesOfType(type: Type): Symbol[] { + var type = getApparentType(type); + var propsByName = createSymbolTable(getPropertiesOfType(type)); + if (getSignaturesOfType(type, SignatureKind.Call).length || getSignaturesOfType(type, SignatureKind.Construct).length) { + forEach(getPropertiesOfType(globalFunctionType), p => { + if (!hasProperty(propsByName, p.name)) { + propsByName[p.name] = p; } }); - - if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) { - forEach(getPropertiesOfType(globalFunctionType), s => { - if (!propertiesByName[s.name]) { - propertiesByName[s.name] = s; - results.push(s); - } - }); - } - - return results; - } - else { - return getPropertiesOfType(apparentType); } + return getNamedMembers(propsByName); } - function getRootSymbol(symbol: Symbol) { - return ((symbol.flags & SymbolFlags.Transient) && getSymbolLinks(symbol).target) || symbol; + function getRootSymbols(symbol: Symbol): Symbol[]{ + if (symbol.flags & SymbolFlags.UnionProperty) { + var symbols: Symbol[] = []; + var name = symbol.name; + forEach(getSymbolLinks(symbol).unionType.types, t => { + symbols.push(getPropertyOfType(t, name)); + }); + return symbols; + } + else if (symbol.flags & SymbolFlags.Transient) { + var target = getSymbolLinks(symbol).target; + if (target) { + return [target]; + } + } + return [symbol]; } // Emitter support @@ -7671,12 +8358,12 @@ module ts { var symbol = getSymbolOfNode(location); var type = symbol && !(symbol.flags & SymbolFlags.TypeLiteral) ? getTypeOfSymbol(symbol) : getTypeFromTypeNode(location); - writeType(type, writer, enclosingDeclaration, flags); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); } function writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) { var signature = getSignatureFromDeclaration(signatureDeclaration); - writeType(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags); + getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags); } function invokeEmitter(targetSourceFile?: SourceFile) { diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 3da94137fc8..ee7f4701d19 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -82,7 +82,7 @@ module ts { return array1.concat(array2); } - export function uniqueElements(array: T[]): T[] { + export function deduplicate(array: T[]): T[] { if (array) { var result: T[] = []; for (var i = 0, len = array.length; i < len; i++) { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index dec1c00027b..ac2a79c603d 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -114,6 +114,7 @@ module ts { Cannot_compile_external_modules_unless_the_module_flag_is_provided: { code: 1148, category: DiagnosticCategory.Error, key: "Cannot compile external modules unless the '--module' flag is provided." }, Filename_0_differs_from_already_included_filename_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "Filename '{0}' differs from already included filename '{1}' only in casing" }, new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array()' instead." }, + An_enum_member_cannot_have_a_numeric_name: { code: 1151, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -180,8 +181,6 @@ module ts { The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2363, category: DiagnosticCategory.Error, key: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." }, Invalid_left_hand_side_of_assignment_expression: { code: 2364, category: DiagnosticCategory.Error, key: "Invalid left-hand side of assignment expression." }, Operator_0_cannot_be_applied_to_types_1_and_2: { code: 2365, category: DiagnosticCategory.Error, key: "Operator '{0}' cannot be applied to types '{1}' and '{2}'." }, - No_best_common_type_exists_between_0_1_and_2: { code: 2366, category: DiagnosticCategory.Error, key: "No best common type exists between '{0}', '{1}', and '{2}'." }, - No_best_common_type_exists_between_0_and_1: { code: 2367, category: DiagnosticCategory.Error, key: "No best common type exists between '{0}' and '{1}'." }, Type_parameter_name_cannot_be_0: { code: 2368, category: DiagnosticCategory.Error, key: "Type parameter name cannot be '{0}'" }, A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2369, category: DiagnosticCategory.Error, key: "A parameter property is only allowed in a constructor implementation." }, A_rest_parameter_must_be_of_an_array_type: { code: 2370, category: DiagnosticCategory.Error, key: "A rest parameter must be of an array type." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 79208be1a0d..d8895d15144 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -11,7 +11,7 @@ "category": "Error", "code": 1005 }, - "A file cannot have a reference to itself.": { + "A file cannot have a reference to itself.": { "category": "Error", "code": 1006 }, @@ -187,7 +187,7 @@ "category": "Error", "code": 1066 }, - "Unexpected token. A constructor, method, accessor, or property was expected." : { + "Unexpected token. A constructor, method, accessor, or property was expected.": { "category": "Error", "code": 1068 }, @@ -444,9 +444,13 @@ "code": 1149 }, "'new T[]' cannot be used to create an array. Use 'new Array()' instead.": { - "category": "Error", - "code": 1150 - }, + "category": "Error", + "code": 1150 + }, + "An enum member cannot have a numeric name.": { + "category": "Error", + "code": 1151 + }, "Duplicate identifier '{0}'.": { "category": "Error", @@ -556,7 +560,7 @@ "category": "Error", "code": 2326 }, - "Property '{0}' is optional in type '{1}' but required in type '{2}'.": { + "Property '{0}' is optional in type '{1}' but required in type '{2}'.": { "category": "Error", "code": 2327 }, @@ -712,14 +716,6 @@ "category": "Error", "code": 2365 }, - "No best common type exists between '{0}', '{1}', and '{2}'.": { - "category": "Error", - "code": 2366 - }, - "No best common type exists between '{0}' and '{1}'.": { - "category": "Error", - "code": 2367 - }, "Type parameter name cannot be '{0}'": { "category": "Error", "code": 2368 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2b03636febb..4dda5c92ca7 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4,8 +4,11 @@ /// module ts { - interface EmitTextWriter extends SymbolWriter { + interface EmitTextWriter { write(s: string): void; + writeLine(): void; + increaseIndent(): void; + decreaseIndent(): void; getText(): string; rawWrite(s: string): void; writeLiteral(s: string): void; @@ -15,6 +18,9 @@ module ts { getIndent(): number; } + interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter{ + } + var indentStrings: string[] = ["", " "]; export function getIndentString(level: number) { if (indentStrings[level] === undefined) { @@ -28,7 +34,7 @@ module ts { } export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean { - if (!(sourceFile.flags & NodeFlags.DeclarationFile)) { + if (!isDeclarationFile(sourceFile)) { if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.filename, ".js")) { return true; } @@ -38,7 +44,7 @@ module ts { } export function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) { - return isExternalModule(sourceFile) || (sourceFile.flags & NodeFlags.DeclarationFile) !== 0; + return isExternalModule(sourceFile) || isDeclarationFile(sourceFile); } // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compilerOnSave feature @@ -103,7 +109,7 @@ module ts { }; } - function createTextWriter(trackSymbol: (symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags)=> void): EmitTextWriter { + function createTextWriter(): EmitTextWriter { var output = ""; var indent = 0; var lineStart = true; @@ -149,17 +155,8 @@ module ts { } } - function writeKind(text: string, kind: SymbolDisplayPartKind) { - write(text); - } - function writeSymbol(text: string, symbol: Symbol) { - write(text); - } return { write: write, - trackSymbol: trackSymbol, - writeKind: writeKind, - writeSymbol: writeSymbol, rawWrite: rawWrite, writeLiteral: writeLiteral, writeLine: writeLine, @@ -170,7 +167,6 @@ module ts { getLine: () => lineCount + 1, getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1, getText: () => output, - clear: () => { } }; } @@ -318,7 +314,7 @@ module ts { } function emitJavaScript(jsFilePath: string, root?: SourceFile) { - var writer = createTextWriter(trackSymbol); + var writer = createTextWriter(); var write = writer.write; var writeLine = writer.writeLine; var increaseIndent = writer.increaseIndent; @@ -374,8 +370,6 @@ module ts { /** Sourcemap data that will get encoded */ var sourceMapData: SourceMapData; - function trackSymbol(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags) { } - function initializeEmitterWithSourceMaps() { var sourceMapDir: string; // The directory in which sourcemap will be @@ -2314,7 +2308,7 @@ module ts { } function emitDeclarations(jsFilePath: string, root?: SourceFile) { - var writer = createTextWriter(trackSymbol); + var writer = createTextWriterWithSymbolWriter(); var write = writer.write; var writeLine = writer.writeLine; var increaseIndent = writer.increaseIndent; @@ -2338,11 +2332,24 @@ module ts { typeName?: Identifier } + function createTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter { + var writer = createTextWriter(); + writer.trackSymbol = trackSymbol; + writer.writeKeyword = writer.write; + writer.writeOperator = writer.write; + writer.writePunctuation = writer.write; + writer.writeSpace = writer.write; + writer.writeStringLiteral = writer.writeLiteral; + writer.writeParameter = writer.write; + writer.writeSymbol = writer.write; + return writer; + } + function writeAsychronousImportDeclarations(importDeclarations: ImportDeclaration[]) { var oldWriter = writer; forEach(importDeclarations, aliasToWrite => { var aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined); - writer = createTextWriter(trackSymbol); + writer = createTextWriterWithSymbolWriter(); for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { writer.increaseIndent(); } @@ -2861,7 +2868,7 @@ module ts { } return { diagnosticMessage: diagnosticMessage, - errorNode: node.parameters[0], + errorNode: node.parameters[0], typeName: node.name }; } @@ -2882,7 +2889,7 @@ module ts { } return { diagnosticMessage: diagnosticMessage, - errorNode: node.name, + errorNode: node.name, typeName: undefined }; } @@ -3253,14 +3260,17 @@ module ts { if (compilerOptions.out) { emitFile(compilerOptions.out); } - } else { - // targetSourceFile is specified (e.g calling emitter from language service) + } + else { + // targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service) if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) { - // If shouldEmitToOwnFile is true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file + // If shouldEmitToOwnFile returns true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js"); emitFile(jsFilePath, targetSourceFile); - } else { - // If shouldEmitToOwnFile is false, then emit all, non-external-module file, into one single output file + } + else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) { + // Otherwise, if --out is specified and targetSourceFile is not a declaration file, + // Emit all, non-external-module file, into one single output file emitFile(compilerOptions.out); } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 392a13c26d9..c755205ee3a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -111,6 +111,10 @@ module ts { return file.externalModuleIndicator !== undefined; } + export function isDeclarationFile(file: SourceFile): boolean { + return (file.flags & NodeFlags.DeclarationFile) !== 0; + } + export function isPrologueDirective(node: Node): boolean { return node.kind === SyntaxKind.ExpressionStatement && (node).expression.kind === SyntaxKind.StringLiteral; } @@ -221,6 +225,10 @@ module ts { return child((node).elementType); case SyntaxKind.TupleType: return children((node).elementTypes); + case SyntaxKind.UnionType: + return children((node).types); + case SyntaxKind.ParenType: + return child((node).type); case SyntaxKind.ArrayLiteral: return children((node).elements); case SyntaxKind.ObjectLiteral: @@ -1072,7 +1080,7 @@ module ts { return isParameter(); case ParsingContext.TypeArguments: case ParsingContext.TupleElementTypes: - return isType(); + return token === SyntaxKind.CommaToken || isType(); } Debug.fail("Non-exhaustive case in 'isListElement'."); @@ -1654,6 +1662,14 @@ module ts { return finishNode(node); } + function parseParenType(): ParenTypeNode { + var node = createNode(SyntaxKind.ParenType); + parseExpected(SyntaxKind.OpenParenToken); + node.type = parseType(); + parseExpected(SyntaxKind.CloseParenToken); + return finishNode(node); + } + function parseFunctionType(signatureKind: SyntaxKind): TypeLiteralNode { var node = createNode(SyntaxKind.TypeLiteral); var member = createNode(signatureKind); @@ -1687,10 +1703,7 @@ module ts { case SyntaxKind.OpenBracketToken: return parseTupleType(); case SyntaxKind.OpenParenToken: - case SyntaxKind.LessThanToken: - return parseFunctionType(SyntaxKind.CallSignature); - case SyntaxKind.NewKeyword: - return parseFunctionType(SyntaxKind.ConstructSignature); + return parseParenType(); default: if (isIdentifier()) { return parseTypeReference(); @@ -1714,20 +1727,20 @@ module ts { case SyntaxKind.NewKeyword: return true; case SyntaxKind.OpenParenToken: - // Only consider an ( as the start of a type if we have () or (id - // We don't want to consider things like (1) as a function type. + // Only consider '(' the start of a type if followed by ')', '...', an identifier, a modifier, + // or something that starts a type. We don't want to consider things like '(1)' a type. return lookAhead(() => { nextToken(); - return token === SyntaxKind.CloseParenToken || isParameter(); + return token === SyntaxKind.CloseParenToken || isParameter() || isType(); }); default: return isIdentifier(); } } - function parseType(): TypeNode { + function parsePrimaryType(): TypeNode { var type = parseNonArrayType(); - while (type && !scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) { + while (!scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) { parseExpected(SyntaxKind.CloseBracketToken); var node = createNode(SyntaxKind.ArrayType, type.pos); node.elementType = type; @@ -1736,6 +1749,64 @@ module ts { return type; } + function parseUnionType(): TypeNode { + var type = parsePrimaryType(); + if (token === SyntaxKind.BarToken) { + var types = >[type]; + types.pos = type.pos; + while (parseOptional(SyntaxKind.BarToken)) { + types.push(parsePrimaryType()); + } + types.end = getNodeEnd(); + var node = createNode(SyntaxKind.UnionType, type.pos); + node.types = types; + type = finishNode(node); + } + return type; + } + + function isFunctionType(): boolean { + return token === SyntaxKind.LessThanToken || token === SyntaxKind.OpenParenToken && lookAhead(() => { + nextToken(); + if (token === SyntaxKind.CloseParenToken || token === SyntaxKind.DotDotDotToken) { + // ( ) + // ( ... + return true; + } + if (isIdentifier() || isModifier(token)) { + nextToken(); + if (token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken || + token === SyntaxKind.QuestionToken || token === SyntaxKind.EqualsToken || + isIdentifier() || isModifier(token)) { + // ( id : + // ( id , + // ( id ? + // ( id = + // ( modifier id + return true; + } + if (token === SyntaxKind.CloseParenToken) { + nextToken(); + if (token === SyntaxKind.EqualsGreaterThanToken) { + // ( id ) => + return true; + } + } + } + return false; + }); + } + + function parseType(): TypeNode { + if (isFunctionType()) { + return parseFunctionType(SyntaxKind.CallSignature); + } + if (token === SyntaxKind.NewKeyword) { + return parseFunctionType(SyntaxKind.ConstructSignature); + } + return parseUnionType(); + } + function parseTypeAnnotation(): TypeNode { return parseOptional(SyntaxKind.ColonToken) ? parseType() : undefined; } @@ -2322,13 +2393,29 @@ module ts { function parseTypeArguments(): NodeArray { var typeArgumentListStart = scanner.getTokenPos(); var errorCountBeforeTypeParameterList = file.syntacticErrors.length; - var result = parseBracketedList(ParsingContext.TypeArguments, parseType, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); + // We pass parseSingleTypeArgument instead of parseType as the element parser + // because parseSingleTypeArgument knows how to parse a missing type argument. + // This is useful for signature help. parseType has the disadvantage that when + // it sees a missing type, it changes the LookAheadMode to Error, and the result + // is a broken binary expression, which breaks signature help. + var result = parseBracketedList(ParsingContext.TypeArguments, parseSingleTypeArgument, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); if (!result.length && file.syntacticErrors.length === errorCountBeforeTypeParameterList) { grammarErrorAtPos(typeArgumentListStart, scanner.getStartPos() - typeArgumentListStart, Diagnostics.Type_argument_list_cannot_be_empty); } return result; } + function parseSingleTypeArgument(): TypeNode { + if (token === SyntaxKind.CommaToken) { + var errorStart = scanner.getTokenPos(); + var errorLength = scanner.getTextPos() - errorStart; + grammarErrorAtPos(errorStart, errorLength, Diagnostics.Type_expected); + return createNode(SyntaxKind.Missing); + } + + return parseType(); + } + function parsePrimaryExpression(): Expression { switch (token) { case SyntaxKind.ThisKeyword: @@ -4031,7 +4118,7 @@ module ts { } } } - else if (node.kind === SyntaxKind.ModuleDeclaration && (node).name.kind === SyntaxKind.StringLiteral && (node.flags & NodeFlags.Ambient || file.flags & NodeFlags.DeclarationFile)) { + else if (node.kind === SyntaxKind.ModuleDeclaration && (node).name.kind === SyntaxKind.StringLiteral && (node.flags & NodeFlags.Ambient || isDeclarationFile(file))) { // TypeScript 1.0 spec (April 2014): 12.1.6 // An AmbientExternalModuleDeclaration declares an external module. // This type of declaration is permitted only in the global module. diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 2f5ff604df3..57ad0260cb6 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -68,7 +68,7 @@ var sys: System = (function () { return fileStream.ReadText(); } catch (e) { - throw e.number === -2147024809 ? new Error(ts.Diagnostics.Unsupported_file_encoding.key) : e; + throw e; } finally { fileStream.Close(); diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index c8cccd2da1c..52dac9695de 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -142,14 +142,19 @@ module ts { // otherwise use toLowerCase as a canonical form. return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); } - + + // returned by CScript sys environment + var unsupportedFileEncodingErrorCode = -2147024809; + function getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile { try { var text = sys.readFile(filename, options.charset); } catch (e) { if (onError) { - onError(e.message); + onError(e.number === unsupportedFileEncodingErrorCode ? + getDiagnosticText(Diagnostics.Unsupported_file_encoding) : + e.message); } text = ""; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 2a291c828cd..ea58b1166c6 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -154,6 +154,8 @@ module ts { TypeLiteral, ArrayType, TupleType, + UnionType, + ParenType, // Expression ArrayLiteral, ObjectLiteral, @@ -224,7 +226,7 @@ module ts { FirstFutureReservedWord = ImplementsKeyword, LastFutureReservedWord = YieldKeyword, FirstTypeNode = TypeReference, - LastTypeNode = TupleType, + LastTypeNode = ParenType, FirstPunctuation = OpenBraceToken, LastPunctuation = CaretEqualsToken, FirstToken = EndOfFileToken, @@ -337,6 +339,14 @@ module ts { elementTypes: NodeArray; } + export interface UnionTypeNode extends TypeNode { + types: NodeArray; + } + + export interface ParenTypeNode extends TypeNode { + type: TypeNode; + } + export interface StringLiteralTypeNode extends TypeNode { text: string; } @@ -634,28 +644,25 @@ module ts { getParentOfSymbol(symbol: Symbol): Symbol; getTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; - getPropertyOfType(type: Type, propetyName: string): Symbol; + getPropertyOfType(type: Type, propertyName: string): Symbol; getSignaturesOfType(type: Type, kind: SignatureKind): Signature[]; getIndexTypeOfType(type: Type, kind: IndexKind): Type; getReturnTypeOfSignature(signature: Signature): Type; getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]; getSymbolInfo(node: Node): Symbol; getTypeOfNode(node: Node): Type; - getApparentType(type: Type): ApparentType; typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string; - writeType(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string; - writeSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void; + getSymbolDisplayBuilder(): SymbolDisplayBuilder; getFullyQualifiedName(symbol: Symbol): string; - getAugmentedPropertiesOfApparentType(type: Type): Symbol[]; - getRootSymbol(symbol: Symbol): Symbol; + getAugmentedPropertiesOfType(type: Type): Symbol[]; + getRootSymbols(symbol: Symbol): Symbol[]; getContextualType(node: Node): Type; getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature; getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature; - writeSignature(signatures: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; - writeTypeParameter(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; - writeTypeParametersOfSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags): void; isImplementationOfOverload(node: FunctionDeclaration): boolean; + isUndefinedSymbol(symbol: Symbol): boolean; + isArgumentsSymbol(symbol: Symbol): boolean; // Returns the constant value of this enum member, or 'undefined' if the enum member has a // computed value. @@ -665,8 +672,25 @@ module ts { getAliasedSymbol(symbol: Symbol): Symbol; } + export interface SymbolDisplayBuilder { + buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildSymbolDisplay(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void; + buildSignatureDisplay(signatures: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildParameterDisplay(parameter: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags): void; + buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + } + export interface SymbolWriter { - writeKind(text: string, kind: SymbolDisplayPartKind): void; + writeKeyword(text: string): void; + writeOperator(text: string): void; + writePunctuation(text: string): void; + writeSpace(text: string): void; + writeStringLiteral(text: string): void; + writeParameter(text: string): void; writeSymbol(text: string, symbol: Symbol): void; writeLine(): void; increaseIndent(): void; @@ -687,6 +711,7 @@ module ts { WriteArrowStyleSignature = 0x00000008, // Write arrow style signature WriteOwnNameForAnyLike = 0x00000010, // Write symbol's own name instead of 'any' for any like types (eg. unknown, __resolving__ etc) WriteTypeArgumentsOfSignature = 0x00000020, // Write the type arguments instead of type parameters of the signature + InElementType = 0x00000040, // Writing an array or union element type } export enum SymbolFormatFlags { @@ -695,6 +720,9 @@ module ts { // eg. class C { p: T } <-- Show p as C.p here // var a: C; // var p = a.p; <--- Here p is property of C so show it as C.p instead of just C.p + UseOnlyExternalAliasing = 0x00000002, // Use only external alias information to get the symbol name in the given context + // eg. module m { export class c { } } import x = m.c; + // When this flag is specified m.c will be used to refer to the class instead of alias symbol x } export enum SymbolAccessibility { @@ -762,11 +790,11 @@ module ts { Instantiated = 0x00800000, // Instantiated symbol Merged = 0x01000000, // Merged symbol (created during program binding) Transient = 0x02000000, // Transient symbol (created during type check) - Prototype = 0x04000000, // Symbol for the prototype property (without source code representation) - - Undefined = 0x08000000, // Symbol for the undefined + Prototype = 0x04000000, // Prototype property (no source representation) + UnionProperty = 0x08000000, // Property in union type Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor, + Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter, Namespace = ValueModule | NamespaceModule, Module = ValueModule | NamespaceModule, @@ -824,6 +852,7 @@ module ts { mapper?: TypeMapper; // Type mapper for instantiation alias referenced?: boolean; // True if alias symbol has been referenced as a value exportAssignSymbol?: Symbol; // Symbol exported from external module + unionType?: UnionType; // Containing union type for union property } export interface TransientSymbol extends Symbol, SymbolLinks { } @@ -846,14 +875,15 @@ module ts { } export interface NodeLinks { - resolvedType?: Type; // Cached type of type node - resolvedSignature?: Signature; // Cached signature of signature node or call expression - resolvedSymbol?: Symbol; // Cached name resolution result - flags?: NodeCheckFlags; // Set of flags specific to Node - enumMemberValue?: number; // Constant value of enum member + resolvedType?: Type; // Cached type of type node + resolvedSignature?: Signature; // Cached signature of signature node or call expression + resolvedSymbol?: Symbol; // Cached name resolution result + flags?: NodeCheckFlags; // Set of flags specific to Node + enumMemberValue?: number; // Constant value of enum member isIllegalTypeReferenceInConstraint?: boolean; // Is type reference in constraint refers to the type parameter from the same list - isVisible?: boolean; // Is this node visible - localModuleName?: string; // Local name for module instance + isVisible?: boolean; // Is this node visible + localModuleName?: string; // Local name for module instance + assignmentChecks?: Map; // Cache of assignment checks } export enum TypeFlags { @@ -871,13 +901,14 @@ module ts { Interface = 0x00000800, // Interface Reference = 0x00001000, // Generic type reference Tuple = 0x00002000, // Tuple - Anonymous = 0x00004000, // Anonymous - FromSignature = 0x00008000, // Created for signature assignment check + Union = 0x00004000, // Union + Anonymous = 0x00008000, // Anonymous + FromSignature = 0x00010000, // Created for signature assignment check - Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null, + Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null, StringLike = String | StringLiteral, NumberLike = Number | Enum, - ObjectType = Class | Interface | Reference | Tuple | Anonymous + ObjectType = Class | Interface | Reference | Tuple | Anonymous, } // Properties common to all types @@ -900,12 +931,6 @@ module ts { // Object types (TypeFlags.ObjectType) export interface ObjectType extends Type { } - export interface ApparentType extends Type { - // This property is not used. It is just to make the type system think ApparentType - // is a strict subtype of Type. - _apparentTypeBrand: any; - } - // Class and interface types (TypeFlags.Class and TypeFlags.Interface) export interface InterfaceType extends ObjectType { typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic) @@ -935,8 +960,13 @@ module ts { baseArrayType: TypeReference; // Array where T is best common type of element types } - // Resolved object type - export interface ResolvedObjectType extends ObjectType { + export interface UnionType extends Type { + types: Type[]; // Constituent types + resolvedProperties: SymbolTable; // Cache of resolved properties + } + + // Resolved object or union type + export interface ResolvedType extends ObjectType, UnionType { members: SymbolTable; // Properties by name properties: Symbol[]; // Properties callSignatures: Signature[]; // Call signatures of type @@ -967,6 +997,7 @@ module ts { hasStringLiterals: boolean; // True if specialized target?: Signature; // Instantiation target mapper?: TypeMapper; // Instantiation mapper + unionSignatures?: Signature[]; // Underlying signatures of a union signature erasedSignatureCache?: Signature; // Erased version of signature (deferred) isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison } @@ -981,9 +1012,11 @@ module ts { } export interface InferenceContext { - typeParameters: TypeParameter[]; - inferences: Type[][]; - inferredTypes: Type[]; + typeParameters: TypeParameter[]; // Type parameters for which inferences are made + inferUnionTypes: boolean; // Infer union types for disjoint candidates (otherwise undefinedType) + inferenceCount: number; // Incremented for every inference made (whether new or not) + inferences: Type[][]; // Inferences made for each type parameter + inferredTypes: Type[]; // Inferred type for each type parameter } export interface DiagnosticMessage { @@ -1212,32 +1245,7 @@ module ts { tab = 0x09, // \t verticalTab = 0x0B, // \v } - - export enum SymbolDisplayPartKind { - aliasName, - className, - enumName, - fieldName, - interfaceName, - keyword, - lineBreak, - numericLiteral, - stringLiteral, - localName, - methodName, - moduleName, - operator, - parameterName, - propertyName, - punctuation, - space, - text, - typeParameterName, - enumMemberName, - functionName, - regularExpressionLiteral, - } - + export interface CancellationToken { isCancellationRequested(): boolean; } diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 31d009c4765..6e211892437 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -61,9 +61,11 @@ class CompilerBaselineRunner extends RunnerBase { var otherFiles: { unitName: string; content: string }[]; var harnessCompiler: Harness.Compiler.HarnessCompiler; - var declToBeCompiled: { unitName: string; content: string }[] = []; - var declOtherFiles: { unitName: string; content: string }[] = []; - var declResult: Harness.Compiler.CompilerResult; + var declFileCompilationResult: { + declInputFiles: { unitName: string; content: string }[]; + declOtherFiles: { unitName: string; content: string }[]; + declResult: Harness.Compiler.CompilerResult; + }; var createNewInstance = false; @@ -147,9 +149,7 @@ class CompilerBaselineRunner extends RunnerBase { toBeCompiled = undefined; otherFiles = undefined; harnessCompiler = undefined; - declToBeCompiled = undefined; - declOtherFiles = undefined; - declResult = undefined; + declFileCompilationResult = undefined; }); function getByteOrderMarkText(file: Harness.Compiler.GeneratedFile): string { @@ -173,61 +173,18 @@ class CompilerBaselineRunner extends RunnerBase { // Source maps? it('Correct sourcemap content for ' + fileName, () => { - if (result.sourceMapRecord) { + if (options.sourceMap) { Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.ts$/, '.sourcemap.txt'), () => { - return result.sourceMapRecord; + return result.getSourceMapRecord(); }); } }); // Compile .d.ts files it('Correct compiler generated.d.ts for ' + fileName, () => { - if (options.declaration && result.errors.length === 0 && result.declFilesCode.length !== result.files.length) { - throw new Error('There were no errors and declFiles generated did not match number of js files generated'); - } - - // if the .d.ts is non-empty, confirm it compiles correctly as well - if (options.declaration && result.errors.length === 0 && result.declFilesCode.length > 0) { - function addDtsFile(file: { unitName: string; content: string }, dtsFiles: { unitName: string; content: string }[]) { - if (Harness.Compiler.isDTS(file.unitName)) { - dtsFiles.push(file); - } - else { - var declFile = findResultCodeFile(file.unitName); - // Look if there is --out file corresponding to this ts file - if (!declFile && options.out) { - declFile = findResultCodeFile(options.out); - if (!declFile || findUnit(declFile.fileName, declToBeCompiled) || - findUnit(declFile.fileName, declOtherFiles)) { - return; - } - } - - if (declFile) { - dtsFiles.push({ unitName: declFile.fileName, content: declFile.code }); - return; - } - } - - function findResultCodeFile(fileName: string) { - return ts.forEach(result.declFilesCode, - declFile => declFile.fileName === (fileName.substr(0, fileName.length - ".ts".length) + ".d.ts") - ? declFile : undefined); - } - - function findUnit(fileName: string, units: { unitName: string; content: string }[]) { - return ts.forEach(units, unit => unit.unitName === fileName ? unit : undefined); - } - } - - ts.forEach(toBeCompiled, file => addDtsFile(file, declToBeCompiled)); - ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles)); - harnessCompiler.compileFiles(declToBeCompiled, declOtherFiles, function (compileResult) { - declResult = compileResult; - }, function (settings) { - harnessCompiler.setCompilerSettings(tcSettings); - }); - } + declFileCompilationResult = harnessCompiler.compileDeclarationFiles(toBeCompiled, otherFiles, result, function (settings) { + harnessCompiler.setCompilerSettings(tcSettings); + }, options); }); @@ -267,10 +224,10 @@ class CompilerBaselineRunner extends RunnerBase { } } - if (declResult && declResult.errors.length) { + if (declFileCompilationResult && declFileCompilationResult.declResult.errors.length) { jsCode += '\r\n\r\n//// [DtsFileErrors]\r\n'; jsCode += '\r\n\r\n'; - jsCode += getErrorBaseline(declToBeCompiled, declOtherFiles, declResult); + jsCode += getErrorBaseline(declFileCompilationResult.declInputFiles, declFileCompilationResult.declOtherFiles, declFileCompilationResult.declResult); } if (jsCode.length > 0) { diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 6a4e13b22e3..ea35bd069eb 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -146,7 +146,7 @@ module FourSlash { function convertGlobalOptionsToCompilationSettings(globalOptions: { [idx: string]: string }): ts.CompilationSettings { var settings: ts.CompilationSettings = {}; - // Convert all property in globalOptions into ts.CompilationSettings + // Convert all property in globalOptions into ts.CompilationSettings for (var prop in globalOptions) { if (globalOptions.hasOwnProperty(prop)) { switch (prop) { @@ -1610,9 +1610,11 @@ module FourSlash { Harness.IO.log(this.getNameOrDottedNameSpan(pos)); } - private verifyClassifications(expected: { classificationType: string; text: string }[], actual: ts.ClassifiedSpan[]) { + private verifyClassifications(expected: { classificationType: string; text: string; textSpan?: TextSpan }[], actual: ts.ClassifiedSpan[]) { if (actual.length !== expected.length) { - this.raiseError('verifyClassifications failed - expected total classifications to be ' + expected.length + ', but was ' + actual.length); + this.raiseError('verifyClassifications failed - expected total classifications to be ' + expected.length + + ', but was ' + actual.length + + jsonMismatchString()); } for (var i = 0; i < expected.length; i++) { @@ -1623,17 +1625,38 @@ module FourSlash { if (expectedType !== actualClassification.classificationType) { this.raiseError('verifyClassifications failed - expected classifications type to be ' + expectedType + ', but was ' + - actualClassification.classificationType); + actualClassification.classificationType + + jsonMismatchString()); } + var expectedSpan = expectedClassification.textSpan; var actualSpan = actualClassification.textSpan; + + if (expectedSpan) { + var expectedLength = expectedSpan.end - expectedSpan.start; + + if (expectedSpan.start !== actualSpan.start() || expectedLength !== actualSpan.length()) { + this.raiseError("verifyClassifications failed - expected span of text to be " + + "{start=" + expectedSpan.start + ", length=" + expectedLength + "}, but was " + + "{start=" + actualSpan.start() + ", length=" + actualSpan.length() + "}" + + jsonMismatchString()); + } + } + var actualText = this.activeFile.content.substr(actualSpan.start(), actualSpan.length()); if (expectedClassification.text !== actualText) { - this.raiseError('verifyClassifications failed - expected classificatied text to be ' + + this.raiseError('verifyClassifications failed - expected classified text to be ' + expectedClassification.text + ', but was ' + - actualText); + actualText + + jsonMismatchString()); } } + + function jsonMismatchString() { + return sys.newLine + + "expected: '" + sys.newLine + JSON.stringify(expected, (k,v) => v, 2) + "'" + sys.newLine + + "actual: '" + sys.newLine + JSON.stringify(actual, (k, v) => v, 2) + "'"; + } } public verifySemanticClassifications(expected: { classificationType: string; text: string }[]) { @@ -1984,7 +2007,8 @@ module FourSlash { var newlinePos = text.indexOf('\n'); if (newlinePos === -1) { return text; - } else { + } + else { if (text.charAt(newlinePos - 1) === '\r') { newlinePos--; } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index e35fe83f9b2..2f7bf780b41 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -139,6 +139,7 @@ module Harness { deleteFile(filename: string): void; listFiles(path: string, filter: RegExp, options?: { recursive?: boolean }): string[]; log(text: string): void; + getMemoryUsage? (): number; } module IOImpl { @@ -275,6 +276,13 @@ module Harness { return filesInFolder(path); } + + export var getMemoryUsage: typeof IO.getMemoryUsage = () => { + if (global.gc) { + global.gc(); + } + return process.memoryUsage().heapUsed; + } } export module Network { @@ -804,15 +812,81 @@ module Harness { }); this.lastErrors = errors; - var result = new CompilerResult(fileOutputs, errors, []); - // Covert the source Map data into the baseline - result.updateSourceMapRecord(program, emitResult ? emitResult.sourceMaps : undefined); + var result = new CompilerResult(fileOutputs, errors, program, sys.getCurrentDirectory(), emitResult ? emitResult.sourceMaps : undefined); onComplete(result, checker); // reset what newline means in case the last test changed it sys.newLine = '\r\n'; return options; } + + public compileDeclarationFiles(inputFiles: { unitName: string; content: string; }[], + otherFiles: { unitName: string; content: string; }[], + result: CompilerResult, + settingsCallback?: (settings: ts.CompilerOptions) => void, + options?: ts.CompilerOptions) { + if (options.declaration && result.errors.length === 0 && result.declFilesCode.length !== result.files.length) { + throw new Error('There were no errors and declFiles generated did not match number of js files generated'); + } + + // if the .d.ts is non-empty, confirm it compiles correctly as well + if (options.declaration && result.errors.length === 0 && result.declFilesCode.length > 0) { + var declInputFiles: { unitName: string; content: string }[] = []; + var declOtherFiles: { unitName: string; content: string }[] = []; + var declResult: Harness.Compiler.CompilerResult; + + ts.forEach(inputFiles, file => addDtsFile(file, declInputFiles)); + ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles)); + this.compileFiles(declInputFiles, declOtherFiles, function (compileResult) { + declResult = compileResult; + }, settingsCallback, options); + + return { declInputFiles: declInputFiles, declOtherFiles: declOtherFiles, declResult: declResult }; + } + + function addDtsFile(file: { unitName: string; content: string }, dtsFiles: { unitName: string; content: string }[]) { + if (isDTS(file.unitName)) { + dtsFiles.push(file); + } + else if (isTS(file.unitName)) { + var declFile = findResultCodeFile(file.unitName); + if (!findUnit(declFile.fileName, declInputFiles) && !findUnit(declFile.fileName, declOtherFiles)) { + dtsFiles.push({ unitName: declFile.fileName, content: declFile.code }); + } + } + + function findResultCodeFile(fileName: string) { + var dTsFileName = ts.forEach(result.program.getSourceFiles(), sourceFile => { + if (sourceFile.filename === fileName) { + // Is this file going to be emitted separately + var sourceFileName: string; + if (ts.isExternalModule(sourceFile) || !options.out) { + if (options.outDir) { + var sourceFilePath = ts.getNormalizedPathFromPathComponents(ts.getNormalizedPathComponents(sourceFile.filename, result.currentDirectoryForProgram)); + sourceFilePath = sourceFilePath.replace(result.program.getCommonSourceDirectory(), ""); + sourceFileName = ts.combinePaths(options.outDir, sourceFilePath); + } + else { + sourceFileName = sourceFile.filename; + } + } + else { + // Goes to single --out file + sourceFileName = options.out; + } + + return ts.removeFileExtension(sourceFileName) + ".d.ts"; + } + }); + + return ts.forEach(result.declFilesCode, declFile => declFile.fileName === dTsFileName ? declFile : undefined); + } + + function findUnit(fileName: string, units: { unitName: string; content: string; }[]) { + return ts.forEach(units, unit => unit.unitName === fileName ? unit : undefined); + } + } + } } export function getMinimalDiagnostic(err: ts.Diagnostic): HarnessDiagnostic { @@ -948,10 +1022,6 @@ module Harness { } */ - /** Recreate the harness compiler instance to its default settings */ - export function recreate(options?: { useMinimalDefaultLib: boolean; noImplicitAny: boolean; }) { - } - /** The harness' compiler instance used when tests are actually run. Reseting or changing settings of this compiler instance must be done within a test case (i.e., describe/it) */ var harnessCompiler: HarnessCompiler; @@ -991,6 +1061,10 @@ module Harness { return str.substr(str.length - end.length) === end; } + export function isTS(fileName: string) { + return stringEndsWith(fileName, '.ts'); + } + export function isDTS(fileName: string) { return stringEndsWith(fileName, '.d.ts'); } @@ -1009,10 +1083,10 @@ module Harness { public errors: HarnessDiagnostic[] = []; public declFilesCode: GeneratedFile[] = []; public sourceMaps: GeneratedFile[] = []; - public sourceMapRecord: string; /** @param fileResults an array of strings for the fileName and an ITextWriter with its code */ - constructor(fileResults: GeneratedFile[], errors: HarnessDiagnostic[], sourceMapRecordLines: string[]) { + constructor(fileResults: GeneratedFile[], errors: HarnessDiagnostic[], public program: ts.Program, + public currentDirectoryForProgram: string, private sourceMapData: ts.SourceMapData[]) { var lines: string[] = []; fileResults.forEach(emittedFile => { @@ -1030,12 +1104,11 @@ module Harness { }); this.errors = errors; - this.sourceMapRecord = sourceMapRecordLines.join('\r\n'); } - public updateSourceMapRecord(program: ts.Program, sourceMapData: ts.SourceMapData[]) { - if (sourceMapData) { - this.sourceMapRecord = Harness.SourceMapRecoder.getSourceMapRecord(sourceMapData, program, this.files); + public getSourceMapRecord() { + if (this.sourceMapData) { + return Harness.SourceMapRecoder.getSourceMapRecord(this.sourceMapData, this.program, this.files); } } diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 2886c43f091..797bc12a42b 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -419,6 +419,16 @@ class ProjectRunner extends RunnerBase { // }) //}); } + + after(() => { + // Mocha holds onto the closure environment of the describe callback even after the test is done. + // Therefore we have to clean out large objects after the test is done. + nodeCompilerResult = undefined; + amdCompilerResult = undefined; + testCase = undefined; + testFileText = undefined; + testCaseJustName = undefined; + }); }); } } \ No newline at end of file diff --git a/src/harness/runner.ts b/src/harness/runner.ts index 331a19819b3..38e23bb10c5 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -18,7 +18,6 @@ // /// /// /// -/// function runTests(runners: RunnerBase[]) { if (reverse) { @@ -67,9 +66,6 @@ if (testConfigFile !== '') { case 'fourslash-generated': runners.push(new GeneratedFourslashRunner()); break; - case 'unittests': - runners.push(new UnitTestRunner()); - break; case 'rwc': runners.push(new RWCRunner()); break; @@ -93,9 +89,6 @@ if (runners.length === 0) { // language services runners.push(new FourslashRunner()); //runners.push(new GeneratedFourslashRunner()); - - // unittests - runners.push(new UnitTestRunner()); } sys.newLine = '\r\n'; diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index f7cc699c075..6590344a8dd 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -46,144 +46,171 @@ module RWC { } export function runRWCTest(jsonPath: string) { - var harnessCompiler = Harness.Compiler.getCompiler(); - var opts: ts.ParsedCommandLine; + describe("Testing a RWC project: " + jsonPath, () => { + var inputFiles: { unitName: string; content: string; }[] = []; + var otherFiles: { unitName: string; content: string; }[] = []; + var compilerResult: Harness.Compiler.CompilerResult; + var compilerOptions: ts.CompilerOptions; + var baselineOpts: Harness.Baseline.BaselineOptions = { Subfolder: 'rwc' }; + var baseName = /(.*)\/(.*).json/.exec(Harness.Path.switchToForwardSlashes(jsonPath))[2]; + // Compile .d.ts files + var declFileCompilationResult: { + declInputFiles: { unitName: string; content: string }[]; + declOtherFiles: { unitName: string; content: string }[]; + declResult: Harness.Compiler.CompilerResult; + }; - var ioLog: IOLog = JSON.parse(Harness.IO.readFile(jsonPath)); - var errors = ''; - - it('has parsable options', () => { - runWithIOLog(ioLog, () => { - opts = ts.parseCommandLine(ioLog.arguments); - assert.equal(opts.errors.length, 0); - }); - }); - - var inputFiles: { unitName: string; content: string; }[] = []; - var otherFiles: { unitName: string; content: string; }[] = []; - var compilerResult: Harness.Compiler.CompilerResult; - it('can compile', () => { - runWithIOLog(ioLog, () => { - harnessCompiler.reset(); - - // Load the files - ts.forEach(opts.filenames, fileName => { - inputFiles.push(getHarnessCompilerInputUnit(fileName)); - }); - - if (!opts.options.noLib) { - // Find the lib.d.ts file in the input file and add it to the input files list - var libFile = ts.forEach(ioLog.filesRead, fileRead=> Harness.isLibraryFile(fileRead.path) ? fileRead.path : undefined); - if (libFile) { - inputFiles.push(getHarnessCompilerInputUnit(libFile)); - } - } - - ts.forEach(ioLog.filesRead, fileRead => { - var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileRead.path)); - var inInputList = ts.forEach(inputFiles, inputFile=> inputFile.unitName === resolvedPath); - if (!inInputList) { - // Add the file to other files - otherFiles.push(getHarnessCompilerInputUnit(fileRead.path)); - } - }); - - // do not use lib since we already read it in above - opts.options.noLib = true; - - // Emit the results - harnessCompiler.compileFiles(inputFiles, otherFiles, compileResult => { - compilerResult = compileResult; - }, /*settingsCallback*/ undefined, opts.options); + after(() => { + // Mocha holds onto the closure environment of the describe callback even after the test is done. + // Therefore we have to clean out large objects after the test is done. + inputFiles = undefined; + otherFiles = undefined; + compilerResult = undefined; + compilerOptions = undefined; + baselineOpts = undefined; + baseName = undefined; + declFileCompilationResult = undefined; }); - function getHarnessCompilerInputUnit(fileName: string) { - var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileName)); - try { - var content = sys.readFile(resolvedPath); + it('can compile', () => { + var harnessCompiler = Harness.Compiler.getCompiler(); + var opts: ts.ParsedCommandLine; + + var ioLog: IOLog = JSON.parse(Harness.IO.readFile(jsonPath)); + runWithIOLog(ioLog, () => { + opts = ts.parseCommandLine(ioLog.arguments); + assert.equal(opts.errors.length, 0); + }); + + runWithIOLog(ioLog, () => { + harnessCompiler.reset(); + + // Load the files + ts.forEach(opts.filenames, fileName => { + inputFiles.push(getHarnessCompilerInputUnit(fileName)); + }); + + if (!opts.options.noLib) { + // Find the lib.d.ts file in the input file and add it to the input files list + var libFile = ts.forEach(ioLog.filesRead, fileRead=> Harness.isLibraryFile(fileRead.path) ? fileRead.path : undefined); + if (libFile) { + inputFiles.push(getHarnessCompilerInputUnit(libFile)); + } + } + + ts.forEach(ioLog.filesRead, fileRead => { + var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileRead.path)); + var inInputList = ts.forEach(inputFiles, inputFile=> inputFile.unitName === resolvedPath); + if (!inInputList) { + // Add the file to other files + otherFiles.push(getHarnessCompilerInputUnit(fileRead.path)); + } + }); + + // do not use lib since we already read it in above + opts.options.noLib = true; + + // Emit the results + compilerOptions = harnessCompiler.compileFiles(inputFiles, otherFiles, compileResult => { + compilerResult = compileResult; + }, /*settingsCallback*/ undefined, opts.options); + }); + + function getHarnessCompilerInputUnit(fileName: string) { + var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileName)); + try { + var content = sys.readFile(resolvedPath); + } + catch (e) { + // Leave content undefined. + } + return { unitName: resolvedPath, content: content }; } - catch (e) { - // Leave content undefined. - } - return { unitName: resolvedPath, content: content }; - } - }); + }); - // Baselines - var baselineOpts: Harness.Baseline.BaselineOptions = { Subfolder: 'rwc' }; - var baseName = /(.*)\/(.*).json/.exec(Harness.Path.switchToForwardSlashes(jsonPath))[2]; + // Baselines + it('Correct compiler generated.d.ts', () => { + declFileCompilationResult = Harness.Compiler.getCompiler().compileDeclarationFiles(inputFiles, otherFiles, compilerResult, /*settingscallback*/ undefined, compilerOptions); + }); - it('has the expected emitted code', () => { - Harness.Baseline.runBaseline('has the expected emitted code', baseName + '.output.js', () => { - return collateOutputs(compilerResult.files, s => SyntacticCleaner.clean(s)); - }, false, baselineOpts); - }); - it('has the expected declaration file content', () => { - Harness.Baseline.runBaseline('has the expected declaration file content', baseName + '.d.ts', () => { - if (compilerResult.errors.length || !compilerResult.declFilesCode.length) { - return null; - } - return collateOutputs(compilerResult.declFilesCode); - }, false, baselineOpts); - }); - - it('has the expected source maps', () => { - Harness.Baseline.runBaseline('has the expected source maps', baseName + '.map', () => { - if (!compilerResult.sourceMaps.length) { - return null; - } - - return collateOutputs(compilerResult.sourceMaps); - }, false, baselineOpts); - }); - - it('has correct source map record', () => { - if (compilerResult.sourceMapRecord) { - Harness.Baseline.runBaseline('has correct source map record', baseName + '.sourcemap.txt', () => { - return compilerResult.sourceMapRecord; + it('has the expected emitted code', () => { + Harness.Baseline.runBaseline('has the expected emitted code', baseName + '.output.js', () => { + return collateOutputs(compilerResult.files, s => SyntacticCleaner.clean(s)); }, false, baselineOpts); - } - }); + }); - it('has the expected errors', () => { - Harness.Baseline.runBaseline('has the expected errors', baseName + '.errors.txt', () => { - if (compilerResult.errors.length === 0) { - return null; + it('has the expected declaration file content', () => { + Harness.Baseline.runBaseline('has the expected declaration file content', baseName + '.d.ts', () => { + if (compilerResult.errors.length || !compilerResult.declFilesCode.length) { + return null; + } + return collateOutputs(compilerResult.declFilesCode); + }, false, baselineOpts); + }); + + it('has the expected source maps', () => { + Harness.Baseline.runBaseline('has the expected source maps', baseName + '.map', () => { + if (!compilerResult.sourceMaps.length) { + return null; + } + + return collateOutputs(compilerResult.sourceMaps); + }, false, baselineOpts); + }); + + //it('has correct source map record', () => { + // if (compilerOptions.sourceMap) { + // Harness.Baseline.runBaseline('has correct source map record', baseName + '.sourcemap.txt', () => { + // return compilerResult.getSourceMapRecord(); + // }, false, baselineOpts); + // } + //}); + + it('has the expected errors', () => { + Harness.Baseline.runBaseline('has the expected errors', baseName + '.errors.txt', () => { + if (compilerResult.errors.length === 0) { + return null; + } + + return Harness.Compiler.getErrorBaseline(inputFiles.concat(otherFiles), compilerResult.errors); + }, false, baselineOpts); + }); + + it('has no errors in generated declaration files', () => { + if (compilerOptions.declaration && !compilerResult.errors.length) { + Harness.Baseline.runBaseline('has no errors in generated declaration files', baseName + '.dts.errors.txt', () => { + if (declFileCompilationResult.declResult.errors.length === 0) { + return null; + } + + return Harness.Compiler.minimalDiagnosticsToString(declFileCompilationResult.declResult.errors) + + sys.newLine + sys.newLine + + Harness.Compiler.getErrorBaseline(declFileCompilationResult.declInputFiles.concat(declFileCompilationResult.declOtherFiles), declFileCompilationResult.declResult.errors); + }, false, baselineOpts); } + }); - return Harness.Compiler.getErrorBaseline(inputFiles.concat(otherFiles), compilerResult.errors); - }, false, baselineOpts); + // TODO: Type baselines (need to refactor out from compilerRunner) }); - - // TODO: Type baselines (need to refactor out from compilerRunner) } } class RWCRunner extends RunnerBase { - private runnerPath = "tests/runners/rwc"; - private sourcePath = "tests/cases/rwc/"; - - private harnessCompiler: Harness.Compiler.HarnessCompiler; + private static sourcePath = "tests/cases/rwc/"; /** Setup the runner's tests so that they are ready to be executed by the harness * The first test should be a describe/it block that sets up the harness's compiler instance appropriately */ public initializeTests(): void { - // Recreate the compiler with the default lib - Harness.Compiler.recreate({ useMinimalDefaultLib: false, noImplicitAny: false }); - this.harnessCompiler = Harness.Compiler.getCompiler(); - // Read in and evaluate the test list - var testList = Harness.IO.listFiles(this.sourcePath, /.+\.json$/); + var testList = Harness.IO.listFiles(RWCRunner.sourcePath, /.+\.json$/); for (var i = 0; i < testList.length; i++) { this.runTest(testList[i]); } } private runTest(jsonFilename: string) { - describe("Testing a RWC project: " + jsonFilename, () => { - RWC.runRWCTest(jsonFilename); - }); + RWC.runRWCTest(jsonFilename); } } \ No newline at end of file diff --git a/src/harness/unittestrunner.ts b/src/harness/unittestrunner.ts deleted file mode 100644 index 95c90415409..00000000000 --- a/src/harness/unittestrunner.ts +++ /dev/null @@ -1,73 +0,0 @@ -/// -/// - -class UnitTestRunner extends RunnerBase { - constructor() { - super(); - } - - public initializeTests() { - this.tests = this.enumerateFiles('tests/cases/unittests/services', /\.ts/i); - - var outfile = new Harness.Compiler.WriterAggregator() - var outerr = new Harness.Compiler.WriterAggregator(); - // note this is running immediately to generate tests to be run later inside describe/it - // need a fresh instance so that the previous runner's last test is not hanging around - var harnessCompiler = Harness.Compiler.getCompiler({ useExistingInstance: false }); - - var toBeAdded = this.tests.map(test => { - return { unitName: test, content: Harness.IO.readFile(test) } - }); - harnessCompiler.addInputFiles(toBeAdded); - harnessCompiler.setCompilerOptions({ noResolve: true }); - - var stdout = new Harness.Compiler.EmitterIOHost(); - var emitDiagnostics = harnessCompiler.emitAll(stdout); - var results = stdout.toArray(); - var lines: string[] = []; - results.forEach(v => lines = lines.concat(v.file.lines)); - var code = lines.join("\n") - - var nodeContext: any = undefined; - if (Utils.getExecutionEnvironment() === Utils.ExecutionEnvironment.Node) { - nodeContext = { - require: require, - process: process, - describe: describe, - it: it, - assert: assert, - beforeEach: beforeEach, - afterEach: afterEach, - before: before, - after: after, - Harness: Harness, - IO: Harness.IO, - ts: ts, - TypeScript: TypeScript - // FourSlash: FourSlash - }; - } - - describe("Setup compiler for compiler unittests", () => { - // ensures a clean compiler instance when tests are eventually executed following this describe block - harnessCompiler = Harness.Compiler.getCompiler({ - useExistingInstance: false, - optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: false } - }); - }); - - // this generated code is a series of top level describe/it blocks that will run in between the setup and cleanup blocks in this file - Utils.evalFile(code, "generated_test_code.js", nodeContext); - - describe("Cleanup after unittests", () => { - var harnessCompiler = Harness.Compiler.getCompiler({ - useExistingInstance: false, - optionsForFreshInstance: { useMinimalDefaultLib: true, noImplicitAny: false } - }); - }); - - // note this runs immediately (ie before this same code in the describe block above) - // to make sure the next runner doesn't include the previous one's stuff - harnessCompiler = Harness.Compiler.getCompiler({ useExistingInstance: false }); - } -} \ No newline at end of file diff --git a/src/services/compiler/declarationEmitter.ts b/src/services/compiler/declarationEmitter.ts index 85e5bf09647..460904b7e88 100644 --- a/src/services/compiler/declarationEmitter.ts +++ b/src/services/compiler/declarationEmitter.ts @@ -476,8 +476,6 @@ module TypeScript { //} } - var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl); - var funcSignature = funcPullDecl.getSignatureSymbol(this.semanticInfoChain); this.emitDeclarationComments(funcDecl); this.emitIndent(); @@ -603,11 +601,6 @@ module TypeScript { private emitConstructSignature(funcDecl: ConstructSignatureSyntax) { var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl); - var start = new Date().getTime(); - var funcSymbol = this.semanticInfoChain.getSymbolForAST(funcDecl); - - TypeScript.declarationEmitFunctionDeclarationGetSymbolTime += new Date().getTime() - start; - this.emitDeclarationComments(funcDecl); this.emitIndent(); @@ -633,11 +626,6 @@ module TypeScript { private emitMethodSignature(funcDecl: MethodSignatureSyntax) { var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl); - var start = new Date().getTime(); - var funcSymbol = this.semanticInfoChain.getSymbolForAST(funcDecl); - - TypeScript.declarationEmitFunctionDeclarationGetSymbolTime += new Date().getTime() - start; - this.emitDeclarationComments(funcDecl); this.emitIndent(); @@ -817,7 +805,6 @@ module TypeScript { var parameter = funcDecl.callSignature.parameterList.parameters[i]; var parameterDecl = this.semanticInfoChain.getDeclForAST(parameter); if (hasFlag(parameterDecl.flags, PullElementFlags.PropertyParameter)) { - var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl); this.emitDeclarationComments(parameter); this.declFile.Write(this.getIndentString()); this.emitClassElementModifiers(parameter.modifiers); @@ -838,7 +825,6 @@ module TypeScript { var className = classDecl.identifier.text(); this.emitDeclarationComments(classDecl); - var classPullDecl = this.semanticInfoChain.getDeclForAST(classDecl); this.emitDeclFlags(classDecl, "class"); this.declFile.Write(className); @@ -934,7 +920,6 @@ module TypeScript { var interfaceName = interfaceDecl.identifier.text(); this.emitDeclarationComments(interfaceDecl); - var interfacePullDecl = this.semanticInfoChain.getDeclForAST(interfaceDecl); this.emitDeclFlags(interfaceDecl, "interface"); this.declFile.Write(interfaceName); @@ -980,7 +965,6 @@ module TypeScript { } this.emitDeclarationComments(moduleDecl); - var modulePullDecl = this.semanticInfoChain.getDeclForAST(moduleDecl); this.emitDeclFlags(moduleDecl, "enum"); this.declFile.WriteLine(moduleDecl.identifier.text() + " {"); diff --git a/src/services/compiler/typescript.ts b/src/services/compiler/typescript.ts index f98d0baf52b..5671d167d1b 100644 --- a/src/services/compiler/typescript.ts +++ b/src/services/compiler/typescript.ts @@ -512,7 +512,7 @@ module TypeScript { for (var i = 0, n = fileNames.length; i < n; i++) { var fileName = fileNames[i]; - var document = this.getDocument(fileNames[i]); + var document = this.getDocument(fileName); sharedEmitter = this._emitDocumentDeclarations(document, emitOptions, file => emitOutput.outputFiles.push(file), sharedEmitter); @@ -578,7 +578,6 @@ module TypeScript { var sourceUnit = document.sourceUnit(); Debug.assert(this._shouldEmit(document)); - var typeScriptFileName = document.fileName; if (!emitter) { var javaScriptFileName = this.mapOutputFileName(document, emitOptions, TypeScriptCompiler.mapToJSFileName); var outFile = new TextWriter(javaScriptFileName, this.writeByteOrderMarkForDocument(document), OutputFileType.JavaScript); @@ -799,8 +798,6 @@ module TypeScript { } private extractResolutionContextFromAST(resolver: PullTypeResolver, ast: ISyntaxElement, document: Document, propagateContextualTypes: boolean): { ast: ISyntaxElement; enclosingDecl: PullDecl; resolutionContext: PullTypeResolutionContext; inContextuallyTypedAssignment: boolean; inWithBlock: boolean; } { - var scriptName = document.fileName; - var enclosingDecl: PullDecl = null; var enclosingDeclAST: ISyntaxElement = null; var inContextuallyTypedAssignment = false; @@ -981,7 +978,6 @@ module TypeScript { case SyntaxKind.ReturnStatement: if (propagateContextualTypes) { - var returnStatement = current; var contextualType: PullTypeSymbol = null; if (enclosingDecl && (enclosingDecl.kind & PullElementKind.SomeFunction)) { diff --git a/src/services/core/integerUtilities.ts b/src/services/core/integerUtilities.ts index 0af38471dfd..b0a4d6667b9 100644 --- a/src/services/core/integerUtilities.ts +++ b/src/services/core/integerUtilities.ts @@ -7,12 +7,6 @@ module TypeScript { } export function integerMultiplyLow32Bits(n1: number, n2: number): number { - var n1Low16 = n1 & 0x0000ffff; - var n1High16 = n1 >>> 16; - - var n2Low16 = n2 & 0x0000ffff; - var n2High16 = n2 >>> 16; - var resultLow32 = (((n1 & 0xffff0000) * n2) >>> 0) + (((n1 & 0x0000ffff) * n2) >>> 0) >>> 0; return resultLow32; } diff --git a/src/services/services.ts b/src/services/services.ts index 9b98b1a0eb3..36561dd8f85 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -580,7 +580,7 @@ module ts { return this.checker.getPropertyOfType(this, propertyName); } getApparentProperties(): Symbol[] { - return this.checker.getAugmentedPropertiesOfApparentType(this); + return this.checker.getAugmentedPropertiesOfType(this); } getCallSignatures(): Signature[] { return this.checker.getSignaturesOfType(this, SignatureKind.Call); @@ -999,12 +999,37 @@ module ts { containerKind: string; containerName: string; } - + + export enum SymbolDisplayPartKind { + aliasName, + className, + enumName, + fieldName, + interfaceName, + keyword, + lineBreak, + numericLiteral, + stringLiteral, + localName, + methodName, + moduleName, + operator, + parameterName, + propertyName, + punctuation, + space, + text, + typeParameterName, + enumMemberName, + functionName, + regularExpressionLiteral, + } + export interface SymbolDisplayPart { text: string; kind: string; } - + export interface QuickInfo { kind: string; kindModifiers: string; @@ -1310,7 +1335,12 @@ module ts { resetWriter(); return { displayParts: () => displayParts, - writeKind: writeKind, + writeKeyword: text => writeKind(text, SymbolDisplayPartKind.keyword), + writeOperator: text => writeKind(text, SymbolDisplayPartKind.operator), + writePunctuation: text => writeKind(text, SymbolDisplayPartKind.punctuation), + writeSpace: text => writeKind(text, SymbolDisplayPartKind.space), + writeStringLiteral: text => writeKind(text, SymbolDisplayPartKind.stringLiteral), + writeParameter: text => writeKind(text, SymbolDisplayPartKind.parameterName), writeSymbol: writeSymbol, writeLine: writeLine, increaseIndent: () => { indent++; }, @@ -1434,7 +1464,7 @@ module ts { } } - function mapToDisplayParts(writeDisplayParts: (writer: DisplayPartsSymbolWriter) => void): SymbolDisplayPart[] { + export function mapToDisplayParts(writeDisplayParts: (writer: DisplayPartsSymbolWriter) => void): SymbolDisplayPart[] { writeDisplayParts(displayPartWriter); var result = displayPartWriter.displayParts(); displayPartWriter.clear(); @@ -1443,19 +1473,19 @@ module ts { export function typeToDisplayParts(typechecker: TypeChecker, type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[] { return mapToDisplayParts(writer => { - typechecker.writeType(type, writer, enclosingDeclaration, flags); + typechecker.getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); }); } export function symbolToDisplayParts(typeChecker: TypeChecker, symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): SymbolDisplayPart[] { return mapToDisplayParts(writer => { - typeChecker.writeSymbol(symbol, writer, enclosingDeclaration, meaning, flags); + typeChecker.getSymbolDisplayBuilder().buildSymbolDisplay(symbol, writer, enclosingDeclaration, meaning, flags); }); } function signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[]{ return mapToDisplayParts(writer => { - typechecker.writeSignature(signature, writer, enclosingDeclaration, flags); + typechecker.getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags); }); } @@ -2287,7 +2317,7 @@ module ts { return undefined; } - function createCompletionEntry(symbol: Symbol): CompletionEntry { + function createCompletionEntry(symbol: Symbol, typeChecker: TypeChecker): CompletionEntry { // Try to get a valid display name for this symbol, if we could not find one, then ignore it. // We would like to only show things that can be added after a dot, so for instance numeric properties can // not be accessed with a dot (a.1 <- invalid) @@ -2302,7 +2332,7 @@ module ts { // We COULD also just do what 'getSymbolModifiers' does, which is to use the first declaration. return { name: displayName, - kind: getSymbolKind(symbol, SemanticMeaning.All), + kind: getSymbolKind(symbol, typeChecker), kindModifiers: getSymbolModifiers(symbol) }; } @@ -2310,7 +2340,7 @@ module ts { function getCompletionsAtPosition(filename: string, position: number, isMemberCompletion: boolean) { function getCompletionEntriesFromSymbols(symbols: Symbol[], session: CompletionSession): void { forEach(symbols, symbol => { - var entry = createCompletionEntry(symbol); + var entry = createCompletionEntry(symbol, session.typeChecker); if (entry && !lookUp(session.symbols, entry.name)) { session.entries.push(entry); session.symbols[entry.name] = symbol; @@ -2567,10 +2597,9 @@ module ts { } var type = typeInfoResolver.getTypeOfNode(node); - var apparentType = type && typeInfoResolver.getApparentType(type); - if (apparentType) { + if (type) { // Filter private properties - forEach(apparentType.getApparentProperties(), symbol => { + forEach(type.getApparentProperties(), symbol => { if (typeInfoResolver.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); } @@ -2638,7 +2667,7 @@ module ts { if (symbol) { var type = session.typeChecker.getTypeOfSymbol(symbol); Debug.assert(type, "Could not find type for symbol"); - var completionEntry = createCompletionEntry(symbol); + var completionEntry = createCompletionEntry(symbol, session.typeChecker); // TODO(drosen): Right now we just permit *all* semantic meanings when calling 'getSymbolKind' // which is permissible given that it is backwards compatible; but really we should consider // passing the meaning for the node so that we don't report that a suggestion for a value is an interface. @@ -2687,20 +2716,16 @@ module ts { } } - function getSymbolKind(symbol: Symbol, meaningAtLocation: SemanticMeaning): string { - var flags = typeInfoResolver.getRootSymbol(symbol).getFlags(); + // TODO(drosen): use contextual SemanticMeaning. + function getSymbolKind(symbol: Symbol, typeResolver: TypeChecker): string { + var flags = symbol.getFlags(); if (flags & SymbolFlags.Class) return ScriptElementKind.classElement; if (flags & SymbolFlags.Enum) return ScriptElementKind.enumElement; - - // The following should only apply if encountered at a type position, - // and need to have precedence over other meanings if this is the case. - if (meaningAtLocation & SemanticMeaning.Type) { - if (flags & SymbolFlags.Interface) return ScriptElementKind.interfaceElement; - if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement; - } - - var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags); + if (flags & SymbolFlags.Interface) return ScriptElementKind.interfaceElement; + if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement; + + var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, typeResolver); if (result === ScriptElementKind.unknown) { if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement; if (flags & SymbolFlags.EnumMember) return ScriptElementKind.variableElement; @@ -2710,23 +2735,40 @@ module ts { return result; } - function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol: Symbol, flags: SymbolFlags) { + function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol: Symbol, flags: SymbolFlags, typeResolver: TypeChecker) { + if (typeResolver.isUndefinedSymbol(symbol)) { + return ScriptElementKind.variableElement; + } + if (typeResolver.isArgumentsSymbol(symbol)) { + return ScriptElementKind.localVariableElement; + } if (flags & SymbolFlags.Variable) { if (isFirstDeclarationOfSymbolParameter(symbol)) { return ScriptElementKind.parameterElement; } return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement; } - if (flags & SymbolFlags.Undefined) { - return ScriptElementKind.variableElement; - } if (flags & SymbolFlags.Function) return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localFunctionElement : ScriptElementKind.functionElement; if (flags & SymbolFlags.GetAccessor) return ScriptElementKind.memberGetAccessorElement; if (flags & SymbolFlags.SetAccessor) return ScriptElementKind.memberSetAccessorElement; if (flags & SymbolFlags.Method) return ScriptElementKind.memberFunctionElement; - if (flags & SymbolFlags.Property) return ScriptElementKind.memberVariableElement; if (flags & SymbolFlags.Constructor) return ScriptElementKind.constructorImplementationElement; + if (flags & SymbolFlags.Property) { + if (flags & SymbolFlags.UnionProperty) { + return forEach(typeInfoResolver.getRootSymbols(symbol), rootSymbol => { + var rootSymbolFlags = rootSymbol.getFlags(); + if (rootSymbolFlags & SymbolFlags.Property) { + return ScriptElementKind.memberVariableElement; + } + if (rootSymbolFlags & SymbolFlags.GetAccessor) return ScriptElementKind.memberVariableElement; + if (rootSymbolFlags & SymbolFlags.SetAccessor) return ScriptElementKind.memberVariableElement; + Debug.assert(rootSymbolFlags & SymbolFlags.Method); + }) || ScriptElementKind.memberFunctionElement; + } + return ScriptElementKind.memberVariableElement; + } + return ScriptElementKind.unknown; } @@ -2778,19 +2820,15 @@ module ts { semanticMeaning = getMeaningFromLocation(location)) { var displayParts: SymbolDisplayPart[] = []; var documentation: SymbolDisplayPart[]; - var symbolFlags = typeResolver.getRootSymbol(symbol).flags; - var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags); + var symbolFlags = symbol.flags; + var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, typeResolver); var hasAddedSymbolInfo: boolean; // Class at constructor site need to be shown as constructor apart from property,method, vars - if (symbolKind !== ScriptElementKind.unknown || symbolFlags & SymbolFlags.Signature || symbolFlags & SymbolFlags.Class) { + if (symbolKind !== ScriptElementKind.unknown || symbolFlags & SymbolFlags.Class || symbolFlags & SymbolFlags.Import) { // If it is accessor they are allowed only if location is at name of the accessor if (symbolKind === ScriptElementKind.memberGetAccessorElement || symbolKind === ScriptElementKind.memberSetAccessorElement) { symbolKind = ScriptElementKind.memberVariableElement; } - else if (symbol.name === "undefined") { - // undefined is symbol and not property - symbolKind = ScriptElementKind.variableElement; - } var type = typeResolver.getTypeOfSymbol(symbol); if (type) { @@ -2833,6 +2871,18 @@ module ts { symbolKind = ScriptElementKind.constructorImplementationElement; addPrefixForAnyFunctionOrVar(type.symbol, symbolKind); } + else if (symbolFlags & SymbolFlags.Import) { + symbolKind = ScriptElementKind.alias; + displayParts.push(punctuationPart(SyntaxKind.OpenParenToken)); + displayParts.push(textPart(symbolKind)); + displayParts.push(punctuationPart(SyntaxKind.CloseParenToken)); + displayParts.push(spacePart()); + if (useConstructSignatures) { + displayParts.push(keywordPart(SyntaxKind.NewKeyword)); + displayParts.push(spacePart()); + } + addFullSymbolName(symbol); + } else { addPrefixForAnyFunctionOrVar(symbol, symbolKind); } @@ -2893,27 +2943,27 @@ module ts { if (symbolFlags & SymbolFlags.Class && !hasAddedSymbolInfo) { displayParts.push(keywordPart(SyntaxKind.ClassKeyword)); displayParts.push(spacePart()); - displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments)); + addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); } if ((symbolFlags & SymbolFlags.Interface) && (semanticMeaning & SemanticMeaning.Type)) { addNewLineIfDisplayPartsExist(); displayParts.push(keywordPart(SyntaxKind.InterfaceKeyword)); displayParts.push(spacePart()); - displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments)); + addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); } if (symbolFlags & SymbolFlags.Enum) { addNewLineIfDisplayPartsExist(); displayParts.push(keywordPart(SyntaxKind.EnumKeyword)); displayParts.push(spacePart()); - displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile)); + addFullSymbolName(symbol); } if (symbolFlags & SymbolFlags.Module) { addNewLineIfDisplayPartsExist(); displayParts.push(keywordPart(SyntaxKind.ModuleKeyword)); displayParts.push(spacePart()); - displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile)); + addFullSymbolName(symbol); } if ((symbolFlags & SymbolFlags.TypeParameter) && (semanticMeaning & SemanticMeaning.Type)) { addNewLineIfDisplayPartsExist(); @@ -2921,13 +2971,13 @@ module ts { displayParts.push(textPart("type parameter")); displayParts.push(punctuationPart(SyntaxKind.CloseParenToken)); displayParts.push(spacePart()); - displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, enclosingDeclaration)); + addFullSymbolName(symbol); displayParts.push(spacePart()); displayParts.push(keywordPart(SyntaxKind.InKeyword)); displayParts.push(spacePart()); if (symbol.parent) { // Class/Interface type parameter - displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol.parent, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments)) + addFullSymbolName(symbol.parent, enclosingDeclaration); writeTypeParametersOfSymbol(symbol.parent, enclosingDeclaration); } else { @@ -2939,7 +2989,7 @@ module ts { displayParts.push(spacePart()); } else if (signatureDeclaration.kind !== SyntaxKind.CallSignature && signatureDeclaration.name) { - displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, signatureDeclaration.symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments)) + addFullSymbolName(signatureDeclaration.symbol); } displayParts.push.apply(displayParts, signatureToDisplayParts(typeResolver, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature)); } @@ -2959,24 +3009,43 @@ module ts { } if (symbolFlags & SymbolFlags.Import) { addNewLineIfDisplayPartsExist(); - displayParts.push(punctuationPart(SyntaxKind.OpenParenToken)); - displayParts.push(textPart("alias")); - displayParts.push(punctuationPart(SyntaxKind.CloseParenToken)); + displayParts.push(keywordPart(SyntaxKind.ImportKeyword)); displayParts.push(spacePart()); - displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile)); + addFullSymbolName(symbol); + displayParts.push(spacePart()); + displayParts.push(punctuationPart(SyntaxKind.EqualsToken)); + displayParts.push(spacePart()); + ts.forEach(symbol.declarations, declaration => { + if (declaration.kind === SyntaxKind.ImportDeclaration) { + var importDeclaration = declaration; + if (importDeclaration.externalModuleName) { + displayParts.push(keywordPart(SyntaxKind.RequireKeyword)); + displayParts.push(punctuationPart(SyntaxKind.OpenParenToken)); + displayParts.push(displayPart(getTextOfNode(importDeclaration.externalModuleName), SymbolDisplayPartKind.stringLiteral)); + displayParts.push(punctuationPart(SyntaxKind.CloseParenToken)); + } + else { + var internalAliasSymbol = typeResolver.getSymbolInfo(importDeclaration.entityName); + addFullSymbolName(internalAliasSymbol, enclosingDeclaration); + } + return true; + } + }); } if (!hasAddedSymbolInfo) { if (symbolKind !== ScriptElementKind.unknown) { if (type) { addPrefixForAnyFunctionOrVar(symbol, symbolKind); + // For properties, variables and local vars: show the type if (symbolKind === ScriptElementKind.memberVariableElement || - symbolFlags & SymbolFlags.Variable) { + symbolFlags & SymbolFlags.Variable || + symbolKind === ScriptElementKind.localVariableElement) { displayParts.push(punctuationPart(SyntaxKind.ColonToken)); displayParts.push(spacePart()); // If the type is type parameter, format it specially if (type.symbol && type.symbol.flags & SymbolFlags.TypeParameter) { var typeParameterParts = mapToDisplayParts(writer => { - typeResolver.writeTypeParameter(type, writer, enclosingDeclaration); + typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(type, writer, enclosingDeclaration); }); displayParts.push.apply(displayParts, typeParameterParts); } @@ -2988,14 +3057,15 @@ module ts { symbolFlags & SymbolFlags.Method || symbolFlags & SymbolFlags.Constructor || symbolFlags & SymbolFlags.Signature || - symbolFlags & SymbolFlags.Accessor) { + symbolFlags & SymbolFlags.Accessor || + symbolKind === ScriptElementKind.memberFunctionElement) { var allSignatures = type.getCallSignatures(); addSignatureDisplayParts(allSignatures[0], allSignatures); } } } else { - symbolKind = getSymbolKind(symbol, semanticMeaning); + symbolKind = getSymbolKind(symbol, typeResolver); } } @@ -3011,6 +3081,12 @@ module ts { } } + function addFullSymbolName(symbol: Symbol, enclosingDeclaration?: Node) { + var fullSymbolDisplayParts = symbolToDisplayParts(typeResolver, symbol, enclosingDeclaration || sourceFile, /*meaning*/ undefined, + SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing); + displayParts.push.apply(displayParts, fullSymbolDisplayParts); + } + function addPrefixForAnyFunctionOrVar(symbol: Symbol, symbolKind: string) { addNewLineIfDisplayPartsExist(); if (symbolKind) { @@ -3018,8 +3094,7 @@ module ts { displayParts.push(textPart(symbolKind)); displayParts.push(punctuationPart(SyntaxKind.CloseParenToken)); displayParts.push(spacePart()); - // Write type parameters of class/Interface if it is property/method of the generic class/interface - displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments)); + addFullSymbolName(symbol); } } @@ -3039,7 +3114,7 @@ module ts { function writeTypeParametersOfSymbol(symbol: Symbol, enclosingDeclaration: Node) { var typeParameterParts = mapToDisplayParts(writer => { - typeResolver.writeTypeParametersOfSymbol(symbol, writer, enclosingDeclaration); + typeResolver.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration); }); displayParts.push.apply(displayParts, typeParameterParts); } @@ -3057,12 +3132,6 @@ module ts { var symbol = typeInfoResolver.getSymbolInfo(node); if (!symbol) { - return undefined; - } - - var symbol = typeInfoResolver.getSymbolInfo(node); - if (!symbol) { - // Try getting just type at this position and show switch (node.kind) { case SyntaxKind.Identifier: @@ -3070,7 +3139,7 @@ module ts { case SyntaxKind.QualifiedName: case SyntaxKind.ThisKeyword: case SyntaxKind.SuperKeyword: - // For the identifiers/this/usper etc get the type at position + // For the identifiers/this/super etc get the type at position var type = typeInfoResolver.getTypeOfNode(node); if (type) { return { @@ -3097,7 +3166,7 @@ module ts { } /// Goto definition - function getDefinitionAtPosition(filename: string, position: number): DefinitionInfo[]{ + function getDefinitionAtPosition(filename: string, position: number): DefinitionInfo[] { function getDefinitionInfo(node: Node, symbolKind: string, symbolName: string, containerName: string): DefinitionInfo { return { fileName: node.getSourceFile().filename, @@ -3129,7 +3198,7 @@ module ts { result.push(getDefinitionInfo(declarations[declarations.length - 1], symbolKind, symbolName, containerName)); return true; } - + return false; } @@ -3193,7 +3262,7 @@ module ts { // Could not find a symbol e.g. node is string or number keyword, // or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol - if (!symbol || !(symbol.getDeclarations())) { + if (!symbol) { return undefined; } @@ -3201,7 +3270,7 @@ module ts { var declarations = symbol.getDeclarations(); var symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol - var symbolKind = getSymbolKind(symbol, getMeaningFromLocation(node)); + var symbolKind = getSymbolKind(symbol, typeInfoResolver); var containerSymbol = symbol.parent; var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : ""; @@ -3726,18 +3795,20 @@ module ts { return [getReferenceEntryFromNode(node)]; } - // the symbol was an internal symbol and does not have a declaration e.g.undefined symbol - if (!symbol.getDeclarations()) { + var declarations = symbol.declarations; + + // The symbol was an internal symbol and does not have a declaration e.g.undefined symbol + if (!declarations || !declarations.length) { return undefined; } var result: ReferenceEntry[]; // Compute the meaning from the location and the symbol it references - var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), symbol.getDeclarations()); + var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations); // Get the text to search for, we need to normalize it as external module names will have quote - var symbolName = getNormalizedSymbolName(symbol); + var symbolName = getNormalizedSymbolName(symbol.name, declarations); // Get syntactic diagnostics var scope = getSymbolScope(symbol); @@ -3759,15 +3830,15 @@ module ts { return result; - function getNormalizedSymbolName(symbol: Symbol): string { + function getNormalizedSymbolName(symbolName: string, declarations: Declaration[]): string { // Special case for function expressions, whose names are solely local to their bodies. - var functionExpression = getDeclarationOfKind(symbol, SyntaxKind.FunctionExpression); + var functionExpression = forEach(declarations, d => d.kind === SyntaxKind.FunctionExpression ? d : undefined); if (functionExpression && functionExpression.name) { var name = functionExpression.name.text; } else { - var name = symbol.name; + var name = symbolName; } var length = name.length; @@ -3794,22 +3865,24 @@ module ts { var scope: Node = undefined; var declarations = symbol.getDeclarations(); - for (var i = 0, n = declarations.length; i < n; i++) { - var container = getContainerNode(declarations[i]); + if (declarations) { + for (var i = 0, n = declarations.length; i < n; i++) { + var container = getContainerNode(declarations[i]); - if (scope && scope !== container) { - // Different declarations have different containers, bail out - return undefined; + if (scope && scope !== container) { + // Different declarations have different containers, bail out + return undefined; + } + + if (container.kind === SyntaxKind.SourceFile && !isExternalModule(container)) { + // This is a global variable and not an external module, any declaration defined + // within this scope is visible outside the file + return undefined; + } + + // The search scope is the container node + scope = container; } - - if (container.kind === SyntaxKind.SourceFile && !isExternalModule(container)) { - // This is a global variable and not an external module, any declaration defined - // within this scope is visible outside the file - return undefined; - } - - // The search scope is the container node - scope = container; } return scope; @@ -3945,14 +4018,7 @@ module ts { } var referenceSymbol = typeInfoResolver.getSymbolInfo(referenceLocation); - - // Could not find a symbol e.g. node is string or number keyword, - // or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol - if (!referenceSymbol || !(referenceSymbol.getDeclarations())) { - return; - } - - if (isRelatableToSearchSet(searchSymbols, referenceSymbol, referenceLocation)) { + if (referenceSymbol && isRelatableToSearchSet(searchSymbols, referenceSymbol, referenceLocation)) { result.push(getReferenceEntryFromNode(referenceLocation)); } }); @@ -4114,24 +4180,27 @@ module ts { // The search set contains at least the current symbol var result = [symbol]; - // If the symbol is an instantiation from a another symbol (e.g. widened symbol) , add the root the list - var rootSymbol = typeInfoResolver.getRootSymbol(symbol); - if (rootSymbol && rootSymbol !== symbol) { - result.push(rootSymbol); - } - // If the location is in a context sensitive location (i.e. in an object literal) try // to get a contextual type for it, and add the property symbol from the contextual // type to the search set if (isNameOfPropertyAssignment(location)) { - var symbolFromContextualType = getPropertySymbolFromContextualType(location); - if (symbolFromContextualType) result.push(typeInfoResolver.getRootSymbol(symbolFromContextualType)); + forEach(getPropertySymbolsFromContextualType(location), contextualSymbol => { + result.push.apply(result, typeInfoResolver.getRootSymbols(contextualSymbol)); + }); } - // Add symbol of properties/methods of the same name in base classes and implemented interfaces definitions - if (symbol.parent && symbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { - getPropertySymbolsFromBaseTypes(symbol.parent, symbol.getName(), result); - } + // If this is a union property, add all the symbols from all its source symbols in all unioned types. + // If the symbol is an instantiation from a another symbol (e.g. widened symbol) , add the root the list + forEach(typeInfoResolver.getRootSymbols(symbol), rootSymbol => { + if (rootSymbol !== symbol) { + result.push(rootSymbol); + } + + // Add symbol of properties/methods of the same name in base classes and implemented interfaces definitions + if (rootSymbol.parent && rootSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { + getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result); + } + }); return result; } @@ -4167,11 +4236,7 @@ module ts { } function isRelatableToSearchSet(searchSymbols: Symbol[], referenceSymbol: Symbol, referenceLocation: Node): boolean { - // Unwrap symbols to get to the root (e.g. transient symbols as a result of widening) - var referenceSymbolTarget = typeInfoResolver.getRootSymbol(referenceSymbol); - - // if it is in the list, then we are done - if (searchSymbols.indexOf(referenceSymbolTarget) >= 0) { + if (searchSymbols.indexOf(referenceSymbol) >= 0) { return true; } @@ -4179,29 +4244,61 @@ module ts { // object literal, lookup the property symbol in the contextual type, and use this symbol to // compare to our searchSymbol if (isNameOfPropertyAssignment(referenceLocation)) { - var symbolFromContextualType = getPropertySymbolFromContextualType(referenceLocation); - if (symbolFromContextualType && searchSymbols.indexOf(typeInfoResolver.getRootSymbol(symbolFromContextualType)) >= 0) { + return forEach(getPropertySymbolsFromContextualType(referenceLocation), contextualSymbol => { + return forEach(typeInfoResolver.getRootSymbols(contextualSymbol), s => searchSymbols.indexOf(s) >= 0); + }); + } + + // Unwrap symbols to get to the root (e.g. transient symbols as a result of widening) + // Or a union property, use its underlying unioned symbols + return forEach(typeInfoResolver.getRootSymbols(referenceSymbol), rootSymbol => { + // if it is in the list, then we are done + if (searchSymbols.indexOf(rootSymbol) >= 0) { return true; } - } - // Finally, try all properties with the same name in any type the containing type extend or implemented, and - // see if any is in the list - if (referenceSymbol.parent && referenceSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { - var result: Symbol[] = []; - getPropertySymbolsFromBaseTypes(referenceSymbol.parent, referenceSymbol.getName(), result); - return forEach(result, s => searchSymbols.indexOf(s) >= 0); - } + // Finally, try all properties with the same name in any type the containing type extended or implemented, and + // see if any is in the list + if (rootSymbol.parent && rootSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { + var result: Symbol[] = []; + getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result); + return forEach(result, s => searchSymbols.indexOf(s) >= 0); + } - return false; + return false; + }); } - function getPropertySymbolFromContextualType(node: Node): Symbol { + function getPropertySymbolsFromContextualType(node: Node): Symbol[] { if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeInfoResolver.getContextualType(objectLiteral); + var name = (node).text; if (contextualType) { - return typeInfoResolver.getPropertyOfType(contextualType, (node).text); + if (contextualType.flags & TypeFlags.Union) { + // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) + // if not, search the constituent types for the property + var unionProperty = contextualType.getProperty(name) + if (unionProperty) { + return [unionProperty]; + } + else { + var result: Symbol[] = []; + forEach((contextualType).types, t => { + var symbol = t.getProperty(name); + if (symbol) { + result.push(symbol); + } + }); + return result; + } + } + else { + var symbol = contextualType.getProperty(name); + if (symbol) { + return [symbol]; + } + } } } return undefined; @@ -4718,7 +4815,24 @@ module ts { } } else if (flags & SymbolFlags.Module) { - return ClassificationTypeNames.moduleName; + // Only classify a module as such if + // - It appears in a namespace context. + // - There exists a module declaration which actually impacts the value side. + if (meaningAtPosition & SemanticMeaning.Namespace || + (meaningAtPosition & SemanticMeaning.Value && hasValueSideModule(symbol))) { + return ClassificationTypeNames.moduleName; + } + } + + return undefined; + + /** + * Returns true if there exists a module that introduces entities on the value side. + */ + function hasValueSideModule(symbol: Symbol): boolean { + return forEach(symbol.declarations, declaration => { + return declaration.kind === SyntaxKind.ModuleDeclaration && isInstantiated(declaration); + }); } } @@ -4749,115 +4863,99 @@ module ts { var sourceFile = getCurrentSourceFile(fileName); var result: ClassifiedSpan[] = []; - processElement(sourceFile.getSourceUnit()); + processElement(sourceFile); return result; - function classifyTrivia(trivia: TypeScript.ISyntaxTrivia) { - if (trivia.isComment() && span.intersectsWith(trivia.fullStart(), trivia.fullWidth())) { + function classifyComment(comment: CommentRange) { + var width = comment.end - comment.pos; + if (span.intersectsWith(comment.pos, width)) { result.push({ - textSpan: new TypeScript.TextSpan(trivia.fullStart(), trivia.fullWidth()), + textSpan: new TypeScript.TextSpan(comment.pos, width), classificationType: ClassificationTypeNames.comment }); } } - function classifyTriviaList(trivia: TypeScript.ISyntaxTriviaList) { - for (var i = 0, n = trivia.count(); i < n; i++) { - classifyTrivia(trivia.syntaxTriviaAt(i)); - } - } + function classifyToken(token: Node): void { + forEach(getLeadingCommentRanges(sourceFile.text, token.getFullStart()), classifyComment); - function classifyToken(token: TypeScript.ISyntaxToken) { - if (token.hasLeadingComment()) { - classifyTriviaList(token.leadingTrivia()); - } - - if (TypeScript.width(token) > 0) { + if (token.getWidth() > 0) { var type = classifyTokenType(token); if (type) { result.push({ - textSpan: new TypeScript.TextSpan(TypeScript.start(token), TypeScript.width(token)), + textSpan: new TypeScript.TextSpan(token.getStart(), token.getWidth()), classificationType: type }); } } - if (token.hasTrailingComment()) { - classifyTriviaList(token.trailingTrivia()); - } + forEach(getTrailingCommentRanges(sourceFile.text, token.getEnd()), classifyComment); } - function classifyTokenType(token: TypeScript.ISyntaxToken): string { - var tokenKind = token.kind(); - if (TypeScript.SyntaxFacts.isAnyKeyword(token.kind())) { + function classifyTokenType(token: Node): string { + var tokenKind = token.kind; + if (isKeyword(tokenKind)) { return ClassificationTypeNames.keyword; } - // Special case < and > If they appear in a generic context they are punctation, + // Special case < and > If they appear in a generic context they are punctuation, // not operators. - if (tokenKind === TypeScript.SyntaxKind.LessThanToken || tokenKind === TypeScript.SyntaxKind.GreaterThanToken) { - var tokenParentKind = token.parent.kind(); - if (tokenParentKind === TypeScript.SyntaxKind.TypeArgumentList || - tokenParentKind === TypeScript.SyntaxKind.TypeParameterList) { - + if (tokenKind === SyntaxKind.LessThanToken || tokenKind === SyntaxKind.GreaterThanToken) { + // If the node owning the token has a type argument list or type parameter list, then + // we can effectively assume that a '<' and '>' belong to those lists. + if (getTypeArgumentOrTypeParameterList(token.parent)) { return ClassificationTypeNames.punctuation; } } - if (TypeScript.SyntaxFacts.isBinaryExpressionOperatorToken(tokenKind) || - TypeScript.SyntaxFacts.isPrefixUnaryExpressionOperatorToken(tokenKind)) { - return ClassificationTypeNames.operator; + if (isPunctuation(token)) { + // the '=' in a variable declaration is special cased here. + if (token.parent.kind === SyntaxKind.BinaryExpression || + token.parent.kind === SyntaxKind.VariableDeclaration || + token.parent.kind === SyntaxKind.PrefixOperator || + token.parent.kind === SyntaxKind.PostfixOperator || + token.parent.kind === SyntaxKind.ConditionalExpression) { + return ClassificationTypeNames.operator; + } + else { + return ClassificationTypeNames.punctuation; + } } - else if (TypeScript.SyntaxFacts.isAnyPunctuation(tokenKind)) { - return ClassificationTypeNames.punctuation; - } - else if (tokenKind === TypeScript.SyntaxKind.NumericLiteral) { + else if (tokenKind === SyntaxKind.NumericLiteral) { return ClassificationTypeNames.numericLiteral; } - else if (tokenKind === TypeScript.SyntaxKind.StringLiteral) { + else if (tokenKind === SyntaxKind.StringLiteral) { return ClassificationTypeNames.stringLiteral; } - else if (tokenKind === TypeScript.SyntaxKind.RegularExpressionLiteral) { - // TODO: we shoudl get another classification type for these literals. + else if (tokenKind === SyntaxKind.RegularExpressionLiteral) { + // TODO: we should get another classification type for these literals. return ClassificationTypeNames.stringLiteral; } - else if (tokenKind === TypeScript.SyntaxKind.IdentifierName) { - var current: TypeScript.ISyntaxNodeOrToken = token; - var parent = token.parent; - while (parent.kind() === TypeScript.SyntaxKind.QualifiedName) { - current = parent; - parent = parent.parent; - } - - switch (parent.kind()) { - case TypeScript.SyntaxKind.SimplePropertyAssignment: - if ((parent).propertyName === token) { - return ClassificationTypeNames.identifier; - } - return; - case TypeScript.SyntaxKind.ClassDeclaration: - if ((parent).identifier === token) { + else if (tokenKind === SyntaxKind.Identifier) { + switch (token.parent.kind) { + case SyntaxKind.ClassDeclaration: + if ((token.parent).name === token) { return ClassificationTypeNames.className; } return; - case TypeScript.SyntaxKind.TypeParameter: - if ((parent).identifier === token) { + case SyntaxKind.TypeParameter: + if ((token.parent).name === token) { return ClassificationTypeNames.typeParameterName; } return; - case TypeScript.SyntaxKind.InterfaceDeclaration: - if ((parent).identifier === token) { + case SyntaxKind.InterfaceDeclaration: + if ((token.parent).name === token) { return ClassificationTypeNames.interfaceName; } return; - case TypeScript.SyntaxKind.EnumDeclaration: - if ((parent).identifier === token) { + case SyntaxKind.EnumDeclaration: + if ((token.parent).name === token) { return ClassificationTypeNames.enumName; } return; - case TypeScript.SyntaxKind.ModuleDeclaration: - if ((parent).name === current) { + case SyntaxKind.ModuleDeclaration: + if ((token.parent).name === token) { return ClassificationTypeNames.moduleName; } return; @@ -4867,19 +4965,18 @@ module ts { } } - function processElement(element: TypeScript.ISyntaxElement) { + function processElement(element: Node) { // Ignore nodes that don't intersect the original span to classify. - if (!TypeScript.isShared(element) && span.intersectsWith(TypeScript.fullStart(element), TypeScript.fullWidth(element))) { - for (var i = 0, n = TypeScript.childCount(element); i < n; i++) { - var child = TypeScript.childAt(element, i); - if (child) { - if (TypeScript.isToken(child)) { - classifyToken(child); - } - else { - // Recurse into our child nodes. - processElement(child); - } + if (span.intersectsWith(element.getFullStart(), element.getFullWidth())) { + var children = element.getChildren(); + for (var i = 0, n = children.length; i < n; i++) { + var child = children[i]; + if (isToken(child)) { + classifyToken(child); + } + else { + // Recurse into our child nodes. + processElement(child); } } } @@ -5179,7 +5276,7 @@ module ts { // Only allow a symbol to be renamed if it actually has at least one declaration. if (symbol && symbol.getDeclarations() && symbol.getDeclarations().length > 0) { - var kind = getSymbolKind(symbol, getMeaningFromLocation(node)); + var kind = getSymbolKind(symbol, typeInfoResolver); if (kind) { return getRenameInfo(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind, getSymbolModifiers(symbol), diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 273cfda99b8..86e378abb45 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -258,6 +258,13 @@ module ts.SignatureHelp { return undefined; } + function getChildListThatStartsWithOpenerToken(parent: Node, openerToken: Node, sourceFile: SourceFile): Node { + var children = parent.getChildren(sourceFile); + var indexOfOpenerToken = children.indexOf(openerToken); + Debug.assert(indexOfOpenerToken >= 0 && children.length > indexOfOpenerToken + 1); + return children[indexOfOpenerToken + 1]; + } + /** * The selectedItemIndex could be negative for several reasons. * 1. There are too many arguments for all of the overloads @@ -287,74 +294,51 @@ module ts.SignatureHelp { function createSignatureHelpItems(candidates: Signature[], bestSignature: Signature, argumentInfoOrTypeArgumentInfo: ListItemInfo): SignatureHelpItems { var argumentListOrTypeArgumentList = argumentInfoOrTypeArgumentInfo.list; + var parent = argumentListOrTypeArgumentList.parent; + var isTypeParameterHelp = parent.typeArguments && parent.typeArguments.pos === argumentListOrTypeArgumentList.pos; + Debug.assert(isTypeParameterHelp || parent.arguments.pos === argumentListOrTypeArgumentList.pos); + + var callTargetNode = (argumentListOrTypeArgumentList.parent).func; + var callTargetSymbol = typeInfoResolver.getSymbolInfo(callTargetNode); + var callTargetDisplayParts = callTargetSymbol && symbolToDisplayParts(typeInfoResolver, callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined); var items: SignatureHelpItem[] = map(candidates, candidateSignature => { - var parameters = candidateSignature.parameters; - var parameterHelpItems: SignatureHelpParameter[] = parameters.length === 0 ? emptyArray : map(parameters, p => { - var displayParts: SymbolDisplayPart[] = []; + var signatureHelpParameters: SignatureHelpParameter[]; + var prefixParts: SymbolDisplayPart[] = []; + var suffixParts: SymbolDisplayPart[] = []; - if (candidateSignature.hasRestParameter && parameters[parameters.length - 1] === p) { - displayParts.push(punctuationPart(SyntaxKind.DotDotDotToken)); - } - - displayParts.push(symbolPart(p.name, p)); - - var isOptional = !!(p.valueDeclaration.flags & NodeFlags.QuestionMark); - if (isOptional) { - displayParts.push(punctuationPart(SyntaxKind.QuestionToken)); - } - - displayParts.push(punctuationPart(SyntaxKind.ColonToken)); - displayParts.push(spacePart()); - - var typeParts = typeToDisplayParts(typeInfoResolver, typeInfoResolver.getTypeOfSymbol(p), argumentListOrTypeArgumentList); - displayParts.push.apply(displayParts, typeParts); - - return { - name: p.name, - documentation: p.getDocumentationComment(), - displayParts: displayParts, - isOptional: isOptional - }; - }); - - var callTargetNode = (argumentListOrTypeArgumentList.parent).func; - var callTargetSymbol = typeInfoResolver.getSymbolInfo(callTargetNode); - - var prefixParts = callTargetSymbol ? symbolToDisplayParts(typeInfoResolver, callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined) : []; - - var separatorParts = [punctuationPart(SyntaxKind.CommaToken), spacePart()]; - - // TODO(jfreeman): Constraints? - if (candidateSignature.typeParameters && candidateSignature.typeParameters.length) { - prefixParts.push(punctuationPart(SyntaxKind.LessThanToken)); - - for (var i = 0, n = candidateSignature.typeParameters.length; i < n; i++) { - if (i) { - prefixParts.push.apply(prefixParts, separatorParts); - } - - var tp = candidateSignature.typeParameters[i].symbol; - prefixParts.push(symbolPart(tp.name, tp)); - } - - prefixParts.push(punctuationPart(SyntaxKind.GreaterThanToken)); + if (callTargetDisplayParts) { + prefixParts.push.apply(prefixParts, callTargetDisplayParts); } - prefixParts.push(punctuationPart(SyntaxKind.OpenParenToken)); + if (isTypeParameterHelp) { + prefixParts.push(punctuationPart(SyntaxKind.LessThanToken)); + var typeParameters = candidateSignature.typeParameters; + signatureHelpParameters = typeParameters && typeParameters.length > 0 ? map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray; + suffixParts.push(punctuationPart(SyntaxKind.GreaterThanToken)); + var parameterParts = mapToDisplayParts(writer => + typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, argumentListOrTypeArgumentList)); + suffixParts.push.apply(suffixParts, parameterParts); + } + else { + var typeParameterParts = mapToDisplayParts(writer => + typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, argumentListOrTypeArgumentList)); + prefixParts.push.apply(prefixParts, typeParameterParts); + prefixParts.push(punctuationPart(SyntaxKind.OpenParenToken)); + var parameters = candidateSignature.parameters; + signatureHelpParameters = parameters.length > 0 ? map(parameters, createSignatureHelpParameterForParameter) : emptyArray; + suffixParts.push(punctuationPart(SyntaxKind.CloseParenToken)); + } - var suffixParts = [punctuationPart(SyntaxKind.CloseParenToken)]; - suffixParts.push(punctuationPart(SyntaxKind.ColonToken)); - suffixParts.push(spacePart()); - - var typeParts = typeToDisplayParts(typeInfoResolver, candidateSignature.getReturnType(), argumentListOrTypeArgumentList); - suffixParts.push.apply(suffixParts, typeParts); + var returnTypeParts = mapToDisplayParts(writer => + typeInfoResolver.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, argumentListOrTypeArgumentList)); + suffixParts.push.apply(suffixParts, returnTypeParts); return { isVariadic: candidateSignature.hasRestParameter, prefixDisplayParts: prefixParts, suffixDisplayParts: suffixParts, - separatorDisplayParts: separatorParts, - parameters: parameterHelpItems, + separatorDisplayParts: [punctuationPart(SyntaxKind.CommaToken), spacePart()], + parameters: signatureHelpParameters, documentation: candidateSignature.getDocumentationComment() }; }); @@ -400,12 +384,32 @@ module ts.SignatureHelp { argumentIndex: argumentIndex, argumentCount: argumentCount }; + + function createSignatureHelpParameterForParameter(parameter: Symbol): SignatureHelpParameter { + var displayParts = mapToDisplayParts(writer => + typeInfoResolver.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, argumentListOrTypeArgumentList)); + + var isOptional = !!(parameter.valueDeclaration.flags & NodeFlags.QuestionMark); + + return { + name: parameter.name, + documentation: parameter.getDocumentationComment(), + displayParts: displayParts, + isOptional: isOptional + }; + } + + function createSignatureHelpParameterForTypeParameter(typeParameter: TypeParameter): SignatureHelpParameter { + var displayParts = mapToDisplayParts(writer => + typeInfoResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, argumentListOrTypeArgumentList)); + + return { + name: typeParameter.symbol.name, + documentation: emptyArray, + displayParts: displayParts, + isOptional: false + }; + } } } - - function getChildListThatStartsWithOpenerToken(parent: Node, openerToken: Node, sourceFile: SourceFile): Node { - var children = parent.getChildren(sourceFile); - var indexOfOpenerToken = children.indexOf(openerToken); - return children[indexOfOpenerToken + 1]; - } } \ No newline at end of file diff --git a/src/services/syntax/syntaxTree.ts b/src/services/syntax/syntaxTree.ts index 1e8ac95c483..1c68350d918 100644 --- a/src/services/syntax/syntaxTree.ts +++ b/src/services/syntax/syntaxTree.ts @@ -84,7 +84,6 @@ module TypeScript { private cacheSyntaxTreeInfo(): void { // If we're not keeping around the syntax tree, store the diagnostics and line // map so they don't have to be recomputed. - var sourceUnit = this.sourceUnit(); var firstToken = firstSyntaxTreeToken(this); var leadingTrivia = firstToken.leadingTrivia(this.text); diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 825c194bc73..f6396bebf9b 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -230,19 +230,35 @@ module ts { return n.kind !== SyntaxKind.SyntaxList || n.getChildCount() !== 0; } + export function getTypeArgumentOrTypeParameterList(node: Node): NodeArray { + if (node.kind === SyntaxKind.TypeReference || node.kind === SyntaxKind.CallExpression) { + return (node).typeArguments; + } + + if (isAnyFunction(node) || node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.InterfaceDeclaration) { + return (node).typeParameters; + } + + return undefined; + } + export function isToken(n: Node): boolean { return n.kind >= SyntaxKind.FirstToken && n.kind <= SyntaxKind.LastToken; } - function isKeyword(n: Node): boolean { - return n.kind >= SyntaxKind.FirstKeyword && n.kind <= SyntaxKind.LastKeyword; - } - function isWord(n: Node): boolean { - return n.kind === SyntaxKind.Identifier || isKeyword(n); + return n.kind === SyntaxKind.Identifier || isKeyword(n.kind); } function isPropertyName(n: Node): boolean { return n.kind === SyntaxKind.StringLiteral || n.kind === SyntaxKind.NumericLiteral || isWord(n); } + + export function isComment(n: Node): boolean { + return n.kind === SyntaxKind.SingleLineCommentTrivia || n.kind === SyntaxKind.MultiLineCommentTrivia; + } + + export function isPunctuation(n: Node): boolean { + return SyntaxKind.FirstPunctuation <= n.kind && n.kind <= SyntaxKind.LastPunctuation; + } } \ No newline at end of file diff --git a/tests/baselines/reference/aliasUsageInArray.types b/tests/baselines/reference/aliasUsageInArray.types index df657233f90..2e792d39603 100644 --- a/tests/baselines/reference/aliasUsageInArray.types +++ b/tests/baselines/reference/aliasUsageInArray.types @@ -17,7 +17,7 @@ interface IHasVisualizationModel { var xs: IHasVisualizationModel[] = [moduleA]; >xs : IHasVisualizationModel[] >IHasVisualizationModel : IHasVisualizationModel ->[moduleA] : IHasVisualizationModel[] +>[moduleA] : typeof moduleA[] >moduleA : typeof moduleA var xs2: typeof moduleA[] = [moduleA]; diff --git a/tests/baselines/reference/aliasUsageInOrExpression.types b/tests/baselines/reference/aliasUsageInOrExpression.types index fdcf0be4479..c937187f049 100644 --- a/tests/baselines/reference/aliasUsageInOrExpression.types +++ b/tests/baselines/reference/aliasUsageInOrExpression.types @@ -53,7 +53,7 @@ var f: { x: IHasVisualizationModel } = <{ x: IHasVisualizationModel }>null ? { x >f : { x: IHasVisualizationModel; } >x : IHasVisualizationModel >IHasVisualizationModel : IHasVisualizationModel -><{ x: IHasVisualizationModel }>null ? { x: moduleA } : null : { x: IHasVisualizationModel; } +><{ x: IHasVisualizationModel }>null ? { x: moduleA } : null : { x: typeof moduleA; } ><{ x: IHasVisualizationModel }>null : { x: IHasVisualizationModel; } >x : IHasVisualizationModel >IHasVisualizationModel : IHasVisualizationModel diff --git a/tests/baselines/reference/arrayBestCommonTypes.js b/tests/baselines/reference/arrayBestCommonTypes.js index 675d84119c0..f8e158e5b02 100644 --- a/tests/baselines/reference/arrayBestCommonTypes.js +++ b/tests/baselines/reference/arrayBestCommonTypes.js @@ -1,55 +1,109 @@ //// [arrayBestCommonTypes.ts] -interface iface { } -class base implements iface { } -class base2 implements iface { } -class derived extends base { } +module EmptyTypes { + interface iface { } + class base implements iface { } + class base2 implements iface { } + class derived extends base { } -class f { - public voidIfAny(x: boolean, y?: boolean): number; - public voidIfAny(x: string, y?: boolean): number; - public voidIfAny(x: number, y?: boolean): number; - public voidIfAny(x: any, y =false): any { return null; } - - public x() { - (this.voidIfAny([4, 2][0])); - (this.voidIfAny([4, 2, undefined][0])); - (this.voidIfAny([undefined, 2, 4][0])); - (this.voidIfAny([null, 2, 4][0])); - (this.voidIfAny([2, 4, null][0])); - (this.voidIfAny([undefined, 4, null][0])); + class f { + public voidIfAny(x: boolean, y?: boolean): number; + public voidIfAny(x: string, y?: boolean): number; + public voidIfAny(x: number, y?: boolean): number; + public voidIfAny(x: any, y = false): any { return null; } - (this.voidIfAny(['', "q"][0])); - (this.voidIfAny(['', "q", undefined][0])); - (this.voidIfAny([undefined, "q", ''][0])); - (this.voidIfAny([null, "q", ''][0])); - (this.voidIfAny(["q", '', null][0])); - (this.voidIfAny([undefined, '', null][0])); + public x() { + (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); - (this.voidIfAny([[3,4],[null]][0][0])); - - - var t1: { x: number; y: base; }[] = [ { x: 7, y: new derived() }, { x: 5, y: new base() } ]; - var t2: { x: boolean; y: base; }[] = [ { x: true, y: new derived() }, { x: false, y: new base() } ]; - var t3: { x: string; y: base; }[] = [ { x: undefined, y: new base() }, { x: '', y: new derived() } ]; + (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny([undefined, '', null][0])); - var anyObj: any = null; - // Order matters here so test all the variants - var a1 = [ {x: 0, y: 'a'}, {x: 'a', y: 'a'}, {x: anyObj, y: 'a'} ]; - var a2 = [ {x: anyObj, y: 'a'}, {x: 0, y: 'a'}, {x: 'a', y: 'a'} ]; - var a3 = [ {x: 0, y: 'a'}, {x: anyObj, y: 'a'}, {x: 'a', y: 'a'} ]; - - var ifaceObj: iface = null; - var baseObj = new base(); - var base2Obj = new base2(); + (this.voidIfAny([[3, 4], [null]][0][0])); - var b1 = [ baseObj, base2Obj, ifaceObj ]; - var b2 = [ base2Obj, baseObj, ifaceObj ]; - var b3 = [ baseObj, ifaceObj, base2Obj ]; - var b4 = [ ifaceObj, baseObj, base2Obj ]; + + var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; + var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }]; + var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; + + var anyObj: any = null; + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; + + var ifaceObj: iface = null; + var baseObj = new base(); + var base2Obj = new base2(); + + var b1 = [baseObj, base2Obj, ifaceObj]; + var b2 = [base2Obj, baseObj, ifaceObj]; + var b3 = [baseObj, ifaceObj, base2Obj]; + var b4 = [ifaceObj, baseObj, base2Obj]; + } } } +module NonEmptyTypes { + interface iface { x: string; } + class base implements iface { x: string; y: string; } + class base2 implements iface { x: string; z: string; } + class derived extends base { a: string; } + + + class f { + public voidIfAny(x: boolean, y?: boolean): number; + public voidIfAny(x: string, y?: boolean): number; + public voidIfAny(x: number, y?: boolean): number; + public voidIfAny(x: any, y = false): any { return null; } + + public x() { + (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); + + (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny([undefined, '', null][0])); + + (this.voidIfAny([[3, 4], [null]][0][0])); + + + var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; + var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }]; + var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; + + var anyObj: any = null; + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; + + var ifaceObj: iface = null; + var baseObj = new base(); + var base2Obj = new base2(); + + var b1 = [baseObj, base2Obj, ifaceObj]; + var b2 = [base2Obj, baseObj, ifaceObj]; + var b3 = [baseObj, ifaceObj, base2Obj]; + var b4 = [ifaceObj, baseObj, base2Obj]; + } + } +} @@ -60,59 +114,121 @@ var __extends = this.__extends || function (d, b) { __.prototype = b.prototype; d.prototype = new __(); }; -var base = (function () { - function base() { - } - return base; -})(); -var base2 = (function () { - function base2() { - } - return base2; -})(); -var derived = (function (_super) { - __extends(derived, _super); - function derived() { - _super.apply(this, arguments); - } - return derived; -})(base); -var f = (function () { - function f() { - } - f.prototype.voidIfAny = function (x, y) { - if (y === void 0) { y = false; } - return null; - }; - f.prototype.x = function () { - (this.voidIfAny([4, 2][0])); - (this.voidIfAny([4, 2, undefined][0])); - (this.voidIfAny([undefined, 2, 4][0])); - (this.voidIfAny([null, 2, 4][0])); - (this.voidIfAny([2, 4, null][0])); - (this.voidIfAny([undefined, 4, null][0])); - (this.voidIfAny(['', "q"][0])); - (this.voidIfAny(['', "q", undefined][0])); - (this.voidIfAny([undefined, "q", ''][0])); - (this.voidIfAny([null, "q", ''][0])); - (this.voidIfAny(["q", '', null][0])); - (this.voidIfAny([undefined, '', null][0])); - (this.voidIfAny([[3, 4], [null]][0][0])); - var t1 = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; - var t2 = [{ x: true, y: new derived() }, { x: false, y: new base() }]; - var t3 = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; - var anyObj = null; - // Order matters here so test all the variants - var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; - var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; - var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; - var ifaceObj = null; - var baseObj = new base(); - var base2Obj = new base2(); - var b1 = [baseObj, base2Obj, ifaceObj]; - var b2 = [base2Obj, baseObj, ifaceObj]; - var b3 = [baseObj, ifaceObj, base2Obj]; - var b4 = [ifaceObj, baseObj, base2Obj]; - }; - return f; -})(); +var EmptyTypes; +(function (EmptyTypes) { + var base = (function () { + function base() { + } + return base; + })(); + var base2 = (function () { + function base2() { + } + return base2; + })(); + var derived = (function (_super) { + __extends(derived, _super); + function derived() { + _super.apply(this, arguments); + } + return derived; + })(base); + var f = (function () { + function f() { + } + f.prototype.voidIfAny = function (x, y) { + if (y === void 0) { y = false; } + return null; + }; + f.prototype.x = function () { + (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); + (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny([undefined, '', null][0])); + (this.voidIfAny([[3, 4], [null]][0][0])); + var t1 = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; + var t2 = [{ x: true, y: new derived() }, { x: false, y: new base() }]; + var t3 = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; + var anyObj = null; + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; + var ifaceObj = null; + var baseObj = new base(); + var base2Obj = new base2(); + var b1 = [baseObj, base2Obj, ifaceObj]; + var b2 = [base2Obj, baseObj, ifaceObj]; + var b3 = [baseObj, ifaceObj, base2Obj]; + var b4 = [ifaceObj, baseObj, base2Obj]; + }; + return f; + })(); +})(EmptyTypes || (EmptyTypes = {})); +var NonEmptyTypes; +(function (NonEmptyTypes) { + var base = (function () { + function base() { + } + return base; + })(); + var base2 = (function () { + function base2() { + } + return base2; + })(); + var derived = (function (_super) { + __extends(derived, _super); + function derived() { + _super.apply(this, arguments); + } + return derived; + })(base); + var f = (function () { + function f() { + } + f.prototype.voidIfAny = function (x, y) { + if (y === void 0) { y = false; } + return null; + }; + f.prototype.x = function () { + (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); + (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny([undefined, '', null][0])); + (this.voidIfAny([[3, 4], [null]][0][0])); + var t1 = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; + var t2 = [{ x: true, y: new derived() }, { x: false, y: new base() }]; + var t3 = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; + var anyObj = null; + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; + var ifaceObj = null; + var baseObj = new base(); + var base2Obj = new base2(); + var b1 = [baseObj, base2Obj, ifaceObj]; + var b2 = [base2Obj, baseObj, ifaceObj]; + var b3 = [baseObj, ifaceObj, base2Obj]; + var b4 = [ifaceObj, baseObj, base2Obj]; + }; + return f; + })(); +})(NonEmptyTypes || (NonEmptyTypes = {})); diff --git a/tests/baselines/reference/arrayBestCommonTypes.types b/tests/baselines/reference/arrayBestCommonTypes.types index a0f407358c3..5e34380673d 100644 --- a/tests/baselines/reference/arrayBestCommonTypes.types +++ b/tests/baselines/reference/arrayBestCommonTypes.types @@ -1,47 +1,50 @@ === tests/cases/compiler/arrayBestCommonTypes.ts === -interface iface { } +module EmptyTypes { +>EmptyTypes : typeof EmptyTypes + + interface iface { } >iface : iface -class base implements iface { } + class base implements iface { } >base : base >iface : iface -class base2 implements iface { } + class base2 implements iface { } >base2 : base2 >iface : iface -class derived extends base { } + class derived extends base { } >derived : derived >base : base -class f { + class f { >f : f - public voidIfAny(x: boolean, y?: boolean): number; + public voidIfAny(x: boolean, y?: boolean): number; >voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } >x : boolean >y : boolean - public voidIfAny(x: string, y?: boolean): number; + public voidIfAny(x: string, y?: boolean): number; >voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } >x : string >y : boolean - public voidIfAny(x: number, y?: boolean): number; + public voidIfAny(x: number, y?: boolean): number; >voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } >x : number >y : boolean - public voidIfAny(x: any, y =false): any { return null; } + public voidIfAny(x: any, y = false): any { return null; } >voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } >x : any >y : boolean - - public x() { + + public x() { >x : () => void - (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2][0])); >(this.voidIfAny([4, 2][0])) : number >(this.voidIfAny([4, 2][0])) : number >this.voidIfAny([4, 2][0]) : number @@ -51,7 +54,7 @@ class f { >[4, 2][0] : number >[4, 2] : number[] - (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([4, 2, undefined][0])); >(this.voidIfAny([4, 2, undefined][0])) : number >(this.voidIfAny([4, 2, undefined][0])) : number >this.voidIfAny([4, 2, undefined][0]) : number @@ -62,7 +65,7 @@ class f { >[4, 2, undefined] : number[] >undefined : undefined - (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([undefined, 2, 4][0])); >(this.voidIfAny([undefined, 2, 4][0])) : number >(this.voidIfAny([undefined, 2, 4][0])) : number >this.voidIfAny([undefined, 2, 4][0]) : number @@ -73,7 +76,7 @@ class f { >[undefined, 2, 4] : number[] >undefined : undefined - (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); >(this.voidIfAny([null, 2, 4][0])) : number >(this.voidIfAny([null, 2, 4][0])) : number >this.voidIfAny([null, 2, 4][0]) : number @@ -83,7 +86,7 @@ class f { >[null, 2, 4][0] : number >[null, 2, 4] : number[] - (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([2, 4, null][0])); >(this.voidIfAny([2, 4, null][0])) : number >(this.voidIfAny([2, 4, null][0])) : number >this.voidIfAny([2, 4, null][0]) : number @@ -93,7 +96,7 @@ class f { >[2, 4, null][0] : number >[2, 4, null] : number[] - (this.voidIfAny([undefined, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); >(this.voidIfAny([undefined, 4, null][0])) : number >(this.voidIfAny([undefined, 4, null][0])) : number >this.voidIfAny([undefined, 4, null][0]) : number @@ -104,7 +107,7 @@ class f { >[undefined, 4, null] : number[] >undefined : undefined - (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q"][0])); >(this.voidIfAny(['', "q"][0])) : number >(this.voidIfAny(['', "q"][0])) : number >this.voidIfAny(['', "q"][0]) : number @@ -114,7 +117,7 @@ class f { >['', "q"][0] : string >['', "q"] : string[] - (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny(['', "q", undefined][0])); >(this.voidIfAny(['', "q", undefined][0])) : number >(this.voidIfAny(['', "q", undefined][0])) : number >this.voidIfAny(['', "q", undefined][0]) : number @@ -125,7 +128,7 @@ class f { >['', "q", undefined] : string[] >undefined : undefined - (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([undefined, "q", ''][0])); >(this.voidIfAny([undefined, "q", ''][0])) : number >(this.voidIfAny([undefined, "q", ''][0])) : number >this.voidIfAny([undefined, "q", ''][0]) : number @@ -136,7 +139,7 @@ class f { >[undefined, "q", ''] : string[] >undefined : undefined - (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); >(this.voidIfAny([null, "q", ''][0])) : number >(this.voidIfAny([null, "q", ''][0])) : number >this.voidIfAny([null, "q", ''][0]) : number @@ -146,7 +149,7 @@ class f { >[null, "q", ''][0] : string >[null, "q", ''] : string[] - (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny(["q", '', null][0])); >(this.voidIfAny(["q", '', null][0])) : number >(this.voidIfAny(["q", '', null][0])) : number >this.voidIfAny(["q", '', null][0]) : number @@ -156,7 +159,7 @@ class f { >["q", '', null][0] : string >["q", '', null] : string[] - (this.voidIfAny([undefined, '', null][0])); + (this.voidIfAny([undefined, '', null][0])); >(this.voidIfAny([undefined, '', null][0])) : number >(this.voidIfAny([undefined, '', null][0])) : number >this.voidIfAny([undefined, '', null][0]) : number @@ -167,26 +170,26 @@ class f { >[undefined, '', null] : string[] >undefined : undefined - (this.voidIfAny([[3,4],[null]][0][0])); ->(this.voidIfAny([[3,4],[null]][0][0])) : number ->(this.voidIfAny([[3,4],[null]][0][0])) : number ->this.voidIfAny([[3,4],[null]][0][0]) : number + (this.voidIfAny([[3, 4], [null]][0][0])); +>(this.voidIfAny([[3, 4], [null]][0][0])) : number +>(this.voidIfAny([[3, 4], [null]][0][0])) : number +>this.voidIfAny([[3, 4], [null]][0][0]) : number >this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } >this : f >voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } ->[[3,4],[null]][0][0] : number ->[[3,4],[null]][0] : number[] ->[[3,4],[null]] : number[][] ->[3,4] : number[] +>[[3, 4], [null]][0][0] : number +>[[3, 4], [null]][0] : number[] +>[[3, 4], [null]] : number[][] +>[3, 4] : number[] >[null] : null[] - - - var t1: { x: number; y: base; }[] = [ { x: 7, y: new derived() }, { x: 5, y: new base() } ]; + + + var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; >t1 : { x: number; y: base; }[] >x : number >y : base >base : base ->[ { x: 7, y: new derived() }, { x: 5, y: new base() } ] : { x: number; y: base; }[] +>[{ x: 7, y: new derived() }, { x: 5, y: new base() }] : { x: number; y: derived; }[] >{ x: 7, y: new derived() } : { x: number; y: derived; } >x : number >y : derived @@ -198,12 +201,12 @@ class f { >new base() : base >base : typeof base - var t2: { x: boolean; y: base; }[] = [ { x: true, y: new derived() }, { x: false, y: new base() } ]; + var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }]; >t2 : { x: boolean; y: base; }[] >x : boolean >y : base >base : base ->[ { x: true, y: new derived() }, { x: false, y: new base() } ] : { x: boolean; y: base; }[] +>[{ x: true, y: new derived() }, { x: false, y: new base() }] : { x: boolean; y: derived; }[] >{ x: true, y: new derived() } : { x: boolean; y: derived; } >x : boolean >y : derived @@ -215,12 +218,12 @@ class f { >new base() : base >base : typeof base - var t3: { x: string; y: base; }[] = [ { x: undefined, y: new base() }, { x: '', y: new derived() } ]; + var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; >t3 : { x: string; y: base; }[] >x : string >y : base >base : base ->[ { x: undefined, y: new base() }, { x: '', y: new derived() } ] : { x: string; y: base; }[] +>[{ x: undefined, y: new base() }, { x: '', y: new derived() }] : { x: string; y: derived; }[] >{ x: undefined, y: new base() } : { x: undefined; y: base; } >x : undefined >undefined : undefined @@ -233,95 +236,429 @@ class f { >new derived() : derived >derived : typeof derived - var anyObj: any = null; + var anyObj: any = null; >anyObj : any - // Order matters here so test all the variants - var a1 = [ {x: 0, y: 'a'}, {x: 'a', y: 'a'}, {x: anyObj, y: 'a'} ]; + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; >a1 : { x: any; y: string; }[] ->[ {x: 0, y: 'a'}, {x: 'a', y: 'a'}, {x: anyObj, y: 'a'} ] : { x: any; y: string; }[] ->{x: 0, y: 'a'} : { x: number; y: string; } +>[{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }] : { x: any; y: string; }[] +>{ x: 0, y: 'a' } : { x: number; y: string; } >x : number >y : string ->{x: 'a', y: 'a'} : { x: string; y: string; } +>{ x: 'a', y: 'a' } : { x: string; y: string; } >x : string >y : string ->{x: anyObj, y: 'a'} : { x: any; y: string; } +>{ x: anyObj, y: 'a' } : { x: any; y: string; } >x : any >anyObj : any >y : string - var a2 = [ {x: anyObj, y: 'a'}, {x: 0, y: 'a'}, {x: 'a', y: 'a'} ]; + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; >a2 : { x: any; y: string; }[] ->[ {x: anyObj, y: 'a'}, {x: 0, y: 'a'}, {x: 'a', y: 'a'} ] : { x: any; y: string; }[] ->{x: anyObj, y: 'a'} : { x: any; y: string; } +>[{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[] +>{ x: anyObj, y: 'a' } : { x: any; y: string; } >x : any >anyObj : any >y : string ->{x: 0, y: 'a'} : { x: number; y: string; } +>{ x: 0, y: 'a' } : { x: number; y: string; } >x : number >y : string ->{x: 'a', y: 'a'} : { x: string; y: string; } +>{ x: 'a', y: 'a' } : { x: string; y: string; } >x : string >y : string - var a3 = [ {x: 0, y: 'a'}, {x: anyObj, y: 'a'}, {x: 'a', y: 'a'} ]; + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; >a3 : { x: any; y: string; }[] ->[ {x: 0, y: 'a'}, {x: anyObj, y: 'a'}, {x: 'a', y: 'a'} ] : { x: any; y: string; }[] ->{x: 0, y: 'a'} : { x: number; y: string; } +>[{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[] +>{ x: 0, y: 'a' } : { x: number; y: string; } >x : number >y : string ->{x: anyObj, y: 'a'} : { x: any; y: string; } +>{ x: anyObj, y: 'a' } : { x: any; y: string; } >x : any >anyObj : any >y : string ->{x: 'a', y: 'a'} : { x: string; y: string; } +>{ x: 'a', y: 'a' } : { x: string; y: string; } >x : string >y : string - - var ifaceObj: iface = null; + + var ifaceObj: iface = null; >ifaceObj : iface >iface : iface - var baseObj = new base(); + var baseObj = new base(); >baseObj : base >new base() : base >base : typeof base - var base2Obj = new base2(); + var base2Obj = new base2(); >base2Obj : base2 >new base2() : base2 >base2 : typeof base2 - var b1 = [ baseObj, base2Obj, ifaceObj ]; ->b1 : base[] ->[ baseObj, base2Obj, ifaceObj ] : base[] + var b1 = [baseObj, base2Obj, ifaceObj]; +>b1 : iface[] +>[baseObj, base2Obj, ifaceObj] : iface[] >baseObj : base >base2Obj : base2 >ifaceObj : iface - var b2 = [ base2Obj, baseObj, ifaceObj ]; ->b2 : base2[] ->[ base2Obj, baseObj, ifaceObj ] : base2[] + var b2 = [base2Obj, baseObj, ifaceObj]; +>b2 : iface[] +>[base2Obj, baseObj, ifaceObj] : iface[] >base2Obj : base2 >baseObj : base >ifaceObj : iface - var b3 = [ baseObj, ifaceObj, base2Obj ]; ->b3 : base[] ->[ baseObj, ifaceObj, base2Obj ] : base[] + var b3 = [baseObj, ifaceObj, base2Obj]; +>b3 : iface[] +>[baseObj, ifaceObj, base2Obj] : iface[] >baseObj : base >ifaceObj : iface >base2Obj : base2 - var b4 = [ ifaceObj, baseObj, base2Obj ]; + var b4 = [ifaceObj, baseObj, base2Obj]; >b4 : iface[] ->[ ifaceObj, baseObj, base2Obj ] : iface[] +>[ifaceObj, baseObj, base2Obj] : iface[] >ifaceObj : iface >baseObj : base >base2Obj : base2 + } + } +} + +module NonEmptyTypes { +>NonEmptyTypes : typeof NonEmptyTypes + + interface iface { x: string; } +>iface : iface +>x : string + + class base implements iface { x: string; y: string; } +>base : base +>iface : iface +>x : string +>y : string + + class base2 implements iface { x: string; z: string; } +>base2 : base2 +>iface : iface +>x : string +>z : string + + class derived extends base { a: string; } +>derived : derived +>base : base +>a : string + + + class f { +>f : f + + public voidIfAny(x: boolean, y?: boolean): number; +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>x : boolean +>y : boolean + + public voidIfAny(x: string, y?: boolean): number; +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>x : string +>y : boolean + + public voidIfAny(x: number, y?: boolean): number; +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>x : number +>y : boolean + + public voidIfAny(x: any, y = false): any { return null; } +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>x : any +>y : boolean + + public x() { +>x : () => void + + (this.voidIfAny([4, 2][0])); +>(this.voidIfAny([4, 2][0])) : number +>(this.voidIfAny([4, 2][0])) : number +>this.voidIfAny([4, 2][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[4, 2][0] : number +>[4, 2] : number[] + + (this.voidIfAny([4, 2, undefined][0])); +>(this.voidIfAny([4, 2, undefined][0])) : number +>(this.voidIfAny([4, 2, undefined][0])) : number +>this.voidIfAny([4, 2, undefined][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[4, 2, undefined][0] : number +>[4, 2, undefined] : number[] +>undefined : undefined + + (this.voidIfAny([undefined, 2, 4][0])); +>(this.voidIfAny([undefined, 2, 4][0])) : number +>(this.voidIfAny([undefined, 2, 4][0])) : number +>this.voidIfAny([undefined, 2, 4][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[undefined, 2, 4][0] : number +>[undefined, 2, 4] : number[] +>undefined : undefined + + (this.voidIfAny([null, 2, 4][0])); +>(this.voidIfAny([null, 2, 4][0])) : number +>(this.voidIfAny([null, 2, 4][0])) : number +>this.voidIfAny([null, 2, 4][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[null, 2, 4][0] : number +>[null, 2, 4] : number[] + + (this.voidIfAny([2, 4, null][0])); +>(this.voidIfAny([2, 4, null][0])) : number +>(this.voidIfAny([2, 4, null][0])) : number +>this.voidIfAny([2, 4, null][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[2, 4, null][0] : number +>[2, 4, null] : number[] + + (this.voidIfAny([undefined, 4, null][0])); +>(this.voidIfAny([undefined, 4, null][0])) : number +>(this.voidIfAny([undefined, 4, null][0])) : number +>this.voidIfAny([undefined, 4, null][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[undefined, 4, null][0] : number +>[undefined, 4, null] : number[] +>undefined : undefined + + (this.voidIfAny(['', "q"][0])); +>(this.voidIfAny(['', "q"][0])) : number +>(this.voidIfAny(['', "q"][0])) : number +>this.voidIfAny(['', "q"][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>['', "q"][0] : string +>['', "q"] : string[] + + (this.voidIfAny(['', "q", undefined][0])); +>(this.voidIfAny(['', "q", undefined][0])) : number +>(this.voidIfAny(['', "q", undefined][0])) : number +>this.voidIfAny(['', "q", undefined][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>['', "q", undefined][0] : string +>['', "q", undefined] : string[] +>undefined : undefined + + (this.voidIfAny([undefined, "q", ''][0])); +>(this.voidIfAny([undefined, "q", ''][0])) : number +>(this.voidIfAny([undefined, "q", ''][0])) : number +>this.voidIfAny([undefined, "q", ''][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[undefined, "q", ''][0] : string +>[undefined, "q", ''] : string[] +>undefined : undefined + + (this.voidIfAny([null, "q", ''][0])); +>(this.voidIfAny([null, "q", ''][0])) : number +>(this.voidIfAny([null, "q", ''][0])) : number +>this.voidIfAny([null, "q", ''][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[null, "q", ''][0] : string +>[null, "q", ''] : string[] + + (this.voidIfAny(["q", '', null][0])); +>(this.voidIfAny(["q", '', null][0])) : number +>(this.voidIfAny(["q", '', null][0])) : number +>this.voidIfAny(["q", '', null][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>["q", '', null][0] : string +>["q", '', null] : string[] + + (this.voidIfAny([undefined, '', null][0])); +>(this.voidIfAny([undefined, '', null][0])) : number +>(this.voidIfAny([undefined, '', null][0])) : number +>this.voidIfAny([undefined, '', null][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[undefined, '', null][0] : string +>[undefined, '', null] : string[] +>undefined : undefined + + (this.voidIfAny([[3, 4], [null]][0][0])); +>(this.voidIfAny([[3, 4], [null]][0][0])) : number +>(this.voidIfAny([[3, 4], [null]][0][0])) : number +>this.voidIfAny([[3, 4], [null]][0][0]) : number +>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>this : f +>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; } +>[[3, 4], [null]][0][0] : number +>[[3, 4], [null]][0] : number[] +>[[3, 4], [null]] : number[][] +>[3, 4] : number[] +>[null] : null[] + + + var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; +>t1 : { x: number; y: base; }[] +>x : number +>y : base +>base : base +>[{ x: 7, y: new derived() }, { x: 5, y: new base() }] : { x: number; y: base; }[] +>{ x: 7, y: new derived() } : { x: number; y: derived; } +>x : number +>y : derived +>new derived() : derived +>derived : typeof derived +>{ x: 5, y: new base() } : { x: number; y: base; } +>x : number +>y : base +>new base() : base +>base : typeof base + + var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }]; +>t2 : { x: boolean; y: base; }[] +>x : boolean +>y : base +>base : base +>[{ x: true, y: new derived() }, { x: false, y: new base() }] : { x: boolean; y: base; }[] +>{ x: true, y: new derived() } : { x: boolean; y: derived; } +>x : boolean +>y : derived +>new derived() : derived +>derived : typeof derived +>{ x: false, y: new base() } : { x: boolean; y: base; } +>x : boolean +>y : base +>new base() : base +>base : typeof base + + var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; +>t3 : { x: string; y: base; }[] +>x : string +>y : base +>base : base +>[{ x: undefined, y: new base() }, { x: '', y: new derived() }] : ({ x: undefined; y: base; } | { x: string; y: derived; })[] +>{ x: undefined, y: new base() } : { x: undefined; y: base; } +>x : undefined +>undefined : undefined +>y : base +>new base() : base +>base : typeof base +>{ x: '', y: new derived() } : { x: string; y: derived; } +>x : string +>y : derived +>new derived() : derived +>derived : typeof derived + + var anyObj: any = null; +>anyObj : any + + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; +>a1 : { x: any; y: string; }[] +>[{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }] : { x: any; y: string; }[] +>{ x: 0, y: 'a' } : { x: number; y: string; } +>x : number +>y : string +>{ x: 'a', y: 'a' } : { x: string; y: string; } +>x : string +>y : string +>{ x: anyObj, y: 'a' } : { x: any; y: string; } +>x : any +>anyObj : any +>y : string + + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; +>a2 : { x: any; y: string; }[] +>[{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[] +>{ x: anyObj, y: 'a' } : { x: any; y: string; } +>x : any +>anyObj : any +>y : string +>{ x: 0, y: 'a' } : { x: number; y: string; } +>x : number +>y : string +>{ x: 'a', y: 'a' } : { x: string; y: string; } +>x : string +>y : string + + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; +>a3 : { x: any; y: string; }[] +>[{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[] +>{ x: 0, y: 'a' } : { x: number; y: string; } +>x : number +>y : string +>{ x: anyObj, y: 'a' } : { x: any; y: string; } +>x : any +>anyObj : any +>y : string +>{ x: 'a', y: 'a' } : { x: string; y: string; } +>x : string +>y : string + + var ifaceObj: iface = null; +>ifaceObj : iface +>iface : iface + + var baseObj = new base(); +>baseObj : base +>new base() : base +>base : typeof base + + var base2Obj = new base2(); +>base2Obj : base2 +>new base2() : base2 +>base2 : typeof base2 + + var b1 = [baseObj, base2Obj, ifaceObj]; +>b1 : iface[] +>[baseObj, base2Obj, ifaceObj] : iface[] +>baseObj : base +>base2Obj : base2 +>ifaceObj : iface + + var b2 = [base2Obj, baseObj, ifaceObj]; +>b2 : iface[] +>[base2Obj, baseObj, ifaceObj] : iface[] +>base2Obj : base2 +>baseObj : base +>ifaceObj : iface + + var b3 = [baseObj, ifaceObj, base2Obj]; +>b3 : iface[] +>[baseObj, ifaceObj, base2Obj] : iface[] +>baseObj : base +>ifaceObj : iface +>base2Obj : base2 + + var b4 = [ifaceObj, baseObj, base2Obj]; +>b4 : iface[] +>[ifaceObj, baseObj, base2Obj] : iface[] +>ifaceObj : iface +>baseObj : base +>base2Obj : base2 + } } } - diff --git a/tests/baselines/reference/arrayConcat2.types b/tests/baselines/reference/arrayConcat2.types index a4036560305..4cd02d31f9d 100644 --- a/tests/baselines/reference/arrayConcat2.types +++ b/tests/baselines/reference/arrayConcat2.types @@ -1,7 +1,7 @@ === tests/cases/compiler/arrayConcat2.ts === var a: string[] = []; >a : string[] ->[] : string[] +>[] : undefined[] a.concat("hello", 'world'); >a.concat("hello", 'world') : string[] diff --git a/tests/baselines/reference/arrayLiteral.types b/tests/baselines/reference/arrayLiteral.types index 1b356773dc7..9378a508228 100644 --- a/tests/baselines/reference/arrayLiteral.types +++ b/tests/baselines/reference/arrayLiteral.types @@ -25,7 +25,7 @@ var y = new Array(); var x2: number[] = []; >x2 : number[] ->[] : number[] +>[] : undefined[] var x2: number[] = new Array(1); >x2 : number[] diff --git a/tests/baselines/reference/arrayLiteralContextualType.errors.txt b/tests/baselines/reference/arrayLiteralContextualType.errors.txt deleted file mode 100644 index 5f661647d9f..00000000000 --- a/tests/baselines/reference/arrayLiteralContextualType.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/compiler/arrayLiteralContextualType.ts(28,5): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'IAnimal[]'. - Type '{}' is not assignable to type 'IAnimal'. -tests/cases/compiler/arrayLiteralContextualType.ts(29,5): error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ [x: number]: IAnimal; }'. - - -==== tests/cases/compiler/arrayLiteralContextualType.ts (2 errors) ==== - interface IAnimal { - name: string; - } - - class Giraffe { - name = "Giraffe"; - neckLength = "3m"; - } - - class Elephant { - name = "Elephant"; - trunkDiameter = "20cm"; - } - - function foo(animals: IAnimal[]) { } - function bar(animals: { [n: number]: IAnimal }) { } - - foo([ - new Giraffe(), - new Elephant() - ]); // Legal because of the contextual type IAnimal provided by the parameter - bar([ - new Giraffe(), - new Elephant() - ]); // Legal because of the contextual type IAnimal provided by the parameter - - var arr = [new Giraffe(), new Elephant()]; - foo(arr); // Error because of no contextual type - ~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'IAnimal[]'. -!!! error TS2345: Type '{}' is not assignable to type 'IAnimal'. - bar(arr); // Error because of no contextual type - ~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ [x: number]: IAnimal; }'. \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiteralContextualType.js b/tests/baselines/reference/arrayLiteralContextualType.js index a551a754204..65e4c135cba 100644 --- a/tests/baselines/reference/arrayLiteralContextualType.js +++ b/tests/baselines/reference/arrayLiteralContextualType.js @@ -26,8 +26,8 @@ bar([ ]); // Legal because of the contextual type IAnimal provided by the parameter var arr = [new Giraffe(), new Elephant()]; -foo(arr); // Error because of no contextual type -bar(arr); // Error because of no contextual type +foo(arr); // ok because arr is Array not {}[] +bar(arr); // ok because arr is Array not {}[] //// [arrayLiteralContextualType.js] var Giraffe = (function () { @@ -57,5 +57,5 @@ bar([ new Elephant() ]); // Legal because of the contextual type IAnimal provided by the parameter var arr = [new Giraffe(), new Elephant()]; -foo(arr); // Error because of no contextual type -bar(arr); // Error because of no contextual type +foo(arr); // ok because arr is Array not {}[] +bar(arr); // ok because arr is Array not {}[] diff --git a/tests/baselines/reference/arrayLiteralContextualType.types b/tests/baselines/reference/arrayLiteralContextualType.types new file mode 100644 index 00000000000..5797999b7df --- /dev/null +++ b/tests/baselines/reference/arrayLiteralContextualType.types @@ -0,0 +1,86 @@ +=== tests/cases/compiler/arrayLiteralContextualType.ts === +interface IAnimal { +>IAnimal : IAnimal + + name: string; +>name : string +} + +class Giraffe { +>Giraffe : Giraffe + + name = "Giraffe"; +>name : string + + neckLength = "3m"; +>neckLength : string +} + +class Elephant { +>Elephant : Elephant + + name = "Elephant"; +>name : string + + trunkDiameter = "20cm"; +>trunkDiameter : string +} + +function foo(animals: IAnimal[]) { } +>foo : (animals: IAnimal[]) => void +>animals : IAnimal[] +>IAnimal : IAnimal + +function bar(animals: { [n: number]: IAnimal }) { } +>bar : (animals: { [x: number]: IAnimal; }) => void +>animals : { [x: number]: IAnimal; } +>n : number +>IAnimal : IAnimal + +foo([ +>foo([ new Giraffe(), new Elephant()]) : void +>foo : (animals: IAnimal[]) => void +>[ new Giraffe(), new Elephant()] : (Giraffe | Elephant)[] + + new Giraffe(), +>new Giraffe() : Giraffe +>Giraffe : typeof Giraffe + + new Elephant() +>new Elephant() : Elephant +>Elephant : typeof Elephant + +]); // Legal because of the contextual type IAnimal provided by the parameter +bar([ +>bar([ new Giraffe(), new Elephant()]) : void +>bar : (animals: { [x: number]: IAnimal; }) => void +>[ new Giraffe(), new Elephant()] : (Giraffe | Elephant)[] + + new Giraffe(), +>new Giraffe() : Giraffe +>Giraffe : typeof Giraffe + + new Elephant() +>new Elephant() : Elephant +>Elephant : typeof Elephant + +]); // Legal because of the contextual type IAnimal provided by the parameter + +var arr = [new Giraffe(), new Elephant()]; +>arr : (Giraffe | Elephant)[] +>[new Giraffe(), new Elephant()] : (Giraffe | Elephant)[] +>new Giraffe() : Giraffe +>Giraffe : typeof Giraffe +>new Elephant() : Elephant +>Elephant : typeof Elephant + +foo(arr); // ok because arr is Array not {}[] +>foo(arr) : void +>foo : (animals: IAnimal[]) => void +>arr : (Giraffe | Elephant)[] + +bar(arr); // ok because arr is Array not {}[] +>bar(arr) : void +>bar : (animals: { [x: number]: IAnimal; }) => void +>arr : (Giraffe | Elephant)[] + diff --git a/tests/baselines/reference/arrayLiteralInNonVarArgParameter.types b/tests/baselines/reference/arrayLiteralInNonVarArgParameter.types index c4889e223bb..4743504c33e 100644 --- a/tests/baselines/reference/arrayLiteralInNonVarArgParameter.types +++ b/tests/baselines/reference/arrayLiteralInNonVarArgParameter.types @@ -7,5 +7,5 @@ function panic(val: string[], ...opt: string[]) { } panic([], 'one', 'two'); >panic([], 'one', 'two') : void >panic : (val: string[], ...opt: string[]) => void ->[] : string[] +>[] : undefined[] diff --git a/tests/baselines/reference/arrayLiteralTypeInference.types b/tests/baselines/reference/arrayLiteralTypeInference.types index 5b4d9b7fff8..adcc28c7440 100644 --- a/tests/baselines/reference/arrayLiteralTypeInference.types +++ b/tests/baselines/reference/arrayLiteralTypeInference.types @@ -25,7 +25,7 @@ class ActionB extends Action { var x1: Action[] = [ >x1 : Action[] >Action : Action ->[ { id: 2, trueness: false }, { id: 3, name: "three" }] : Action[] +>[ { id: 2, trueness: false }, { id: 3, name: "three" }] : ({ id: number; trueness: boolean; } | { id: number; name: string; })[] { id: 2, trueness: false }, >{ id: 2, trueness: false } : { id: number; trueness: boolean; } @@ -42,7 +42,7 @@ var x1: Action[] = [ var x2: Action[] = [ >x2 : Action[] >Action : Action ->[ new ActionA(), new ActionB()] : Action[] +>[ new ActionA(), new ActionB()] : (ActionA | ActionB)[] new ActionA(), >new ActionA() : ActionA @@ -78,7 +78,7 @@ var z1: { id: number }[] = >id : number [ ->[ { id: 2, trueness: false }, { id: 3, name: "three" } ] : { id: number; }[] +>[ { id: 2, trueness: false }, { id: 3, name: "three" } ] : ({ id: number; trueness: boolean; } | { id: number; name: string; })[] { id: 2, trueness: false }, >{ id: 2, trueness: false } : { id: number; trueness: boolean; } @@ -97,7 +97,7 @@ var z2: { id: number }[] = >id : number [ ->[ new ActionA(), new ActionB() ] : { id: number; }[] +>[ new ActionA(), new ActionB() ] : (ActionA | ActionB)[] new ActionA(), >new ActionA() : ActionA @@ -114,7 +114,7 @@ var z3: { id: number }[] = >id : number [ ->[ new Action(), new ActionA(), new ActionB() ] : { id: number; }[] +>[ new Action(), new ActionA(), new ActionB() ] : Action[] new Action(), >new Action() : Action diff --git a/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types b/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types index 7729b280160..bc21ec39073 100644 --- a/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types +++ b/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types @@ -17,27 +17,27 @@ var c: { x: number; a?: number }; >a : number var as = [a, b]; // { x: number; y?: number };[] ->as : { x: number; y?: number; }[] ->[a, b] : { x: number; y?: number; }[] +>as : ({ x: number; y?: number; } | { x: number; z?: number; })[] +>[a, b] : ({ x: number; y?: number; } | { x: number; z?: number; })[] >a : { x: number; y?: number; } >b : { x: number; z?: number; } var bs = [b, a]; // { x: number; z?: number };[] ->bs : { x: number; z?: number; }[] ->[b, a] : { x: number; z?: number; }[] +>bs : ({ x: number; y?: number; } | { x: number; z?: number; })[] +>[b, a] : ({ x: number; y?: number; } | { x: number; z?: number; })[] >b : { x: number; z?: number; } >a : { x: number; y?: number; } var cs = [a, b, c]; // { x: number; y?: number };[] ->cs : { x: number; y?: number; }[] ->[a, b, c] : { x: number; y?: number; }[] +>cs : ({ x: number; y?: number; } | { x: number; z?: number; } | { x: number; a?: number; })[] +>[a, b, c] : ({ x: number; y?: number; } | { x: number; z?: number; } | { x: number; a?: number; })[] >a : { x: number; y?: number; } >b : { x: number; z?: number; } >c : { x: number; a?: number; } var ds = [(x: Object) => 1, (x: string) => 2]; // { (x:Object) => number }[] ->ds : { (x: Object): number; }[] ->[(x: Object) => 1, (x: string) => 2] : { (x: Object): number; }[] +>ds : ((x: Object) => number)[] +>[(x: Object) => 1, (x: string) => 2] : ((x: Object) => number)[] >(x: Object) => 1 : (x: Object) => number >x : Object >Object : Object @@ -45,8 +45,8 @@ var ds = [(x: Object) => 1, (x: string) => 2]; // { (x:Object) => number }[] >x : string var es = [(x: string) => 2, (x: Object) => 1]; // { (x:string) => number }[] ->es : { (x: string): number; }[] ->[(x: string) => 2, (x: Object) => 1] : { (x: string): number; }[] +>es : ((x: string) => number)[] +>[(x: string) => 2, (x: Object) => 1] : ((x: string) => number)[] >(x: string) => 2 : (x: string) => number >x : string >(x: Object) => 1 : (x: Object) => number @@ -54,8 +54,8 @@ var es = [(x: string) => 2, (x: Object) => 1]; // { (x:string) => number }[] >Object : Object var fs = [(a: { x: number; y?: number }) => 1, (b: { x: number; z?: number }) => 2]; // (a: { x: number; y?: number }) => number[] ->fs : { (a: { x: number; y?: number; }): number; }[] ->[(a: { x: number; y?: number }) => 1, (b: { x: number; z?: number }) => 2] : { (a: { x: number; y?: number; }): number; }[] +>fs : (((a: { x: number; y?: number; }) => number) | ((b: { x: number; z?: number; }) => number))[] +>[(a: { x: number; y?: number }) => 1, (b: { x: number; z?: number }) => 2] : (((a: { x: number; y?: number; }) => number) | ((b: { x: number; z?: number; }) => number))[] >(a: { x: number; y?: number }) => 1 : (a: { x: number; y?: number; }) => number >a : { x: number; y?: number; } >x : number @@ -66,8 +66,8 @@ var fs = [(a: { x: number; y?: number }) => 1, (b: { x: number; z?: number }) => >z : number var gs = [(b: { x: number; z?: number }) => 2, (a: { x: number; y?: number }) => 1]; // (b: { x: number; z?: number }) => number[] ->gs : { (b: { x: number; z?: number; }): number; }[] ->[(b: { x: number; z?: number }) => 2, (a: { x: number; y?: number }) => 1] : { (b: { x: number; z?: number; }): number; }[] +>gs : (((b: { x: number; z?: number; }) => number) | ((a: { x: number; y?: number; }) => number))[] +>[(b: { x: number; z?: number }) => 2, (a: { x: number; y?: number }) => 1] : (((b: { x: number; z?: number; }) => number) | ((a: { x: number; y?: number; }) => number))[] >(b: { x: number; z?: number }) => 2 : (b: { x: number; z?: number; }) => number >b : { x: number; z?: number; } >x : number diff --git a/tests/baselines/reference/arrayLiterals.js b/tests/baselines/reference/arrayLiterals.js index 800d2a12550..16e5ec7eee4 100644 --- a/tests/baselines/reference/arrayLiterals.js +++ b/tests/baselines/reference/arrayLiterals.js @@ -2,28 +2,21 @@ // Empty array literal with no contextual type has type Undefined[] var arr1= [[], [1], ['']]; -var arr1: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK var arr2 = [[null], [1], ['']]; -var arr2: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK // Array literal with elements of only EveryType E has type E[] var stringArrArr = [[''], [""]]; -var stringArrArr: string[][]; var stringArr = ['', ""]; -var stringArr: string[]; var numberArr = [0, 0.0, 0x00, 1e1]; -var numberArr: number[]; var boolArr = [false, true, false, true]; -var boolArr: boolean[]; class C { private p; } var classArr = [new C(), new C()]; -var classArr: C[]; // Should be OK var classTypeArray = [C, C, C]; var classTypeArray: Array; // Should OK, not be a parse error @@ -31,7 +24,6 @@ var classTypeArray: Array; // Should OK, not be a parse error // Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[] var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; -var context2: Array<{}>; // Should be OK // Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] class Base { private p; } @@ -53,31 +45,23 @@ var __extends = this.__extends || function (d, b) { d.prototype = new __(); }; var arr1 = [[], [1], ['']]; -var arr1; // Bug 825172: Error ({}[] does not match {}[]), but should be OK var arr2 = [[null], [1], ['']]; -var arr2; // Bug 825172: Error ({}[] does not match {}[]), but should be OK // Array literal with elements of only EveryType E has type E[] var stringArrArr = [[''], [""]]; -var stringArrArr; var stringArr = ['', ""]; -var stringArr; var numberArr = [0, 0.0, 0x00, 1e1]; -var numberArr; var boolArr = [false, true, false, true]; -var boolArr; var C = (function () { function C() { } return C; })(); var classArr = [new C(), new C()]; -var classArr; // Should be OK var classTypeArray = [C, C, C]; var classTypeArray; // Should OK, not be a parse error // Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[] var context1 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; -var context2; // Should be OK // Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] var Base = (function () { function Base() { diff --git a/tests/baselines/reference/arrayLiterals.types b/tests/baselines/reference/arrayLiterals.types index 29dd1b19970..62475fa2b4a 100644 --- a/tests/baselines/reference/arrayLiterals.types +++ b/tests/baselines/reference/arrayLiterals.types @@ -2,25 +2,19 @@ // Empty array literal with no contextual type has type Undefined[] var arr1= [[], [1], ['']]; ->arr1 : {}[] ->[[], [1], ['']] : {}[] +>arr1 : (string[] | number[])[] +>[[], [1], ['']] : (string[] | number[])[] >[] : undefined[] >[1] : number[] >[''] : string[] -var arr1: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK ->arr1 : {}[] - var arr2 = [[null], [1], ['']]; ->arr2 : {}[] ->[[null], [1], ['']] : {}[] +>arr2 : (string[] | number[])[] +>[[null], [1], ['']] : (string[] | number[])[] >[null] : null[] >[1] : number[] >[''] : string[] -var arr2: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK ->arr2 : {}[] - // Array literal with elements of only EveryType E has type E[] var stringArrArr = [[''], [""]]; @@ -29,30 +23,18 @@ var stringArrArr = [[''], [""]]; >[''] : string[] >[""] : string[] -var stringArrArr: string[][]; ->stringArrArr : string[][] - var stringArr = ['', ""]; >stringArr : string[] >['', ""] : string[] -var stringArr: string[]; ->stringArr : string[] - var numberArr = [0, 0.0, 0x00, 1e1]; >numberArr : number[] >[0, 0.0, 0x00, 1e1] : number[] -var numberArr: number[]; ->numberArr : number[] - var boolArr = [false, true, false, true]; >boolArr : boolean[] >[false, true, false, true] : boolean[] -var boolArr: boolean[]; ->boolArr : boolean[] - class C { private p; } >C : C >p : any @@ -65,10 +47,6 @@ var classArr = [new C(), new C()]; >new C() : C >C : typeof C -var classArr: C[]; // Should be OK ->classArr : C[] ->C : C - var classTypeArray = [C, C, C]; >classTypeArray : typeof C[] >[C, C, C] : typeof C[] @@ -87,7 +65,7 @@ var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: ' >n : number >a : string >b : number ->[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : { a: string; b: number; }[] +>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[] >{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; } >a : string >b : number @@ -98,8 +76,8 @@ var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: ' >c : number var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; ->context2 : {}[] ->[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : {}[] +>context2 : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[] +>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : ({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[] >{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; } >a : string >b : number @@ -109,10 +87,6 @@ var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; >b : number >c : number -var context2: Array<{}>; // Should be OK ->context2 : {}[] ->Array : T[] - // Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] class Base { private p; } >Base : Base @@ -131,7 +105,7 @@ class Derived2 extends Base { private n }; var context3: Base[] = [new Derived1(), new Derived2()]; >context3 : Base[] >Base : Base ->[new Derived1(), new Derived2()] : Base[] +>[new Derived1(), new Derived2()] : (Derived1 | Derived2)[] >new Derived1() : Derived1 >Derived1 : typeof Derived1 >new Derived2() : Derived2 @@ -141,7 +115,7 @@ var context3: Base[] = [new Derived1(), new Derived2()]; var context4: Base[] = [new Derived1(), new Derived1()]; >context4 : Base[] >Base : Base ->[new Derived1(), new Derived1()] : Base[] +>[new Derived1(), new Derived1()] : Derived1[] >new Derived1() : Derived1 >Derived1 : typeof Derived1 >new Derived1() : Derived1 diff --git a/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types b/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types index becff7617b7..1496e99adca 100644 --- a/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types +++ b/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types @@ -61,8 +61,8 @@ var xs = [list, myList]; // {}[] >myList : MyList var ys = [list, list2]; // {}[] ->ys : {}[] ->[list, list2] : {}[] +>ys : (List | List)[] +>[list, list2] : (List | List)[] >list : List >list2 : List diff --git a/tests/baselines/reference/arrayOfFunctionTypes3.types b/tests/baselines/reference/arrayOfFunctionTypes3.types index b224ff881e3..3ef5334382c 100644 --- a/tests/baselines/reference/arrayOfFunctionTypes3.types +++ b/tests/baselines/reference/arrayOfFunctionTypes3.types @@ -2,8 +2,8 @@ // valid uses of arrays of function types var x = [() => 1, () => { }]; ->x : { (): void; }[] ->[() => 1, () => { }] : { (): void; }[] +>x : (() => void)[] +>[() => 1, () => { }] : (() => void)[] >() => 1 : () => number >() => { } : () => void @@ -11,7 +11,7 @@ var r2 = x[0](); >r2 : void >x[0]() : void >x[0] : () => void ->x : { (): void; }[] +>x : (() => void)[] class C { >C : C diff --git a/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt b/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt index 7c0a3a5c8b9..2395f2bf364 100644 --- a/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt +++ b/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt @@ -1,36 +1,38 @@ -tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(17,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]': - Types of property 'pop' are incompatible: - Type '() => {}' is not assignable to type '() => number': - Type '{}' is not assignable to type 'number'. -tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(18,1): error TS2322: Type '{}[]' is not assignable to type '[{}]': - Property '0' is missing in type '{}[]'. - - -==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts (2 errors) ==== - var numStrTuple: [number, string]; - var numNumTuple: [number, number]; - var numEmptyObjTuple: [number, {}]; - var emptyObjTuple: [{}]; - - var numArray: number[]; - var emptyObjArray: {}[]; - - // no error - numArray = numNumTuple; - emptyObjArray = emptyObjTuple; - emptyObjArray = numStrTuple; - emptyObjArray = numNumTuple; - emptyObjArray = numEmptyObjTuple; - - // error - numArray = numStrTuple; - ~~~~~~~~ -!!! error TS2322: Type '[number, string]' is not assignable to type 'number[]': -!!! error TS2322: Types of property 'pop' are incompatible: -!!! error TS2322: Type '() => {}' is not assignable to type '() => number': -!!! error TS2322: Type '{}' is not assignable to type 'number'. - emptyObjTuple = emptyObjArray; - ~~~~~~~~~~~~~ -!!! error TS2322: Type '{}[]' is not assignable to type '[{}]': -!!! error TS2322: Property '0' is missing in type '{}[]'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(17,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]': + Types of property 'pop' are incompatible: + Type '() => string | number' is not assignable to type '() => number': + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(18,1): error TS2322: Type '{}[]' is not assignable to type '[{}]': + Property '0' is missing in type '{}[]'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts (2 errors) ==== + var numStrTuple: [number, string]; + var numNumTuple: [number, number]; + var numEmptyObjTuple: [number, {}]; + var emptyObjTuple: [{}]; + + var numArray: number[]; + var emptyObjArray: {}[]; + + // no error + numArray = numNumTuple; + emptyObjArray = emptyObjTuple; + emptyObjArray = numStrTuple; + emptyObjArray = numNumTuple; + emptyObjArray = numEmptyObjTuple; + + // error + numArray = numStrTuple; + ~~~~~~~~ +!!! error TS2322: Type '[number, string]' is not assignable to type 'number[]': +!!! error TS2322: Types of property 'pop' are incompatible: +!!! error TS2322: Type '() => string | number' is not assignable to type '() => number': +!!! error TS2322: Type 'string | number' is not assignable to type 'number': +!!! error TS2322: Type 'string' is not assignable to type 'number'. + emptyObjTuple = emptyObjArray; + ~~~~~~~~~~~~~ +!!! error TS2322: Type '{}[]' is not assignable to type '[{}]': +!!! error TS2322: Property '0' is missing in type '{}[]'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.js b/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.js index cbe6b1ff04e..fd3ac1d46f1 100644 --- a/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.js +++ b/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.js @@ -1,4 +1,4 @@ -//// [assignmentCompatBetweenTupleAndArray.ts] +//// [assignmentCompatBetweenTupleAndArray.ts] var numStrTuple: [number, string]; var numNumTuple: [number, number]; var numEmptyObjTuple: [number, {}]; @@ -17,21 +17,21 @@ emptyObjArray = numEmptyObjTuple; // error numArray = numStrTuple; emptyObjTuple = emptyObjArray; - - -//// [assignmentCompatBetweenTupleAndArray.js] -var numStrTuple; -var numNumTuple; -var numEmptyObjTuple; -var emptyObjTuple; -var numArray; -var emptyObjArray; -// no error -numArray = numNumTuple; -emptyObjArray = emptyObjTuple; -emptyObjArray = numStrTuple; -emptyObjArray = numNumTuple; -emptyObjArray = numEmptyObjTuple; -// error -numArray = numStrTuple; -emptyObjTuple = emptyObjArray; + + +//// [assignmentCompatBetweenTupleAndArray.js] +var numStrTuple; +var numNumTuple; +var numEmptyObjTuple; +var emptyObjTuple; +var numArray; +var emptyObjArray; +// no error +numArray = numNumTuple; +emptyObjArray = emptyObjTuple; +emptyObjArray = numStrTuple; +emptyObjArray = numNumTuple; +emptyObjArray = numEmptyObjTuple; +// error +numArray = numStrTuple; +emptyObjTuple = emptyObjArray; diff --git a/tests/baselines/reference/badOverloadError.types b/tests/baselines/reference/badOverloadError.types index 837eb5c5c83..ba9d6e76c1c 100644 --- a/tests/baselines/reference/badOverloadError.types +++ b/tests/baselines/reference/badOverloadError.types @@ -6,6 +6,6 @@ function method() { >dictionary : { [x: string]: string; } ><{ [index: string]: string; }>{} : { [x: string]: string; } >index : string ->{} : { [x: string]: string; } +>{} : { [x: string]: undefined; } } diff --git a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types index 3deeae69bbe..eb94c140883 100644 --- a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types +++ b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types @@ -48,14 +48,14 @@ var r3 = true ? 1 : {}; >{} : {} var r4 = true ? a : b; // typeof a ->r4 : { x: number; y?: number; } ->true ? a : b : { x: number; y?: number; } +>r4 : { x: number; y?: number; } | { x: number; z?: number; } +>true ? a : b : { x: number; y?: number; } | { x: number; z?: number; } >a : { x: number; y?: number; } >b : { x: number; z?: number; } var r5 = true ? b : a; // typeof b ->r5 : { x: number; z?: number; } ->true ? b : a : { x: number; z?: number; } +>r5 : { x: number; y?: number; } | { x: number; z?: number; } +>true ? b : a : { x: number; y?: number; } | { x: number; z?: number; } >b : { x: number; z?: number; } >a : { x: number; y?: number; } @@ -72,7 +72,7 @@ var r7: (x: Object) => void = true ? (x: number) => { } : (x: Object) => { }; >r7 : (x: Object) => void >x : Object >Object : Object ->true ? (x: number) => { } : (x: Object) => { } : (x: Object) => void +>true ? (x: number) => { } : (x: Object) => { } : (x: number) => void >(x: number) => { } : (x: number) => void >x : number >(x: Object) => { } : (x: Object) => void @@ -91,7 +91,7 @@ var r8 = true ? (x: Object) => { } : (x: number) => { }; // returns Object => vo var r10: Base = true ? derived : derived2; // no error since we use the contextual type in BCT >r10 : Base >Base : Base ->true ? derived : derived2 : Base +>true ? derived : derived2 : Derived | Derived2 >derived : Derived >derived2 : Derived2 @@ -112,7 +112,7 @@ function foo5(t: T, u: U): Object { >Object : Object return true ? t : u; // BCT is Object ->true ? t : u : Object +>true ? t : u : T | U >t : T >u : U } diff --git a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.errors.txt b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.errors.txt index 532a40becd9..83f4678c8f3 100644 --- a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.errors.txt +++ b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.errors.txt @@ -1,14 +1,9 @@ -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(11,10): error TS2367: No best common type exists between 'number' and 'string'. -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(12,10): error TS2367: No best common type exists between 'Derived' and 'Derived2'. -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(15,12): error TS2367: No best common type exists between 'T' and 'U'. tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(18,15): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(19,12): error TS2367: No best common type exists between 'T' and 'U'. tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(22,15): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(22,28): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(23,12): error TS2367: No best common type exists between 'T' and 'U'. -==== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts (8 errors) ==== +==== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts (3 errors) ==== // conditional expressions return the best common type of the branches plus contextual type (using the first candidate if multiple BCTs exist) // these are errors @@ -20,24 +15,16 @@ tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfC var derived2: Derived2; var r2 = true ? 1 : ''; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'number' and 'string'. var r9 = true ? derived : derived2; - ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Derived' and 'Derived2'. function foo(t: T, u: U) { return true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. } function foo2(t: T, u: U) { // Error for referencing own type parameter ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. return true ? t : u; // Ok because BCT(T, U) = U - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. } function foo3(t: T, u: U) { @@ -46,6 +33,4 @@ tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfC ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. return true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. } \ No newline at end of file diff --git a/tests/baselines/reference/bestCommonTypeOfTuple.js b/tests/baselines/reference/bestCommonTypeOfTuple.js index a668b9978b0..752523317b5 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple.js +++ b/tests/baselines/reference/bestCommonTypeOfTuple.js @@ -1,4 +1,4 @@ -//// [bestCommonTypeOfTuple.ts] +//// [bestCommonTypeOfTuple.ts] function f1(x: number): string { return "foo"; } function f2(x: number): number { return 10; } @@ -23,36 +23,36 @@ t4 = [E1.one, E2.two, 20]; var e1 = t1[2]; // {} var e2 = t2[2]; // {} var e3 = t3[2]; // any -var e4 = t4[3]; // number - -//// [bestCommonTypeOfTuple.js] -function f1(x) { - return "foo"; -} -function f2(x) { - return 10; -} -function f3(x) { - return true; -} -var E1; -(function (E1) { - E1[E1["one"] = 0] = "one"; -})(E1 || (E1 = {})); -var E2; -(function (E2) { - E2[E2["two"] = 0] = "two"; -})(E2 || (E2 = {})); -var t1; -var t2; -var t3; -var t4; -// no error -t1 = [f1, f2]; -t2 = [0 /* one */, 0 /* two */]; -t3 = [5, undefined]; -t4 = [0 /* one */, 0 /* two */, 20]; -var e1 = t1[2]; // {} -var e2 = t2[2]; // {} -var e3 = t3[2]; // any -var e4 = t4[3]; // number +var e4 = t4[3]; // number + +//// [bestCommonTypeOfTuple.js] +function f1(x) { + return "foo"; +} +function f2(x) { + return 10; +} +function f3(x) { + return true; +} +var E1; +(function (E1) { + E1[E1["one"] = 0] = "one"; +})(E1 || (E1 = {})); +var E2; +(function (E2) { + E2[E2["two"] = 0] = "two"; +})(E2 || (E2 = {})); +var t1; +var t2; +var t3; +var t4; +// no error +t1 = [f1, f2]; +t2 = [0 /* one */, 0 /* two */]; +t3 = [5, undefined]; +t4 = [0 /* one */, 0 /* two */, 20]; +var e1 = t1[2]; // {} +var e2 = t2[2]; // {} +var e3 = t3[2]; // any +var e4 = t4[3]; // number diff --git a/tests/baselines/reference/bestCommonTypeOfTuple.types b/tests/baselines/reference/bestCommonTypeOfTuple.types index 936607769e7..0516fc4af2b 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple.types +++ b/tests/baselines/reference/bestCommonTypeOfTuple.types @@ -1,96 +1,96 @@ -=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple.ts === -function f1(x: number): string { return "foo"; } ->f1 : (x: number) => string ->x : number - -function f2(x: number): number { return 10; } ->f2 : (x: number) => number ->x : number - -function f3(x: number): boolean { return true; } ->f3 : (x: number) => boolean ->x : number - -enum E1 { one } ->E1 : E1 ->one : E1 - -enum E2 { two } ->E2 : E2 ->two : E2 - - -var t1: [(x: number) => string, (x: number) => number]; ->t1 : [(x: number) => string, (x: number) => number] ->x : number ->x : number - -var t2: [E1, E2]; ->t2 : [E1, E2] ->E1 : E1 ->E2 : E2 - -var t3: [number, any]; ->t3 : [number, any] - -var t4: [E1, E2, number]; ->t4 : [E1, E2, number] ->E1 : E1 ->E2 : E2 - -// no error -t1 = [f1, f2]; ->t1 = [f1, f2] : [(x: number) => string, (x: number) => number] ->t1 : [(x: number) => string, (x: number) => number] ->[f1, f2] : [(x: number) => string, (x: number) => number] ->f1 : (x: number) => string ->f2 : (x: number) => number - -t2 = [E1.one, E2.two]; ->t2 = [E1.one, E2.two] : [E1, E2] ->t2 : [E1, E2] ->[E1.one, E2.two] : [E1, E2] ->E1.one : E1 ->E1 : typeof E1 ->one : E1 ->E2.two : E2 ->E2 : typeof E2 ->two : E2 - -t3 = [5, undefined]; ->t3 = [5, undefined] : [number, undefined] ->t3 : [number, any] ->[5, undefined] : [number, undefined] ->undefined : undefined - -t4 = [E1.one, E2.two, 20]; ->t4 = [E1.one, E2.two, 20] : [E1, E2, number] ->t4 : [E1, E2, number] ->[E1.one, E2.two, 20] : [E1, E2, number] ->E1.one : E1 ->E1 : typeof E1 ->one : E1 ->E2.two : E2 ->E2 : typeof E2 ->two : E2 - -var e1 = t1[2]; // {} ->e1 : {} ->t1[2] : {} ->t1 : [(x: number) => string, (x: number) => number] - -var e2 = t2[2]; // {} ->e2 : {} ->t2[2] : {} ->t2 : [E1, E2] - -var e3 = t3[2]; // any ->e3 : any ->t3[2] : any ->t3 : [number, any] - -var e4 = t4[3]; // number ->e4 : number ->t4[3] : number ->t4 : [E1, E2, number] - +=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple.ts === +function f1(x: number): string { return "foo"; } +>f1 : (x: number) => string +>x : number + +function f2(x: number): number { return 10; } +>f2 : (x: number) => number +>x : number + +function f3(x: number): boolean { return true; } +>f3 : (x: number) => boolean +>x : number + +enum E1 { one } +>E1 : E1 +>one : E1 + +enum E2 { two } +>E2 : E2 +>two : E2 + + +var t1: [(x: number) => string, (x: number) => number]; +>t1 : [(x: number) => string, (x: number) => number] +>x : number +>x : number + +var t2: [E1, E2]; +>t2 : [E1, E2] +>E1 : E1 +>E2 : E2 + +var t3: [number, any]; +>t3 : [number, any] + +var t4: [E1, E2, number]; +>t4 : [E1, E2, number] +>E1 : E1 +>E2 : E2 + +// no error +t1 = [f1, f2]; +>t1 = [f1, f2] : [(x: number) => string, (x: number) => number] +>t1 : [(x: number) => string, (x: number) => number] +>[f1, f2] : [(x: number) => string, (x: number) => number] +>f1 : (x: number) => string +>f2 : (x: number) => number + +t2 = [E1.one, E2.two]; +>t2 = [E1.one, E2.two] : [E1, E2] +>t2 : [E1, E2] +>[E1.one, E2.two] : [E1, E2] +>E1.one : E1 +>E1 : typeof E1 +>one : E1 +>E2.two : E2 +>E2 : typeof E2 +>two : E2 + +t3 = [5, undefined]; +>t3 = [5, undefined] : [number, undefined] +>t3 : [number, any] +>[5, undefined] : [number, undefined] +>undefined : undefined + +t4 = [E1.one, E2.two, 20]; +>t4 = [E1.one, E2.two, 20] : [E1, E2, number] +>t4 : [E1, E2, number] +>[E1.one, E2.two, 20] : [E1, E2, number] +>E1.one : E1 +>E1 : typeof E1 +>one : E1 +>E2.two : E2 +>E2 : typeof E2 +>two : E2 + +var e1 = t1[2]; // {} +>e1 : ((x: number) => string) | ((x: number) => number) +>t1[2] : ((x: number) => string) | ((x: number) => number) +>t1 : [(x: number) => string, (x: number) => number] + +var e2 = t2[2]; // {} +>e2 : E1 | E2 +>t2[2] : E1 | E2 +>t2 : [E1, E2] + +var e3 = t3[2]; // any +>e3 : any +>t3[2] : any +>t3 : [number, any] + +var e4 = t4[3]; // number +>e4 : number +>t4[3] : number +>t4 : [E1, E2, number] + diff --git a/tests/baselines/reference/bestCommonTypeOfTuple2.js b/tests/baselines/reference/bestCommonTypeOfTuple2.js index 2f2db308fc9..f9183f41348 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple2.js +++ b/tests/baselines/reference/bestCommonTypeOfTuple2.js @@ -1,4 +1,4 @@ -//// [bestCommonTypeOfTuple2.ts] +//// [bestCommonTypeOfTuple2.ts] interface base { } interface base1 { i } class C implements base { c } @@ -20,58 +20,58 @@ var e21 = t2[4]; // {} var e31 = t3[4]; // C1 var e41 = t4[2]; // base1 var e51 = t5[2]; // {} - - -//// [bestCommonTypeOfTuple2.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C = (function () { - function C() { - } - return C; -})(); -var D = (function () { - function D() { - } - return D; -})(); -var E = (function () { - function E() { - } - return E; -})(); -var F = (function (_super) { - __extends(F, _super); - function F() { - _super.apply(this, arguments); - } - return F; -})(C); -var C1 = (function () { - function C1() { - this.i = "foo"; - } - return C1; -})(); -var D1 = (function (_super) { - __extends(D1, _super); - function D1() { - _super.apply(this, arguments); - this.i = "bar"; - } - return D1; -})(C1); -var t1; -var t2; -var t3; -var t4; -var t5; -var e11 = t1[4]; // base -var e21 = t2[4]; // {} -var e31 = t3[4]; // C1 -var e41 = t4[2]; // base1 -var e51 = t5[2]; // {} + + +//// [bestCommonTypeOfTuple2.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var C = (function () { + function C() { + } + return C; +})(); +var D = (function () { + function D() { + } + return D; +})(); +var E = (function () { + function E() { + } + return E; +})(); +var F = (function (_super) { + __extends(F, _super); + function F() { + _super.apply(this, arguments); + } + return F; +})(C); +var C1 = (function () { + function C1() { + this.i = "foo"; + } + return C1; +})(); +var D1 = (function (_super) { + __extends(D1, _super); + function D1() { + _super.apply(this, arguments); + this.i = "bar"; + } + return D1; +})(C1); +var t1; +var t2; +var t3; +var t4; +var t5; +var e11 = t1[4]; // base +var e21 = t2[4]; // {} +var e31 = t3[4]; // C1 +var e41 = t4[2]; // base1 +var e51 = t5[2]; // {} diff --git a/tests/baselines/reference/bestCommonTypeOfTuple2.types b/tests/baselines/reference/bestCommonTypeOfTuple2.types index ec52e6c685f..a87407e98fc 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple2.types +++ b/tests/baselines/reference/bestCommonTypeOfTuple2.types @@ -1,90 +1,90 @@ -=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple2.ts === -interface base { } ->base : base - -interface base1 { i } ->base1 : base1 ->i : any - -class C implements base { c } ->C : C ->base : base ->c : any - -class D implements base { d } ->D : D ->base : base ->d : any - -class E implements base { e } ->E : E ->base : base ->e : any - -class F extends C { f } ->F : F ->C : C ->f : any - -class C1 implements base1 { i = "foo"; c } ->C1 : C1 ->base1 : base1 ->i : string ->c : any - -class D1 extends C1 { i = "bar"; d } ->D1 : D1 ->C1 : C1 ->i : string ->d : any - -var t1: [C, base]; ->t1 : [C, base] ->C : C ->base : base - -var t2: [C, D]; ->t2 : [C, D] ->C : C ->D : D - -var t3: [C1, D1]; ->t3 : [C1, D1] ->C1 : C1 ->D1 : D1 - -var t4: [base1, C1]; ->t4 : [base1, C1] ->base1 : base1 ->C1 : C1 - -var t5: [C1, F] ->t5 : [C1, F] ->C1 : C1 ->F : F - -var e11 = t1[4]; // base ->e11 : base ->t1[4] : base ->t1 : [C, base] - -var e21 = t2[4]; // {} ->e21 : {} ->t2[4] : {} ->t2 : [C, D] - -var e31 = t3[4]; // C1 ->e31 : C1 ->t3[4] : C1 ->t3 : [C1, D1] - -var e41 = t4[2]; // base1 ->e41 : base1 ->t4[2] : base1 ->t4 : [base1, C1] - -var e51 = t5[2]; // {} ->e51 : {} ->t5[2] : {} ->t5 : [C1, F] - +=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple2.ts === +interface base { } +>base : base + +interface base1 { i } +>base1 : base1 +>i : any + +class C implements base { c } +>C : C +>base : base +>c : any + +class D implements base { d } +>D : D +>base : base +>d : any + +class E implements base { e } +>E : E +>base : base +>e : any + +class F extends C { f } +>F : F +>C : C +>f : any + +class C1 implements base1 { i = "foo"; c } +>C1 : C1 +>base1 : base1 +>i : string +>c : any + +class D1 extends C1 { i = "bar"; d } +>D1 : D1 +>C1 : C1 +>i : string +>d : any + +var t1: [C, base]; +>t1 : [C, base] +>C : C +>base : base + +var t2: [C, D]; +>t2 : [C, D] +>C : C +>D : D + +var t3: [C1, D1]; +>t3 : [C1, D1] +>C1 : C1 +>D1 : D1 + +var t4: [base1, C1]; +>t4 : [base1, C1] +>base1 : base1 +>C1 : C1 + +var t5: [C1, F] +>t5 : [C1, F] +>C1 : C1 +>F : F + +var e11 = t1[4]; // base +>e11 : base +>t1[4] : base +>t1 : [C, base] + +var e21 = t2[4]; // {} +>e21 : C | D +>t2[4] : C | D +>t2 : [C, D] + +var e31 = t3[4]; // C1 +>e31 : C1 +>t3[4] : C1 +>t3 : [C1, D1] + +var e41 = t4[2]; // base1 +>e41 : base1 +>t4[2] : base1 +>t4 : [base1, C1] + +var e51 = t5[2]; // {} +>e51 : F | C1 +>t5[2] : F | C1 +>t5 : [C1, F] + diff --git a/tests/baselines/reference/bitwiseCompoundAssignmentOperators.errors.txt b/tests/baselines/reference/bitwiseCompoundAssignmentOperators.errors.txt index 1cd51984682..ae7a8fdce0a 100644 --- a/tests/baselines/reference/bitwiseCompoundAssignmentOperators.errors.txt +++ b/tests/baselines/reference/bitwiseCompoundAssignmentOperators.errors.txt @@ -1,59 +1,59 @@ -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(3,1): error TS2447: The '^=' operator is not allowed for boolean types. Consider using '!==' instead. -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(7,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(9,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(14,1): error TS2447: The '&=' operator is not allowed for boolean types. Consider using '&&' instead. -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(18,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(20,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(24,1): error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. -tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(28,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - - -==== tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts (8 errors) ==== - var a = true; - var b = 1; - a ^= a; - ~~~~~~ -!!! error TS2447: The '^=' operator is not allowed for boolean types. Consider using '!==' instead. - a = true; - b ^= b; - b = 1; - a ^= b; - ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - a = true; - b ^= a; - ~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - b = 1; - - var c = false; - var d = 2; - c &= c; - ~~~~~~ -!!! error TS2447: The '&=' operator is not allowed for boolean types. Consider using '&&' instead. - c = false; - d &= d; - d = 2; - c &= d; - ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - c = false; - d &= c; - ~ -!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - - var e = true; - var f = 0; - e |= e; - ~~~~~~ -!!! error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. - e = true; - f |= f; - f = 0; - e |= f; - ~ -!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. - e = true; - f |= f; - +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(3,1): error TS2447: The '^=' operator is not allowed for boolean types. Consider using '!==' instead. +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(7,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(9,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(14,1): error TS2447: The '&=' operator is not allowed for boolean types. Consider using '&&' instead. +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(18,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(20,6): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(24,1): error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. +tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts(28,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + +==== tests/cases/compiler/bitwiseCompoundAssignmentOperators.ts (8 errors) ==== + var a = true; + var b = 1; + a ^= a; + ~~~~~~ +!!! error TS2447: The '^=' operator is not allowed for boolean types. Consider using '!==' instead. + a = true; + b ^= b; + b = 1; + a ^= b; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + a = true; + b ^= a; + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + b = 1; + + var c = false; + var d = 2; + c &= c; + ~~~~~~ +!!! error TS2447: The '&=' operator is not allowed for boolean types. Consider using '&&' instead. + c = false; + d &= d; + d = 2; + c &= d; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + c = false; + d &= c; + ~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + var e = true; + var f = 0; + e |= e; + ~~~~~~ +!!! error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. + e = true; + f |= f; + f = 0; + e |= f; + ~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + e = true; + f |= f; + \ No newline at end of file diff --git a/tests/baselines/reference/bitwiseCompoundAssignmentOperators.js b/tests/baselines/reference/bitwiseCompoundAssignmentOperators.js index e9bfeabb965..c148fc0142c 100644 --- a/tests/baselines/reference/bitwiseCompoundAssignmentOperators.js +++ b/tests/baselines/reference/bitwiseCompoundAssignmentOperators.js @@ -1,4 +1,4 @@ -//// [bitwiseCompoundAssignmentOperators.ts] +//// [bitwiseCompoundAssignmentOperators.ts] var a = true; var b = 1; a ^= a; @@ -30,34 +30,34 @@ e |= f; e = true; f |= f; - - -//// [bitwiseCompoundAssignmentOperators.js] -var a = true; -var b = 1; -a ^= a; -a = true; -b ^= b; -b = 1; -a ^= b; -a = true; -b ^= a; -b = 1; -var c = false; -var d = 2; -c &= c; -c = false; -d &= d; -d = 2; -c &= d; -c = false; -d &= c; -var e = true; -var f = 0; -e |= e; -e = true; -f |= f; -f = 0; -e |= f; -e = true; -f |= f; + + +//// [bitwiseCompoundAssignmentOperators.js] +var a = true; +var b = 1; +a ^= a; +a = true; +b ^= b; +b = 1; +a ^= b; +a = true; +b ^= a; +b = 1; +var c = false; +var d = 2; +c &= c; +c = false; +d &= d; +d = 2; +c &= d; +c = false; +d &= c; +var e = true; +var f = 0; +e |= e; +e = true; +f |= f; +f = 0; +e |= f; +e = true; +f |= f; diff --git a/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js b/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js index e38520ef71a..9cd5a63912e 100644 --- a/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js +++ b/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js @@ -1,40 +1,40 @@ //// [bitwiseNotOperatorWithEnumType.ts] // ~ operator on enum type -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsNumber1 = ~ENUM1; // enum type expressions -var ResultIsNumber2 = ~ENUM1[1]; -var ResultIsNumber3 = ~(ENUM1[1] + ENUM1[2]); +var ResultIsNumber2 = ~ENUM1["A"]; +var ResultIsNumber3 = ~(ENUM1.A + ENUM1["B"]); // multiple ~ operators -var ResultIsNumber4 = ~~~(ENUM1[1] + ENUM1[2]); +var ResultIsNumber4 = ~~~(ENUM1["A"] + ENUM1.B); // miss assignment operators ~ENUM1; -~ENUM1[1]; -~ENUM1[1], ~ENUM1[2]; +~ENUM1["A"]; +~ENUM1.A, ~ENUM1["B"]; //// [bitwiseNotOperatorWithEnumType.js] // ~ operator on enum type var ENUM1; (function (ENUM1) { - ENUM1[ENUM1["1"] = 0] = "1"; - ENUM1[ENUM1["2"] = 1] = "2"; + ENUM1[ENUM1["A"] = 0] = "A"; + ENUM1[ENUM1["B"] = 1] = "B"; ENUM1[ENUM1[""] = 2] = ""; })(ENUM1 || (ENUM1 = {})); ; // enum type var var ResultIsNumber1 = ~ENUM1; // enum type expressions -var ResultIsNumber2 = ~ENUM1[1]; -var ResultIsNumber3 = ~(ENUM1[1] + ENUM1[2]); +var ResultIsNumber2 = ~ENUM1["A"]; +var ResultIsNumber3 = ~(0 /* A */ + ENUM1["B"]); // multiple ~ operators -var ResultIsNumber4 = ~~~(ENUM1[1] + ENUM1[2]); +var ResultIsNumber4 = ~~~(ENUM1["A"] + 1 /* B */); // miss assignment operators ~ENUM1; -~ENUM1[1]; -~ENUM1[1], ~ENUM1[2]; +~ENUM1["A"]; +~0 /* A */, ~ENUM1["B"]; diff --git a/tests/baselines/reference/bitwiseNotOperatorWithEnumType.types b/tests/baselines/reference/bitwiseNotOperatorWithEnumType.types index 077b8fdd4d6..71598c6f693 100644 --- a/tests/baselines/reference/bitwiseNotOperatorWithEnumType.types +++ b/tests/baselines/reference/bitwiseNotOperatorWithEnumType.types @@ -1,8 +1,10 @@ === tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithEnumType.ts === // ~ operator on enum type -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; >ENUM1 : ENUM1 +>A : ENUM1 +>B : ENUM1 // enum type var var ResultIsNumber1 = ~ENUM1; @@ -11,51 +13,54 @@ var ResultIsNumber1 = ~ENUM1; >ENUM1 : typeof ENUM1 // enum type expressions -var ResultIsNumber2 = ~ENUM1[1]; +var ResultIsNumber2 = ~ENUM1["A"]; >ResultIsNumber2 : number ->~ENUM1[1] : number ->ENUM1[1] : ENUM1 +>~ENUM1["A"] : number +>ENUM1["A"] : ENUM1 >ENUM1 : typeof ENUM1 -var ResultIsNumber3 = ~(ENUM1[1] + ENUM1[2]); +var ResultIsNumber3 = ~(ENUM1.A + ENUM1["B"]); >ResultIsNumber3 : number ->~(ENUM1[1] + ENUM1[2]) : number ->(ENUM1[1] + ENUM1[2]) : number ->ENUM1[1] + ENUM1[2] : number ->ENUM1[1] : ENUM1 +>~(ENUM1.A + ENUM1["B"]) : number +>(ENUM1.A + ENUM1["B"]) : number +>ENUM1.A + ENUM1["B"] : number +>ENUM1.A : ENUM1 >ENUM1 : typeof ENUM1 ->ENUM1[2] : ENUM1 +>A : ENUM1 +>ENUM1["B"] : ENUM1 >ENUM1 : typeof ENUM1 // multiple ~ operators -var ResultIsNumber4 = ~~~(ENUM1[1] + ENUM1[2]); +var ResultIsNumber4 = ~~~(ENUM1["A"] + ENUM1.B); >ResultIsNumber4 : number ->~~~(ENUM1[1] + ENUM1[2]) : number ->~~(ENUM1[1] + ENUM1[2]) : number ->~(ENUM1[1] + ENUM1[2]) : number ->(ENUM1[1] + ENUM1[2]) : number ->ENUM1[1] + ENUM1[2] : number ->ENUM1[1] : ENUM1 +>~~~(ENUM1["A"] + ENUM1.B) : number +>~~(ENUM1["A"] + ENUM1.B) : number +>~(ENUM1["A"] + ENUM1.B) : number +>(ENUM1["A"] + ENUM1.B) : number +>ENUM1["A"] + ENUM1.B : number +>ENUM1["A"] : ENUM1 >ENUM1 : typeof ENUM1 ->ENUM1[2] : ENUM1 +>ENUM1.B : ENUM1 >ENUM1 : typeof ENUM1 +>B : ENUM1 // miss assignment operators ~ENUM1; >~ENUM1 : number >ENUM1 : typeof ENUM1 -~ENUM1[1]; ->~ENUM1[1] : number ->ENUM1[1] : ENUM1 +~ENUM1["A"]; +>~ENUM1["A"] : number +>ENUM1["A"] : ENUM1 >ENUM1 : typeof ENUM1 -~ENUM1[1], ~ENUM1[2]; ->~ENUM1[1], ~ENUM1[2] : number ->~ENUM1[1] : number ->ENUM1[1] : ENUM1 +~ENUM1.A, ~ENUM1["B"]; +>~ENUM1.A, ~ENUM1["B"] : number +>~ENUM1.A : number +>ENUM1.A : ENUM1 >ENUM1 : typeof ENUM1 ->~ENUM1[2] : number ->ENUM1[2] : ENUM1 +>A : ENUM1 +>~ENUM1["B"] : number +>ENUM1["B"] : ENUM1 >ENUM1 : typeof ENUM1 diff --git a/tests/baselines/reference/castingTuple.errors.txt b/tests/baselines/reference/castingTuple.errors.txt index ee09362f01f..c3079699a80 100644 --- a/tests/baselines/reference/castingTuple.errors.txt +++ b/tests/baselines/reference/castingTuple.errors.txt @@ -1,61 +1,73 @@ -tests/cases/conformance/types/tuple/castingTuple.ts(24,10): error TS2353: Neither type '[number, string]' nor type '[number, number]' is assignable to the other: - Types of property '1' are incompatible: - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/tuple/castingTuple.ts(25,10): error TS2353: Neither type '[C, D]' nor type '[A, I]' is assignable to the other: - Types of property '0' are incompatible: - Type 'C' is not assignable to type 'A': - Property 'a' is missing in type 'C'. -tests/cases/conformance/types/tuple/castingTuple.ts(26,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. -tests/cases/conformance/types/tuple/castingTuple.ts(26,14): error TS2353: Neither type '[number, string]' nor type 'number[]' is assignable to the other: - Types of property 'pop' are incompatible: - Type '() => {}' is not assignable to type '() => number': - Type '{}' is not assignable to type 'number'. -tests/cases/conformance/types/tuple/castingTuple.ts(27,1): error TS2304: Cannot find name 't4'. - - -==== tests/cases/conformance/types/tuple/castingTuple.ts (5 errors) ==== - interface I { } - class A { a = 10; } - class C implements I { c }; - class D implements I { d }; - class E extends A { e }; - class F extends A { f }; - enum E1 { one } - enum E2 { one } - - // no error - var numStrTuple: [number, string] = [5, "foo"]; - var emptyObjTuple = <[{}, {}]>numStrTuple; - var numStrBoolTuple = <[number, string, boolean]>numStrTuple; - var classCDTuple: [C, D] = [new C(), new D()]; - var interfaceIITuple = <[I, I]>classCDTuple; - var classCDATuple = <[C, D, A]>classCDTuple; - var eleFromCDA1 = classCDATuple[2]; // A - var eleFromCDA2 = classCDATuple[5]; // {} - var t10: [E1, E2] = [E1.one, E2.one]; - var t11 = <[number, number]>t10; - var array1 = <{}[]>emptyObjTuple; - - // error - var t3 = <[number, number]>numStrTuple; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2353: Neither type '[number, string]' nor type '[number, number]' is assignable to the other: -!!! error TS2353: Types of property '1' are incompatible: -!!! error TS2353: Type 'string' is not assignable to type 'number'. - var t9 = <[A, I]>classCDTuple; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2353: Neither type '[C, D]' nor type '[A, I]' is assignable to the other: -!!! error TS2353: Types of property '0' are incompatible: -!!! error TS2353: Type 'C' is not assignable to type 'A': -!!! error TS2353: Property 'a' is missing in type 'C'. - var array1 = numStrTuple; - ~~~~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2353: Neither type '[number, string]' nor type 'number[]' is assignable to the other: -!!! error TS2353: Types of property 'pop' are incompatible: -!!! error TS2353: Type '() => {}' is not assignable to type '() => number': -!!! error TS2353: Type '{}' is not assignable to type 'number'. - t4[2] = 10; - ~~ +tests/cases/conformance/types/tuple/castingTuple.ts(13,23): error TS2353: Neither type '[number, string]' nor type '[number, string, boolean]' is assignable to the other: + Property '2' is missing in type '[number, string]'. +tests/cases/conformance/types/tuple/castingTuple.ts(16,21): error TS2353: Neither type '[C, D]' nor type '[C, D, A]' is assignable to the other: + Property '2' is missing in type '[C, D]'. +tests/cases/conformance/types/tuple/castingTuple.ts(24,10): error TS2353: Neither type '[number, string]' nor type '[number, number]' is assignable to the other: + Types of property '1' are incompatible: + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/castingTuple.ts(25,10): error TS2353: Neither type '[C, D]' nor type '[A, I]' is assignable to the other: + Types of property '0' are incompatible: + Type 'C' is not assignable to type 'A': + Property 'a' is missing in type 'C'. +tests/cases/conformance/types/tuple/castingTuple.ts(26,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. +tests/cases/conformance/types/tuple/castingTuple.ts(26,14): error TS2353: Neither type '[number, string]' nor type 'number[]' is assignable to the other: + Types of property 'pop' are incompatible: + Type '() => string | number' is not assignable to type '() => number': + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/castingTuple.ts(27,1): error TS2304: Cannot find name 't4'. + + +==== tests/cases/conformance/types/tuple/castingTuple.ts (7 errors) ==== + interface I { } + class A { a = 10; } + class C implements I { c }; + class D implements I { d }; + class E extends A { e }; + class F extends A { f }; + enum E1 { one } + enum E2 { one } + + // no error + var numStrTuple: [number, string] = [5, "foo"]; + var emptyObjTuple = <[{}, {}]>numStrTuple; + var numStrBoolTuple = <[number, string, boolean]>numStrTuple; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2353: Neither type '[number, string]' nor type '[number, string, boolean]' is assignable to the other: +!!! error TS2353: Property '2' is missing in type '[number, string]'. + var classCDTuple: [C, D] = [new C(), new D()]; + var interfaceIITuple = <[I, I]>classCDTuple; + var classCDATuple = <[C, D, A]>classCDTuple; + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2353: Neither type '[C, D]' nor type '[C, D, A]' is assignable to the other: +!!! error TS2353: Property '2' is missing in type '[C, D]'. + var eleFromCDA1 = classCDATuple[2]; // A + var eleFromCDA2 = classCDATuple[5]; // {} + var t10: [E1, E2] = [E1.one, E2.one]; + var t11 = <[number, number]>t10; + var array1 = <{}[]>emptyObjTuple; + + // error + var t3 = <[number, number]>numStrTuple; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2353: Neither type '[number, string]' nor type '[number, number]' is assignable to the other: +!!! error TS2353: Types of property '1' are incompatible: +!!! error TS2353: Type 'string' is not assignable to type 'number'. + var t9 = <[A, I]>classCDTuple; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2353: Neither type '[C, D]' nor type '[A, I]' is assignable to the other: +!!! error TS2353: Types of property '0' are incompatible: +!!! error TS2353: Type 'C' is not assignable to type 'A': +!!! error TS2353: Property 'a' is missing in type 'C'. + var array1 = numStrTuple; + ~~~~~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2353: Neither type '[number, string]' nor type 'number[]' is assignable to the other: +!!! error TS2353: Types of property 'pop' are incompatible: +!!! error TS2353: Type '() => string | number' is not assignable to type '() => number': +!!! error TS2353: Type 'string | number' is not assignable to type 'number': +!!! error TS2353: Type 'string' is not assignable to type 'number'. + t4[2] = 10; + ~~ !!! error TS2304: Cannot find name 't4'. \ No newline at end of file diff --git a/tests/baselines/reference/castingTuple.js b/tests/baselines/reference/castingTuple.js index c1835e9d117..0671062bb4e 100644 --- a/tests/baselines/reference/castingTuple.js +++ b/tests/baselines/reference/castingTuple.js @@ -1,4 +1,4 @@ -//// [castingTuple.ts] +//// [castingTuple.ts] interface I { } class A { a = 10; } class C implements I { c }; @@ -25,71 +25,71 @@ var array1 = <{}[]>emptyObjTuple; var t3 = <[number, number]>numStrTuple; var t9 = <[A, I]>classCDTuple; var array1 = numStrTuple; -t4[2] = 10; - -//// [castingTuple.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var A = (function () { - function A() { - this.a = 10; - } - return A; -})(); -var C = (function () { - function C() { - } - return C; -})(); -; -var D = (function () { - function D() { - } - return D; -})(); -; -var E = (function (_super) { - __extends(E, _super); - function E() { - _super.apply(this, arguments); - } - return E; -})(A); -; -var F = (function (_super) { - __extends(F, _super); - function F() { - _super.apply(this, arguments); - } - return F; -})(A); -; -var E1; -(function (E1) { - E1[E1["one"] = 0] = "one"; -})(E1 || (E1 = {})); -var E2; -(function (E2) { - E2[E2["one"] = 0] = "one"; -})(E2 || (E2 = {})); -// no error -var numStrTuple = [5, "foo"]; -var emptyObjTuple = numStrTuple; -var numStrBoolTuple = numStrTuple; -var classCDTuple = [new C(), new D()]; -var interfaceIITuple = classCDTuple; -var classCDATuple = classCDTuple; -var eleFromCDA1 = classCDATuple[2]; // A -var eleFromCDA2 = classCDATuple[5]; // {} -var t10 = [0 /* one */, 0 /* one */]; -var t11 = t10; -var array1 = emptyObjTuple; -// error -var t3 = numStrTuple; -var t9 = classCDTuple; -var array1 = numStrTuple; -t4[2] = 10; +t4[2] = 10; + +//// [castingTuple.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var A = (function () { + function A() { + this.a = 10; + } + return A; +})(); +var C = (function () { + function C() { + } + return C; +})(); +; +var D = (function () { + function D() { + } + return D; +})(); +; +var E = (function (_super) { + __extends(E, _super); + function E() { + _super.apply(this, arguments); + } + return E; +})(A); +; +var F = (function (_super) { + __extends(F, _super); + function F() { + _super.apply(this, arguments); + } + return F; +})(A); +; +var E1; +(function (E1) { + E1[E1["one"] = 0] = "one"; +})(E1 || (E1 = {})); +var E2; +(function (E2) { + E2[E2["one"] = 0] = "one"; +})(E2 || (E2 = {})); +// no error +var numStrTuple = [5, "foo"]; +var emptyObjTuple = numStrTuple; +var numStrBoolTuple = numStrTuple; +var classCDTuple = [new C(), new D()]; +var interfaceIITuple = classCDTuple; +var classCDATuple = classCDTuple; +var eleFromCDA1 = classCDATuple[2]; // A +var eleFromCDA2 = classCDATuple[5]; // {} +var t10 = [0 /* one */, 0 /* one */]; +var t11 = t10; +var array1 = emptyObjTuple; +// error +var t3 = numStrTuple; +var t9 = classCDTuple; +var array1 = numStrTuple; +t4[2] = 10; diff --git a/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.errors.txt b/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.errors.txt deleted file mode 100644 index 2e63bf0a795..00000000000 --- a/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.errors.txt +++ /dev/null @@ -1,215 +0,0 @@ -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(32,12): error TS2365: Operator '<' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(40,12): error TS2365: Operator '<' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(49,12): error TS2365: Operator '>' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(57,12): error TS2365: Operator '>' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(66,12): error TS2365: Operator '<=' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(74,12): error TS2365: Operator '<=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(83,12): error TS2365: Operator '>=' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(91,12): error TS2365: Operator '>=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(100,12): error TS2365: Operator '==' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(108,12): error TS2365: Operator '==' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(117,12): error TS2365: Operator '!=' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(125,12): error TS2365: Operator '!=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(134,12): error TS2365: Operator '===' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(142,12): error TS2365: Operator '===' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(151,12): error TS2365: Operator '!==' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts(159,12): error TS2365: Operator '!==' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - - -==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts (16 errors) ==== - class Base { - public a: string; - } - - class Derived extends Base { - public b: string; - } - - var a1: { fn(x: T): T }; - var b1: { fn(x: string): string }; - - var a2: { fn(x: T): T }; - var b2: { fn(x: string, y: number): string }; - - var a3: { fn(x: T, y: U): T }; - var b3: { fn(x: string, y: number): string }; - - var a4: { fn(x?: T): T }; - var b4: { fn(x?: string): string }; - - var a5: { fn(...x: T[]): T }; - var b5: { fn(...x: string[]): string }; - - var a6: { fn(x: T, y: T): T }; - var b6: { fn(x: string, y: number): {} }; - - //var a7: { fn(x: T, y: U): T }; - var b7: { fn(x: Base, y: Derived): Base }; - - // operator < - var r1a1 = a1 < b1; - var r1a2 = a2 < b2; - ~~~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r1a3 = a3 < b3; - var r1a4 = a4 < b4; - var r1a5 = a5 < b5; - var r1a6 = a6 < b6; - //var r1a7 = a7 < b7; - - var r1b1 = b1 < a1; - var r1b2 = b2 < a2; - ~~~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r1b3 = b3 < a3; - var r1b4 = b4 < a4; - var r1b5 = b5 < a5; - var r1b6 = b6 < a6; - //var r1b7 = b7 < a7; - - // operator > - var r2a1 = a1 > b1; - var r2a2 = a2 > b2; - ~~~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r2a3 = a3 > b3; - var r2a4 = a4 > b4; - var r2a5 = a5 > b5; - var r2a6 = a6 > b6; - //var r2a7 = a7 > b7; - - var r2b1 = b1 > a1; - var r2b2 = b2 > a2; - ~~~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r2b3 = b3 > a3; - var r2b4 = b4 > a4; - var r2b5 = b5 > a5; - var r2b6 = b6 > a6; - //var r2b7 = b7 > a7; - - // operator <= - var r3a1 = a1 <= b1; - var r3a2 = a2 <= b2; - ~~~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r3a3 = a3 <= b3; - var r3a4 = a4 <= b4; - var r3a5 = a5 <= b5; - var r3a6 = a6 <= b6; - //var r3a7 = a7 <= b7; - - var r3b1 = b1 <= a1; - var r3b2 = b2 <= a2; - ~~~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r3b3 = b3 <= a3; - var r3b4 = b4 <= a4; - var r3b5 = b5 <= a5; - var r3b6 = b6 <= a6; - //var r3b7 = b7 <= a7; - - // operator >= - var r4a1 = a1 >= b1; - var r4a2 = a2 >= b2; - ~~~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r4a3 = a3 >= b3; - var r4a4 = a4 >= b4; - var r4a5 = a5 >= b5; - var r4a6 = a6 >= b6; - //var r4a7 = a7 >= b7; - - var r4b1 = b1 >= a1; - var r4b2 = b2 >= a2; - ~~~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r4b3 = b3 >= a3; - var r4b4 = b4 >= a4; - var r4b5 = b5 >= a5; - var r4b6 = b6 >= a6; - //var r4b7 = b7 >= a7; - - // operator == - var r5a1 = a1 == b1; - var r5a2 = a2 == b2; - ~~~~~~~~ -!!! error TS2365: Operator '==' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r5a3 = a3 == b3; - var r5a4 = a4 == b4; - var r5a5 = a5 == b5; - var r5a6 = a6 == b6; - //var r5a7 = a7 == b7; - - var r5b1 = b1 == a1; - var r5b2 = b2 == a2; - ~~~~~~~~ -!!! error TS2365: Operator '==' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r5b3 = b3 == a3; - var r5b4 = b4 == a4; - var r5b5 = b5 == a5; - var r5b6 = b6 == a6; - //var r5b7 = b7 == a7; - - // operator != - var r6a1 = a1 != b1; - var r6a2 = a2 != b2; - ~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r6a3 = a3 != b3; - var r6a4 = a4 != b4; - var r6a5 = a5 != b5; - var r6a6 = a6 != b6; - //var r6a7 = a7 != b7; - - var r6b1 = b1 != a1; - var r6b2 = b2 != a2; - ~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r6b3 = b3 != a3; - var r6b4 = b4 != a4; - var r6b5 = b5 != a5; - var r6b6 = b6 != a6; - //var r6b7 = b7 != a7; - - // operator === - var r7a1 = a1 === b1; - var r7a2 = a2 === b2; - ~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r7a3 = a3 === b3; - var r7a4 = a4 === b4; - var r7a5 = a5 === b5; - var r7a6 = a6 === b6; - //var r7a7 = a7 === b7; - - var r7b1 = b1 === a1; - var r7b2 = b2 === a2; - ~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r7b3 = b3 === a3; - var r7b4 = b4 === a4; - var r7b5 = b5 === a5; - var r7b6 = b6 === a6; - //var r7b7 = b7 === a7; - - // operator !== - var r8a1 = a1 !== b1; - var r8a2 = a2 !== b2; - ~~~~~~~~~ -!!! error TS2365: Operator '!==' cannot be applied to types '{ fn(x: T): T; }' and '{ fn(x: string, y: number): string; }'. - var r8a3 = a3 !== b3; - var r8a4 = a4 !== b4; - var r8a5 = a5 !== b5; - var r8a6 = a6 !== b6; - //var r8a7 = a7 !== b7; - - var r8b1 = b1 !== a1; - var r8b2 = b2 !== a2; - ~~~~~~~~~ -!!! error TS2365: Operator '!==' cannot be applied to types '{ fn(x: string, y: number): string; }' and '{ fn(x: T): T; }'. - var r8b3 = b3 !== a3; - var r8b4 = b4 !== a4; - var r8b5 = b5 !== a5; - var r8b6 = b6 !== a6; - //var r8b7 = b7 !== a7; \ No newline at end of file diff --git a/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.types b/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.types new file mode 100644 index 00000000000..c3f0d96e839 --- /dev/null +++ b/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.types @@ -0,0 +1,727 @@ +=== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedCallSignature.ts === +class Base { +>Base : Base + + public a: string; +>a : string +} + +class Derived extends Base { +>Derived : Derived +>Base : Base + + public b: string; +>b : string +} + +var a1: { fn(x: T): T }; +>a1 : { fn(x: T): T; } +>fn : (x: T) => T +>T : T +>x : T +>T : T +>T : T + +var b1: { fn(x: string): string }; +>b1 : { fn(x: string): string; } +>fn : (x: string) => string +>x : string + +var a2: { fn(x: T): T }; +>a2 : { fn(x: T): T; } +>fn : (x: T) => T +>T : T +>x : T +>T : T +>T : T + +var b2: { fn(x: string, y: number): string }; +>b2 : { fn(x: string, y: number): string; } +>fn : (x: string, y: number) => string +>x : string +>y : number + +var a3: { fn(x: T, y: U): T }; +>a3 : { fn(x: T, y: U): T; } +>fn : (x: T, y: U) => T +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U +>T : T + +var b3: { fn(x: string, y: number): string }; +>b3 : { fn(x: string, y: number): string; } +>fn : (x: string, y: number) => string +>x : string +>y : number + +var a4: { fn(x?: T): T }; +>a4 : { fn(x?: T): T; } +>fn : (x?: T) => T +>T : T +>x : T +>T : T +>T : T + +var b4: { fn(x?: string): string }; +>b4 : { fn(x?: string): string; } +>fn : (x?: string) => string +>x : string + +var a5: { fn(...x: T[]): T }; +>a5 : { fn(...x: T[]): T; } +>fn : (...x: T[]) => T +>T : T +>x : T[] +>T : T +>T : T + +var b5: { fn(...x: string[]): string }; +>b5 : { fn(...x: string[]): string; } +>fn : (...x: string[]) => string +>x : string[] + +var a6: { fn(x: T, y: T): T }; +>a6 : { fn(x: T, y: T): T; } +>fn : (x: T, y: T) => T +>T : T +>x : T +>T : T +>y : T +>T : T +>T : T + +var b6: { fn(x: string, y: number): {} }; +>b6 : { fn(x: string, y: number): {}; } +>fn : (x: string, y: number) => {} +>x : string +>y : number + +//var a7: { fn(x: T, y: U): T }; +var b7: { fn(x: Base, y: Derived): Base }; +>b7 : { fn(x: Base, y: Derived): Base; } +>fn : (x: Base, y: Derived) => Base +>x : Base +>Base : Base +>y : Derived +>Derived : Derived +>Base : Base + +// operator < +var r1a1 = a1 < b1; +>r1a1 : boolean +>a1 < b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r1a2 = a2 < b2; +>r1a2 : boolean +>a2 < b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r1a3 = a3 < b3; +>r1a3 : boolean +>a3 < b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r1a4 = a4 < b4; +>r1a4 : boolean +>a4 < b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r1a5 = a5 < b5; +>r1a5 : boolean +>a5 < b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r1a6 = a6 < b6; +>r1a6 : boolean +>a6 < b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r1a7 = a7 < b7; + +var r1b1 = b1 < a1; +>r1b1 : boolean +>b1 < a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r1b2 = b2 < a2; +>r1b2 : boolean +>b2 < a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r1b3 = b3 < a3; +>r1b3 : boolean +>b3 < a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r1b4 = b4 < a4; +>r1b4 : boolean +>b4 < a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r1b5 = b5 < a5; +>r1b5 : boolean +>b5 < a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r1b6 = b6 < a6; +>r1b6 : boolean +>b6 < a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r1b7 = b7 < a7; + +// operator > +var r2a1 = a1 > b1; +>r2a1 : boolean +>a1 > b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r2a2 = a2 > b2; +>r2a2 : boolean +>a2 > b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r2a3 = a3 > b3; +>r2a3 : boolean +>a3 > b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r2a4 = a4 > b4; +>r2a4 : boolean +>a4 > b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r2a5 = a5 > b5; +>r2a5 : boolean +>a5 > b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r2a6 = a6 > b6; +>r2a6 : boolean +>a6 > b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r2a7 = a7 > b7; + +var r2b1 = b1 > a1; +>r2b1 : boolean +>b1 > a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r2b2 = b2 > a2; +>r2b2 : boolean +>b2 > a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r2b3 = b3 > a3; +>r2b3 : boolean +>b3 > a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r2b4 = b4 > a4; +>r2b4 : boolean +>b4 > a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r2b5 = b5 > a5; +>r2b5 : boolean +>b5 > a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r2b6 = b6 > a6; +>r2b6 : boolean +>b6 > a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r2b7 = b7 > a7; + +// operator <= +var r3a1 = a1 <= b1; +>r3a1 : boolean +>a1 <= b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r3a2 = a2 <= b2; +>r3a2 : boolean +>a2 <= b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r3a3 = a3 <= b3; +>r3a3 : boolean +>a3 <= b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r3a4 = a4 <= b4; +>r3a4 : boolean +>a4 <= b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r3a5 = a5 <= b5; +>r3a5 : boolean +>a5 <= b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r3a6 = a6 <= b6; +>r3a6 : boolean +>a6 <= b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r3a7 = a7 <= b7; + +var r3b1 = b1 <= a1; +>r3b1 : boolean +>b1 <= a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r3b2 = b2 <= a2; +>r3b2 : boolean +>b2 <= a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r3b3 = b3 <= a3; +>r3b3 : boolean +>b3 <= a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r3b4 = b4 <= a4; +>r3b4 : boolean +>b4 <= a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r3b5 = b5 <= a5; +>r3b5 : boolean +>b5 <= a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r3b6 = b6 <= a6; +>r3b6 : boolean +>b6 <= a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r3b7 = b7 <= a7; + +// operator >= +var r4a1 = a1 >= b1; +>r4a1 : boolean +>a1 >= b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r4a2 = a2 >= b2; +>r4a2 : boolean +>a2 >= b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r4a3 = a3 >= b3; +>r4a3 : boolean +>a3 >= b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r4a4 = a4 >= b4; +>r4a4 : boolean +>a4 >= b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r4a5 = a5 >= b5; +>r4a5 : boolean +>a5 >= b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r4a6 = a6 >= b6; +>r4a6 : boolean +>a6 >= b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r4a7 = a7 >= b7; + +var r4b1 = b1 >= a1; +>r4b1 : boolean +>b1 >= a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r4b2 = b2 >= a2; +>r4b2 : boolean +>b2 >= a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r4b3 = b3 >= a3; +>r4b3 : boolean +>b3 >= a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r4b4 = b4 >= a4; +>r4b4 : boolean +>b4 >= a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r4b5 = b5 >= a5; +>r4b5 : boolean +>b5 >= a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r4b6 = b6 >= a6; +>r4b6 : boolean +>b6 >= a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r4b7 = b7 >= a7; + +// operator == +var r5a1 = a1 == b1; +>r5a1 : boolean +>a1 == b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r5a2 = a2 == b2; +>r5a2 : boolean +>a2 == b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r5a3 = a3 == b3; +>r5a3 : boolean +>a3 == b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r5a4 = a4 == b4; +>r5a4 : boolean +>a4 == b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r5a5 = a5 == b5; +>r5a5 : boolean +>a5 == b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r5a6 = a6 == b6; +>r5a6 : boolean +>a6 == b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r5a7 = a7 == b7; + +var r5b1 = b1 == a1; +>r5b1 : boolean +>b1 == a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r5b2 = b2 == a2; +>r5b2 : boolean +>b2 == a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r5b3 = b3 == a3; +>r5b3 : boolean +>b3 == a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r5b4 = b4 == a4; +>r5b4 : boolean +>b4 == a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r5b5 = b5 == a5; +>r5b5 : boolean +>b5 == a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r5b6 = b6 == a6; +>r5b6 : boolean +>b6 == a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r5b7 = b7 == a7; + +// operator != +var r6a1 = a1 != b1; +>r6a1 : boolean +>a1 != b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r6a2 = a2 != b2; +>r6a2 : boolean +>a2 != b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r6a3 = a3 != b3; +>r6a3 : boolean +>a3 != b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r6a4 = a4 != b4; +>r6a4 : boolean +>a4 != b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r6a5 = a5 != b5; +>r6a5 : boolean +>a5 != b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r6a6 = a6 != b6; +>r6a6 : boolean +>a6 != b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r6a7 = a7 != b7; + +var r6b1 = b1 != a1; +>r6b1 : boolean +>b1 != a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r6b2 = b2 != a2; +>r6b2 : boolean +>b2 != a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r6b3 = b3 != a3; +>r6b3 : boolean +>b3 != a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r6b4 = b4 != a4; +>r6b4 : boolean +>b4 != a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r6b5 = b5 != a5; +>r6b5 : boolean +>b5 != a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r6b6 = b6 != a6; +>r6b6 : boolean +>b6 != a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r6b7 = b7 != a7; + +// operator === +var r7a1 = a1 === b1; +>r7a1 : boolean +>a1 === b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r7a2 = a2 === b2; +>r7a2 : boolean +>a2 === b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r7a3 = a3 === b3; +>r7a3 : boolean +>a3 === b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r7a4 = a4 === b4; +>r7a4 : boolean +>a4 === b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r7a5 = a5 === b5; +>r7a5 : boolean +>a5 === b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r7a6 = a6 === b6; +>r7a6 : boolean +>a6 === b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r7a7 = a7 === b7; + +var r7b1 = b1 === a1; +>r7b1 : boolean +>b1 === a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r7b2 = b2 === a2; +>r7b2 : boolean +>b2 === a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r7b3 = b3 === a3; +>r7b3 : boolean +>b3 === a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r7b4 = b4 === a4; +>r7b4 : boolean +>b4 === a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r7b5 = b5 === a5; +>r7b5 : boolean +>b5 === a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r7b6 = b6 === a6; +>r7b6 : boolean +>b6 === a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r7b7 = b7 === a7; + +// operator !== +var r8a1 = a1 !== b1; +>r8a1 : boolean +>a1 !== b1 : boolean +>a1 : { fn(x: T): T; } +>b1 : { fn(x: string): string; } + +var r8a2 = a2 !== b2; +>r8a2 : boolean +>a2 !== b2 : boolean +>a2 : { fn(x: T): T; } +>b2 : { fn(x: string, y: number): string; } + +var r8a3 = a3 !== b3; +>r8a3 : boolean +>a3 !== b3 : boolean +>a3 : { fn(x: T, y: U): T; } +>b3 : { fn(x: string, y: number): string; } + +var r8a4 = a4 !== b4; +>r8a4 : boolean +>a4 !== b4 : boolean +>a4 : { fn(x?: T): T; } +>b4 : { fn(x?: string): string; } + +var r8a5 = a5 !== b5; +>r8a5 : boolean +>a5 !== b5 : boolean +>a5 : { fn(...x: T[]): T; } +>b5 : { fn(...x: string[]): string; } + +var r8a6 = a6 !== b6; +>r8a6 : boolean +>a6 !== b6 : boolean +>a6 : { fn(x: T, y: T): T; } +>b6 : { fn(x: string, y: number): {}; } + +//var r8a7 = a7 !== b7; + +var r8b1 = b1 !== a1; +>r8b1 : boolean +>b1 !== a1 : boolean +>b1 : { fn(x: string): string; } +>a1 : { fn(x: T): T; } + +var r8b2 = b2 !== a2; +>r8b2 : boolean +>b2 !== a2 : boolean +>b2 : { fn(x: string, y: number): string; } +>a2 : { fn(x: T): T; } + +var r8b3 = b3 !== a3; +>r8b3 : boolean +>b3 !== a3 : boolean +>b3 : { fn(x: string, y: number): string; } +>a3 : { fn(x: T, y: U): T; } + +var r8b4 = b4 !== a4; +>r8b4 : boolean +>b4 !== a4 : boolean +>b4 : { fn(x?: string): string; } +>a4 : { fn(x?: T): T; } + +var r8b5 = b5 !== a5; +>r8b5 : boolean +>b5 !== a5 : boolean +>b5 : { fn(...x: string[]): string; } +>a5 : { fn(...x: T[]): T; } + +var r8b6 = b6 !== a6; +>r8b6 : boolean +>b6 !== a6 : boolean +>b6 : { fn(x: string, y: number): {}; } +>a6 : { fn(x: T, y: T): T; } + +//var r8b7 = b7 !== a7; diff --git a/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.errors.txt b/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.errors.txt deleted file mode 100644 index 0e352ebcc9d..00000000000 --- a/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.errors.txt +++ /dev/null @@ -1,215 +0,0 @@ -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(32,12): error TS2365: Operator '<' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(40,12): error TS2365: Operator '<' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(49,12): error TS2365: Operator '>' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(57,12): error TS2365: Operator '>' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(66,12): error TS2365: Operator '<=' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(74,12): error TS2365: Operator '<=' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(83,12): error TS2365: Operator '>=' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(91,12): error TS2365: Operator '>=' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(100,12): error TS2365: Operator '==' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(108,12): error TS2365: Operator '==' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(117,12): error TS2365: Operator '!=' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(125,12): error TS2365: Operator '!=' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(134,12): error TS2365: Operator '===' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(142,12): error TS2365: Operator '===' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(151,12): error TS2365: Operator '!==' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. -tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts(159,12): error TS2365: Operator '!==' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - - -==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts (16 errors) ==== - class Base { - public a: string; - } - - class Derived extends Base { - public b: string; - } - - var a1: { new (x: T): T }; - var b1: { new (x: string): string }; - - var a2: { new (x: T): T }; - var b2: { new (x: string, y: number): string }; - - var a3: { new (x: T, y: U): T }; - var b3: { new (x: string, y: number): string }; - - var a4: { new (x?: T): T }; - var b4: { new (x?: string): string }; - - var a5: { new (...x: T[]): T }; - var b5: { new (...x: string[]): string }; - - var a6: { new (x: T, y: T): T }; - var b6: { new (x: string, y: number): {} }; - - //var a7: { new (x: T, y: U): T }; - var b7: { new (x: Base, y: Derived): Base }; - - // operator < - var r1a1 = a1 < b1; - var r1a2 = a2 < b2; - ~~~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r1a3 = a3 < b3; - var r1a4 = a4 < b4; - var r1a5 = a5 < b5; - var r1a6 = a6 < b6; - //var r1a7 = a7 < b7; - - var r1b1 = b1 < a1; - var r1b2 = b2 < a2; - ~~~~~~~ -!!! error TS2365: Operator '<' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r1b3 = b3 < a3; - var r1b4 = b4 < a4; - var r1b5 = b5 < a5; - var r1b6 = b6 < a6; - //var r1b7 = b7 < a7; - - // operator > - var r2a1 = a1 > b1; - var r2a2 = a2 > b2; - ~~~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r2a3 = a3 > b3; - var r2a4 = a4 > b4; - var r2a5 = a5 > b5; - var r2a6 = a6 > b6; - //var r2a7 = a7 > b7; - - var r2b1 = b1 > a1; - var r2b2 = b2 > a2; - ~~~~~~~ -!!! error TS2365: Operator '>' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r2b3 = b3 > a3; - var r2b4 = b4 > a4; - var r2b5 = b5 > a5; - var r2b6 = b6 > a6; - //var r2b7 = b7 > a7; - - // operator <= - var r3a1 = a1 <= b1; - var r3a2 = a2 <= b2; - ~~~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r3a3 = a3 <= b3; - var r3a4 = a4 <= b4; - var r3a5 = a5 <= b5; - var r3a6 = a6 <= b6; - //var r3a7 = a7 <= b7; - - var r3b1 = b1 <= a1; - var r3b2 = b2 <= a2; - ~~~~~~~~ -!!! error TS2365: Operator '<=' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r3b3 = b3 <= a3; - var r3b4 = b4 <= a4; - var r3b5 = b5 <= a5; - var r3b6 = b6 <= a6; - //var r3b7 = b7 <= a7; - - // operator >= - var r4a1 = a1 >= b1; - var r4a2 = a2 >= b2; - ~~~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r4a3 = a3 >= b3; - var r4a4 = a4 >= b4; - var r4a5 = a5 >= b5; - var r4a6 = a6 >= b6; - //var r4a7 = a7 >= b7; - - var r4b1 = b1 >= a1; - var r4b2 = b2 >= a2; - ~~~~~~~~ -!!! error TS2365: Operator '>=' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r4b3 = b3 >= a3; - var r4b4 = b4 >= a4; - var r4b5 = b5 >= a5; - var r4b6 = b6 >= a6; - //var r4b7 = b7 >= a7; - - // operator == - var r5a1 = a1 == b1; - var r5a2 = a2 == b2; - ~~~~~~~~ -!!! error TS2365: Operator '==' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r5a3 = a3 == b3; - var r5a4 = a4 == b4; - var r5a5 = a5 == b5; - var r5a6 = a6 == b6; - //var r5a7 = a7 == b7; - - var r5b1 = b1 == a1; - var r5b2 = b2 == a2; - ~~~~~~~~ -!!! error TS2365: Operator '==' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r5b3 = b3 == a3; - var r5b4 = b4 == a4; - var r5b5 = b5 == a5; - var r5b6 = b6 == a6; - //var r5b7 = b7 == a7; - - // operator != - var r6a1 = a1 != b1; - var r6a2 = a2 != b2; - ~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r6a3 = a3 != b3; - var r6a4 = a4 != b4; - var r6a5 = a5 != b5; - var r6a6 = a6 != b6; - //var r6a7 = a7 != b7; - - var r6b1 = b1 != a1; - var r6b2 = b2 != a2; - ~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r6b3 = b3 != a3; - var r6b4 = b4 != a4; - var r6b5 = b5 != a5; - var r6b6 = b6 != a6; - //var r6b7 = b7 != a7; - - // operator === - var r7a1 = a1 === b1; - var r7a2 = a2 === b2; - ~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r7a3 = a3 === b3; - var r7a4 = a4 === b4; - var r7a5 = a5 === b5; - var r7a6 = a6 === b6; - //var r7a7 = a7 === b7; - - var r7b1 = b1 === a1; - var r7b2 = b2 === a2; - ~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r7b3 = b3 === a3; - var r7b4 = b4 === a4; - var r7b5 = b5 === a5; - var r7b6 = b6 === a6; - //var r7b7 = b7 === a7; - - // operator !== - var r8a1 = a1 !== b1; - var r8a2 = a2 !== b2; - ~~~~~~~~~ -!!! error TS2365: Operator '!==' cannot be applied to types 'new (x: T) => T' and 'new (x: string, y: number) => string'. - var r8a3 = a3 !== b3; - var r8a4 = a4 !== b4; - var r8a5 = a5 !== b5; - var r8a6 = a6 !== b6; - //var r8a7 = a7 !== b7; - - var r8b1 = b1 !== a1; - var r8b2 = b2 !== a2; - ~~~~~~~~~ -!!! error TS2365: Operator '!==' cannot be applied to types 'new (x: string, y: number) => string' and 'new (x: T) => T'. - var r8b3 = b3 !== a3; - var r8b4 = b4 !== a4; - var r8b5 = b5 !== a5; - var r8b6 = b6 !== a6; - //var r8b7 = b7 !== a7; \ No newline at end of file diff --git a/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.types b/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.types new file mode 100644 index 00000000000..29d92c25726 --- /dev/null +++ b/tests/baselines/reference/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.types @@ -0,0 +1,714 @@ +=== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithSubtypeObjectOnInstantiatedConstructorSignature.ts === +class Base { +>Base : Base + + public a: string; +>a : string +} + +class Derived extends Base { +>Derived : Derived +>Base : Base + + public b: string; +>b : string +} + +var a1: { new (x: T): T }; +>a1 : new (x: T) => T +>T : T +>x : T +>T : T +>T : T + +var b1: { new (x: string): string }; +>b1 : new (x: string) => string +>x : string + +var a2: { new (x: T): T }; +>a2 : new (x: T) => T +>T : T +>x : T +>T : T +>T : T + +var b2: { new (x: string, y: number): string }; +>b2 : new (x: string, y: number) => string +>x : string +>y : number + +var a3: { new (x: T, y: U): T }; +>a3 : new (x: T, y: U) => T +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U +>T : T + +var b3: { new (x: string, y: number): string }; +>b3 : new (x: string, y: number) => string +>x : string +>y : number + +var a4: { new (x?: T): T }; +>a4 : new (x?: T) => T +>T : T +>x : T +>T : T +>T : T + +var b4: { new (x?: string): string }; +>b4 : new (x?: string) => string +>x : string + +var a5: { new (...x: T[]): T }; +>a5 : new (...x: T[]) => T +>T : T +>x : T[] +>T : T +>T : T + +var b5: { new (...x: string[]): string }; +>b5 : new (...x: string[]) => string +>x : string[] + +var a6: { new (x: T, y: T): T }; +>a6 : new (x: T, y: T) => T +>T : T +>x : T +>T : T +>y : T +>T : T +>T : T + +var b6: { new (x: string, y: number): {} }; +>b6 : new (x: string, y: number) => {} +>x : string +>y : number + +//var a7: { new (x: T, y: U): T }; +var b7: { new (x: Base, y: Derived): Base }; +>b7 : new (x: Base, y: Derived) => Base +>x : Base +>Base : Base +>y : Derived +>Derived : Derived +>Base : Base + +// operator < +var r1a1 = a1 < b1; +>r1a1 : boolean +>a1 < b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r1a2 = a2 < b2; +>r1a2 : boolean +>a2 < b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r1a3 = a3 < b3; +>r1a3 : boolean +>a3 < b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r1a4 = a4 < b4; +>r1a4 : boolean +>a4 < b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r1a5 = a5 < b5; +>r1a5 : boolean +>a5 < b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r1a6 = a6 < b6; +>r1a6 : boolean +>a6 < b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r1a7 = a7 < b7; + +var r1b1 = b1 < a1; +>r1b1 : boolean +>b1 < a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r1b2 = b2 < a2; +>r1b2 : boolean +>b2 < a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r1b3 = b3 < a3; +>r1b3 : boolean +>b3 < a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r1b4 = b4 < a4; +>r1b4 : boolean +>b4 < a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r1b5 = b5 < a5; +>r1b5 : boolean +>b5 < a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r1b6 = b6 < a6; +>r1b6 : boolean +>b6 < a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r1b7 = b7 < a7; + +// operator > +var r2a1 = a1 > b1; +>r2a1 : boolean +>a1 > b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r2a2 = a2 > b2; +>r2a2 : boolean +>a2 > b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r2a3 = a3 > b3; +>r2a3 : boolean +>a3 > b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r2a4 = a4 > b4; +>r2a4 : boolean +>a4 > b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r2a5 = a5 > b5; +>r2a5 : boolean +>a5 > b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r2a6 = a6 > b6; +>r2a6 : boolean +>a6 > b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r2a7 = a7 > b7; + +var r2b1 = b1 > a1; +>r2b1 : boolean +>b1 > a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r2b2 = b2 > a2; +>r2b2 : boolean +>b2 > a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r2b3 = b3 > a3; +>r2b3 : boolean +>b3 > a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r2b4 = b4 > a4; +>r2b4 : boolean +>b4 > a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r2b5 = b5 > a5; +>r2b5 : boolean +>b5 > a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r2b6 = b6 > a6; +>r2b6 : boolean +>b6 > a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r2b7 = b7 > a7; + +// operator <= +var r3a1 = a1 <= b1; +>r3a1 : boolean +>a1 <= b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r3a2 = a2 <= b2; +>r3a2 : boolean +>a2 <= b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r3a3 = a3 <= b3; +>r3a3 : boolean +>a3 <= b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r3a4 = a4 <= b4; +>r3a4 : boolean +>a4 <= b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r3a5 = a5 <= b5; +>r3a5 : boolean +>a5 <= b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r3a6 = a6 <= b6; +>r3a6 : boolean +>a6 <= b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r3a7 = a7 <= b7; + +var r3b1 = b1 <= a1; +>r3b1 : boolean +>b1 <= a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r3b2 = b2 <= a2; +>r3b2 : boolean +>b2 <= a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r3b3 = b3 <= a3; +>r3b3 : boolean +>b3 <= a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r3b4 = b4 <= a4; +>r3b4 : boolean +>b4 <= a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r3b5 = b5 <= a5; +>r3b5 : boolean +>b5 <= a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r3b6 = b6 <= a6; +>r3b6 : boolean +>b6 <= a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r3b7 = b7 <= a7; + +// operator >= +var r4a1 = a1 >= b1; +>r4a1 : boolean +>a1 >= b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r4a2 = a2 >= b2; +>r4a2 : boolean +>a2 >= b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r4a3 = a3 >= b3; +>r4a3 : boolean +>a3 >= b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r4a4 = a4 >= b4; +>r4a4 : boolean +>a4 >= b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r4a5 = a5 >= b5; +>r4a5 : boolean +>a5 >= b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r4a6 = a6 >= b6; +>r4a6 : boolean +>a6 >= b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r4a7 = a7 >= b7; + +var r4b1 = b1 >= a1; +>r4b1 : boolean +>b1 >= a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r4b2 = b2 >= a2; +>r4b2 : boolean +>b2 >= a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r4b3 = b3 >= a3; +>r4b3 : boolean +>b3 >= a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r4b4 = b4 >= a4; +>r4b4 : boolean +>b4 >= a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r4b5 = b5 >= a5; +>r4b5 : boolean +>b5 >= a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r4b6 = b6 >= a6; +>r4b6 : boolean +>b6 >= a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r4b7 = b7 >= a7; + +// operator == +var r5a1 = a1 == b1; +>r5a1 : boolean +>a1 == b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r5a2 = a2 == b2; +>r5a2 : boolean +>a2 == b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r5a3 = a3 == b3; +>r5a3 : boolean +>a3 == b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r5a4 = a4 == b4; +>r5a4 : boolean +>a4 == b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r5a5 = a5 == b5; +>r5a5 : boolean +>a5 == b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r5a6 = a6 == b6; +>r5a6 : boolean +>a6 == b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r5a7 = a7 == b7; + +var r5b1 = b1 == a1; +>r5b1 : boolean +>b1 == a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r5b2 = b2 == a2; +>r5b2 : boolean +>b2 == a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r5b3 = b3 == a3; +>r5b3 : boolean +>b3 == a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r5b4 = b4 == a4; +>r5b4 : boolean +>b4 == a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r5b5 = b5 == a5; +>r5b5 : boolean +>b5 == a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r5b6 = b6 == a6; +>r5b6 : boolean +>b6 == a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r5b7 = b7 == a7; + +// operator != +var r6a1 = a1 != b1; +>r6a1 : boolean +>a1 != b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r6a2 = a2 != b2; +>r6a2 : boolean +>a2 != b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r6a3 = a3 != b3; +>r6a3 : boolean +>a3 != b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r6a4 = a4 != b4; +>r6a4 : boolean +>a4 != b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r6a5 = a5 != b5; +>r6a5 : boolean +>a5 != b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r6a6 = a6 != b6; +>r6a6 : boolean +>a6 != b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r6a7 = a7 != b7; + +var r6b1 = b1 != a1; +>r6b1 : boolean +>b1 != a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r6b2 = b2 != a2; +>r6b2 : boolean +>b2 != a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r6b3 = b3 != a3; +>r6b3 : boolean +>b3 != a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r6b4 = b4 != a4; +>r6b4 : boolean +>b4 != a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r6b5 = b5 != a5; +>r6b5 : boolean +>b5 != a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r6b6 = b6 != a6; +>r6b6 : boolean +>b6 != a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r6b7 = b7 != a7; + +// operator === +var r7a1 = a1 === b1; +>r7a1 : boolean +>a1 === b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r7a2 = a2 === b2; +>r7a2 : boolean +>a2 === b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r7a3 = a3 === b3; +>r7a3 : boolean +>a3 === b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r7a4 = a4 === b4; +>r7a4 : boolean +>a4 === b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r7a5 = a5 === b5; +>r7a5 : boolean +>a5 === b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r7a6 = a6 === b6; +>r7a6 : boolean +>a6 === b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r7a7 = a7 === b7; + +var r7b1 = b1 === a1; +>r7b1 : boolean +>b1 === a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r7b2 = b2 === a2; +>r7b2 : boolean +>b2 === a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r7b3 = b3 === a3; +>r7b3 : boolean +>b3 === a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r7b4 = b4 === a4; +>r7b4 : boolean +>b4 === a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r7b5 = b5 === a5; +>r7b5 : boolean +>b5 === a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r7b6 = b6 === a6; +>r7b6 : boolean +>b6 === a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r7b7 = b7 === a7; + +// operator !== +var r8a1 = a1 !== b1; +>r8a1 : boolean +>a1 !== b1 : boolean +>a1 : new (x: T) => T +>b1 : new (x: string) => string + +var r8a2 = a2 !== b2; +>r8a2 : boolean +>a2 !== b2 : boolean +>a2 : new (x: T) => T +>b2 : new (x: string, y: number) => string + +var r8a3 = a3 !== b3; +>r8a3 : boolean +>a3 !== b3 : boolean +>a3 : new (x: T, y: U) => T +>b3 : new (x: string, y: number) => string + +var r8a4 = a4 !== b4; +>r8a4 : boolean +>a4 !== b4 : boolean +>a4 : new (x?: T) => T +>b4 : new (x?: string) => string + +var r8a5 = a5 !== b5; +>r8a5 : boolean +>a5 !== b5 : boolean +>a5 : new (...x: T[]) => T +>b5 : new (...x: string[]) => string + +var r8a6 = a6 !== b6; +>r8a6 : boolean +>a6 !== b6 : boolean +>a6 : new (x: T, y: T) => T +>b6 : new (x: string, y: number) => {} + +//var r8a7 = a7 !== b7; + +var r8b1 = b1 !== a1; +>r8b1 : boolean +>b1 !== a1 : boolean +>b1 : new (x: string) => string +>a1 : new (x: T) => T + +var r8b2 = b2 !== a2; +>r8b2 : boolean +>b2 !== a2 : boolean +>b2 : new (x: string, y: number) => string +>a2 : new (x: T) => T + +var r8b3 = b3 !== a3; +>r8b3 : boolean +>b3 !== a3 : boolean +>b3 : new (x: string, y: number) => string +>a3 : new (x: T, y: U) => T + +var r8b4 = b4 !== a4; +>r8b4 : boolean +>b4 !== a4 : boolean +>b4 : new (x?: string) => string +>a4 : new (x?: T) => T + +var r8b5 = b5 !== a5; +>r8b5 : boolean +>b5 !== a5 : boolean +>b5 : new (...x: string[]) => string +>a5 : new (...x: T[]) => T + +var r8b6 = b6 !== a6; +>r8b6 : boolean +>b6 !== a6 : boolean +>b6 : new (x: string, y: number) => {} +>a6 : new (x: T, y: T) => T + +//var r8b7 = b7 !== a7; diff --git a/tests/baselines/reference/conditionalExpression1.errors.txt b/tests/baselines/reference/conditionalExpression1.errors.txt index 542b660ba42..30703c7169e 100644 --- a/tests/baselines/reference/conditionalExpression1.errors.txt +++ b/tests/baselines/reference/conditionalExpression1.errors.txt @@ -1,10 +1,9 @@ -tests/cases/compiler/conditionalExpression1.ts(1,5): error TS2323: Type '{}' is not assignable to type 'boolean'. -tests/cases/compiler/conditionalExpression1.ts(1,19): error TS2367: No best common type exists between 'number' and 'string'. +tests/cases/compiler/conditionalExpression1.ts(1,5): error TS2322: Type 'string | number' is not assignable to type 'boolean': + Type 'string' is not assignable to type 'boolean'. -==== tests/cases/compiler/conditionalExpression1.ts (2 errors) ==== +==== tests/cases/compiler/conditionalExpression1.ts (1 errors) ==== var x: boolean = (true ? 1 : ""); // should be an error ~ -!!! error TS2323: Type '{}' is not assignable to type 'boolean'. - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'number' and 'string'. \ No newline at end of file +!!! error TS2322: Type 'string | number' is not assignable to type 'boolean': +!!! error TS2322: Type 'string' is not assignable to type 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types b/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types index 8ad918936d2..f925f7f1db6 100644 --- a/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types +++ b/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types @@ -80,7 +80,7 @@ var result4: (t: A) => any = true ? (m) => m.propertyX : (n) => n.propertyA; >result4 : (t: A) => any >t : A >A : A ->true ? (m) => m.propertyX : (n) => n.propertyA : (t: A) => any +>true ? (m) => m.propertyX : (n) => n.propertyA : (m: A) => any >(m) => m.propertyX : (m: A) => any >m : A >m.propertyX : any @@ -144,7 +144,7 @@ var result8: (t: A) => any = true ? (m) => m.propertyA : (n) => n.propertyX; >result8 : (t: A) => any >t : A >A : A ->true ? (m) => m.propertyA : (n) => n.propertyX : (t: A) => any +>true ? (m) => m.propertyA : (n) => n.propertyX : (n: A) => any >(m) => m.propertyA : (m: A) => number >m : A >m.propertyA : number @@ -161,7 +161,7 @@ var result8: (t: A) => any = true ? (m) => m.propertyA : (n) => n.propertyX; var resultIsX3: X = true ? a : b; >resultIsX3 : X >X : X ->true ? a : b : X +>true ? a : b : A | B >a : A >b : B @@ -169,7 +169,7 @@ var result10: (t: X) => any = true ? (m) => m.propertyX1 : (n) => n.propertyX2; >result10 : (t: X) => any >t : X >X : X ->true ? (m) => m.propertyX1 : (n) => n.propertyX2 : (t: X) => any +>true ? (m) => m.propertyX1 : (n) => n.propertyX2 : ((m: X) => number) | ((n: X) => string) >(m) => m.propertyX1 : (m: X) => number >m : X >m.propertyX1 : number @@ -184,5 +184,5 @@ var result10: (t: X) => any = true ? (m) => m.propertyX1 : (n) => n.propertyX2; //Expr1 and Expr2 are literals var result11: any = true ? 1 : 'string'; >result11 : any ->true ? 1 : 'string' : any +>true ? 1 : 'string' : string | number diff --git a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt index 7db921cbe1a..b1dd23fc3e3 100644 --- a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt +++ b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt @@ -1,20 +1,21 @@ -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(12,1): error TS2367: No best common type exists between 'A' and 'B'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(13,15): error TS2367: No best common type exists between 'A' and 'B'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,5): error TS2322: Type '{}' is not assignable to type 'A': - Property 'propertyA' is missing in type '{}'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,18): error TS2366: No best common type exists between 'A', 'A', and 'B'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(17,5): error TS2322: Type '{}' is not assignable to type 'B': - Property 'propertyB' is missing in type '{}'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(17,18): error TS2366: No best common type exists between 'B', 'A', and 'B'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,5): error TS2323: Type '{}' is not assignable to type '(t: X) => number'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,33): error TS2366: No best common type exists between '(t: X) => number', '(m: X) => number', and '(n: X) => string'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,5): error TS2323: Type '{}' is not assignable to type '(t: X) => string'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,33): error TS2366: No best common type exists between '(t: X) => string', '(m: X) => number', and '(n: X) => string'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(21,5): error TS2323: Type '{}' is not assignable to type '(t: X) => boolean'. -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(21,34): error TS2366: No best common type exists between '(t: X) => boolean', '(m: X) => number', and '(n: X) => string'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(15,5): error TS2322: Type 'A | B' is not assignable to type 'A': + Type 'B' is not assignable to type 'A': + Property 'propertyA' is missing in type 'B'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,5): error TS2322: Type 'A | B' is not assignable to type 'B': + Type 'A' is not assignable to type 'B': + Property 'propertyB' is missing in type 'A'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(18,5): error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => number': + Type '(n: X) => string' is not assignable to type '(t: X) => number': + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,5): error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => string': + Type '(m: X) => number' is not assignable to type '(t: X) => string': + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,5): error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => boolean': + Type '(m: X) => number' is not assignable to type '(t: X) => boolean': + Type 'number' is not assignable to type 'boolean'. -==== tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts (12 errors) ==== +==== tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts (5 errors) ==== //Cond ? Expr1 : Expr2, Expr1 and Expr2 have no identical best common type class X { propertyX: any; propertyX1: number; propertyX2: string }; class A extends X { propertyA: number }; @@ -24,41 +25,34 @@ tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithou var a: A; var b: B; - //Expect to have compiler errors - //Be not contextually typed + // No errors anymore, uses union types true ? a : b; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'A' and 'B'. var result1 = true ? a : b; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'A' and 'B'. - //Be contextually typed and and bct is not identical + //Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target var result2: A = true ? a : b; ~~~~~~~ -!!! error TS2322: Type '{}' is not assignable to type 'A': -!!! error TS2322: Property 'propertyA' is missing in type '{}'. - ~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between 'A', 'A', and 'B'. +!!! error TS2322: Type 'A | B' is not assignable to type 'A': +!!! error TS2322: Type 'B' is not assignable to type 'A': +!!! error TS2322: Property 'propertyA' is missing in type 'B'. var result3: B = true ? a : b; ~~~~~~~ -!!! error TS2322: Type '{}' is not assignable to type 'B': -!!! error TS2322: Property 'propertyB' is missing in type '{}'. - ~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between 'B', 'A', and 'B'. +!!! error TS2322: Type 'A | B' is not assignable to type 'B': +!!! error TS2322: Type 'A' is not assignable to type 'B': +!!! error TS2322: Property 'propertyB' is missing in type 'A'. var result4: (t: X) => number = true ? (m) => m.propertyX1 : (n) => n.propertyX2; ~~~~~~~ -!!! error TS2323: Type '{}' is not assignable to type '(t: X) => number'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between '(t: X) => number', '(m: X) => number', and '(n: X) => string'. +!!! error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => number': +!!! error TS2322: Type '(n: X) => string' is not assignable to type '(t: X) => number': +!!! error TS2322: Type 'string' is not assignable to type 'number'. var result5: (t: X) => string = true ? (m) => m.propertyX1 : (n) => n.propertyX2; ~~~~~~~ -!!! error TS2323: Type '{}' is not assignable to type '(t: X) => string'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between '(t: X) => string', '(m: X) => number', and '(n: X) => string'. +!!! error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => string': +!!! error TS2322: Type '(m: X) => number' is not assignable to type '(t: X) => string': +!!! error TS2322: Type 'number' is not assignable to type 'string'. var result6: (t: X) => boolean = true ? (m) => m.propertyX1 : (n) => n.propertyX2; ~~~~~~~ -!!! error TS2323: Type '{}' is not assignable to type '(t: X) => boolean'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between '(t: X) => boolean', '(m: X) => number', and '(n: X) => string'. \ No newline at end of file +!!! error TS2322: Type '((m: X) => number) | ((n: X) => string)' is not assignable to type '(t: X) => boolean': +!!! error TS2322: Type '(m: X) => number' is not assignable to type '(t: X) => boolean': +!!! error TS2322: Type 'number' is not assignable to type 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.js b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.js index 90125d4ebf6..b6376dd781f 100644 --- a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.js +++ b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.js @@ -8,12 +8,11 @@ var x: X; var a: A; var b: B; -//Expect to have compiler errors -//Be not contextually typed +// No errors anymore, uses union types true ? a : b; var result1 = true ? a : b; -//Be contextually typed and and bct is not identical +//Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target var result2: A = true ? a : b; var result3: B = true ? a : b; @@ -54,11 +53,10 @@ var B = (function (_super) { var x; var a; var b; -//Expect to have compiler errors -//Be not contextually typed +// No errors anymore, uses union types true ? a : b; var result1 = true ? a : b; -//Be contextually typed and and bct is not identical +//Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target var result2 = true ? a : b; var result3 = true ? a : b; var result4 = true ? function (m) { return m.propertyX1; } : function (n) { return n.propertyX2; }; diff --git a/tests/baselines/reference/contextualSignatureInstantiation.js b/tests/baselines/reference/contextualSignatureInstantiation.js new file mode 100644 index 00000000000..11e19b3262e --- /dev/null +++ b/tests/baselines/reference/contextualSignatureInstantiation.js @@ -0,0 +1,50 @@ +//// [contextualSignatureInstantiation.ts] +// TypeScript Spec, section 4.12.2: +// If e is an expression of a function type that contains exactly one generic call signature and no other members, +// and T is a function type with exactly one non - generic call signature and no other members, then any inferences +// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed +// to a function type with e's call signature instantiated in the context of T's call signature (section 3.8.5). + +declare function foo(cb: (x: number, y: string) => T): T; +declare function bar(x: T, y: U, cb: (x: T, y: U) => V): V; +declare function baz(x: T, y: T, cb: (x: T, y: T) => U): U; + +declare function g(x: T, y: T): T; +declare function h(x: T, y: U): T[] | U[]; + +var a: number; +var a = bar(1, 1, g); // Should be number +var a = baz(1, 1, g); // Should be number + +var b: number | string; +var b = foo(g); // Should be number | string +var b = bar(1, "one", g); // Should be number | string +var b = bar("one", 1, g); // Should be number | string +var b = baz(b, b, g); // Should be number | string + +var d: number[] | string[]; +var d = foo(h); // Should be number[] | string[] +var d = bar(1, "one", h); // Should be number[] | string[] +var d = bar("one", 1, h); // Should be number[] | string[] +var d = baz(d, d, g); // Should be number[] | string[] + + +//// [contextualSignatureInstantiation.js] +// TypeScript Spec, section 4.12.2: +// If e is an expression of a function type that contains exactly one generic call signature and no other members, +// and T is a function type with exactly one non - generic call signature and no other members, then any inferences +// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed +// to a function type with e's call signature instantiated in the context of T's call signature (section 3.8.5). +var a; +var a = bar(1, 1, g); // Should be number +var a = baz(1, 1, g); // Should be number +var b; +var b = foo(g); // Should be number | string +var b = bar(1, "one", g); // Should be number | string +var b = bar("one", 1, g); // Should be number | string +var b = baz(b, b, g); // Should be number | string +var d; +var d = foo(h); // Should be number[] | string[] +var d = bar(1, "one", h); // Should be number[] | string[] +var d = bar("one", 1, h); // Should be number[] | string[] +var d = baz(d, d, g); // Should be number[] | string[] diff --git a/tests/baselines/reference/contextualSignatureInstantiation.types b/tests/baselines/reference/contextualSignatureInstantiation.types new file mode 100644 index 00000000000..4363272622a --- /dev/null +++ b/tests/baselines/reference/contextualSignatureInstantiation.types @@ -0,0 +1,142 @@ +=== tests/cases/conformance/types/typeRelationships/typeInference/contextualSignatureInstantiation.ts === +// TypeScript Spec, section 4.12.2: +// If e is an expression of a function type that contains exactly one generic call signature and no other members, +// and T is a function type with exactly one non - generic call signature and no other members, then any inferences +// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed +// to a function type with e's call signature instantiated in the context of T's call signature (section 3.8.5). + +declare function foo(cb: (x: number, y: string) => T): T; +>foo : (cb: (x: number, y: string) => T) => T +>T : T +>cb : (x: number, y: string) => T +>x : number +>y : string +>T : T +>T : T + +declare function bar(x: T, y: U, cb: (x: T, y: U) => V): V; +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>T : T +>U : U +>V : V +>x : T +>T : T +>y : U +>U : U +>cb : (x: T, y: U) => V +>x : T +>T : T +>y : U +>U : U +>V : V +>V : V + +declare function baz(x: T, y: T, cb: (x: T, y: T) => U): U; +>baz : (x: T, y: T, cb: (x: T, y: T) => U) => U +>T : T +>U : U +>x : T +>T : T +>y : T +>T : T +>cb : (x: T, y: T) => U +>x : T +>T : T +>y : T +>T : T +>U : U +>U : U + +declare function g(x: T, y: T): T; +>g : (x: T, y: T) => T +>T : T +>x : T +>T : T +>y : T +>T : T +>T : T + +declare function h(x: T, y: U): T[] | U[]; +>h : (x: T, y: U) => T[] | U[] +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U +>T : T +>U : U + +var a: number; +>a : number + +var a = bar(1, 1, g); // Should be number +>a : number +>bar(1, 1, g) : number +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>g : (x: T, y: T) => T + +var a = baz(1, 1, g); // Should be number +>a : number +>baz(1, 1, g) : number +>baz : (x: T, y: T, cb: (x: T, y: T) => U) => U +>g : (x: T, y: T) => T + +var b: number | string; +>b : string | number + +var b = foo(g); // Should be number | string +>b : string | number +>foo(g) : string | number +>foo : (cb: (x: number, y: string) => T) => T +>g : (x: T, y: T) => T + +var b = bar(1, "one", g); // Should be number | string +>b : string | number +>bar(1, "one", g) : string | number +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>g : (x: T, y: T) => T + +var b = bar("one", 1, g); // Should be number | string +>b : string | number +>bar("one", 1, g) : string | number +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>g : (x: T, y: T) => T + +var b = baz(b, b, g); // Should be number | string +>b : string | number +>baz(b, b, g) : string | number +>baz : (x: T, y: T, cb: (x: T, y: T) => U) => U +>b : string | number +>b : string | number +>g : (x: T, y: T) => T + +var d: number[] | string[]; +>d : string[] | number[] + +var d = foo(h); // Should be number[] | string[] +>d : string[] | number[] +>foo(h) : string[] | number[] +>foo : (cb: (x: number, y: string) => T) => T +>h : (x: T, y: U) => T[] | U[] + +var d = bar(1, "one", h); // Should be number[] | string[] +>d : string[] | number[] +>bar(1, "one", h) : string[] | number[] +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>h : (x: T, y: U) => T[] | U[] + +var d = bar("one", 1, h); // Should be number[] | string[] +>d : string[] | number[] +>bar("one", 1, h) : string[] | number[] +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>h : (x: T, y: U) => T[] | U[] + +var d = baz(d, d, g); // Should be number[] | string[] +>d : string[] | number[] +>baz(d, d, g) : string[] | number[] +>baz : (x: T, y: T, cb: (x: T, y: T) => U) => U +>d : string[] | number[] +>d : string[] | number[] +>g : (x: T, y: T) => T + diff --git a/tests/baselines/reference/contextualTypeArrayReturnType.types b/tests/baselines/reference/contextualTypeArrayReturnType.types index b0cd03f8510..ceb7aa53f67 100644 --- a/tests/baselines/reference/contextualTypeArrayReturnType.types +++ b/tests/baselines/reference/contextualTypeArrayReturnType.types @@ -26,18 +26,18 @@ interface Transform3D { var style: IBookStyle = { >style : IBookStyle >IBookStyle : IBookStyle ->{ initialLeftPageTransforms: (width: number) => { return [ {'ry': null } ]; }} : { initialLeftPageTransforms: (width: number) => NamedTransform[]; } +>{ initialLeftPageTransforms: (width: number) => { return [ {'ry': null } ]; }} : { initialLeftPageTransforms: (width: number) => { [x: string]: any; 'ry': any; }[]; } initialLeftPageTransforms: (width: number) => { ->initialLeftPageTransforms : (width: number) => NamedTransform[] ->(width: number) => { return [ {'ry': null } ]; } : (width: number) => NamedTransform[] +>initialLeftPageTransforms : (width: number) => { [x: string]: any; 'ry': any; }[] +>(width: number) => { return [ {'ry': null } ]; } : (width: number) => { [x: string]: any; 'ry': any; }[] >width : number return [ ->[ {'ry': null } ] : NamedTransform[] +>[ {'ry': null } ] : { [x: string]: null; 'ry': null; }[] {'ry': null } ->{'ry': null } : { [x: string]: Transform3D; 'ry': null; } +>{'ry': null } : { [x: string]: null; 'ry': null; } ]; } diff --git a/tests/baselines/reference/contextualTypeWithTuple.errors.txt b/tests/baselines/reference/contextualTypeWithTuple.errors.txt index e739c916c8a..bd1aa155661 100644 --- a/tests/baselines/reference/contextualTypeWithTuple.errors.txt +++ b/tests/baselines/reference/contextualTypeWithTuple.errors.txt @@ -1,40 +1,58 @@ -tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(11,1): error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]': - Types of property '0' are incompatible: - Type '{}' is not assignable to type '{ a: string; }': - Property 'a' is missing in type '{}'. -tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(12,1): error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]': - Property '2' is missing in type '[number, string]'. -tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(13,5): error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]': - Types of property 'pop' are incompatible: - Type '() => {}' is not assignable to type '() => string': - Type '{}' is not assignable to type 'string'. - - -==== tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts (3 errors) ==== - // no error - var numStrTuple: [number, string] = [5, "hello"]; - var numStrTuple2: [number, string] = [5, "foo", true]; - var numStrBoolTuple: [number, string, boolean] = [5, "foo", true]; - var objNumTuple: [{ a: string }, number] = [{ a: "world" }, 5]; - var strTupleTuple: [string, [number, {}]] = ["bar", [5, { x: 1, y: 1 }]]; - numStrTuple = numStrTuple2; - numStrTuple = numStrBoolTuple; - - // error - objNumTuple = [ {}, 5]; - ~~~~~~~~~~~ -!!! error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]': -!!! error TS2322: Types of property '0' are incompatible: -!!! error TS2322: Type '{}' is not assignable to type '{ a: string; }': -!!! error TS2322: Property 'a' is missing in type '{}'. - numStrBoolTuple = numStrTuple; - ~~~~~~~~~~~~~~~ -!!! error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]': -!!! error TS2322: Property '2' is missing in type '[number, string]'. - var strStrTuple: [string, string] = ["foo", "bar", 5]; - ~~~~~~~~~~~ -!!! error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]': -!!! error TS2322: Types of property 'pop' are incompatible: -!!! error TS2322: Type '() => {}' is not assignable to type '() => string': -!!! error TS2322: Type '{}' is not assignable to type 'string'. +tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(3,5): error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]': + Types of property 'pop' are incompatible: + Type '() => string | number | boolean' is not assignable to type '() => string | number': + Type 'string | number | boolean' is not assignable to type 'string | number': + Type 'boolean' is not assignable to type 'string | number': + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(8,1): error TS2323: Type '[number, string, boolean]' is not assignable to type '[number, string]'. +tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(11,1): error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]': + Types of property '0' are incompatible: + Type '{}' is not assignable to type '{ a: string; }': + Property 'a' is missing in type '{}'. +tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(12,1): error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]': + Property '2' is missing in type '[number, string]'. +tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(13,5): error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]': + Types of property 'pop' are incompatible: + Type '() => string | number' is not assignable to type '() => string': + Type 'string | number' is not assignable to type 'string': + Type 'number' is not assignable to type 'string'. + + +==== tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts (5 errors) ==== + // no error + var numStrTuple: [number, string] = [5, "hello"]; + var numStrTuple2: [number, string] = [5, "foo", true]; + ~~~~~~~~~~~~ +!!! error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]': +!!! error TS2322: Types of property 'pop' are incompatible: +!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => string | number': +!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'string | number': +!!! error TS2322: Type 'boolean' is not assignable to type 'string | number': +!!! error TS2322: Type 'boolean' is not assignable to type 'number'. + var numStrBoolTuple: [number, string, boolean] = [5, "foo", true]; + var objNumTuple: [{ a: string }, number] = [{ a: "world" }, 5]; + var strTupleTuple: [string, [number, {}]] = ["bar", [5, { x: 1, y: 1 }]]; + numStrTuple = numStrTuple2; + numStrTuple = numStrBoolTuple; + ~~~~~~~~~~~ +!!! error TS2323: Type '[number, string, boolean]' is not assignable to type '[number, string]'. + + // error + objNumTuple = [ {}, 5]; + ~~~~~~~~~~~ +!!! error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]': +!!! error TS2322: Types of property '0' are incompatible: +!!! error TS2322: Type '{}' is not assignable to type '{ a: string; }': +!!! error TS2322: Property 'a' is missing in type '{}'. + numStrBoolTuple = numStrTuple; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '[number, string]' is not assignable to type '[number, string, boolean]': +!!! error TS2322: Property '2' is missing in type '[number, string]'. + var strStrTuple: [string, string] = ["foo", "bar", 5]; + ~~~~~~~~~~~ +!!! error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]': +!!! error TS2322: Types of property 'pop' are incompatible: +!!! error TS2322: Type '() => string | number' is not assignable to type '() => string': +!!! error TS2322: Type 'string | number' is not assignable to type 'string': +!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypeWithTuple.js b/tests/baselines/reference/contextualTypeWithTuple.js index 0e53cea283b..61a2df5d8ce 100644 --- a/tests/baselines/reference/contextualTypeWithTuple.js +++ b/tests/baselines/reference/contextualTypeWithTuple.js @@ -1,4 +1,4 @@ -//// [contextualTypeWithTuple.ts] +//// [contextualTypeWithTuple.ts] // no error var numStrTuple: [number, string] = [5, "hello"]; var numStrTuple2: [number, string] = [5, "foo", true]; @@ -12,18 +12,18 @@ numStrTuple = numStrBoolTuple; objNumTuple = [ {}, 5]; numStrBoolTuple = numStrTuple; var strStrTuple: [string, string] = ["foo", "bar", 5]; - - -//// [contextualTypeWithTuple.js] -// no error -var numStrTuple = [5, "hello"]; -var numStrTuple2 = [5, "foo", true]; -var numStrBoolTuple = [5, "foo", true]; -var objNumTuple = [{ a: "world" }, 5]; -var strTupleTuple = ["bar", [5, { x: 1, y: 1 }]]; -numStrTuple = numStrTuple2; -numStrTuple = numStrBoolTuple; -// error -objNumTuple = [{}, 5]; -numStrBoolTuple = numStrTuple; -var strStrTuple = ["foo", "bar", 5]; + + +//// [contextualTypeWithTuple.js] +// no error +var numStrTuple = [5, "hello"]; +var numStrTuple2 = [5, "foo", true]; +var numStrBoolTuple = [5, "foo", true]; +var objNumTuple = [{ a: "world" }, 5]; +var strTupleTuple = ["bar", [5, { x: 1, y: 1 }]]; +numStrTuple = numStrTuple2; +numStrTuple = numStrBoolTuple; +// error +objNumTuple = [{}, 5]; +numStrBoolTuple = numStrTuple; +var strStrTuple = ["foo", "bar", 5]; diff --git a/tests/baselines/reference/contextualTyping21.errors.txt b/tests/baselines/reference/contextualTyping21.errors.txt index 999cfcbd769..c6ca82d87ac 100644 --- a/tests/baselines/reference/contextualTyping21.errors.txt +++ b/tests/baselines/reference/contextualTyping21.errors.txt @@ -1,11 +1,13 @@ -tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type '{}[]' is not assignable to type '{ id: number; }[]': - Type '{}' is not assignable to type '{ id: number; }': - Property 'id' is missing in type '{}'. +tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type '(number | { id: number; })[]' is not assignable to type '{ id: number; }[]': + Type 'number | { id: number; }' is not assignable to type '{ id: number; }': + Type 'number' is not assignable to type '{ id: number; }': + Property 'id' is missing in type 'Number'. ==== tests/cases/compiler/contextualTyping21.ts (1 errors) ==== var foo:{id:number;}[] = [{id:1}]; foo = [{id:1}, 1]; ~~~ -!!! error TS2322: Type '{}[]' is not assignable to type '{ id: number; }[]': -!!! error TS2322: Type '{}' is not assignable to type '{ id: number; }': -!!! error TS2322: Property 'id' is missing in type '{}'. \ No newline at end of file +!!! error TS2322: Type '(number | { id: number; })[]' is not assignable to type '{ id: number; }[]': +!!! error TS2322: Type 'number | { id: number; }' is not assignable to type '{ id: number; }': +!!! error TS2322: Type 'number' is not assignable to type '{ id: number; }': +!!! error TS2322: Property 'id' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping30.errors.txt b/tests/baselines/reference/contextualTyping30.errors.txt index 3b2fbc8aac6..f7a9eeead35 100644 --- a/tests/baselines/reference/contextualTyping30.errors.txt +++ b/tests/baselines/reference/contextualTyping30.errors.txt @@ -1,9 +1,11 @@ -tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. - Type '{}' is not assignable to type 'number'. +tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. ==== tests/cases/compiler/contextualTyping30.ts (1 errors) ==== function foo(param:number[]){}; foo([1, "a"]); ~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type '{}' is not assignable to type 'number'. \ No newline at end of file +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number': +!!! error TS2345: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping32.types b/tests/baselines/reference/contextualTyping32.types index a9d41405b93..c273be967e3 100644 --- a/tests/baselines/reference/contextualTyping32.types +++ b/tests/baselines/reference/contextualTyping32.types @@ -5,7 +5,7 @@ function foo(param: {():number; (i:number):number; }[]) { }; foo([function(){ret >i : number >foo([function(){return 1;}, function(){return 4}]) : void >foo : (param: { (): number; (i: number): number; }[]) => void ->[function(){return 1;}, function(){return 4}] : { (): number; (i: number): number; }[] +>[function(){return 1;}, function(){return 4}] : (() => number)[] >function(){return 1;} : () => number >function(){return 4} : () => number diff --git a/tests/baselines/reference/contextualTyping33.errors.txt b/tests/baselines/reference/contextualTyping33.errors.txt index 8f83fc37ab1..4aafb6d9645 100644 --- a/tests/baselines/reference/contextualTyping33.errors.txt +++ b/tests/baselines/reference/contextualTyping33.errors.txt @@ -1,9 +1,11 @@ -tests/cases/compiler/contextualTyping33.ts(1,66): error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. - Type '{}' is not assignable to type '{ (): number; (i: number): number; }'. +tests/cases/compiler/contextualTyping33.ts(1,66): error TS2345: Argument of type '((() => number) | (() => string))[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. + Type '(() => number) | (() => string)' is not assignable to type '{ (): number; (i: number): number; }': + Type '() => string' is not assignable to type '{ (): number; (i: number): number; }'. ==== tests/cases/compiler/contextualTyping33.ts (1 errors) ==== function foo(param: {():number; (i:number):number; }[]) { }; foo([function(){return 1;}, function(){return "foo"}]); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. -!!! error TS2345: Type '{}' is not assignable to type '{ (): number; (i: number): number; }'. \ No newline at end of file +!!! error TS2345: Argument of type '((() => number) | (() => string))[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'. +!!! error TS2345: Type '(() => number) | (() => string)' is not assignable to type '{ (): number; (i: number): number; }': +!!! error TS2345: Type '() => string' is not assignable to type '{ (): number; (i: number): number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingArrayOfLambdas.types b/tests/baselines/reference/contextualTypingArrayOfLambdas.types index f3bb8bab70f..d3e5b9942e3 100644 --- a/tests/baselines/reference/contextualTypingArrayOfLambdas.types +++ b/tests/baselines/reference/contextualTypingArrayOfLambdas.types @@ -23,8 +23,8 @@ class C extends A { } var xs = [(x: A) => { }, (x: B) => { }, (x: C) => { }]; ->xs : { (x: A): void; }[] ->[(x: A) => { }, (x: B) => { }, (x: C) => { }] : { (x: A): void; }[] +>xs : ((x: A) => void)[] +>[(x: A) => { }, (x: B) => { }, (x: C) => { }] : ((x: A) => void)[] >(x: A) => { } : (x: A) => void >x : A >A : A diff --git a/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt b/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt index 0f9fc64536b..92b74829e55 100644 --- a/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt +++ b/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt @@ -1,7 +1,8 @@ -tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type '{}[]' is not assignable to type 'I': +tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type '(number | Date)[]' is not assignable to type 'I': Index signatures are incompatible: - Type '{}' is not assignable to type 'Date': - Property 'toDateString' is missing in type '{}'. + Type 'number | Date' is not assignable to type 'Date': + Type 'number' is not assignable to type 'Date': + Property 'toDateString' is missing in type 'Number'. ==== tests/cases/compiler/contextualTypingOfArrayLiterals1.ts (1 errors) ==== @@ -11,10 +12,11 @@ tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Typ var x3: I = [new Date(), 1]; ~~ -!!! error TS2322: Type '{}[]' is not assignable to type 'I': +!!! error TS2322: Type '(number | Date)[]' is not assignable to type 'I': !!! error TS2322: Index signatures are incompatible: -!!! error TS2322: Type '{}' is not assignable to type 'Date': -!!! error TS2322: Property 'toDateString' is missing in type '{}'. +!!! error TS2322: Type 'number | Date' is not assignable to type 'Date': +!!! error TS2322: Type 'number' is not assignable to type 'Date': +!!! error TS2322: Property 'toDateString' is missing in type 'Number'. var r2 = x3[1]; r2.getDate(); \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingOfConditionalExpression.types b/tests/baselines/reference/contextualTypingOfConditionalExpression.types index 6c6f9b04457..2cd2b671b40 100644 --- a/tests/baselines/reference/contextualTypingOfConditionalExpression.types +++ b/tests/baselines/reference/contextualTypingOfConditionalExpression.types @@ -2,7 +2,7 @@ var x: (a: number) => void = true ? (a) => a.toExponential() : (b) => b.toFixed(); >x : (a: number) => void >a : number ->true ? (a) => a.toExponential() : (b) => b.toFixed() : (a: number) => void +>true ? (a) => a.toExponential() : (b) => b.toFixed() : (a: number) => string >(a) => a.toExponential() : (a: number) => string >a : number >a.toExponential() : string @@ -41,7 +41,7 @@ var x2: (a: A) => void = true ? (a) => a.foo : (b) => b.foo; >x2 : (a: A) => void >a : A >A : A ->true ? (a) => a.foo : (b) => b.foo : (a: A) => void +>true ? (a) => a.foo : (b) => b.foo : (a: A) => number >(a) => a.foo : (a: A) => number >a : A >a.foo : number diff --git a/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt b/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt index c433bd1d8ca..3bcfb557048 100644 --- a/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt +++ b/tests/baselines/reference/contextualTypingOfConditionalExpression2.errors.txt @@ -1,8 +1,11 @@ -tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,5): error TS2323: Type '{}' is not assignable to type '(a: A) => void'. -tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,26): error TS2366: No best common type exists between '(a: A) => void', '(a: C) => number', and '(b: number) => void'. +tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,5): error TS2322: Type '((a: C) => number) | ((b: number) => void)' is not assignable to type '(a: A) => void': + Type '(b: number) => void' is not assignable to type '(a: A) => void': + Types of parameters 'b' and 'a' are incompatible: + Type 'number' is not assignable to type 'A': + Property 'foo' is missing in type 'Number'. -==== tests/cases/compiler/contextualTypingOfConditionalExpression2.ts (2 errors) ==== +==== tests/cases/compiler/contextualTypingOfConditionalExpression2.ts (1 errors) ==== class A { foo: number; } @@ -15,7 +18,9 @@ tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,26): error T var x2: (a: A) => void = true ? (a: C) => a.foo : (b: number) => { }; ~~ -!!! error TS2323: Type '{}' is not assignable to type '(a: A) => void'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2366: No best common type exists between '(a: A) => void', '(a: C) => number', and '(b: number) => void'. +!!! error TS2322: Type '((a: C) => number) | ((b: number) => void)' is not assignable to type '(a: A) => void': +!!! error TS2322: Type '(b: number) => void' is not assignable to type '(a: A) => void': +!!! error TS2322: Types of parameters 'b' and 'a' are incompatible: +!!! error TS2322: Type 'number' is not assignable to type 'A': +!!! error TS2322: Property 'foo' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt index e4d8a82c47e..a524fd3be31 100644 --- a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt +++ b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt @@ -1,9 +1,12 @@ tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(2,22): error TS2339: Property 'foo' does not exist on type 'string'. +tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,10): error TS2346: Supplied parameters do not match any signature of call target. -==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (1 errors) ==== +==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (2 errors) ==== var f10: (x: T, b: () => (a: T) => void, y: T) => T; - f10('', () => a => a.foo, ''); // a is string, fixed by first parameter + f10('', () => a => a.foo, ''); // a is string ~~~ !!! error TS2339: Property 'foo' does not exist on type 'string'. - var r9 = f10('', () => (a => a.foo), 1); // now a should be any \ No newline at end of file + var r9 = f10('', () => (a => a.foo), 1); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.js b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.js index cf7274db8a0..55f7580b3f8 100644 --- a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.js +++ b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.js @@ -1,9 +1,9 @@ //// [contextualTypingWithFixedTypeParameters1.ts] var f10: (x: T, b: () => (a: T) => void, y: T) => T; -f10('', () => a => a.foo, ''); // a is string, fixed by first parameter -var r9 = f10('', () => (a => a.foo), 1); // now a should be any +f10('', () => a => a.foo, ''); // a is string +var r9 = f10('', () => (a => a.foo), 1); // error //// [contextualTypingWithFixedTypeParameters1.js] var f10; -f10('', function () { return function (a) { return a.foo; }; }, ''); // a is string, fixed by first parameter -var r9 = f10('', function () { return (function (a) { return a.foo; }); }, 1); // now a should be any +f10('', function () { return function (a) { return a.foo; }; }, ''); // a is string +var r9 = f10('', function () { return (function (a) { return a.foo; }); }, 1); // error diff --git a/tests/baselines/reference/contextuallyTypingOrOperator.types b/tests/baselines/reference/contextuallyTypingOrOperator.types index ee1ac4b0bba..47b78f5691d 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator.types +++ b/tests/baselines/reference/contextuallyTypingOrOperator.types @@ -3,7 +3,7 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; >v : { a: (_: string) => number; } >a : (_: string) => number >_ : string ->{ a: s => s.length } || { a: s => 1 } : { a: (_: string) => number; } +>{ a: s => s.length } || { a: s => 1 } : { a: (s: string) => number; } >{ a: s => s.length } : { a: (s: string) => number; } >a : (s: string) => number >s => s.length : (s: string) => number @@ -17,10 +17,10 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; >s : string var v2 = (s: string) => s.length || function (s) { s.length }; ->v2 : (s: string) => {} ->(s: string) => s.length || function (s) { s.length } : (s: string) => {} +>v2 : (s: string) => number | ((s: any) => void) +>(s: string) => s.length || function (s) { s.length } : (s: string) => number | ((s: any) => void) >s : string ->s.length || function (s) { s.length } : {} +>s.length || function (s) { s.length } : number | ((s: any) => void) >s.length : number >s : string >length : number @@ -31,10 +31,10 @@ var v2 = (s: string) => s.length || function (s) { s.length }; >length : any var v3 = (s: string) => s.length || function (s: number) { return 1 }; ->v3 : (s: string) => {} ->(s: string) => s.length || function (s: number) { return 1 } : (s: string) => {} +>v3 : (s: string) => number | ((s: number) => number) +>(s: string) => s.length || function (s: number) { return 1 } : (s: string) => number | ((s: number) => number) >s : string ->s.length || function (s: number) { return 1 } : {} +>s.length || function (s: number) { return 1 } : number | ((s: number) => number) >s.length : number >s : string >length : number @@ -42,10 +42,10 @@ var v3 = (s: string) => s.length || function (s: number) { return 1 }; >s : number var v4 = (s: number) => 1 || function (s: string) { return s.length }; ->v4 : (s: number) => {} ->(s: number) => 1 || function (s: string) { return s.length } : (s: number) => {} +>v4 : (s: number) => number | ((s: string) => number) +>(s: number) => 1 || function (s: string) { return s.length } : (s: number) => number | ((s: string) => number) >s : number ->1 || function (s: string) { return s.length } : {} +>1 || function (s: string) { return s.length } : number | ((s: string) => number) >function (s: string) { return s.length } : (s: string) => number >s : string >s.length : number diff --git a/tests/baselines/reference/contextuallyTypingOrOperator2.types b/tests/baselines/reference/contextuallyTypingOrOperator2.types index 57c9992436d..65ed442d5e9 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator2.types +++ b/tests/baselines/reference/contextuallyTypingOrOperator2.types @@ -3,7 +3,7 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; >v : { a: (_: string) => number; } >a : (_: string) => number >_ : string ->{ a: s => s.length } || { a: s => 1 } : { a: (_: string) => number; } +>{ a: s => s.length } || { a: s => 1 } : { a: (s: string) => number; } >{ a: s => s.length } : { a: (s: string) => number; } >a : (s: string) => number >s => s.length : (s: string) => number @@ -17,10 +17,10 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 }; >s : string var v2 = (s: string) => s.length || function (s) { s.aaa }; ->v2 : (s: string) => {} ->(s: string) => s.length || function (s) { s.aaa } : (s: string) => {} +>v2 : (s: string) => number | ((s: any) => void) +>(s: string) => s.length || function (s) { s.aaa } : (s: string) => number | ((s: any) => void) >s : string ->s.length || function (s) { s.aaa } : {} +>s.length || function (s) { s.aaa } : number | ((s: any) => void) >s.length : number >s : string >length : number diff --git a/tests/baselines/reference/declFileGenericType2.types b/tests/baselines/reference/declFileGenericType2.types index a6b6546326c..f9345b5ff11 100644 --- a/tests/baselines/reference/declFileGenericType2.types +++ b/tests/baselines/reference/declFileGenericType2.types @@ -131,11 +131,11 @@ module templa.dom.mvc.composite { >super : typeof AbstractElementController this._controllers = []; ->this._controllers = [] : templa.mvc.IController[] +>this._controllers = [] : undefined[] >this._controllers : templa.mvc.IController[] >this : AbstractCompositeElementController >_controllers : templa.mvc.IController[] ->[] : templa.mvc.IController[] +>[] : undefined[] } } } diff --git a/tests/baselines/reference/decrementOperatorWithAnyOtherType.types b/tests/baselines/reference/decrementOperatorWithAnyOtherType.types index 4e8387f9066..ab21dd9db5c 100644 --- a/tests/baselines/reference/decrementOperatorWithAnyOtherType.types +++ b/tests/baselines/reference/decrementOperatorWithAnyOtherType.types @@ -9,7 +9,7 @@ var ANY1; var ANY2: any[] = ["", ""]; >ANY2 : any[] ->["", ""] : any[] +>["", ""] : string[] var obj = {x:1,y:null}; >obj : { x: number; y: any; } diff --git a/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt b/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt new file mode 100644 index 00000000000..a0c30e9dc93 --- /dev/null +++ b/tests/baselines/reference/decrementOperatorWithEnumType.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(7,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts(12,7): error TS2304: Cannot find name 'A'. + + +==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts (3 errors) ==== + // -- operator on enum type + + enum ENUM1 { A, B, "" }; + + // expression + var ResultIsNumber1 = --ENUM1["A"]; + var ResultIsNumber2 = ENUM1.A--; + ~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + + // miss assignment operator + --ENUM1["A"]; + + ENUM1[A]--; + ~~~~~~~~ +!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. + ~ +!!! error TS2304: Cannot find name 'A'. \ No newline at end of file diff --git a/tests/baselines/reference/decrementOperatorWithEnumType.js b/tests/baselines/reference/decrementOperatorWithEnumType.js index 8c22fd18928..13947a6a948 100644 --- a/tests/baselines/reference/decrementOperatorWithEnumType.js +++ b/tests/baselines/reference/decrementOperatorWithEnumType.js @@ -1,29 +1,29 @@ //// [decrementOperatorWithEnumType.ts] // -- operator on enum type -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // expression -var ResultIsNumber1 = --ENUM1[1]; -var ResultIsNumber2 = ENUM1[1]--; +var ResultIsNumber1 = --ENUM1["A"]; +var ResultIsNumber2 = ENUM1.A--; // miss assignment operator ---ENUM1[1]; +--ENUM1["A"]; -ENUM1[1]--; +ENUM1[A]--; //// [decrementOperatorWithEnumType.js] // -- operator on enum type var ENUM1; (function (ENUM1) { - ENUM1[ENUM1["1"] = 0] = "1"; - ENUM1[ENUM1["2"] = 1] = "2"; + ENUM1[ENUM1["A"] = 0] = "A"; + ENUM1[ENUM1["B"] = 1] = "B"; ENUM1[ENUM1[""] = 2] = ""; })(ENUM1 || (ENUM1 = {})); ; // expression -var ResultIsNumber1 = --ENUM1[1]; -var ResultIsNumber2 = ENUM1[1]--; +var ResultIsNumber1 = --ENUM1["A"]; +var ResultIsNumber2 = 0 /* A */--; // miss assignment operator ---ENUM1[1]; -ENUM1[1]--; +--ENUM1["A"]; +ENUM1[A]--; diff --git a/tests/baselines/reference/decrementOperatorWithEnumType.types b/tests/baselines/reference/decrementOperatorWithEnumType.types deleted file mode 100644 index fc670ddc6f7..00000000000 --- a/tests/baselines/reference/decrementOperatorWithEnumType.types +++ /dev/null @@ -1,30 +0,0 @@ -=== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts === -// -- operator on enum type - -enum ENUM1 { 1, 2, "" }; ->ENUM1 : ENUM1 - -// expression -var ResultIsNumber1 = --ENUM1[1]; ->ResultIsNumber1 : number ->--ENUM1[1] : number ->ENUM1[1] : ENUM1 ->ENUM1 : typeof ENUM1 - -var ResultIsNumber2 = ENUM1[1]--; ->ResultIsNumber2 : number ->ENUM1[1]-- : number ->ENUM1[1] : ENUM1 ->ENUM1 : typeof ENUM1 - -// miss assignment operator ---ENUM1[1]; ->--ENUM1[1] : number ->ENUM1[1] : ENUM1 ->ENUM1 : typeof ENUM1 - -ENUM1[1]--; ->ENUM1[1]-- : number ->ENUM1[1] : ENUM1 ->ENUM1 : typeof ENUM1 - diff --git a/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.errors.txt b/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.errors.txt index 652aae1ab5a..079bb2a6b64 100644 --- a/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.errors.txt @@ -2,19 +2,21 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(8,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(10,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(11,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(14,25): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(15,23): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(14,25): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(14,43): error TS2339: Property 'B' does not exist on type 'typeof ENUM'. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(15,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(15,29): error TS2339: Property 'A' does not exist on type 'typeof ENUM'. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(18,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(19,3): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(21,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts(22,1): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. -==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts (10 errors) ==== +==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts (12 errors) ==== // -- operator on enum type enum ENUM { }; - enum ENUM1 { 1, 2, "" }; + enum ENUM1 { A, B, "" }; // enum type var var ResultIsNumber1 = --ENUM; @@ -32,12 +34,16 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. // enum type expressions - var ResultIsNumber5 = --(ENUM[1] + ENUM[2]); - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. - var ResultIsNumber6 = (ENUM[1] + ENUM[2])--; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. + var ResultIsNumber5 = --(ENUM["A"] + ENUM.B); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + ~ +!!! error TS2339: Property 'B' does not exist on type 'typeof ENUM'. + var ResultIsNumber6 = (ENUM.A + ENUM["B"])--; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + ~ +!!! error TS2339: Property 'A' does not exist on type 'typeof ENUM'. // miss assignment operator --ENUM; diff --git a/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.js b/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.js index 410e3c144ef..66a1252cdd0 100644 --- a/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.js +++ b/tests/baselines/reference/decrementOperatorWithEnumTypeInvalidOperations.js @@ -2,7 +2,7 @@ // -- operator on enum type enum ENUM { }; -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsNumber1 = --ENUM; @@ -12,8 +12,8 @@ var ResultIsNumber3 = ENUM--; var ResultIsNumber4 = ENUM1--; // enum type expressions -var ResultIsNumber5 = --(ENUM[1] + ENUM[2]); -var ResultIsNumber6 = (ENUM[1] + ENUM[2])--; +var ResultIsNumber5 = --(ENUM["A"] + ENUM.B); +var ResultIsNumber6 = (ENUM.A + ENUM["B"])--; // miss assignment operator --ENUM; @@ -30,8 +30,8 @@ var ENUM; ; var ENUM1; (function (ENUM1) { - ENUM1[ENUM1["1"] = 0] = "1"; - ENUM1[ENUM1["2"] = 1] = "2"; + ENUM1[ENUM1["A"] = 0] = "A"; + ENUM1[ENUM1["B"] = 1] = "B"; ENUM1[ENUM1[""] = 2] = ""; })(ENUM1 || (ENUM1 = {})); ; @@ -41,8 +41,8 @@ var ResultIsNumber2 = --ENUM1; var ResultIsNumber3 = ENUM--; var ResultIsNumber4 = ENUM1--; // enum type expressions -var ResultIsNumber5 = --(ENUM[1] + ENUM[2]); -var ResultIsNumber6 = (ENUM[1] + ENUM[2])--; +var ResultIsNumber5 = --(ENUM["A"] + ENUM.B); +var ResultIsNumber6 = (ENUM.A + ENUM["B"])--; // miss assignment operator --ENUM; --ENUM1; diff --git a/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt b/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt index ada7f83af3d..21296783f28 100644 --- a/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt +++ b/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt @@ -1,31 +1,27 @@ -tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(4,6): error TS2339: Property 'length' does not exist on type '{}'. -tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(10,6): error TS2339: Property 'length' does not exist on type 'Object'. -tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(18,27): error TS2339: Property 'length' does not exist on type '{}'. +tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(2,6): error TS2339: Property 'length' does not exist on type '{}'. +tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(5,6): error TS2339: Property 'length' does not exist on type 'Object'. +tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(8,14): error TS2346: Supplied parameters do not match any signature of call target. ==== tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts (3 errors) ==== - var obj1: {}; - obj1.length; ~~~~~~ !!! error TS2339: Property 'length' does not exist on type '{}'. - - var obj2: Object; - obj2.length; ~~~~~~ !!! error TS2339: Property 'length' does not exist on type 'Object'. - - function concat(x: T, y: T): T { return null; } + var result = concat(1, ""); // error + ~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var elementCount = result.length; - var result = concat(1, ""); + function concat2(x: T, y: U) { return null; } + var result2 = concat2(1, ""); // result2 will be number|string + var elementCount2 = result.length; - var elementCount = result.length; // would like to get an error by now - ~~~~~~ -!!! error TS2339: Property 'length' does not exist on type '{}'. \ No newline at end of file diff --git a/tests/baselines/reference/defaultBestCommonTypesHaveDecls.js b/tests/baselines/reference/defaultBestCommonTypesHaveDecls.js index 59935cc53af..98e135cc712 100644 --- a/tests/baselines/reference/defaultBestCommonTypesHaveDecls.js +++ b/tests/baselines/reference/defaultBestCommonTypesHaveDecls.js @@ -1,22 +1,18 @@ //// [defaultBestCommonTypesHaveDecls.ts] - var obj1: {}; - obj1.length; - - var obj2: Object; - obj2.length; - - function concat(x: T, y: T): T { return null; } +var result = concat(1, ""); // error +var elementCount = result.length; -var result = concat(1, ""); +function concat2(x: T, y: U) { return null; } +var result2 = concat2(1, ""); // result2 will be number|string +var elementCount2 = result.length; -var elementCount = result.length; // would like to get an error by now //// [defaultBestCommonTypesHaveDecls.js] @@ -27,5 +23,10 @@ obj2.length; function concat(x, y) { return null; } -var result = concat(1, ""); -var elementCount = result.length; // would like to get an error by now +var result = concat(1, ""); // error +var elementCount = result.length; +function concat2(x, y) { + return null; +} +var result2 = concat2(1, ""); // result2 will be number|string +var elementCount2 = result.length; diff --git a/tests/baselines/reference/deleteOperatorWithEnumType.js b/tests/baselines/reference/deleteOperatorWithEnumType.js index d7fd9c95ee8..e694790091c 100644 --- a/tests/baselines/reference/deleteOperatorWithEnumType.js +++ b/tests/baselines/reference/deleteOperatorWithEnumType.js @@ -2,24 +2,24 @@ // delete operator on enum type enum ENUM { }; -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsBoolean1 = delete ENUM; var ResultIsBoolean2 = delete ENUM1; // enum type expressions -var ResultIsBoolean3 = delete ENUM1[0]; -var ResultIsBoolean4 = delete (ENUM[0] + ENUM1[1]); +var ResultIsBoolean3 = delete ENUM1["A"]; +var ResultIsBoolean4 = delete (ENUM[0] + ENUM1["B"]); // multiple delete operators var ResultIsBoolean5 = delete delete ENUM; -var ResultIsBoolean6 = delete delete delete (ENUM[0] + ENUM1[1]); +var ResultIsBoolean6 = delete delete delete (ENUM[0] + ENUM1["B"]); // miss assignment operators delete ENUM; delete ENUM1; -delete ENUM1[1]; +delete ENUM1.B; delete ENUM, ENUM1; //// [deleteOperatorWithEnumType.js] @@ -30,8 +30,8 @@ var ENUM; ; var ENUM1; (function (ENUM1) { - ENUM1[ENUM1["1"] = 0] = "1"; - ENUM1[ENUM1["2"] = 1] = "2"; + ENUM1[ENUM1["A"] = 0] = "A"; + ENUM1[ENUM1["B"] = 1] = "B"; ENUM1[ENUM1[""] = 2] = ""; })(ENUM1 || (ENUM1 = {})); ; @@ -39,13 +39,13 @@ var ENUM1; var ResultIsBoolean1 = delete ENUM; var ResultIsBoolean2 = delete ENUM1; // enum type expressions -var ResultIsBoolean3 = delete ENUM1[0]; -var ResultIsBoolean4 = delete (ENUM[0] + ENUM1[1]); +var ResultIsBoolean3 = delete ENUM1["A"]; +var ResultIsBoolean4 = delete (ENUM[0] + ENUM1["B"]); // multiple delete operators var ResultIsBoolean5 = delete delete ENUM; -var ResultIsBoolean6 = delete delete delete (ENUM[0] + ENUM1[1]); +var ResultIsBoolean6 = delete delete delete (ENUM[0] + ENUM1["B"]); // miss assignment operators delete ENUM; delete ENUM1; -delete ENUM1[1]; +delete 1 /* B */; delete ENUM, ENUM1; diff --git a/tests/baselines/reference/deleteOperatorWithEnumType.types b/tests/baselines/reference/deleteOperatorWithEnumType.types index d356693616f..e436ac3373f 100644 --- a/tests/baselines/reference/deleteOperatorWithEnumType.types +++ b/tests/baselines/reference/deleteOperatorWithEnumType.types @@ -4,8 +4,10 @@ enum ENUM { }; >ENUM : ENUM -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; >ENUM1 : ENUM1 +>A : ENUM1 +>B : ENUM1 // enum type var var ResultIsBoolean1 = delete ENUM; @@ -19,20 +21,20 @@ var ResultIsBoolean2 = delete ENUM1; >ENUM1 : typeof ENUM1 // enum type expressions -var ResultIsBoolean3 = delete ENUM1[0]; +var ResultIsBoolean3 = delete ENUM1["A"]; >ResultIsBoolean3 : boolean ->delete ENUM1[0] : boolean ->ENUM1[0] : string +>delete ENUM1["A"] : boolean +>ENUM1["A"] : ENUM1 >ENUM1 : typeof ENUM1 -var ResultIsBoolean4 = delete (ENUM[0] + ENUM1[1]); +var ResultIsBoolean4 = delete (ENUM[0] + ENUM1["B"]); >ResultIsBoolean4 : boolean ->delete (ENUM[0] + ENUM1[1]) : boolean ->(ENUM[0] + ENUM1[1]) : string ->ENUM[0] + ENUM1[1] : string +>delete (ENUM[0] + ENUM1["B"]) : boolean +>(ENUM[0] + ENUM1["B"]) : string +>ENUM[0] + ENUM1["B"] : string >ENUM[0] : string >ENUM : typeof ENUM ->ENUM1[1] : ENUM1 +>ENUM1["B"] : ENUM1 >ENUM1 : typeof ENUM1 // multiple delete operators @@ -42,16 +44,16 @@ var ResultIsBoolean5 = delete delete ENUM; >delete ENUM : boolean >ENUM : typeof ENUM -var ResultIsBoolean6 = delete delete delete (ENUM[0] + ENUM1[1]); +var ResultIsBoolean6 = delete delete delete (ENUM[0] + ENUM1["B"]); >ResultIsBoolean6 : boolean ->delete delete delete (ENUM[0] + ENUM1[1]) : boolean ->delete delete (ENUM[0] + ENUM1[1]) : boolean ->delete (ENUM[0] + ENUM1[1]) : boolean ->(ENUM[0] + ENUM1[1]) : string ->ENUM[0] + ENUM1[1] : string +>delete delete delete (ENUM[0] + ENUM1["B"]) : boolean +>delete delete (ENUM[0] + ENUM1["B"]) : boolean +>delete (ENUM[0] + ENUM1["B"]) : boolean +>(ENUM[0] + ENUM1["B"]) : string +>ENUM[0] + ENUM1["B"] : string >ENUM[0] : string >ENUM : typeof ENUM ->ENUM1[1] : ENUM1 +>ENUM1["B"] : ENUM1 >ENUM1 : typeof ENUM1 // miss assignment operators @@ -63,10 +65,11 @@ delete ENUM1; >delete ENUM1 : boolean >ENUM1 : typeof ENUM1 -delete ENUM1[1]; ->delete ENUM1[1] : boolean ->ENUM1[1] : ENUM1 +delete ENUM1.B; +>delete ENUM1.B : boolean +>ENUM1.B : ENUM1 >ENUM1 : typeof ENUM1 +>B : ENUM1 delete ENUM, ENUM1; >delete ENUM, ENUM1 : typeof ENUM1 diff --git a/tests/baselines/reference/derivedTypeDoesNotRequireExtendsClause.types b/tests/baselines/reference/derivedTypeDoesNotRequireExtendsClause.types index 9821ff91123..36b85d7950c 100644 --- a/tests/baselines/reference/derivedTypeDoesNotRequireExtendsClause.types +++ b/tests/baselines/reference/derivedTypeDoesNotRequireExtendsClause.types @@ -49,7 +49,7 @@ b = d2; var r: Base[] = [d1, d2]; >r : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived | Derived2)[] >d1 : Derived >d2 : Derived2 diff --git a/tests/baselines/reference/doNotWidenAtObjectLiteralPropertyAssignment.types b/tests/baselines/reference/doNotWidenAtObjectLiteralPropertyAssignment.types index 225bca8de63..cd8c03fd6a6 100644 --- a/tests/baselines/reference/doNotWidenAtObjectLiteralPropertyAssignment.types +++ b/tests/baselines/reference/doNotWidenAtObjectLiteralPropertyAssignment.types @@ -21,7 +21,7 @@ interface IIntervalTreeNode { var test: IIntervalTreeNode[] = [{ interval: { begin: 0 }, children: null }]; // was error here because best common type is {} >test : IIntervalTreeNode[] >IIntervalTreeNode : IIntervalTreeNode ->[{ interval: { begin: 0 }, children: null }] : IIntervalTreeNode[] +>[{ interval: { begin: 0 }, children: null }] : { interval: { begin: number; }; children: null; }[] >{ interval: { begin: 0 }, children: null } : { interval: { begin: number; }; children: null; } >interval : { begin: number; } >{ begin: 0 } : { begin: number; } diff --git a/tests/baselines/reference/enumBasics.types b/tests/baselines/reference/enumBasics.types index f775295891a..c0d7fb9bed1 100644 --- a/tests/baselines/reference/enumBasics.types +++ b/tests/baselines/reference/enumBasics.types @@ -157,8 +157,8 @@ enum E9 { // (refer to .js to validate) // Enum constant members are propagated var doNotPropagate = [ ->doNotPropagate : {}[] ->[ E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : {}[] +>doNotPropagate : (E3 | E4 | E7 | E8)[] +>[ E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : (E3 | E4 | E7 | E8)[] E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z >E8.B : E8 @@ -183,8 +183,8 @@ var doNotPropagate = [ ]; // Enum computed members are not propagated var doPropagate = [ ->doPropagate : {}[] ->[ E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : {}[] +>doPropagate : (E5 | E6 | E9)[] +>[ E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : (E5 | E6 | E9)[] E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C >E9.A : E9 diff --git a/tests/baselines/reference/enumIdenticalIdentifierValues.errors.txt b/tests/baselines/reference/enumIdenticalIdentifierValues.errors.txt deleted file mode 100644 index 551b5d9d929..00000000000 --- a/tests/baselines/reference/enumIdenticalIdentifierValues.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -tests/cases/compiler/enumIdenticalIdentifierValues.ts(2,5): error TS2300: Duplicate identifier '1'. -tests/cases/compiler/enumIdenticalIdentifierValues.ts(3,5): error TS2300: Duplicate identifier '1.0'. - - -==== tests/cases/compiler/enumIdenticalIdentifierValues.ts (2 errors) ==== - enum Enum { - 1, - ~ -!!! error TS2300: Duplicate identifier '1'. - 1.0 - ~~~ -!!! error TS2300: Duplicate identifier '1.0'. - } \ No newline at end of file diff --git a/tests/baselines/reference/enumIdenticalIdentifierValues.js b/tests/baselines/reference/enumIdenticalIdentifierValues.js deleted file mode 100644 index 3f435ac6537..00000000000 --- a/tests/baselines/reference/enumIdenticalIdentifierValues.js +++ /dev/null @@ -1,12 +0,0 @@ -//// [enumIdenticalIdentifierValues.ts] -enum Enum { - 1, - 1.0 -} - -//// [enumIdenticalIdentifierValues.js] -var Enum; -(function (Enum) { - Enum[Enum["1"] = 0] = "1"; - Enum[Enum["1"] = 1] = "1"; -})(Enum || (Enum = {})); diff --git a/tests/baselines/reference/enumIdentifierLiterals.errors.txt b/tests/baselines/reference/enumIdentifierLiterals.errors.txt new file mode 100644 index 00000000000..60d8ed81f84 --- /dev/null +++ b/tests/baselines/reference/enumIdentifierLiterals.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/enumIdentifierLiterals.ts(2,5): error TS1151: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(3,5): error TS1151: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(4,5): error TS1151: An enum member cannot have a numeric name. +tests/cases/compiler/enumIdentifierLiterals.ts(6,5): error TS1151: An enum member cannot have a numeric name. + + +==== tests/cases/compiler/enumIdentifierLiterals.ts (4 errors) ==== + enum Nums { + 1.0, + ~~~ +!!! error TS1151: An enum member cannot have a numeric name. + 11e-1, + ~~~~~ +!!! error TS1151: An enum member cannot have a numeric name. + 0.12e1, + ~~~~~~ +!!! error TS1151: An enum member cannot have a numeric name. + "13e-1", + 0xF00D + ~~~~~~ +!!! error TS1151: An enum member cannot have a numeric name. + } \ No newline at end of file diff --git a/tests/baselines/reference/enumIdentifierLiterals.types b/tests/baselines/reference/enumIdentifierLiterals.types deleted file mode 100644 index b259e57d1dd..00000000000 --- a/tests/baselines/reference/enumIdentifierLiterals.types +++ /dev/null @@ -1,10 +0,0 @@ -=== tests/cases/compiler/enumIdentifierLiterals.ts === -enum Nums { ->Nums : Nums - - 1.0, - 11e-1, - 0.12e1, - "13e-1", - 0xF00D -} diff --git a/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types b/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types index fefa692b509..991d324e822 100644 --- a/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types +++ b/tests/baselines/reference/extendingClassFromAliasAndUsageInIndexer.types @@ -25,7 +25,7 @@ var moduleMap: { [key: string]: IHasVisualizationModel } = { >moduleMap : { [x: string]: IHasVisualizationModel; } >key : string >IHasVisualizationModel : IHasVisualizationModel ->{ "moduleA": moduleA, "moduleB": moduleB} : { [x: string]: IHasVisualizationModel; "moduleA": typeof moduleA; "moduleB": typeof moduleB; } +>{ "moduleA": moduleA, "moduleB": moduleB} : { [x: string]: typeof moduleA; "moduleA": typeof moduleA; "moduleB": typeof moduleB; } "moduleA": moduleA, >moduleA : typeof moduleA diff --git a/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt b/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt new file mode 100644 index 00000000000..d9416eb4c25 --- /dev/null +++ b/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts(2,1): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts (1 errors) ==== + function bar(item1: T, item2: T) { } + bar(1, ""); // Should be ok + ~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.types b/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.types deleted file mode 100644 index 95214571df9..00000000000 --- a/tests/baselines/reference/fixTypeParameterInSignatureWithRestParameters.types +++ /dev/null @@ -1,13 +0,0 @@ -=== tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts === -function bar(item1: T, item2: T) { } ->bar : (item1: T, item2: T) => void ->T : T ->item1 : T ->T : T ->item2 : T ->T : T - -bar(1, ""); // Should be ok ->bar(1, "") : void ->bar : (item1: T, item2: T) => void - diff --git a/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt b/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt index b653bc01f55..53ecb88363d 100644 --- a/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt +++ b/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt @@ -7,7 +7,7 @@ tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDec tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(40,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'I', but here has type 'C2'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(43,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'f' must be of type '(x: string) => number', but here has type '(x: number) => string'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(46,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. -tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(47,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '{}[]'. +tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(47,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '(C | D)[]'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(50,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'D[]', but here has type 'D[]'. tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(53,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'm' must be of type 'typeof M', but here has type 'typeof A'. @@ -79,7 +79,7 @@ tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDec !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. for( var arr = [new C(), new C2(), new D()];;){} ~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '{}[]'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '(C | D)[]'. for(var arr2 = [new D()];;){} for( var arr2 = new Array>();;){} diff --git a/tests/baselines/reference/forStatementsMultipleValidDecl.types b/tests/baselines/reference/forStatementsMultipleValidDecl.types index 2f3bfd70cea..c2458a306c7 100644 --- a/tests/baselines/reference/forStatementsMultipleValidDecl.types +++ b/tests/baselines/reference/forStatementsMultipleValidDecl.types @@ -109,11 +109,11 @@ for (var a = ['a', 'b']; ;) { } for (var a = []; ;) { } >a : string[] >[] : string[] ->[] : string[] +>[] : undefined[] for (var a: string[] = []; ;) { } >a : string[] ->[] : string[] +>[] : undefined[] for (var a = new Array(); ;) { } >a : string[] diff --git a/tests/baselines/reference/functionCall3.types b/tests/baselines/reference/functionCall3.types index a9b8e46069c..ea47de3e6d9 100644 --- a/tests/baselines/reference/functionCall3.types +++ b/tests/baselines/reference/functionCall3.types @@ -1,7 +1,7 @@ === tests/cases/compiler/functionCall3.ts === function foo():any[]{return [1];} >foo : () => any[] ->[1] : any[] +>[1] : number[] var x = foo(); >x : any[] diff --git a/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.js b/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.js index 37bcf84669c..f58b1047b8f 100644 --- a/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.js +++ b/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.js @@ -11,6 +11,4 @@ function foo(args) { //// [functionDeclarationWithArgumentOfTypeFunctionTypeArray.d.ts] -declare function foo(args: { - (x: any): number; -}[]): number; +declare function foo(args: ((x: any) => number)[]): number; diff --git a/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.types b/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.types index af751fbb0e9..a1d32a2a405 100644 --- a/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.types +++ b/tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.types @@ -1,12 +1,12 @@ === tests/cases/compiler/functionDeclarationWithArgumentOfTypeFunctionTypeArray.ts === function foo(args: { (x): number }[]) { ->foo : (args: { (x: any): number; }[]) => number ->args : { (x: any): number; }[] +>foo : (args: ((x: any) => number)[]) => number +>args : ((x: any) => number)[] >x : any return args.length; >args.length : number ->args : { (x: any): number; }[] +>args : ((x: any) => number)[] >length : number } diff --git a/tests/baselines/reference/functionOverloads42.types b/tests/baselines/reference/functionOverloads42.types index dec6a041440..6641a28c87a 100644 --- a/tests/baselines/reference/functionOverloads42.types +++ b/tests/baselines/reference/functionOverloads42.types @@ -19,7 +19,7 @@ var x = foo([{a:'s'}]); >x : number >foo([{a:'s'}]) : number >foo : { (bar: { a: number; }[]): string; (bar: { a: any; }[]): number; } ->[{a:'s'}] : { a: any; }[] +>[{a:'s'}] : { a: string; }[] >{a:'s'} : { a: string; } >a : string diff --git a/tests/baselines/reference/functionSubtypingOfVarArgs2.types b/tests/baselines/reference/functionSubtypingOfVarArgs2.types index 2fef933594d..5e2b14ffc7a 100644 --- a/tests/baselines/reference/functionSubtypingOfVarArgs2.types +++ b/tests/baselines/reference/functionSubtypingOfVarArgs2.types @@ -3,9 +3,9 @@ class EventBase { >EventBase : EventBase private _listeners: { (...args: any[]): void; }[] = []; ->_listeners : { (...args: any[]): void; }[] +>_listeners : ((...args: any[]) => void)[] >args : any[] ->[] : { (...args: any[]): void; }[] +>[] : undefined[] add(listener: (...args: any[]) => void): void { >add : (listener: (...args: any[]) => void) => void @@ -14,11 +14,11 @@ class EventBase { this._listeners.push(listener); >this._listeners.push(listener) : number ->this._listeners.push : (...items: { (...args: any[]): void; }[]) => number ->this._listeners : { (...args: any[]): void; }[] +>this._listeners.push : (...items: ((...args: any[]) => void)[]) => number +>this._listeners : ((...args: any[]) => void)[] >this : EventBase ->_listeners : { (...args: any[]): void; }[] ->push : (...items: { (...args: any[]): void; }[]) => number +>_listeners : ((...args: any[]) => void)[] +>push : (...items: ((...args: any[]) => void)[]) => number >listener : (...args: any[]) => void } } diff --git a/tests/baselines/reference/functionTypesLackingReturnTypes.errors.txt b/tests/baselines/reference/functionTypesLackingReturnTypes.errors.txt index a0be6f32df0..84ec6ff1ba5 100644 --- a/tests/baselines/reference/functionTypesLackingReturnTypes.errors.txt +++ b/tests/baselines/reference/functionTypesLackingReturnTypes.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/functionTypesLackingReturnTypes.ts(3,17): error TS1005: '=>' expected. -tests/cases/compiler/functionTypesLackingReturnTypes.ts(7,15): error TS1005: '=>' expected. +tests/cases/compiler/functionTypesLackingReturnTypes.ts(7,9): error TS2304: Cannot find name 'param'. ==== tests/cases/compiler/functionTypesLackingReturnTypes.ts (2 errors) ==== @@ -12,8 +12,8 @@ tests/cases/compiler/functionTypesLackingReturnTypes.ts(7,15): error TS1005: '=> // Error (no '=>') var g: (param); - ~ -!!! error TS1005: '=>' expected. + ~~~~~ +!!! error TS2304: Cannot find name 'param'. // Okay var h: { () } diff --git a/tests/baselines/reference/functionWithMultipleReturnStatements2.errors.txt b/tests/baselines/reference/functionWithMultipleReturnStatements2.errors.txt new file mode 100644 index 00000000000..2b14bd97bad --- /dev/null +++ b/tests/baselines/reference/functionWithMultipleReturnStatements2.errors.txt @@ -0,0 +1,112 @@ +tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements2.ts(58,1): error TS2354: No best common type exists among return expressions. +tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements2.ts(67,1): error TS2354: No best common type exists among return expressions. + + +==== tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements2.ts (2 errors) ==== + // return type of a function with multiple returns is the BCT of each return statement + // no errors expected here + + function f1() { + if (true) { + return 1; + } else { + return null; + } + } + + function f2() { + if (true) { + return 1; + } else if (false) { + return null; + } else { + return 2; + } + } + + function f4() { + try { + return 1; + } + catch (e) { + return undefined; + } + finally { + return 1; + } + } + + function f5() { + return 1; + return new Object(); + } + + function f6(x: T) { + if (true) { + return x; + } else { + return null; + } + } + + //function f7(x: T, y: U) { + // if (true) { + // return x; + // } else { + // return y; + // } + //} + + var a: { x: number; y?: number }; + var b: { x: number; z?: number }; + // returns typeof a + function f9() { + ~~~~~~~~~~~~~~~ + if (true) { + ~~~~~~~~~~~~~~~ + return a; + ~~~~~~~~~~~~~~~~~ + } else { + ~~~~~~~~~~~~ + return b; + ~~~~~~~~~~~~~~~~~ + } + ~~~~~ + } + ~ +!!! error TS2354: No best common type exists among return expressions. + + // returns typeof b + function f10() { + ~~~~~~~~~~~~~~~~ + if (true) { + ~~~~~~~~~~~~~~~ + return b; + ~~~~~~~~~~~~~~~~~ + } else { + ~~~~~~~~~~~~ + return a; + ~~~~~~~~~~~~~~~~~ + } + ~~~~~ + } + ~ +!!! error TS2354: No best common type exists among return expressions. + + // returns number => void + function f11() { + if (true) { + return (x: number) => { } + } else { + return (x: Object) => { } + } + } + + // returns Object => void + function f12() { + if (true) { + return (x: Object) => { } + } else { + return (x: number) => { } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/functionWithMultipleReturnStatements2.types b/tests/baselines/reference/functionWithMultipleReturnStatements2.types deleted file mode 100644 index 706aca40c94..00000000000 --- a/tests/baselines/reference/functionWithMultipleReturnStatements2.types +++ /dev/null @@ -1,146 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/bestCommonType/functionWithMultipleReturnStatements2.ts === -// return type of a function with multiple returns is the BCT of each return statement -// no errors expected here - -function f1() { ->f1 : () => number - - if (true) { - return 1; - } else { - return null; - } -} - -function f2() { ->f2 : () => number - - if (true) { - return 1; - } else if (false) { - return null; - } else { - return 2; - } -} - -function f4() { ->f4 : () => number - - try { - return 1; - } - catch (e) { ->e : any - - return undefined; ->undefined : undefined - } - finally { - return 1; - } -} - -function f5() { ->f5 : () => Object - - return 1; - return new Object(); ->new Object() : Object ->Object : { (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any): any; getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor; getOwnPropertyNames(o: any): string[]; create(o: any, properties?: PropertyDescriptorMap): any; defineProperty(o: any, p: string, attributes: PropertyDescriptor): any; defineProperties(o: any, properties: PropertyDescriptorMap): any; seal(o: any): any; freeze(o: any): any; preventExtensions(o: any): any; isSealed(o: any): boolean; isFrozen(o: any): boolean; isExtensible(o: any): boolean; keys(o: any): string[]; } -} - -function f6(x: T) { ->f6 : (x: T) => T ->T : T ->x : T ->T : T - - if (true) { - return x; ->x : T - - } else { - return null; - } -} - -//function f7(x: T, y: U) { -// if (true) { -// return x; -// } else { -// return y; -// } -//} - -var a: { x: number; y?: number }; ->a : { x: number; y?: number; } ->x : number ->y : number - -var b: { x: number; z?: number }; ->b : { x: number; z?: number; } ->x : number ->z : number - -// returns typeof a -function f9() { ->f9 : () => { x: number; y?: number; } - - if (true) { - return a; ->a : { x: number; y?: number; } - - } else { - return b; ->b : { x: number; z?: number; } - } -} - -// returns typeof b -function f10() { ->f10 : () => { x: number; z?: number; } - - if (true) { - return b; ->b : { x: number; z?: number; } - - } else { - return a; ->a : { x: number; y?: number; } - } -} - -// returns number => void -function f11() { ->f11 : () => (x: number) => void - - if (true) { - return (x: number) => { } ->(x: number) => { } : (x: number) => void ->x : number - - } else { - return (x: Object) => { } ->(x: Object) => { } : (x: Object) => void ->x : Object ->Object : Object - } -} - -// returns Object => void -function f12() { ->f12 : () => (x: Object) => void - - if (true) { - return (x: Object) => { } ->(x: Object) => { } : (x: Object) => void ->x : Object ->Object : Object - - } else { - return (x: number) => { } ->(x: number) => { } : (x: number) => void ->x : number - } -} diff --git a/tests/baselines/reference/generatedContextualTyping.types b/tests/baselines/reference/generatedContextualTyping.types index 57b5408eabe..79787f6d994 100644 --- a/tests/baselines/reference/generatedContextualTyping.types +++ b/tests/baselines/reference/generatedContextualTyping.types @@ -34,57 +34,57 @@ var b = new Base(), d1 = new Derived1(), d2 = new Derived2(); var x1: () => Base[] = () => [d1, d2]; >x1 : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x2: () => Base[] = function() { return [d1, d2] }; >x2 : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x3: () => Base[] = function named() { return [d1, d2] }; >x3 : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x4: { (): Base[]; } = () => [d1, d2]; >x4 : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x5: { (): Base[]; } = function() { return [d1, d2] }; >x5 : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x6: { (): Base[]; } = function named() { return [d1, d2] }; >x6 : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x7: Base[] = [d1, d2]; >x7 : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -92,7 +92,7 @@ var x8: Array = [d1, d2]; >x8 : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -100,7 +100,7 @@ var x9: { [n: number]: Base; } = [d1, d2]; >x9 : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -108,9 +108,9 @@ var x10: {n: Base[]; } = { n: [d1, d2] }; >x10 : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -127,11 +127,11 @@ var x12: Genric = { func: n => { return [d1, d2]; } }; >x12 : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -139,8 +139,8 @@ class x13 { member: () => Base[] = () => [d1, d2] } >x13 : x13 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -148,8 +148,8 @@ class x14 { member: () => Base[] = function() { return [d1, d2] } } >x14 : x14 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -157,9 +157,9 @@ class x15 { member: () => Base[] = function named() { return [d1, d2] } } >x15 : x15 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -167,8 +167,8 @@ class x16 { member: { (): Base[]; } = () => [d1, d2] } >x16 : x16 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -176,8 +176,8 @@ class x17 { member: { (): Base[]; } = function() { return [d1, d2] } } >x17 : x17 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -185,9 +185,9 @@ class x18 { member: { (): Base[]; } = function named() { return [d1, d2] } } >x18 : x18 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -195,7 +195,7 @@ class x19 { member: Base[] = [d1, d2] } >x19 : x19 >member : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -204,7 +204,7 @@ class x20 { member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -213,7 +213,7 @@ class x21 { member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -222,9 +222,9 @@ class x22 { member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -243,11 +243,11 @@ class x24 { member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -255,8 +255,8 @@ class x25 { private member: () => Base[] = () => [d1, d2] } >x25 : x25 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -264,8 +264,8 @@ class x26 { private member: () => Base[] = function() { return [d1, d2] } } >x26 : x26 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -273,9 +273,9 @@ class x27 { private member: () => Base[] = function named() { return [d1, d2] } >x27 : x27 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -283,8 +283,8 @@ class x28 { private member: { (): Base[]; } = () => [d1, d2] } >x28 : x28 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -292,8 +292,8 @@ class x29 { private member: { (): Base[]; } = function() { return [d1, d2] } } >x29 : x29 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -301,9 +301,9 @@ class x30 { private member: { (): Base[]; } = function named() { return [d1, d2] >x30 : x30 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -311,7 +311,7 @@ class x31 { private member: Base[] = [d1, d2] } >x31 : x31 >member : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -320,7 +320,7 @@ class x32 { private member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -329,7 +329,7 @@ class x33 { private member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -338,9 +338,9 @@ class x34 { private member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -359,11 +359,11 @@ class x36 { private member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -371,8 +371,8 @@ class x37 { public member: () => Base[] = () => [d1, d2] } >x37 : x37 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -380,8 +380,8 @@ class x38 { public member: () => Base[] = function() { return [d1, d2] } } >x38 : x38 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -389,9 +389,9 @@ class x39 { public member: () => Base[] = function named() { return [d1, d2] } } >x39 : x39 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -399,8 +399,8 @@ class x40 { public member: { (): Base[]; } = () => [d1, d2] } >x40 : x40 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -408,8 +408,8 @@ class x41 { public member: { (): Base[]; } = function() { return [d1, d2] } } >x41 : x41 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -417,9 +417,9 @@ class x42 { public member: { (): Base[]; } = function named() { return [d1, d2] >x42 : x42 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -427,7 +427,7 @@ class x43 { public member: Base[] = [d1, d2] } >x43 : x43 >member : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -436,7 +436,7 @@ class x44 { public member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -445,7 +445,7 @@ class x45 { public member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -454,9 +454,9 @@ class x46 { public member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -475,11 +475,11 @@ class x48 { public member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -487,8 +487,8 @@ class x49 { static member: () => Base[] = () => [d1, d2] } >x49 : x49 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -496,8 +496,8 @@ class x50 { static member: () => Base[] = function() { return [d1, d2] } } >x50 : x50 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -505,9 +505,9 @@ class x51 { static member: () => Base[] = function named() { return [d1, d2] } } >x51 : x51 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -515,8 +515,8 @@ class x52 { static member: { (): Base[]; } = () => [d1, d2] } >x52 : x52 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -524,8 +524,8 @@ class x53 { static member: { (): Base[]; } = function() { return [d1, d2] } } >x53 : x53 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -533,9 +533,9 @@ class x54 { static member: { (): Base[]; } = function named() { return [d1, d2] >x54 : x54 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -543,7 +543,7 @@ class x55 { static member: Base[] = [d1, d2] } >x55 : x55 >member : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -552,7 +552,7 @@ class x56 { static member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -561,7 +561,7 @@ class x57 { static member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -570,9 +570,9 @@ class x58 { static member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -591,11 +591,11 @@ class x60 { static member: Genric = { func: n => { return [d1, d2]; } } } >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -603,8 +603,8 @@ class x61 { private static member: () => Base[] = () => [d1, d2] } >x61 : x61 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -612,8 +612,8 @@ class x62 { private static member: () => Base[] = function() { return [d1, d2] } >x62 : x62 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -621,9 +621,9 @@ class x63 { private static member: () => Base[] = function named() { return [d1, >x63 : x63 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -631,8 +631,8 @@ class x64 { private static member: { (): Base[]; } = () => [d1, d2] } >x64 : x64 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -640,8 +640,8 @@ class x65 { private static member: { (): Base[]; } = function() { return [d1, d2 >x65 : x65 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -649,9 +649,9 @@ class x66 { private static member: { (): Base[]; } = function named() { return [ >x66 : x66 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -659,7 +659,7 @@ class x67 { private static member: Base[] = [d1, d2] } >x67 : x67 >member : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -668,7 +668,7 @@ class x68 { private static member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -677,7 +677,7 @@ class x69 { private static member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -686,9 +686,9 @@ class x70 { private static member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -707,11 +707,11 @@ class x72 { private static member: Genric = { func: n => { return [d1, d2] >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -719,8 +719,8 @@ class x73 { public static member: () => Base[] = () => [d1, d2] } >x73 : x73 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -728,8 +728,8 @@ class x74 { public static member: () => Base[] = function() { return [d1, d2] } >x74 : x74 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -737,9 +737,9 @@ class x75 { public static member: () => Base[] = function named() { return [d1, >x75 : x75 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -747,8 +747,8 @@ class x76 { public static member: { (): Base[]; } = () => [d1, d2] } >x76 : x76 >member : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -756,8 +756,8 @@ class x77 { public static member: { (): Base[]; } = function() { return [d1, d2] >x77 : x77 >member : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -765,9 +765,9 @@ class x78 { public static member: { (): Base[]; } = function named() { return [d >x78 : x78 >member : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -775,7 +775,7 @@ class x79 { public static member: Base[] = [d1, d2] } >x79 : x79 >member : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -784,7 +784,7 @@ class x80 { public static member: Array = [d1, d2] } >member : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -793,7 +793,7 @@ class x81 { public static member: { [n: number]: Base; } = [d1, d2] } >member : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -802,9 +802,9 @@ class x82 { public static member: {n: Base[]; } = { n: [d1, d2] } } >member : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -823,11 +823,11 @@ class x84 { public static member: Genric = { func: n => { return [d1, d2]; >member : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -835,8 +835,8 @@ class x85 { constructor(parm: () => Base[] = () => [d1, d2]) { } } >x85 : x85 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -844,8 +844,8 @@ class x86 { constructor(parm: () => Base[] = function() { return [d1, d2] }) { } >x86 : x86 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -853,9 +853,9 @@ class x87 { constructor(parm: () => Base[] = function named() { return [d1, d2] >x87 : x87 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -863,8 +863,8 @@ class x88 { constructor(parm: { (): Base[]; } = () => [d1, d2]) { } } >x88 : x88 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -872,8 +872,8 @@ class x89 { constructor(parm: { (): Base[]; } = function() { return [d1, d2] }) >x89 : x89 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -881,9 +881,9 @@ class x90 { constructor(parm: { (): Base[]; } = function named() { return [d1, d >x90 : x90 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -891,7 +891,7 @@ class x91 { constructor(parm: Base[] = [d1, d2]) { } } >x91 : x91 >parm : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -900,7 +900,7 @@ class x92 { constructor(parm: Array = [d1, d2]) { } } >parm : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -909,7 +909,7 @@ class x93 { constructor(parm: { [n: number]: Base; } = [d1, d2]) { } } >parm : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -918,9 +918,9 @@ class x94 { constructor(parm: {n: Base[]; } = { n: [d1, d2] }) { } } >parm : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -939,11 +939,11 @@ class x96 { constructor(parm: Genric = { func: n => { return [d1, d2]; } } >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -951,8 +951,8 @@ class x97 { constructor(public parm: () => Base[] = () => [d1, d2]) { } } >x97 : x97 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -960,8 +960,8 @@ class x98 { constructor(public parm: () => Base[] = function() { return [d1, d2] >x98 : x98 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -969,9 +969,9 @@ class x99 { constructor(public parm: () => Base[] = function named() { return [d >x99 : x99 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -979,8 +979,8 @@ class x100 { constructor(public parm: { (): Base[]; } = () => [d1, d2]) { } } >x100 : x100 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -988,8 +988,8 @@ class x101 { constructor(public parm: { (): Base[]; } = function() { return [d1, >x101 : x101 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -997,9 +997,9 @@ class x102 { constructor(public parm: { (): Base[]; } = function named() { retur >x102 : x102 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1007,7 +1007,7 @@ class x103 { constructor(public parm: Base[] = [d1, d2]) { } } >x103 : x103 >parm : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1016,7 +1016,7 @@ class x104 { constructor(public parm: Array = [d1, d2]) { } } >parm : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1025,7 +1025,7 @@ class x105 { constructor(public parm: { [n: number]: Base; } = [d1, d2]) { } } >parm : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1034,9 +1034,9 @@ class x106 { constructor(public parm: {n: Base[]; } = { n: [d1, d2] }) { } } >parm : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1055,11 +1055,11 @@ class x108 { constructor(public parm: Genric = { func: n => { return [d1, >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1067,8 +1067,8 @@ class x109 { constructor(private parm: () => Base[] = () => [d1, d2]) { } } >x109 : x109 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1076,8 +1076,8 @@ class x110 { constructor(private parm: () => Base[] = function() { return [d1, d >x110 : x110 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1085,9 +1085,9 @@ class x111 { constructor(private parm: () => Base[] = function named() { return >x111 : x111 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1095,8 +1095,8 @@ class x112 { constructor(private parm: { (): Base[]; } = () => [d1, d2]) { } } >x112 : x112 >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1104,8 +1104,8 @@ class x113 { constructor(private parm: { (): Base[]; } = function() { return [d1 >x113 : x113 >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1113,9 +1113,9 @@ class x114 { constructor(private parm: { (): Base[]; } = function named() { retu >x114 : x114 >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1123,7 +1123,7 @@ class x115 { constructor(private parm: Base[] = [d1, d2]) { } } >x115 : x115 >parm : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1132,7 +1132,7 @@ class x116 { constructor(private parm: Array = [d1, d2]) { } } >parm : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1141,7 +1141,7 @@ class x117 { constructor(private parm: { [n: number]: Base; } = [d1, d2]) { } } >parm : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1150,9 +1150,9 @@ class x118 { constructor(private parm: {n: Base[]; } = { n: [d1, d2] }) { } } >parm : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1171,11 +1171,11 @@ class x120 { constructor(private parm: Genric = { func: n => { return [d1, >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1183,8 +1183,8 @@ function x121(parm: () => Base[] = () => [d1, d2]) { } >x121 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1192,8 +1192,8 @@ function x122(parm: () => Base[] = function() { return [d1, d2] }) { } >x122 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1201,9 +1201,9 @@ function x123(parm: () => Base[] = function named() { return [d1, d2] }) { } >x123 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1211,8 +1211,8 @@ function x124(parm: { (): Base[]; } = () => [d1, d2]) { } >x124 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1220,8 +1220,8 @@ function x125(parm: { (): Base[]; } = function() { return [d1, d2] }) { } >x125 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1229,9 +1229,9 @@ function x126(parm: { (): Base[]; } = function named() { return [d1, d2] }) { } >x126 : (parm?: () => Base[]) => void >parm : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1239,7 +1239,7 @@ function x127(parm: Base[] = [d1, d2]) { } >x127 : (parm?: Base[]) => void >parm : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1248,7 +1248,7 @@ function x128(parm: Array = [d1, d2]) { } >parm : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1257,7 +1257,7 @@ function x129(parm: { [n: number]: Base; } = [d1, d2]) { } >parm : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1266,9 +1266,9 @@ function x130(parm: {n: Base[]; } = { n: [d1, d2] }) { } >parm : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1287,68 +1287,68 @@ function x132(parm: Genric = { func: n => { return [d1, d2]; } }) { } >parm : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x133(): () => Base[] { return () => [d1, d2]; } >x133 : () => () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x134(): () => Base[] { return function() { return [d1, d2] }; } >x134 : () => () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x135(): () => Base[] { return function named() { return [d1, d2] }; } >x135 : () => () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x136(): { (): Base[]; } { return () => [d1, d2]; } >x136 : () => () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x137(): { (): Base[]; } { return function() { return [d1, d2] }; } >x137 : () => () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x138(): { (): Base[]; } { return function named() { return [d1, d2] }; } >x138 : () => () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x139(): Base[] { return [d1, d2]; } >x139 : () => Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1356,7 +1356,7 @@ function x140(): Array { return [d1, d2]; } >x140 : () => Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1364,7 +1364,7 @@ function x141(): { [n: number]: Base; } { return [d1, d2]; } >x141 : () => { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1372,9 +1372,9 @@ function x142(): {n: Base[]; } { return { n: [d1, d2] }; } >x142 : () => { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1391,97 +1391,97 @@ function x144(): Genric { return { func: n => { return [d1, d2]; } }; } >x144 : () => Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x145(): () => Base[] { return () => [d1, d2]; return () => [d1, d2]; } >x145 : () => () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x146(): () => Base[] { return function() { return [d1, d2] }; return function() { return [d1, d2] }; } >x146 : () => () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x147(): () => Base[] { return function named() { return [d1, d2] }; return function named() { return [d1, d2] }; } >x147 : () => () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x148(): { (): Base[]; } { return () => [d1, d2]; return () => [d1, d2]; } >x148 : () => () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x149(): { (): Base[]; } { return function() { return [d1, d2] }; return function() { return [d1, d2] }; } >x149 : () => () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x150(): { (): Base[]; } { return function named() { return [d1, d2] }; return function named() { return [d1, d2] }; } >x150 : () => () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 function x151(): Base[] { return [d1, d2]; return [d1, d2]; } >x151 : () => Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1489,10 +1489,10 @@ function x152(): Array { return [d1, d2]; return [d1, d2]; } >x152 : () => Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1500,10 +1500,10 @@ function x153(): { [n: number]: Base; } { return [d1, d2]; return [d1, d2]; } >x153 : () => { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1511,14 +1511,14 @@ function x154(): {n: Base[]; } { return { n: [d1, d2] }; return { n: [d1, d2] } >x154 : () => { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1539,82 +1539,82 @@ function x156(): Genric { return { func: n => { return [d1, d2]; } }; retu >x156 : () => Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x157: () => () => Base[] = () => { return () => [d1, d2]; }; >x157 : () => () => Base[] >Base : Base ->() => { return () => [d1, d2]; } : () => () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => { return () => [d1, d2]; } : () => () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x158: () => () => Base[] = () => { return function() { return [d1, d2] }; }; >x158 : () => () => Base[] >Base : Base ->() => { return function() { return [d1, d2] }; } : () => () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>() => { return function() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x159: () => () => Base[] = () => { return function named() { return [d1, d2] }; }; >x159 : () => () => Base[] >Base : Base ->() => { return function named() { return [d1, d2] }; } : () => () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>() => { return function named() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x160: () => { (): Base[]; } = () => { return () => [d1, d2]; }; >x160 : () => () => Base[] >Base : Base ->() => { return () => [d1, d2]; } : () => () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => { return () => [d1, d2]; } : () => () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x161: () => { (): Base[]; } = () => { return function() { return [d1, d2] }; }; >x161 : () => () => Base[] >Base : Base ->() => { return function() { return [d1, d2] }; } : () => () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>() => { return function() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x162: () => { (): Base[]; } = () => { return function named() { return [d1, d2] }; }; >x162 : () => () => Base[] >Base : Base ->() => { return function named() { return [d1, d2] }; } : () => () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>() => { return function named() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x163: () => Base[] = () => { return [d1, d2]; }; >x163 : () => Base[] >Base : Base ->() => { return [d1, d2]; } : () => Base[] ->[d1, d2] : Base[] +>() => { return [d1, d2]; } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1622,8 +1622,8 @@ var x164: () => Array = () => { return [d1, d2]; }; >x164 : () => Base[] >Array : T[] >Base : Base ->() => { return [d1, d2]; } : () => Base[] ->[d1, d2] : Base[] +>() => { return [d1, d2]; } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1631,8 +1631,8 @@ var x165: () => { [n: number]: Base; } = () => { return [d1, d2]; }; >x165 : () => { [x: number]: Base; } >n : number >Base : Base ->() => { return [d1, d2]; } : () => Base[] ->[d1, d2] : Base[] +>() => { return [d1, d2]; } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1640,10 +1640,10 @@ var x166: () => {n: Base[]; } = () => { return { n: [d1, d2] }; }; >x166 : () => { n: Base[]; } >n : Base[] >Base : Base ->() => { return { n: [d1, d2] }; } : () => { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>() => { return { n: [d1, d2] }; } : () => { n: (Derived1 | Derived2)[]; } +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1661,76 +1661,76 @@ var x168: () => Genric = () => { return { func: n => { return [d1, d2]; } >x168 : () => Genric >Genric : Genric >Base : Base ->() => { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => {}[]; } ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>() => { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x169: () => () => Base[] = function() { return () => [d1, d2]; }; >x169 : () => () => Base[] >Base : Base ->function() { return () => [d1, d2]; } : () => () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>function() { return () => [d1, d2]; } : () => () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x170: () => () => Base[] = function() { return function() { return [d1, d2] }; }; >x170 : () => () => Base[] >Base : Base ->function() { return function() { return [d1, d2] }; } : () => () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return function() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x171: () => () => Base[] = function() { return function named() { return [d1, d2] }; }; >x171 : () => () => Base[] >Base : Base ->function() { return function named() { return [d1, d2] }; } : () => () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function() { return function named() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x172: () => { (): Base[]; } = function() { return () => [d1, d2]; }; >x172 : () => () => Base[] >Base : Base ->function() { return () => [d1, d2]; } : () => () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>function() { return () => [d1, d2]; } : () => () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x173: () => { (): Base[]; } = function() { return function() { return [d1, d2] }; }; >x173 : () => () => Base[] >Base : Base ->function() { return function() { return [d1, d2] }; } : () => () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return function() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x174: () => { (): Base[]; } = function() { return function named() { return [d1, d2] }; }; >x174 : () => () => Base[] >Base : Base ->function() { return function named() { return [d1, d2] }; } : () => () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function() { return function named() { return [d1, d2] }; } : () => () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x175: () => Base[] = function() { return [d1, d2]; }; >x175 : () => Base[] >Base : Base ->function() { return [d1, d2]; } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2]; } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1738,8 +1738,8 @@ var x176: () => Array = function() { return [d1, d2]; }; >x176 : () => Base[] >Array : T[] >Base : Base ->function() { return [d1, d2]; } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2]; } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1747,8 +1747,8 @@ var x177: () => { [n: number]: Base; } = function() { return [d1, d2]; }; >x177 : () => { [x: number]: Base; } >n : number >Base : Base ->function() { return [d1, d2]; } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2]; } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1756,10 +1756,10 @@ var x178: () => {n: Base[]; } = function() { return { n: [d1, d2] }; }; >x178 : () => { n: Base[]; } >n : Base[] >Base : Base ->function() { return { n: [d1, d2] }; } : () => { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>function() { return { n: [d1, d2] }; } : () => { n: (Derived1 | Derived2)[]; } +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1777,12 +1777,12 @@ var x180: () => Genric = function() { return { func: n => { return [d1, d2 >x180 : () => Genric >Genric : Genric >Base : Base ->function() { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => {}[]; } ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>function() { return { func: n => { return [d1, d2]; } }; } : () => { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1790,8 +1790,8 @@ module x181 { var t: () => Base[] = () => [d1, d2]; } >x181 : typeof x181 >t : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1799,8 +1799,8 @@ module x182 { var t: () => Base[] = function() { return [d1, d2] }; } >x182 : typeof x182 >t : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1808,9 +1808,9 @@ module x183 { var t: () => Base[] = function named() { return [d1, d2] }; } >x183 : typeof x183 >t : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1818,8 +1818,8 @@ module x184 { var t: { (): Base[]; } = () => [d1, d2]; } >x184 : typeof x184 >t : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1827,8 +1827,8 @@ module x185 { var t: { (): Base[]; } = function() { return [d1, d2] }; } >x185 : typeof x185 >t : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1836,9 +1836,9 @@ module x186 { var t: { (): Base[]; } = function named() { return [d1, d2] }; } >x186 : typeof x186 >t : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1846,7 +1846,7 @@ module x187 { var t: Base[] = [d1, d2]; } >x187 : typeof x187 >t : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1855,7 +1855,7 @@ module x188 { var t: Array = [d1, d2]; } >t : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1864,7 +1864,7 @@ module x189 { var t: { [n: number]: Base; } = [d1, d2]; } >t : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1873,9 +1873,9 @@ module x190 { var t: {n: Base[]; } = { n: [d1, d2] }; } >t : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1894,11 +1894,11 @@ module x192 { var t: Genric = { func: n => { return [d1, d2]; } }; } >t : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1906,8 +1906,8 @@ module x193 { export var t: () => Base[] = () => [d1, d2]; } >x193 : typeof x193 >t : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1915,8 +1915,8 @@ module x194 { export var t: () => Base[] = function() { return [d1, d2] }; } >x194 : typeof x194 >t : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1924,9 +1924,9 @@ module x195 { export var t: () => Base[] = function named() { return [d1, d2] }; >x195 : typeof x195 >t : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1934,8 +1934,8 @@ module x196 { export var t: { (): Base[]; } = () => [d1, d2]; } >x196 : typeof x196 >t : () => Base[] >Base : Base ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1943,8 +1943,8 @@ module x197 { export var t: { (): Base[]; } = function() { return [d1, d2] }; } >x197 : typeof x197 >t : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1952,9 +1952,9 @@ module x198 { export var t: { (): Base[]; } = function named() { return [d1, d2] >x198 : typeof x198 >t : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1962,7 +1962,7 @@ module x199 { export var t: Base[] = [d1, d2]; } >x199 : typeof x199 >t : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1971,7 +1971,7 @@ module x200 { export var t: Array = [d1, d2]; } >t : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1980,7 +1980,7 @@ module x201 { export var t: { [n: number]: Base; } = [d1, d2]; } >t : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -1989,9 +1989,9 @@ module x202 { export var t: {n: Base[]; } = { n: [d1, d2] }; } >t : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2010,11 +2010,11 @@ module x204 { export var t: Genric = { func: n => { return [d1, d2]; } }; >t : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2022,8 +2022,8 @@ var x206 = <() => Base[]>function() { return [d1, d2] }; >x206 : () => Base[] ><() => Base[]>function() { return [d1, d2] } : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2031,9 +2031,9 @@ var x207 = <() => Base[]>function named() { return [d1, d2] }; >x207 : () => Base[] ><() => Base[]>function named() { return [d1, d2] } : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2041,8 +2041,8 @@ var x209 = <{ (): Base[]; }>function() { return [d1, d2] }; >x209 : () => Base[] ><{ (): Base[]; }>function() { return [d1, d2] } : () => Base[] >Base : Base ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2050,9 +2050,9 @@ var x210 = <{ (): Base[]; }>function named() { return [d1, d2] }; >x210 : () => Base[] ><{ (): Base[]; }>function named() { return [d1, d2] } : () => Base[] >Base : Base ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2060,7 +2060,7 @@ var x211 = [d1, d2]; >x211 : Base[] >[d1, d2] : Base[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2069,7 +2069,7 @@ var x212 = >[d1, d2]; >>[d1, d2] : Base[] >Array : T[] >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2078,7 +2078,7 @@ var x213 = <{ [n: number]: Base; }>[d1, d2]; ><{ [n: number]: Base; }>[d1, d2] : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2087,9 +2087,9 @@ var x214 = <{n: Base[]; } >{ n: [d1, d2] }; ><{n: Base[]; } >{ n: [d1, d2] } : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2098,11 +2098,11 @@ var x216 = >{ func: n => { return [d1, d2]; } }; >>{ func: n => { return [d1, d2]; } } : Genric >Genric : Genric >Base : Base ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2113,8 +2113,8 @@ var x217 = (<() => Base[]>undefined) || function() { return [d1, d2] }; ><() => Base[]>undefined : () => Base[] >Base : Base >undefined : undefined ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2125,9 +2125,9 @@ var x218 = (<() => Base[]>undefined) || function named() { return [d1, d2] }; ><() => Base[]>undefined : () => Base[] >Base : Base >undefined : undefined ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2138,8 +2138,8 @@ var x219 = (<{ (): Base[]; }>undefined) || function() { return [d1, d2] }; ><{ (): Base[]; }>undefined : () => Base[] >Base : Base >undefined : undefined ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2150,9 +2150,9 @@ var x220 = (<{ (): Base[]; }>undefined) || function named() { return [d1, d2] }; ><{ (): Base[]; }>undefined : () => Base[] >Base : Base >undefined : undefined ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2163,7 +2163,7 @@ var x221 = (undefined) || [d1, d2]; >undefined : Base[] >Base : Base >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2175,7 +2175,7 @@ var x222 = (>undefined) || [d1, d2]; >Array : T[] >Base : Base >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2187,7 +2187,7 @@ var x223 = (<{ [n: number]: Base; }>undefined) || [d1, d2]; >n : number >Base : Base >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2199,80 +2199,80 @@ var x224 = (<{n: Base[]; } >undefined) || { n: [d1, d2] }; >n : Base[] >Base : Base >undefined : undefined ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x225: () => Base[]; x225 = () => [d1, d2]; >x225 : () => Base[] >Base : Base ->x225 = () => [d1, d2] : () => Base[] +>x225 = () => [d1, d2] : () => (Derived1 | Derived2)[] >x225 : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x226: () => Base[]; x226 = function() { return [d1, d2] }; >x226 : () => Base[] >Base : Base ->x226 = function() { return [d1, d2] } : () => Base[] +>x226 = function() { return [d1, d2] } : () => (Derived1 | Derived2)[] >x226 : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x227: () => Base[]; x227 = function named() { return [d1, d2] }; >x227 : () => Base[] >Base : Base ->x227 = function named() { return [d1, d2] } : () => Base[] +>x227 = function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] >x227 : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x228: { (): Base[]; }; x228 = () => [d1, d2]; >x228 : () => Base[] >Base : Base ->x228 = () => [d1, d2] : () => Base[] +>x228 = () => [d1, d2] : () => (Derived1 | Derived2)[] >x228 : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x229: { (): Base[]; }; x229 = function() { return [d1, d2] }; >x229 : () => Base[] >Base : Base ->x229 = function() { return [d1, d2] } : () => Base[] +>x229 = function() { return [d1, d2] } : () => (Derived1 | Derived2)[] >x229 : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x230: { (): Base[]; }; x230 = function named() { return [d1, d2] }; >x230 : () => Base[] >Base : Base ->x230 = function named() { return [d1, d2] } : () => Base[] +>x230 = function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] >x230 : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x231: Base[]; x231 = [d1, d2]; >x231 : Base[] >Base : Base ->x231 = [d1, d2] : Base[] +>x231 = [d1, d2] : (Derived1 | Derived2)[] >x231 : Base[] ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2280,9 +2280,9 @@ var x232: Array; x232 = [d1, d2]; >x232 : Base[] >Array : T[] >Base : Base ->x232 = [d1, d2] : Base[] +>x232 = [d1, d2] : (Derived1 | Derived2)[] >x232 : Base[] ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2290,9 +2290,9 @@ var x233: { [n: number]: Base; }; x233 = [d1, d2]; >x233 : { [x: number]: Base; } >n : number >Base : Base ->x233 = [d1, d2] : Base[] +>x233 = [d1, d2] : (Derived1 | Derived2)[] >x233 : { [x: number]: Base; } ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2300,11 +2300,11 @@ var x234: {n: Base[]; } ; x234 = { n: [d1, d2] }; >x234 : { n: Base[]; } >n : Base[] >Base : Base ->x234 = { n: [d1, d2] } : { n: Base[]; } +>x234 = { n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } >x234 : { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2323,13 +2323,13 @@ var x236: Genric; x236 = { func: n => { return [d1, d2]; } }; >x236 : Genric >Genric : Genric >Base : Base ->x236 = { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } +>x236 = { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } >x236 : Genric ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2337,10 +2337,10 @@ var x237: { n: () => Base[]; } = { n: () => [d1, d2] }; >x237 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: () => [d1, d2] } : { n: () => Base[]; } ->n : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>{ n: () => [d1, d2] } : { n: () => (Derived1 | Derived2)[]; } +>n : () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2348,10 +2348,10 @@ var x238: { n: () => Base[]; } = { n: function() { return [d1, d2] } }; >x238 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: function() { return [d1, d2] } } : { n: () => Base[]; } ->n : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>{ n: function() { return [d1, d2] } } : { n: () => (Derived1 | Derived2)[]; } +>n : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2359,11 +2359,11 @@ var x239: { n: () => Base[]; } = { n: function named() { return [d1, d2] } }; >x239 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: function named() { return [d1, d2] } } : { n: () => Base[]; } ->n : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>{ n: function named() { return [d1, d2] } } : { n: () => (Derived1 | Derived2)[]; } +>n : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2371,10 +2371,10 @@ var x240: { n: { (): Base[]; }; } = { n: () => [d1, d2] }; >x240 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: () => [d1, d2] } : { n: () => Base[]; } ->n : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>{ n: () => [d1, d2] } : { n: () => (Derived1 | Derived2)[]; } +>n : () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2382,10 +2382,10 @@ var x241: { n: { (): Base[]; }; } = { n: function() { return [d1, d2] } }; >x241 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: function() { return [d1, d2] } } : { n: () => Base[]; } ->n : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>{ n: function() { return [d1, d2] } } : { n: () => (Derived1 | Derived2)[]; } +>n : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2393,11 +2393,11 @@ var x242: { n: { (): Base[]; }; } = { n: function named() { return [d1, d2] } }; >x242 : { n: () => Base[]; } >n : () => Base[] >Base : Base ->{ n: function named() { return [d1, d2] } } : { n: () => Base[]; } ->n : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>{ n: function named() { return [d1, d2] } } : { n: () => (Derived1 | Derived2)[]; } +>n : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2405,9 +2405,9 @@ var x243: { n: Base[]; } = { n: [d1, d2] }; >x243 : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2416,9 +2416,9 @@ var x244: { n: Array; } = { n: [d1, d2] }; >n : Base[] >Array : T[] >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2427,9 +2427,9 @@ var x245: { n: { [n: number]: Base; }; } = { n: [d1, d2] }; >n : { [x: number]: Base; } >n : number >Base : Base ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2438,11 +2438,11 @@ var x246: { n: {n: Base[]; } ; } = { n: { n: [d1, d2] } }; >n : { n: Base[]; } >n : Base[] >Base : Base ->{ n: { n: [d1, d2] } } : { n: { n: Base[]; }; } ->n : { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: { n: [d1, d2] } } : { n: { n: (Derived1 | Derived2)[]; }; } +>n : { n: (Derived1 | Derived2)[]; } +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2463,49 +2463,49 @@ var x248: { n: Genric; } = { n: { func: n => { return [d1, d2]; } } }; >n : Genric >Genric : Genric >Base : Base ->{ n: { func: n => { return [d1, d2]; } } } : { n: { func: (n: Base[]) => {}[]; }; } ->n : { func: (n: Base[]) => {}[]; } ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ n: { func: n => { return [d1, d2]; } } } : { n: { func: (n: Base[]) => (Derived1 | Derived2)[]; }; } +>n : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x252: { (): Base[]; }[] = [() => [d1, d2]]; ->x252 : { (): Base[]; }[] +>x252 : (() => Base[])[] >Base : Base ->[() => [d1, d2]] : { (): Base[]; }[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>[() => [d1, d2]] : (() => (Derived1 | Derived2)[])[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x253: { (): Base[]; }[] = [function() { return [d1, d2] }]; ->x253 : { (): Base[]; }[] +>x253 : (() => Base[])[] >Base : Base ->[function() { return [d1, d2] }] : { (): Base[]; }[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>[function() { return [d1, d2] }] : (() => (Derived1 | Derived2)[])[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x254: { (): Base[]; }[] = [function named() { return [d1, d2] }]; ->x254 : { (): Base[]; }[] +>x254 : (() => Base[])[] >Base : Base ->[function named() { return [d1, d2] }] : { (): Base[]; }[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>[function named() { return [d1, d2] }] : (() => (Derived1 | Derived2)[])[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x255: Base[][] = [[d1, d2]]; >x255 : Base[][] >Base : Base ->[[d1, d2]] : Base[][] ->[d1, d2] : Base[] +>[[d1, d2]] : (Derived1 | Derived2)[][] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2513,8 +2513,8 @@ var x256: Array[] = [[d1, d2]]; >x256 : Base[][] >Array : T[] >Base : Base ->[[d1, d2]] : Base[][] ->[d1, d2] : Base[] +>[[d1, d2]] : (Derived1 | Derived2)[][] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2522,8 +2522,8 @@ var x257: { [n: number]: Base; }[] = [[d1, d2]]; >x257 : { [x: number]: Base; }[] >n : number >Base : Base ->[[d1, d2]] : { [x: number]: Base; }[] ->[d1, d2] : Base[] +>[[d1, d2]] : (Derived1 | Derived2)[][] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2531,10 +2531,10 @@ var x258: {n: Base[]; } [] = [{ n: [d1, d2] }]; >x258 : { n: Base[]; }[] >n : Base[] >Base : Base ->[{ n: [d1, d2] }] : { n: Base[]; }[] ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>[{ n: [d1, d2] }] : { n: (Derived1 | Derived2)[]; }[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2542,21 +2542,21 @@ var x260: Genric[] = [{ func: n => { return [d1, d2]; } }]; >x260 : Genric[] >Genric : Genric >Base : Base ->[{ func: n => { return [d1, d2]; } }] : Genric[] ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>[{ func: n => { return [d1, d2]; } }] : { func: (n: Base[]) => (Derived1 | Derived2)[]; }[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x261: () => Base[] = function() { return [d1, d2] } || undefined; >x261 : () => Base[] >Base : Base ->function() { return [d1, d2] } || undefined : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } || undefined : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2564,10 +2564,10 @@ var x261: () => Base[] = function() { return [d1, d2] } || undefined; var x262: () => Base[] = function named() { return [d1, d2] } || undefined; >x262 : () => Base[] >Base : Base ->function named() { return [d1, d2] } || undefined : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } || undefined : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2575,9 +2575,9 @@ var x262: () => Base[] = function named() { return [d1, d2] } || undefined; var x263: { (): Base[]; } = function() { return [d1, d2] } || undefined; >x263 : () => Base[] >Base : Base ->function() { return [d1, d2] } || undefined : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } || undefined : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2585,10 +2585,10 @@ var x263: { (): Base[]; } = function() { return [d1, d2] } || undefined; var x264: { (): Base[]; } = function named() { return [d1, d2] } || undefined; >x264 : () => Base[] >Base : Base ->function named() { return [d1, d2] } || undefined : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } || undefined : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2596,8 +2596,8 @@ var x264: { (): Base[]; } = function named() { return [d1, d2] } || undefined; var x265: Base[] = [d1, d2] || undefined; >x265 : Base[] >Base : Base ->[d1, d2] || undefined : Base[] ->[d1, d2] : Base[] +>[d1, d2] || undefined : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2606,8 +2606,8 @@ var x266: Array = [d1, d2] || undefined; >x266 : Base[] >Array : T[] >Base : Base ->[d1, d2] || undefined : Base[] ->[d1, d2] : Base[] +>[d1, d2] || undefined : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2616,8 +2616,8 @@ var x267: { [n: number]: Base; } = [d1, d2] || undefined; >x267 : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] || undefined : { [x: number]: Base; } ->[d1, d2] : Base[] +>[d1, d2] || undefined : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2626,10 +2626,10 @@ var x268: {n: Base[]; } = { n: [d1, d2] } || undefined; >x268 : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } || undefined : { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } || undefined : { n: (Derived1 | Derived2)[]; } +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -2637,51 +2637,51 @@ var x268: {n: Base[]; } = { n: [d1, d2] } || undefined; var x269: () => Base[] = undefined || function() { return [d1, d2] }; >x269 : () => Base[] >Base : Base ->undefined || function() { return [d1, d2] } : () => Base[] +>undefined || function() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x270: () => Base[] = undefined || function named() { return [d1, d2] }; >x270 : () => Base[] >Base : Base ->undefined || function named() { return [d1, d2] } : () => Base[] +>undefined || function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x271: { (): Base[]; } = undefined || function() { return [d1, d2] }; >x271 : () => Base[] >Base : Base ->undefined || function() { return [d1, d2] } : () => Base[] +>undefined || function() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x272: { (): Base[]; } = undefined || function named() { return [d1, d2] }; >x272 : () => Base[] >Base : Base ->undefined || function named() { return [d1, d2] } : () => Base[] +>undefined || function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x273: Base[] = undefined || [d1, d2]; >x273 : Base[] >Base : Base ->undefined || [d1, d2] : Base[] +>undefined || [d1, d2] : (Derived1 | Derived2)[] >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2689,9 +2689,9 @@ var x274: Array = undefined || [d1, d2]; >x274 : Base[] >Array : T[] >Base : Base ->undefined || [d1, d2] : Base[] +>undefined || [d1, d2] : (Derived1 | Derived2)[] >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2699,9 +2699,9 @@ var x275: { [n: number]: Base; } = undefined || [d1, d2]; >x275 : { [x: number]: Base; } >n : number >Base : Base ->undefined || [d1, d2] : { [x: number]: Base; } +>undefined || [d1, d2] : (Derived1 | Derived2)[] >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2709,78 +2709,78 @@ var x276: {n: Base[]; } = undefined || { n: [d1, d2] }; >x276 : { n: Base[]; } >n : Base[] >Base : Base ->undefined || { n: [d1, d2] } : { n: Base[]; } +>undefined || { n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } >undefined : undefined ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x277: () => Base[] = function() { return [d1, d2] } || function() { return [d1, d2] }; >x277 : () => Base[] >Base : Base ->function() { return [d1, d2] } || function() { return [d1, d2] } : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } || function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x278: () => Base[] = function named() { return [d1, d2] } || function named() { return [d1, d2] }; >x278 : () => Base[] >Base : Base ->function named() { return [d1, d2] } || function named() { return [d1, d2] } : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } || function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x279: { (): Base[]; } = function() { return [d1, d2] } || function() { return [d1, d2] }; >x279 : () => Base[] >Base : Base ->function() { return [d1, d2] } || function() { return [d1, d2] } : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } || function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x280: { (): Base[]; } = function named() { return [d1, d2] } || function named() { return [d1, d2] }; >x280 : () => Base[] >Base : Base ->function named() { return [d1, d2] } || function named() { return [d1, d2] } : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } || function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x281: Base[] = [d1, d2] || [d1, d2]; >x281 : Base[] >Base : Base ->[d1, d2] || [d1, d2] : Base[] ->[d1, d2] : Base[] +>[d1, d2] || [d1, d2] : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2788,11 +2788,11 @@ var x282: Array = [d1, d2] || [d1, d2]; >x282 : Base[] >Array : T[] >Base : Base ->[d1, d2] || [d1, d2] : Base[] ->[d1, d2] : Base[] +>[d1, d2] || [d1, d2] : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2800,11 +2800,11 @@ var x283: { [n: number]: Base; } = [d1, d2] || [d1, d2]; >x283 : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] || [d1, d2] : { [x: number]: Base; } ->[d1, d2] : Base[] +>[d1, d2] || [d1, d2] : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2812,108 +2812,108 @@ var x284: {n: Base[]; } = { n: [d1, d2] } || { n: [d1, d2] }; >x284 : { n: Base[]; } >n : Base[] >Base : Base ->{ n: [d1, d2] } || { n: [d1, d2] } : { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } || { n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x285: () => Base[] = true ? () => [d1, d2] : () => [d1, d2]; >x285 : () => Base[] >Base : Base ->true ? () => [d1, d2] : () => [d1, d2] : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>true ? () => [d1, d2] : () => [d1, d2] : () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x286: () => Base[] = true ? function() { return [d1, d2] } : function() { return [d1, d2] }; >x286 : () => Base[] >Base : Base ->true ? function() { return [d1, d2] } : function() { return [d1, d2] } : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>true ? function() { return [d1, d2] } : function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x287: () => Base[] = true ? function named() { return [d1, d2] } : function named() { return [d1, d2] }; >x287 : () => Base[] >Base : Base ->true ? function named() { return [d1, d2] } : function named() { return [d1, d2] } : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>true ? function named() { return [d1, d2] } : function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x288: { (): Base[]; } = true ? () => [d1, d2] : () => [d1, d2]; >x288 : () => Base[] >Base : Base ->true ? () => [d1, d2] : () => [d1, d2] : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>true ? () => [d1, d2] : () => [d1, d2] : () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x289: { (): Base[]; } = true ? function() { return [d1, d2] } : function() { return [d1, d2] }; >x289 : () => Base[] >Base : Base ->true ? function() { return [d1, d2] } : function() { return [d1, d2] } : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>true ? function() { return [d1, d2] } : function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x290: { (): Base[]; } = true ? function named() { return [d1, d2] } : function named() { return [d1, d2] }; >x290 : () => Base[] >Base : Base ->true ? function named() { return [d1, d2] } : function named() { return [d1, d2] } : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>true ? function named() { return [d1, d2] } : function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x291: Base[] = true ? [d1, d2] : [d1, d2]; >x291 : Base[] >Base : Base ->true ? [d1, d2] : [d1, d2] : Base[] ->[d1, d2] : Base[] +>true ? [d1, d2] : [d1, d2] : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2921,11 +2921,11 @@ var x292: Array = true ? [d1, d2] : [d1, d2]; >x292 : Base[] >Array : T[] >Base : Base ->true ? [d1, d2] : [d1, d2] : Base[] ->[d1, d2] : Base[] +>true ? [d1, d2] : [d1, d2] : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2933,11 +2933,11 @@ var x293: { [n: number]: Base; } = true ? [d1, d2] : [d1, d2]; >x293 : { [x: number]: Base; } >n : number >Base : Base ->true ? [d1, d2] : [d1, d2] : { [x: number]: Base; } ->[d1, d2] : Base[] +>true ? [d1, d2] : [d1, d2] : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2945,15 +2945,15 @@ var x294: {n: Base[]; } = true ? { n: [d1, d2] } : { n: [d1, d2] }; >x294 : { n: Base[]; } >n : Base[] >Base : Base ->true ? { n: [d1, d2] } : { n: [d1, d2] } : { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>true ? { n: [d1, d2] } : { n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -2961,7 +2961,7 @@ var x295: (s: Base[]) => any = true ? n => { var n: Base[]; return null; } : n = >x295 : (s: Base[]) => any >s : Base[] >Base : Base ->true ? n => { var n: Base[]; return null; } : n => { var n: Base[]; return null; } : (s: Base[]) => any +>true ? n => { var n: Base[]; return null; } : n => { var n: Base[]; return null; } : (n: Base[]) => any >n => { var n: Base[]; return null; } : (n: Base[]) => any >n : Base[] >n : Base[] @@ -2975,90 +2975,90 @@ var x296: Genric = true ? { func: n => { return [d1, d2]; } } : { func: n >x296 : Genric >Genric : Genric >Base : Base ->true ? { func: n => { return [d1, d2]; } } : { func: n => { return [d1, d2]; } } : Genric ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>true ? { func: n => { return [d1, d2]; } } : { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x297: () => Base[] = true ? undefined : () => [d1, d2]; >x297 : () => Base[] >Base : Base ->true ? undefined : () => [d1, d2] : () => Base[] +>true ? undefined : () => [d1, d2] : () => (Derived1 | Derived2)[] >undefined : undefined ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x298: () => Base[] = true ? undefined : function() { return [d1, d2] }; >x298 : () => Base[] >Base : Base ->true ? undefined : function() { return [d1, d2] } : () => Base[] +>true ? undefined : function() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x299: () => Base[] = true ? undefined : function named() { return [d1, d2] }; >x299 : () => Base[] >Base : Base ->true ? undefined : function named() { return [d1, d2] } : () => Base[] +>true ? undefined : function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x300: { (): Base[]; } = true ? undefined : () => [d1, d2]; >x300 : () => Base[] >Base : Base ->true ? undefined : () => [d1, d2] : () => Base[] +>true ? undefined : () => [d1, d2] : () => (Derived1 | Derived2)[] >undefined : undefined ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x301: { (): Base[]; } = true ? undefined : function() { return [d1, d2] }; >x301 : () => Base[] >Base : Base ->true ? undefined : function() { return [d1, d2] } : () => Base[] +>true ? undefined : function() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x302: { (): Base[]; } = true ? undefined : function named() { return [d1, d2] }; >x302 : () => Base[] >Base : Base ->true ? undefined : function named() { return [d1, d2] } : () => Base[] +>true ? undefined : function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] >undefined : undefined ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x303: Base[] = true ? undefined : [d1, d2]; >x303 : Base[] >Base : Base ->true ? undefined : [d1, d2] : Base[] +>true ? undefined : [d1, d2] : (Derived1 | Derived2)[] >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3066,9 +3066,9 @@ var x304: Array = true ? undefined : [d1, d2]; >x304 : Base[] >Array : T[] >Base : Base ->true ? undefined : [d1, d2] : Base[] +>true ? undefined : [d1, d2] : (Derived1 | Derived2)[] >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3076,9 +3076,9 @@ var x305: { [n: number]: Base; } = true ? undefined : [d1, d2]; >x305 : { [x: number]: Base; } >n : number >Base : Base ->true ? undefined : [d1, d2] : { [x: number]: Base; } +>true ? undefined : [d1, d2] : (Derived1 | Derived2)[] >undefined : undefined ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3086,11 +3086,11 @@ var x306: {n: Base[]; } = true ? undefined : { n: [d1, d2] }; >x306 : { n: Base[]; } >n : Base[] >Base : Base ->true ? undefined : { n: [d1, d2] } : { n: Base[]; } +>true ? undefined : { n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } >undefined : undefined ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3098,7 +3098,7 @@ var x307: (s: Base[]) => any = true ? undefined : n => { var n: Base[]; return n >x307 : (s: Base[]) => any >s : Base[] >Base : Base ->true ? undefined : n => { var n: Base[]; return null; } : (s: Base[]) => any +>true ? undefined : n => { var n: Base[]; return null; } : (n: Base[]) => any >undefined : undefined >n => { var n: Base[]; return null; } : (n: Base[]) => any >n : Base[] @@ -3109,22 +3109,22 @@ var x308: Genric = true ? undefined : { func: n => { return [d1, d2]; } }; >x308 : Genric >Genric : Genric >Base : Base ->true ? undefined : { func: n => { return [d1, d2]; } } : Genric +>true ? undefined : { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } >undefined : undefined ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 var x309: () => Base[] = true ? () => [d1, d2] : undefined; >x309 : () => Base[] >Base : Base ->true ? () => [d1, d2] : undefined : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>true ? () => [d1, d2] : undefined : () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3132,9 +3132,9 @@ var x309: () => Base[] = true ? () => [d1, d2] : undefined; var x310: () => Base[] = true ? function() { return [d1, d2] } : undefined; >x310 : () => Base[] >Base : Base ->true ? function() { return [d1, d2] } : undefined : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>true ? function() { return [d1, d2] } : undefined : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3142,10 +3142,10 @@ var x310: () => Base[] = true ? function() { return [d1, d2] } : undefined; var x311: () => Base[] = true ? function named() { return [d1, d2] } : undefined; >x311 : () => Base[] >Base : Base ->true ? function named() { return [d1, d2] } : undefined : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>true ? function named() { return [d1, d2] } : undefined : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3153,9 +3153,9 @@ var x311: () => Base[] = true ? function named() { return [d1, d2] } : undefined var x312: { (): Base[]; } = true ? () => [d1, d2] : undefined; >x312 : () => Base[] >Base : Base ->true ? () => [d1, d2] : undefined : () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>true ? () => [d1, d2] : undefined : () => (Derived1 | Derived2)[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3163,9 +3163,9 @@ var x312: { (): Base[]; } = true ? () => [d1, d2] : undefined; var x313: { (): Base[]; } = true ? function() { return [d1, d2] } : undefined; >x313 : () => Base[] >Base : Base ->true ? function() { return [d1, d2] } : undefined : () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>true ? function() { return [d1, d2] } : undefined : () => (Derived1 | Derived2)[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3173,10 +3173,10 @@ var x313: { (): Base[]; } = true ? function() { return [d1, d2] } : undefined; var x314: { (): Base[]; } = true ? function named() { return [d1, d2] } : undefined; >x314 : () => Base[] >Base : Base ->true ? function named() { return [d1, d2] } : undefined : () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>true ? function named() { return [d1, d2] } : undefined : () => (Derived1 | Derived2)[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3184,8 +3184,8 @@ var x314: { (): Base[]; } = true ? function named() { return [d1, d2] } : undefi var x315: Base[] = true ? [d1, d2] : undefined; >x315 : Base[] >Base : Base ->true ? [d1, d2] : undefined : Base[] ->[d1, d2] : Base[] +>true ? [d1, d2] : undefined : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3194,8 +3194,8 @@ var x316: Array = true ? [d1, d2] : undefined; >x316 : Base[] >Array : T[] >Base : Base ->true ? [d1, d2] : undefined : Base[] ->[d1, d2] : Base[] +>true ? [d1, d2] : undefined : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3204,8 +3204,8 @@ var x317: { [n: number]: Base; } = true ? [d1, d2] : undefined; >x317 : { [x: number]: Base; } >n : number >Base : Base ->true ? [d1, d2] : undefined : { [x: number]: Base; } ->[d1, d2] : Base[] +>true ? [d1, d2] : undefined : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3214,10 +3214,10 @@ var x318: {n: Base[]; } = true ? { n: [d1, d2] } : undefined; >x318 : { n: Base[]; } >n : Base[] >Base : Base ->true ? { n: [d1, d2] } : undefined : { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>true ? { n: [d1, d2] } : undefined : { n: (Derived1 | Derived2)[]; } +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3226,7 +3226,7 @@ var x319: (s: Base[]) => any = true ? n => { var n: Base[]; return null; } : und >x319 : (s: Base[]) => any >s : Base[] >Base : Base ->true ? n => { var n: Base[]; return null; } : undefined : (s: Base[]) => any +>true ? n => { var n: Base[]; return null; } : undefined : (n: Base[]) => any >n => { var n: Base[]; return null; } : (n: Base[]) => any >n : Base[] >n : Base[] @@ -3237,12 +3237,12 @@ var x320: Genric = true ? { func: n => { return [d1, d2]; } } : undefined; >x320 : Genric >Genric : Genric >Base : Base ->true ? { func: n => { return [d1, d2]; } } : undefined : Genric ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>true ? { func: n => { return [d1, d2]; } } : undefined : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 >undefined : undefined @@ -3253,8 +3253,8 @@ function x321(n: () => Base[]) { }; x321(() => [d1, d2]); >Base : Base >x321(() => [d1, d2]) : void >x321 : (n: () => Base[]) => void ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3264,8 +3264,8 @@ function x322(n: () => Base[]) { }; x322(function() { return [d1, d2] }); >Base : Base >x322(function() { return [d1, d2] }) : void >x322 : (n: () => Base[]) => void ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3275,9 +3275,9 @@ function x323(n: () => Base[]) { }; x323(function named() { return [d1, d2] }); >Base : Base >x323(function named() { return [d1, d2] }) : void >x323 : (n: () => Base[]) => void ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3287,8 +3287,8 @@ function x324(n: { (): Base[]; }) { }; x324(() => [d1, d2]); >Base : Base >x324(() => [d1, d2]) : void >x324 : (n: () => Base[]) => void ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3298,8 +3298,8 @@ function x325(n: { (): Base[]; }) { }; x325(function() { return [d1, d2] }); >Base : Base >x325(function() { return [d1, d2] }) : void >x325 : (n: () => Base[]) => void ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3309,9 +3309,9 @@ function x326(n: { (): Base[]; }) { }; x326(function named() { return [d1, d2] } >Base : Base >x326(function named() { return [d1, d2] }) : void >x326 : (n: () => Base[]) => void ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3321,7 +3321,7 @@ function x327(n: Base[]) { }; x327([d1, d2]); >Base : Base >x327([d1, d2]) : void >x327 : (n: Base[]) => void ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3332,7 +3332,7 @@ function x328(n: Array) { }; x328([d1, d2]); >Base : Base >x328([d1, d2]) : void >x328 : (n: Base[]) => void ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3343,7 +3343,7 @@ function x329(n: { [n: number]: Base; }) { }; x329([d1, d2]); >Base : Base >x329([d1, d2]) : void >x329 : (n: { [x: number]: Base; }) => void ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3354,9 +3354,9 @@ function x330(n: {n: Base[]; } ) { }; x330({ n: [d1, d2] }); >Base : Base >x330({ n: [d1, d2] }) : void >x330 : (n: { n: Base[]; }) => void ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3379,11 +3379,11 @@ function x332(n: Genric) { }; x332({ func: n => { return [d1, d2]; } }); >Base : Base >x332({ func: n => { return [d1, d2]; } }) : void >x332 : (n: Genric) => void ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3395,8 +3395,8 @@ var x333 = (n: () => Base[]) => n; x333(() => [d1, d2]); >n : () => Base[] >x333(() => [d1, d2]) : () => Base[] >x333 : (n: () => Base[]) => () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3408,8 +3408,8 @@ var x334 = (n: () => Base[]) => n; x334(function() { return [d1, d2] }); >n : () => Base[] >x334(function() { return [d1, d2] }) : () => Base[] >x334 : (n: () => Base[]) => () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3421,9 +3421,9 @@ var x335 = (n: () => Base[]) => n; x335(function named() { return [d1, d2] }); >n : () => Base[] >x335(function named() { return [d1, d2] }) : () => Base[] >x335 : (n: () => Base[]) => () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3435,8 +3435,8 @@ var x336 = (n: { (): Base[]; }) => n; x336(() => [d1, d2]); >n : () => Base[] >x336(() => [d1, d2]) : () => Base[] >x336 : (n: () => Base[]) => () => Base[] ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3448,8 +3448,8 @@ var x337 = (n: { (): Base[]; }) => n; x337(function() { return [d1, d2] }); >n : () => Base[] >x337(function() { return [d1, d2] }) : () => Base[] >x337 : (n: () => Base[]) => () => Base[] ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3461,9 +3461,9 @@ var x338 = (n: { (): Base[]; }) => n; x338(function named() { return [d1, d2] }) >n : () => Base[] >x338(function named() { return [d1, d2] }) : () => Base[] >x338 : (n: () => Base[]) => () => Base[] ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3475,7 +3475,7 @@ var x339 = (n: Base[]) => n; x339([d1, d2]); >n : Base[] >x339([d1, d2]) : Base[] >x339 : (n: Base[]) => Base[] ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3488,7 +3488,7 @@ var x340 = (n: Array) => n; x340([d1, d2]); >n : Base[] >x340([d1, d2]) : Base[] >x340 : (n: Base[]) => Base[] ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3501,7 +3501,7 @@ var x341 = (n: { [n: number]: Base; }) => n; x341([d1, d2]); >n : { [x: number]: Base; } >x341([d1, d2]) : { [x: number]: Base; } >x341 : (n: { [x: number]: Base; }) => { [x: number]: Base; } ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3514,9 +3514,9 @@ var x342 = (n: {n: Base[]; } ) => n; x342({ n: [d1, d2] }); >n : { n: Base[]; } >x342({ n: [d1, d2] }) : { n: Base[]; } >x342 : (n: { n: Base[]; }) => { n: Base[]; } ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3543,11 +3543,11 @@ var x344 = (n: Genric) => n; x344({ func: n => { return [d1, d2]; } }); >n : Genric >x344({ func: n => { return [d1, d2]; } }) : Genric >x344 : (n: Genric) => Genric ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3558,8 +3558,8 @@ var x345 = function(n: () => Base[]) { }; x345(() => [d1, d2]); >Base : Base >x345(() => [d1, d2]) : void >x345 : (n: () => Base[]) => void ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3570,8 +3570,8 @@ var x346 = function(n: () => Base[]) { }; x346(function() { return [d1, d2] }); >Base : Base >x346(function() { return [d1, d2] }) : void >x346 : (n: () => Base[]) => void ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3582,9 +3582,9 @@ var x347 = function(n: () => Base[]) { }; x347(function named() { return [d1, d2 >Base : Base >x347(function named() { return [d1, d2] }) : void >x347 : (n: () => Base[]) => void ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3595,8 +3595,8 @@ var x348 = function(n: { (): Base[]; }) { }; x348(() => [d1, d2]); >Base : Base >x348(() => [d1, d2]) : void >x348 : (n: () => Base[]) => void ->() => [d1, d2] : () => Base[] ->[d1, d2] : Base[] +>() => [d1, d2] : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3607,8 +3607,8 @@ var x349 = function(n: { (): Base[]; }) { }; x349(function() { return [d1, d2] } >Base : Base >x349(function() { return [d1, d2] }) : void >x349 : (n: () => Base[]) => void ->function() { return [d1, d2] } : () => Base[] ->[d1, d2] : Base[] +>function() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3619,9 +3619,9 @@ var x350 = function(n: { (): Base[]; }) { }; x350(function named() { return [d1, >Base : Base >x350(function named() { return [d1, d2] }) : void >x350 : (n: () => Base[]) => void ->function named() { return [d1, d2] } : () => Base[] ->named : () => Base[] ->[d1, d2] : Base[] +>function named() { return [d1, d2] } : () => (Derived1 | Derived2)[] +>named : () => (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3632,7 +3632,7 @@ var x351 = function(n: Base[]) { }; x351([d1, d2]); >Base : Base >x351([d1, d2]) : void >x351 : (n: Base[]) => void ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3644,7 +3644,7 @@ var x352 = function(n: Array) { }; x352([d1, d2]); >Base : Base >x352([d1, d2]) : void >x352 : (n: Base[]) => void ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3656,7 +3656,7 @@ var x353 = function(n: { [n: number]: Base; }) { }; x353([d1, d2]); >Base : Base >x353([d1, d2]) : void >x353 : (n: { [x: number]: Base; }) => void ->[d1, d2] : Base[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3668,9 +3668,9 @@ var x354 = function(n: {n: Base[]; } ) { }; x354({ n: [d1, d2] }); >Base : Base >x354({ n: [d1, d2] }) : void >x354 : (n: { n: Base[]; }) => void ->{ n: [d1, d2] } : { n: Base[]; } ->n : Base[] ->[d1, d2] : Base[] +>{ n: [d1, d2] } : { n: (Derived1 | Derived2)[]; } +>n : (Derived1 | Derived2)[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 @@ -3695,11 +3695,11 @@ var x356 = function(n: Genric) { }; x356({ func: n => { return [d1, d2]; } >Base : Base >x356({ func: n => { return [d1, d2]; } }) : void >x356 : (n: Genric) => void ->{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => {}[]; } ->func : (n: Base[]) => {}[] ->n => { return [d1, d2]; } : (n: Base[]) => {}[] +>{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => (Derived1 | Derived2)[]; } +>func : (n: Base[]) => (Derived1 | Derived2)[] +>n => { return [d1, d2]; } : (n: Base[]) => (Derived1 | Derived2)[] >n : Base[] ->[d1, d2] : {}[] +>[d1, d2] : (Derived1 | Derived2)[] >d1 : Derived1 >d2 : Derived2 diff --git a/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types b/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types index 2ac2483c405..768b8846880 100644 --- a/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types +++ b/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types @@ -49,7 +49,7 @@ _.all([true, 1, null, 'yes'], _.identity); >_.all : (list: T[], iterator?: Underscore.Iterator, context?: any) => boolean >_ : Underscore.Static >all : (list: T[], iterator?: Underscore.Iterator, context?: any) => boolean ->[true, 1, null, 'yes'] : {}[] +>[true, 1, null, 'yes'] : (string | number | boolean)[] >_.identity : (value: T) => T >_ : Underscore.Static >identity : (value: T) => T diff --git a/tests/baselines/reference/genericArray0.types b/tests/baselines/reference/genericArray0.types index 80a9d5199bd..bf0155bb9ba 100644 --- a/tests/baselines/reference/genericArray0.types +++ b/tests/baselines/reference/genericArray0.types @@ -16,6 +16,6 @@ function map() { var ys: U[] = []; >ys : U[] >U : U ->[] : U[] +>[] : undefined[] } diff --git a/tests/baselines/reference/genericBaseClassLiteralProperty2.types b/tests/baselines/reference/genericBaseClassLiteralProperty2.types index b2d156e3c16..9caa45b8b8f 100644 --- a/tests/baselines/reference/genericBaseClassLiteralProperty2.types +++ b/tests/baselines/reference/genericBaseClassLiteralProperty2.types @@ -14,11 +14,11 @@ class BaseCollection2 { constructor() { this._itemsByKey = {}; ->this._itemsByKey = {} : { [x: string]: TItem; } +>this._itemsByKey = {} : { [x: string]: undefined; } >this._itemsByKey : { [x: string]: TItem; } >this : BaseCollection2 >_itemsByKey : { [x: string]: TItem; } ->{} : { [x: string]: TItem; } +>{} : { [x: string]: undefined; } } } diff --git a/tests/baselines/reference/genericCallWithArrayLiteralArgs.types b/tests/baselines/reference/genericCallWithArrayLiteralArgs.types index c79efb0792c..f4965940436 100644 --- a/tests/baselines/reference/genericCallWithArrayLiteralArgs.types +++ b/tests/baselines/reference/genericCallWithArrayLiteralArgs.types @@ -25,36 +25,36 @@ var ra = foo([1, 2]); // any[] >ra : any[] >foo([1, 2]) : any[] >foo : (t: T) => T ->[1, 2] : any[] +>[1, 2] : number[] var r2 = foo([]); // any[] >r2 : any[] >foo([]) : any[] >foo : (t: T) => T ->[] : any[] +>[] : undefined[] var r3 = foo([]); // number[] >r3 : number[] >foo([]) : number[] >foo : (t: T) => T ->[] : number[] +>[] : undefined[] var r4 = foo([1, '']); // {}[] ->r4 : {}[] ->foo([1, '']) : {}[] +>r4 : (string | number)[] +>foo([1, '']) : (string | number)[] >foo : (t: T) => T ->[1, ''] : {}[] +>[1, ''] : (string | number)[] var r5 = foo([1, '']); // any[] >r5 : any[] >foo([1, '']) : any[] >foo : (t: T) => T ->[1, ''] : any[] +>[1, ''] : (string | number)[] var r6 = foo([1, '']); // Object[] >r6 : Object[] >foo([1, '']) : Object[] >foo : (t: T) => T >Object : Object ->[1, ''] : Object[] +>[1, ''] : (string | number)[] diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt b/tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt new file mode 100644 index 00000000000..36a22868333 --- /dev/null +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt @@ -0,0 +1,58 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(26,18): error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(30,15): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(33,15): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(34,16): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(35,23): error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts (5 errors) ==== + // Generic functions used as arguments for function typed parameters are not used to make inferences from + // Using function arguments, no errors expected + + function foo(x: (a: T) => T) { + return x(null); + } + + var r = foo((x: U) => ''); // {} + var r2 = foo((x: U) => ''); // string + var r3 = foo(x => ''); // {} + + function foo2(x: T, cb: (a: T) => U) { + return cb(x); + } + + var r4 = foo2(1, function (a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions + var r5 = foo2(1, (a) => ''); // string + var r6 = foo2('', (a: Z) => 1); + + function foo3(x: T, cb: (a: T) => U, y: U) { + return cb(x); + } + + var r7 = foo3(1, (a: Z) => '', ''); // string + + var r8 = foo3(1, function (a) { return '' }, 1); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + var r9 = foo3(1, (a) => '', ''); // string + + function other(t: T, u: U) { + var r10 = foo2(1, (x: T) => ''); // error + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r10 = foo2(1, (x) => ''); // string + + var r11 = foo3(1, (x: T) => '', ''); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r11b = foo3(1, (x: T) => '', 1); // error + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r12 = foo3(1, function (a) { return '' }, 1); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + } \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments.js b/tests/baselines/reference/genericCallWithFunctionTypedArguments.js index 8e844cfbc5a..fed1d4ca990 100644 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments.js +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments.js @@ -24,16 +24,16 @@ function foo3(x: T, cb: (a: T) => U, y: U) { var r7 = foo3(1, (a: Z) => '', ''); // string -var r8 = foo3(1, function (a) { return '' }, 1); // {} +var r8 = foo3(1, function (a) { return '' }, 1); // error var r9 = foo3(1, (a) => '', ''); // string function other(t: T, u: U) { - var r10 = foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made + var r10 = foo2(1, (x: T) => ''); // error var r10 = foo2(1, (x) => ''); // string - var r11 = foo3(1, (x: T) => '', ''); // string - var r11b = foo3(1, (x: T) => '', 1); // {} - var r12 = foo3(1, function (a) { return '' }, 1); // {} + var r11 = foo3(1, (x: T) => '', ''); // error + var r11b = foo3(1, (x: T) => '', 1); // error + var r12 = foo3(1, function (a) { return '' }, 1); // error } //// [genericCallWithFunctionTypedArguments.js] @@ -59,14 +59,14 @@ function foo3(x, cb, y) { var r7 = foo3(1, function (a) { return ''; }, ''); // string var r8 = foo3(1, function (a) { return ''; -}, 1); // {} +}, 1); // error var r9 = foo3(1, function (a) { return ''; }, ''); // string function other(t, u) { - var r10 = foo2(1, function (x) { return ''; }); // string, non-generic signature allows inferences to be made + var r10 = foo2(1, function (x) { return ''; }); // error var r10 = foo2(1, function (x) { return ''; }); // string - var r11 = foo3(1, function (x) { return ''; }, ''); // string - var r11b = foo3(1, function (x) { return ''; }, 1); // {} + var r11 = foo3(1, function (x) { return ''; }, ''); // error + var r11b = foo3(1, function (x) { return ''; }, 1); // error var r12 = foo3(1, function (a) { return ''; - }, 1); // {} + }, 1); // error } diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments.types b/tests/baselines/reference/genericCallWithFunctionTypedArguments.types deleted file mode 100644 index 2d3b234d0e1..00000000000 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments.types +++ /dev/null @@ -1,173 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts === -// Generic functions used as arguments for function typed parameters are not used to make inferences from -// Using function arguments, no errors expected - -function foo(x: (a: T) => T) { ->foo : (x: (a: T) => T) => T ->T : T ->x : (a: T) => T ->a : T ->T : T ->T : T - - return x(null); ->x(null) : T ->x : (a: T) => T -} - -var r = foo((x: U) => ''); // {} ->r : {} ->foo((x: U) => '') : {} ->foo : (x: (a: T) => T) => T ->(x: U) => '' : (x: U) => string ->U : U ->x : U ->U : U - -var r2 = foo((x: U) => ''); // string ->r2 : string ->foo((x: U) => '') : string ->foo : (x: (a: T) => T) => T ->(x: U) => '' : (x: U) => string ->U : U ->x : U ->U : U - -var r3 = foo(x => ''); // {} ->r3 : {} ->foo(x => '') : {} ->foo : (x: (a: T) => T) => T ->x => '' : (x: {}) => string ->x : {} - -function foo2(x: T, cb: (a: T) => U) { ->foo2 : (x: T, cb: (a: T) => U) => U ->T : T ->U : U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T -} - -var r4 = foo2(1, function (a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions ->r4 : string ->foo2(1, function (a: Z) { return '' }) : string ->foo2 : (x: T, cb: (a: T) => U) => U ->function (a: Z) { return '' } : (a: Z) => string ->Z : Z ->a : Z ->Z : Z - -var r5 = foo2(1, (a) => ''); // string ->r5 : string ->foo2(1, (a) => '') : string ->foo2 : (x: T, cb: (a: T) => U) => U ->(a) => '' : (a: number) => string ->a : number - -var r6 = foo2('', (a: Z) => 1); ->r6 : number ->foo2('', (a: Z) => 1) : number ->foo2 : (x: T, cb: (a: T) => U) => U ->(a: Z) => 1 : (a: Z) => number ->Z : Z ->a : Z ->Z : Z - -function foo3(x: T, cb: (a: T) => U, y: U) { ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->T : T ->U : U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U ->y : U ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T -} - -var r7 = foo3(1, (a: Z) => '', ''); // string ->r7 : string ->foo3(1, (a: Z) => '', '') : string ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(a: Z) => '' : (a: Z) => string ->Z : Z ->a : Z ->Z : Z - -var r8 = foo3(1, function (a) { return '' }, 1); // {} ->r8 : {} ->foo3(1, function (a) { return '' }, 1) : {} ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->function (a) { return '' } : (a: number) => string ->a : number - -var r9 = foo3(1, (a) => '', ''); // string ->r9 : string ->foo3(1, (a) => '', '') : string ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(a) => '' : (a: number) => string ->a : number - -function other(t: T, u: U) { ->other : (t: T, u: U) => void ->T : T ->U : U ->t : T ->T : T ->u : U ->U : U - - var r10 = foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made ->r10 : string ->foo2(1, (x: T) => '') : string ->foo2 : (x: T, cb: (a: T) => U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r10 = foo2(1, (x) => ''); // string ->r10 : string ->foo2(1, (x) => '') : string ->foo2 : (x: T, cb: (a: T) => U) => U ->(x) => '' : (x: number) => string ->x : number - - var r11 = foo3(1, (x: T) => '', ''); // string ->r11 : string ->foo3(1, (x: T) => '', '') : string ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r11b = foo3(1, (x: T) => '', 1); // {} ->r11b : {} ->foo3(1, (x: T) => '', 1) : {} ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r12 = foo3(1, function (a) { return '' }, 1); // {} ->r12 : {} ->foo3(1, function (a) { return '' }, 1) : {} ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->function (a) { return '' } : (a: number) => string ->a : number -} diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt new file mode 100644 index 00000000000..083d197bbb4 --- /dev/null +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt @@ -0,0 +1,50 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts(29,10): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts(40,10): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts (2 errors) ==== + // Generic functions used as arguments for function typed parameters are not used to make inferences from + // Using construct signature arguments, no errors expected + + function foo(x: new(a: T) => T) { + return new x(null); + } + + interface I { + new (x: T): T; + } + interface I2 { + new (x: T): T; + } + var i: I; + var i2: I2; + var a: { + new (x: T): T; + } + + var r = foo(i); // any + var r2 = foo(i); // string + var r3 = foo(i2); // string + var r3b = foo(a); // any + + function foo2(x: T, cb: new(a: T) => U) { + return new cb(x); + } + + var r4 = foo2(1, i2); // error + ~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r4b = foo2(1, a); // any + var r5 = foo2(1, i); // any + var r6 = foo2('', i2); // string + + function foo3(x: T, cb: new(a: T) => U, y: U) { + return new cb(x); + } + + var r7 = foo3(null, i, ''); // any + var r7b = foo3(null, a, ''); // any + var r8 = foo3(1, i2, 1); // error + ~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r9 = foo3('', i2, ''); // string \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.js b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.js index ca9b79c3507..7e9b7886fb4 100644 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.js +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.js @@ -27,7 +27,7 @@ function foo2(x: T, cb: new(a: T) => U) { return new cb(x); } -var r4 = foo2(1, i2); // string, instantiated generic +var r4 = foo2(1, i2); // error var r4b = foo2(1, a); // any var r5 = foo2(1, i); // any var r6 = foo2('', i2); // string @@ -38,7 +38,7 @@ function foo3(x: T, cb: new(a: T) => U, y: U) { var r7 = foo3(null, i, ''); // any var r7b = foo3(null, a, ''); // any -var r8 = foo3(1, i2, 1); // {} +var r8 = foo3(1, i2, 1); // error var r9 = foo3('', i2, ''); // string //// [genericCallWithFunctionTypedArguments2.js] @@ -57,7 +57,7 @@ var r3b = foo(a); // any function foo2(x, cb) { return new cb(x); } -var r4 = foo2(1, i2); // string, instantiated generic +var r4 = foo2(1, i2); // error var r4b = foo2(1, a); // any var r5 = foo2(1, i); // any var r6 = foo2('', i2); // string @@ -66,5 +66,5 @@ function foo3(x, cb, y) { } var r7 = foo3(null, i, ''); // any var r7b = foo3(null, a, ''); // any -var r8 = foo3(1, i2, 1); // {} +var r8 = foo3(1, i2, 1); // error var r9 = foo3('', i2, ''); // string diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.types b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.types deleted file mode 100644 index 89d7afd94e2..00000000000 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.types +++ /dev/null @@ -1,161 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts === -// Generic functions used as arguments for function typed parameters are not used to make inferences from -// Using construct signature arguments, no errors expected - -function foo(x: new(a: T) => T) { ->foo : (x: new (a: T) => T) => T ->T : T ->x : new (a: T) => T ->a : T ->T : T ->T : T - - return new x(null); ->new x(null) : T ->x : new (a: T) => T -} - -interface I { ->I : I - - new (x: T): T; ->T : T ->x : T ->T : T ->T : T -} -interface I2 { ->I2 : I2 ->T : T - - new (x: T): T; ->x : T ->T : T ->T : T -} -var i: I; ->i : I ->I : I - -var i2: I2; ->i2 : I2 ->I2 : I2 - -var a: { ->a : new (x: T) => T - - new (x: T): T; ->T : T ->x : T ->T : T ->T : T -} - -var r = foo(i); // any ->r : any ->foo(i) : any ->foo : (x: new (a: T) => T) => T ->i : I - -var r2 = foo(i); // string ->r2 : string ->foo(i) : string ->foo : (x: new (a: T) => T) => T ->i : I - -var r3 = foo(i2); // string ->r3 : string ->foo(i2) : string ->foo : (x: new (a: T) => T) => T ->i2 : I2 - -var r3b = foo(a); // any ->r3b : any ->foo(a) : any ->foo : (x: new (a: T) => T) => T ->a : new (x: T) => T - -function foo2(x: T, cb: new(a: T) => U) { ->foo2 : (x: T, cb: new (a: T) => U) => U ->T : T ->U : U ->x : T ->T : T ->cb : new (a: T) => U ->a : T ->T : T ->U : U - - return new cb(x); ->new cb(x) : U ->cb : new (a: T) => U ->x : T -} - -var r4 = foo2(1, i2); // string, instantiated generic ->r4 : string ->foo2(1, i2) : string ->foo2 : (x: T, cb: new (a: T) => U) => U ->i2 : I2 - -var r4b = foo2(1, a); // any ->r4b : any ->foo2(1, a) : any ->foo2 : (x: T, cb: new (a: T) => U) => U ->a : new (x: T) => T - -var r5 = foo2(1, i); // any ->r5 : any ->foo2(1, i) : any ->foo2 : (x: T, cb: new (a: T) => U) => U ->i : I - -var r6 = foo2('', i2); // string ->r6 : string ->foo2('', i2) : string ->foo2 : (x: T, cb: new (a: T) => U) => U ->i2 : I2 - -function foo3(x: T, cb: new(a: T) => U, y: U) { ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->T : T ->U : U ->x : T ->T : T ->cb : new (a: T) => U ->a : T ->T : T ->U : U ->y : U ->U : U - - return new cb(x); ->new cb(x) : U ->cb : new (a: T) => U ->x : T -} - -var r7 = foo3(null, i, ''); // any ->r7 : any ->foo3(null, i, '') : any ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->i : I - -var r7b = foo3(null, a, ''); // any ->r7b : any ->foo3(null, a, '') : any ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->a : new (x: T) => T - -var r8 = foo3(1, i2, 1); // {} ->r8 : {} ->foo3(1, i2, 1) : {} ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->i2 : I2 - -var r9 = foo3('', i2, ''); // string ->r9 : string ->foo3('', i2, '') : string ->foo3 : (x: T, cb: new (a: T) => U, y: U) => U ->i2 : I2 - diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments.errors.txt new file mode 100644 index 00000000000..43bad8f6a1d --- /dev/null +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments.errors.txt @@ -0,0 +1,51 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments.ts(18,10): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments.ts(19,10): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments.ts (2 errors) ==== + // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, + // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. + + function foo(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + //var r1 = foo((x: number) => 1, (x: string) => ''); // error + var r1b = foo((x) => 1, (x) => ''); // {} => {} + var r2 = foo((x: Object) => null, (x: string) => ''); // Object => Object + var r3 = foo((x: number) => 1, (x: Object) => null); // number => number + var r3ii = foo((x: number) => 1, (x: number) => 1); // number => number + + var a: { x: number; y?: number; }; + var b: { x: number; z?: number; }; + + var r4 = foo((x: typeof a) => a, (x: typeof b) => b); // typeof a => typeof a + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r5 = foo((x: typeof b) => b, (x: typeof a) => a); // typeof b => typeof b + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + + function other(x: T) { + var r6 = foo((a: T) => a, (b: T) => b); // T => T + var r6b = foo((a) => a, (b) => b); // {} => {} + } + + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); // T => T + var r7b = foo((a) => a, (b) => b); // {} => {} + var r8 = r7(null); + // BUG 835518 + //var r9 = r7(new Date()); + } + + + function foo2(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + function other3(x: T) { + var r8 = foo2((a: Date) => a, (b: Date) => b); // Date => Date + } \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments.types b/tests/baselines/reference/genericCallWithGenericSignatureArguments.types deleted file mode 100644 index 9f634070b56..00000000000 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments.types +++ /dev/null @@ -1,216 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments.ts === -// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, -// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. - -function foo(a: (x: T) => T, b: (x: T) => T) { ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->T : T ->a : (x: T) => T ->x : T ->T : T ->T : T ->b : (x: T) => T ->x : T ->T : T ->T : T - - var r: (x: T) => T; ->r : (x: T) => T ->x : T ->T : T ->T : T - - return r; ->r : (x: T) => T -} - -//var r1 = foo((x: number) => 1, (x: string) => ''); // error -var r1b = foo((x) => 1, (x) => ''); // {} => {} ->r1b : (x: {}) => {} ->foo((x) => 1, (x) => '') : (x: {}) => {} ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x) => 1 : (x: {}) => number ->x : {} ->(x) => '' : (x: {}) => string ->x : {} - -var r2 = foo((x: Object) => null, (x: string) => ''); // Object => Object ->r2 : (x: any) => any ->foo((x: Object) => null, (x: string) => '') : (x: any) => any ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: Object) => null : (x: Object) => any ->x : Object ->Object : Object ->(x: string) => '' : (x: string) => string ->x : string - -var r3 = foo((x: number) => 1, (x: Object) => null); // number => number ->r3 : (x: any) => any ->foo((x: number) => 1, (x: Object) => null) : (x: any) => any ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: number) => 1 : (x: number) => number ->x : number ->(x: Object) => null : (x: Object) => any ->x : Object ->Object : Object - -var r3ii = foo((x: number) => 1, (x: number) => 1); // number => number ->r3ii : (x: number) => number ->foo((x: number) => 1, (x: number) => 1) : (x: number) => number ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: number) => 1 : (x: number) => number ->x : number ->(x: number) => 1 : (x: number) => number ->x : number - -var a: { x: number; y?: number; }; ->a : { x: number; y?: number; } ->x : number ->y : number - -var b: { x: number; z?: number; }; ->b : { x: number; z?: number; } ->x : number ->z : number - -var r4 = foo((x: typeof a) => a, (x: typeof b) => b); // typeof a => typeof a ->r4 : (x: { x: number; y?: number; }) => { x: number; y?: number; } ->foo((x: typeof a) => a, (x: typeof b) => b) : (x: { x: number; y?: number; }) => { x: number; y?: number; } ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: typeof a) => a : (x: { x: number; y?: number; }) => { x: number; y?: number; } ->x : { x: number; y?: number; } ->a : { x: number; y?: number; } ->a : { x: number; y?: number; } ->(x: typeof b) => b : (x: { x: number; z?: number; }) => { x: number; z?: number; } ->x : { x: number; z?: number; } ->b : { x: number; z?: number; } ->b : { x: number; z?: number; } - -var r5 = foo((x: typeof b) => b, (x: typeof a) => a); // typeof b => typeof b ->r5 : (x: { x: number; z?: number; }) => { x: number; z?: number; } ->foo((x: typeof b) => b, (x: typeof a) => a) : (x: { x: number; z?: number; }) => { x: number; z?: number; } ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: typeof b) => b : (x: { x: number; z?: number; }) => { x: number; z?: number; } ->x : { x: number; z?: number; } ->b : { x: number; z?: number; } ->b : { x: number; z?: number; } ->(x: typeof a) => a : (x: { x: number; y?: number; }) => { x: number; y?: number; } ->x : { x: number; y?: number; } ->a : { x: number; y?: number; } ->a : { x: number; y?: number; } - -function other(x: T) { ->other : (x: T) => void ->T : T ->x : T ->T : T - - var r6 = foo((a: T) => a, (b: T) => b); // T => T ->r6 : (x: T) => T ->foo((a: T) => a, (b: T) => b) : (x: T) => T ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(a: T) => a : (a: T) => T ->a : T ->T : T ->a : T ->(b: T) => b : (b: T) => T ->b : T ->T : T ->b : T - - var r6b = foo((a) => a, (b) => b); // {} => {} ->r6b : (x: {}) => {} ->foo((a) => a, (b) => b) : (x: {}) => {} ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(a) => a : (a: {}) => {} ->a : {} ->a : {} ->(b) => b : (b: {}) => {} ->b : {} ->b : {} -} - -function other2(x: T) { ->other2 : (x: T) => void ->T : T ->Date : Date ->x : T ->T : T - - var r7 = foo((a: T) => a, (b: T) => b); // T => T ->r7 : (x: T) => T ->foo((a: T) => a, (b: T) => b) : (x: T) => T ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(a: T) => a : (a: T) => T ->a : T ->T : T ->a : T ->(b: T) => b : (b: T) => T ->b : T ->T : T ->b : T - - var r7b = foo((a) => a, (b) => b); // {} => {} ->r7b : (x: {}) => {} ->foo((a) => a, (b) => b) : (x: {}) => {} ->foo : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(a) => a : (a: {}) => {} ->a : {} ->a : {} ->(b) => b : (b: {}) => {} ->b : {} ->b : {} - - var r8 = r7(null); ->r8 : T ->r7(null) : T ->r7 : (x: T) => T - - // BUG 835518 - //var r9 = r7(new Date()); -} - - -function foo2(a: (x: T) => T, b: (x: T) => T) { ->foo2 : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->T : T ->Date : Date ->a : (x: T) => T ->x : T ->T : T ->T : T ->b : (x: T) => T ->x : T ->T : T ->T : T - - var r: (x: T) => T; ->r : (x: T) => T ->x : T ->T : T ->T : T - - return r; ->r : (x: T) => T -} - -function other3(x: T) { ->other3 : (x: T) => void ->T : T ->RegExp : RegExp ->x : T ->T : T - - var r8 = foo2((a: Date) => a, (b: Date) => b); // Date => Date ->r8 : (x: Date) => Date ->foo2((a: Date) => a, (b: Date) => b) : (x: Date) => Date ->foo2 : (a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(a: Date) => a : (a: Date) => Date ->a : Date ->Date : Date ->a : Date ->(b: Date) => b : (b: Date) => Date ->b : Date ->Date : Date ->b : Date -} diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt index 7f4fa26aad1..55318f268bd 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt @@ -1,51 +1,106 @@ -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(14,17): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'. -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(15,18): error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'. -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(24,19): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(36,32): error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(10,29): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(15,21): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(16,22): error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(25,23): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(37,36): error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(50,21): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(51,22): error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(60,23): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(67,51): error TS2304: Cannot find name 'U'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(67,57): error TS2304: Cannot find name 'U'. -==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts (4 errors) ==== +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts (10 errors) ==== // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. - function foo(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; - } + module onlyT { + function foo(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } - var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); + var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. - function other2(x: T) { - var r7 = foo((a: T) => a, (b: T) => b); // T => T - // BUG 835518 - var r9 = r7(new Date()); // should be ok - ~~~~~~~~~~ + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); // T => T + // BUG 835518 + var r9 = r7(new Date()); // should be ok + ~~~~~~~~~~ !!! error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'. - var r10 = r7(1); // error - ~ + var r10 = r7(1); // error + ~ !!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'. - } + } - function foo2(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; - } + function foo2(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } - function other3(x: T) { - var r7 = foo2((a: T) => a, (b: T) => b); // error - ~~~~~~~~~~~ + function other3(x: T) { + var r7 = foo2((a: T) => a, (b: T) => b); // error + ~~~~~~~~~~~ !!! error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. - var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date + var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date + } + + enum E { A } + enum F { A } + + function foo3(x: T, a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error + ~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'. } - enum E { A } - enum F { A } + module TU { + function foo(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } - function foo3(x: T, a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; - } + var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); - var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error - ~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'. \ No newline at end of file + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); + var r9 = r7(new Date()); + ~~~~~~~~~~ +!!! error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'. + var r10 = r7(1); + ~ +!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'. + } + + function foo2(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } + + function other3(x: T) { + var r7 = foo2((a: T) => a, (b: T) => b); + ~~~~~~~~~~~ +!!! error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. + var r7b = foo2((a) => a, (b) => b); + } + + enum E { A } + enum F { A } + + function foo3(x: T, a: (x: T) => T, b: (x: U) => U) { + ~ +!!! error TS2304: Cannot find name 'U'. + ~ +!!! error TS2304: Cannot find name 'U'. + var r: (x: T) => T; + return r; + } + + var r7 = foo3(E.A, (x) => E.A, (x) => F.A); + } \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js index 7dc955b6172..7acdcc32536 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js @@ -2,72 +2,146 @@ // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. -function foo(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; +module onlyT { + function foo(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); + + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); // T => T + // BUG 835518 + var r9 = r7(new Date()); // should be ok + var r10 = r7(1); // error + } + + function foo2(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + function other3(x: T) { + var r7 = foo2((a: T) => a, (b: T) => b); // error + var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date + } + + enum E { A } + enum F { A } + + function foo3(x: T, a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error } -var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); +module TU { + function foo(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } -function other2(x: T) { - var r7 = foo((a: T) => a, (b: T) => b); // T => T - // BUG 835518 - var r9 = r7(new Date()); // should be ok - var r10 = r7(1); // error -} + var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); -function foo2(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; -} + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); + var r9 = r7(new Date()); + var r10 = r7(1); + } -function other3(x: T) { - var r7 = foo2((a: T) => a, (b: T) => b); // error - var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date -} + function foo2(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } -enum E { A } -enum F { A } + function other3(x: T) { + var r7 = foo2((a: T) => a, (b: T) => b); + var r7b = foo2((a) => a, (b) => b); + } -function foo3(x: T, a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; -} + enum E { A } + enum F { A } -var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error + function foo3(x: T, a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } + + var r7 = foo3(E.A, (x) => E.A, (x) => F.A); +} //// [genericCallWithGenericSignatureArguments2.js] // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. -function foo(a, b) { - var r; - return r; -} -var r1 = foo(function (x) { return 1; }, function (x) { return ''; }); -function other2(x) { - var r7 = foo(function (a) { return a; }, function (b) { return b; }); // T => T - // BUG 835518 - var r9 = r7(new Date()); // should be ok - var r10 = r7(1); // error -} -function foo2(a, b) { - var r; - return r; -} -function other3(x) { - var r7 = foo2(function (a) { return a; }, function (b) { return b; }); // error - var r7b = foo2(function (a) { return a; }, function (b) { return b; }); // valid, T is inferred to be Date -} -var E; -(function (E) { - E[E["A"] = 0] = "A"; -})(E || (E = {})); -var F; -(function (F) { - F[F["A"] = 0] = "A"; -})(F || (F = {})); -function foo3(x, a, b) { - var r; - return r; -} -var r7 = foo3(0 /* A */, function (x) { return 0 /* A */; }, function (x) { return 0 /* A */; }); // error +var onlyT; +(function (onlyT) { + function foo(a, b) { + var r; + return r; + } + var r1 = foo(function (x) { return 1; }, function (x) { return ''; }); + function other2(x) { + var r7 = foo(function (a) { return a; }, function (b) { return b; }); // T => T + // BUG 835518 + var r9 = r7(new Date()); // should be ok + var r10 = r7(1); // error + } + function foo2(a, b) { + var r; + return r; + } + function other3(x) { + var r7 = foo2(function (a) { return a; }, function (b) { return b; }); // error + var r7b = foo2(function (a) { return a; }, function (b) { return b; }); // valid, T is inferred to be Date + } + var E; + (function (E) { + E[E["A"] = 0] = "A"; + })(E || (E = {})); + var F; + (function (F) { + F[F["A"] = 0] = "A"; + })(F || (F = {})); + function foo3(x, a, b) { + var r; + return r; + } + var r7 = foo3(0 /* A */, function (x) { return 0 /* A */; }, function (x) { return 0 /* A */; }); // error +})(onlyT || (onlyT = {})); +var TU; +(function (TU) { + function foo(a, b) { + var r; + return r; + } + var r1 = foo(function (x) { return 1; }, function (x) { return ''; }); + function other2(x) { + var r7 = foo(function (a) { return a; }, function (b) { return b; }); + var r9 = r7(new Date()); + var r10 = r7(1); + } + function foo2(a, b) { + var r; + return r; + } + function other3(x) { + var r7 = foo2(function (a) { return a; }, function (b) { return b; }); + var r7b = foo2(function (a) { return a; }, function (b) { return b; }); + } + var E; + (function (E) { + E[E["A"] = 0] = "A"; + })(E || (E = {})); + var F; + (function (F) { + F[F["A"] = 0] = "A"; + })(F || (F = {})); + function foo3(x, a, b) { + var r; + return r; + } + var r7 = foo3(0 /* A */, function (x) { return 0 /* A */; }, function (x) { return 0 /* A */; }); +})(TU || (TU = {})); diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt new file mode 100644 index 00000000000..0a42d940625 --- /dev/null +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt @@ -0,0 +1,42 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(32,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(33,11): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts (2 errors) ==== + // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, + // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. + + function foo(x: T, a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + var r1 = foo('', (x: string) => '', (x: Object) => null); // any => any + var r1ii = foo('', (x) => '', (x) => null); // string => string + var r2 = foo('', (x: string) => '', (x: Object) => ''); // string => string + var r3 = foo(null, (x: Object) => '', (x: string) => ''); // Object => Object + var r4 = foo(null, (x) => '', (x) => ''); // any => any + var r5 = foo(new Object(), (x) => '', (x) => ''); // Object => Object + + enum E { A } + enum F { A } + + var r6 = foo(E.A, (x: number) => E.A, (x: F) => F.A); // number => number + + + function foo2(x: T, a: (x: T) => U, b: (x: T) => U) { + var r: (x: T) => U; + return r; + } + + var r8 = foo2('', (x) => '', (x) => null); // string => string + var r9 = foo2(null, (x) => '', (x) => ''); // any => any + var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object + + var x: (a: string) => boolean; + var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js index 8ffb4f9970b..ca28878daa3 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js @@ -30,8 +30,8 @@ var r9 = foo2(null, (x) => '', (x) => ''); // any => any var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object var x: (a: string) => boolean; -var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // {} => {} -var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // (string => boolean) => {} +var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // error +var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // error //// [genericCallWithGenericSignatureArguments3.js] // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, @@ -63,5 +63,5 @@ var r8 = foo2('', function (x) { return ''; }, function (x) { return null; }); / var r9 = foo2(null, function (x) { return ''; }, function (x) { return ''; }); // any => any var r10 = foo2(null, function (x) { return ''; }, function (x) { return ''; }); // Object => Object var x; -var r11 = foo2(x, function (a1) { return function (n) { return 1; }; }, function (a2) { return 2; }); // {} => {} -var r12 = foo2(x, function (a1) { return function (n) { return 1; }; }, function (a2) { return 2; }); // (string => boolean) => {} +var r11 = foo2(x, function (a1) { return function (n) { return 1; }; }, function (a2) { return 2; }); // error +var r12 = foo2(x, function (a1) { return function (n) { return 1; }; }, function (a2) { return 2; }); // error diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.types b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.types deleted file mode 100644 index 2c0d21a5a07..00000000000 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.types +++ /dev/null @@ -1,202 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts === -// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, -// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. - -function foo(x: T, a: (x: T) => T, b: (x: T) => T) { ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->T : T ->x : T ->T : T ->a : (x: T) => T ->x : T ->T : T ->T : T ->b : (x: T) => T ->x : T ->T : T ->T : T - - var r: (x: T) => T; ->r : (x: T) => T ->x : T ->T : T ->T : T - - return r; ->r : (x: T) => T -} - -var r1 = foo('', (x: string) => '', (x: Object) => null); // any => any ->r1 : (x: any) => any ->foo('', (x: string) => '', (x: Object) => null) : (x: any) => any ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: string) => '' : (x: string) => string ->x : string ->(x: Object) => null : (x: Object) => any ->x : Object ->Object : Object - -var r1ii = foo('', (x) => '', (x) => null); // string => string ->r1ii : (x: string) => string ->foo('', (x) => '', (x) => null) : (x: string) => string ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x) => '' : (x: string) => string ->x : string ->(x) => null : (x: string) => any ->x : string - -var r2 = foo('', (x: string) => '', (x: Object) => ''); // string => string ->r2 : (x: Object) => Object ->foo('', (x: string) => '', (x: Object) => '') : (x: Object) => Object ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: string) => '' : (x: string) => string ->x : string ->(x: Object) => '' : (x: Object) => string ->x : Object ->Object : Object - -var r3 = foo(null, (x: Object) => '', (x: string) => ''); // Object => Object ->r3 : (x: Object) => Object ->foo(null, (x: Object) => '', (x: string) => '') : (x: Object) => Object ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x: Object) => '' : (x: Object) => string ->x : Object ->Object : Object ->(x: string) => '' : (x: string) => string ->x : string - -var r4 = foo(null, (x) => '', (x) => ''); // any => any ->r4 : (x: any) => any ->foo(null, (x) => '', (x) => '') : (x: any) => any ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->(x) => '' : (x: any) => string ->x : any ->(x) => '' : (x: any) => string ->x : any - -var r5 = foo(new Object(), (x) => '', (x) => ''); // Object => Object ->r5 : (x: Object) => Object ->foo(new Object(), (x) => '', (x) => '') : (x: Object) => Object ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->new Object() : Object ->Object : { (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any): any; getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor; getOwnPropertyNames(o: any): string[]; create(o: any, properties?: PropertyDescriptorMap): any; defineProperty(o: any, p: string, attributes: PropertyDescriptor): any; defineProperties(o: any, properties: PropertyDescriptorMap): any; seal(o: any): any; freeze(o: any): any; preventExtensions(o: any): any; isSealed(o: any): boolean; isFrozen(o: any): boolean; isExtensible(o: any): boolean; keys(o: any): string[]; } ->(x) => '' : (x: Object) => string ->x : Object ->(x) => '' : (x: Object) => string ->x : Object - -enum E { A } ->E : E ->A : E - -enum F { A } ->F : F ->A : F - -var r6 = foo(E.A, (x: number) => E.A, (x: F) => F.A); // number => number ->r6 : (x: number) => number ->foo(E.A, (x: number) => E.A, (x: F) => F.A) : (x: number) => number ->foo : (x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T ->E.A : E ->E : typeof E ->A : E ->(x: number) => E.A : (x: number) => E ->x : number ->E.A : E ->E : typeof E ->A : E ->(x: F) => F.A : (x: F) => F ->x : F ->F : F ->F.A : F ->F : typeof F ->A : F - - -function foo2(x: T, a: (x: T) => U, b: (x: T) => U) { ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->T : T ->U : U ->x : T ->T : T ->a : (x: T) => U ->x : T ->T : T ->U : U ->b : (x: T) => U ->x : T ->T : T ->U : U - - var r: (x: T) => U; ->r : (x: T) => U ->x : T ->T : T ->U : U - - return r; ->r : (x: T) => U -} - -var r8 = foo2('', (x) => '', (x) => null); // string => string ->r8 : (x: string) => any ->foo2('', (x) => '', (x) => null) : (x: string) => any ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->(x) => '' : (x: string) => string ->x : string ->(x) => null : (x: string) => any ->x : string - -var r9 = foo2(null, (x) => '', (x) => ''); // any => any ->r9 : (x: any) => string ->foo2(null, (x) => '', (x) => '') : (x: any) => string ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->(x) => '' : (x: any) => string ->x : any ->(x) => '' : (x: any) => string ->x : any - -var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object ->r10 : (x: Object) => string ->foo2(null, (x: Object) => '', (x: string) => '') : (x: Object) => string ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->(x: Object) => '' : (x: Object) => string ->x : Object ->Object : Object ->(x: string) => '' : (x: string) => string ->x : string - -var x: (a: string) => boolean; ->x : (a: string) => boolean ->a : string - -var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // {} => {} ->r11 : (x: {}) => {} ->foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2) : (x: {}) => {} ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->x : (a: string) => boolean ->(a1: (y: string) => string) => (n: Object) => 1 : (a1: (y: string) => string) => (n: Object) => number ->a1 : (y: string) => string ->y : string ->(n: Object) => 1 : (n: Object) => number ->n : Object ->Object : Object ->(a2: (z: string) => string) => 2 : (a2: (z: string) => string) => number ->a2 : (z: string) => string ->z : string - -var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // (string => boolean) => {} ->r12 : (x: (a: string) => boolean) => {} ->foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2) : (x: (a: string) => boolean) => {} ->foo2 : (x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U ->x : (a: string) => boolean ->(a1: (y: string) => boolean) => (n: Object) => 1 : (a1: (y: string) => boolean) => (n: Object) => number ->a1 : (y: string) => boolean ->y : string ->(n: Object) => 1 : (n: Object) => number ->n : Object ->Object : Object ->(a2: (z: string) => boolean) => 2 : (a2: (z: string) => boolean) => number ->a2 : (z: string) => boolean ->z : string - diff --git a/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.errors.txt b/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.errors.txt new file mode 100644 index 00000000000..c14db877073 --- /dev/null +++ b/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.errors.txt @@ -0,0 +1,40 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts(12,9): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts(13,10): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts (2 errors) ==== + // generic type argument inference where inference leads to two candidates that are both supertypes of all candidates + // we choose the first candidate so the result is dependent on the order of the arguments provided + + function foo(x: T, y: T) { + var r: T; + return r; + } + + var a: { x: number; y?: number; }; + var b: { x: number; z?: number; }; + + var r = foo(a, b); // { x: number; y?: number; }; + ~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r2 = foo(b, a); // { x: number; z?: number; }; + ~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + + var x: { x: number; }; + var y: { x?: number; }; + + var r3 = foo(a, x); // { x: number; y?: number; }; + var r4 = foo(x, a); // { x: number; }; + + var r5 = foo(a, y); // { x?: number; }; + var r5 = foo(y, a); // { x?: number; }; + + var r6 = foo(x, y); // { x?: number; }; + var r6 = foo(y, x); // { x?: number; }; + + var s1: (x: Object) => string; + var s2: (x: string) => string; + + var r7 = foo(s1, s2); // (x: Object) => string; + var r8 = foo(s2, s1); // (x: string) => string; \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.types b/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.types deleted file mode 100644 index e37a010baed..00000000000 --- a/tests/baselines/reference/genericCallWithNonSymmetricSubtypes.types +++ /dev/null @@ -1,117 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithNonSymmetricSubtypes.ts === -// generic type argument inference where inference leads to two candidates that are both supertypes of all candidates -// we choose the first candidate so the result is dependent on the order of the arguments provided - -function foo(x: T, y: T) { ->foo : (x: T, y: T) => T ->T : T ->x : T ->T : T ->y : T ->T : T - - var r: T; ->r : T ->T : T - - return r; ->r : T -} - -var a: { x: number; y?: number; }; ->a : { x: number; y?: number; } ->x : number ->y : number - -var b: { x: number; z?: number; }; ->b : { x: number; z?: number; } ->x : number ->z : number - -var r = foo(a, b); // { x: number; y?: number; }; ->r : { x: number; y?: number; } ->foo(a, b) : { x: number; y?: number; } ->foo : (x: T, y: T) => T ->a : { x: number; y?: number; } ->b : { x: number; z?: number; } - -var r2 = foo(b, a); // { x: number; z?: number; }; ->r2 : { x: number; z?: number; } ->foo(b, a) : { x: number; z?: number; } ->foo : (x: T, y: T) => T ->b : { x: number; z?: number; } ->a : { x: number; y?: number; } - -var x: { x: number; }; ->x : { x: number; } ->x : number - -var y: { x?: number; }; ->y : { x?: number; } ->x : number - -var r3 = foo(a, x); // { x: number; y?: number; }; ->r3 : { x: number; y?: number; } ->foo(a, x) : { x: number; y?: number; } ->foo : (x: T, y: T) => T ->a : { x: number; y?: number; } ->x : { x: number; } - -var r4 = foo(x, a); // { x: number; }; ->r4 : { x: number; } ->foo(x, a) : { x: number; } ->foo : (x: T, y: T) => T ->x : { x: number; } ->a : { x: number; y?: number; } - -var r5 = foo(a, y); // { x?: number; }; ->r5 : { x?: number; } ->foo(a, y) : { x?: number; } ->foo : (x: T, y: T) => T ->a : { x: number; y?: number; } ->y : { x?: number; } - -var r5 = foo(y, a); // { x?: number; }; ->r5 : { x?: number; } ->foo(y, a) : { x?: number; } ->foo : (x: T, y: T) => T ->y : { x?: number; } ->a : { x: number; y?: number; } - -var r6 = foo(x, y); // { x?: number; }; ->r6 : { x?: number; } ->foo(x, y) : { x?: number; } ->foo : (x: T, y: T) => T ->x : { x: number; } ->y : { x?: number; } - -var r6 = foo(y, x); // { x?: number; }; ->r6 : { x?: number; } ->foo(y, x) : { x?: number; } ->foo : (x: T, y: T) => T ->y : { x?: number; } ->x : { x: number; } - -var s1: (x: Object) => string; ->s1 : (x: Object) => string ->x : Object ->Object : Object - -var s2: (x: string) => string; ->s2 : (x: string) => string ->x : string - -var r7 = foo(s1, s2); // (x: Object) => string; ->r7 : (x: Object) => string ->foo(s1, s2) : (x: Object) => string ->foo : (x: T, y: T) => T ->s1 : (x: Object) => string ->s2 : (x: string) => string - -var r8 = foo(s2, s1); // (x: string) => string; ->r8 : (x: string) => string ->foo(s2, s1) : (x: string) => string ->foo : (x: T, y: T) => T ->s2 : (x: string) => string ->s1 : (x: Object) => string - diff --git a/tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt b/tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt new file mode 100644 index 00000000000..856f35a57f6 --- /dev/null +++ b/tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts(5,9): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts (1 errors) ==== + function foo(x: { bar: T; baz: T }) { + return x; + } + + var r = foo({ bar: 1, baz: '' }); // error + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r2 = foo({ bar: 1, baz: 1 }); // T = number + var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo + var r4 = foo({ bar: 1, baz: '' }); // T = Object \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithObjectLiteralArgs.js b/tests/baselines/reference/genericCallWithObjectLiteralArgs.js index 84a630425be..2515bbef293 100644 --- a/tests/baselines/reference/genericCallWithObjectLiteralArgs.js +++ b/tests/baselines/reference/genericCallWithObjectLiteralArgs.js @@ -3,7 +3,7 @@ function foo(x: { bar: T; baz: T }) { return x; } -var r = foo({ bar: 1, baz: '' }); // T = {} +var r = foo({ bar: 1, baz: '' }); // error var r2 = foo({ bar: 1, baz: 1 }); // T = number var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo var r4 = foo({ bar: 1, baz: '' }); // T = Object @@ -12,7 +12,7 @@ var r4 = foo({ bar: 1, baz: '' }); // T = Object function foo(x) { return x; } -var r = foo({ bar: 1, baz: '' }); // T = {} +var r = foo({ bar: 1, baz: '' }); // error var r2 = foo({ bar: 1, baz: 1 }); // T = number var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo var r4 = foo({ bar: 1, baz: '' }); // T = Object diff --git a/tests/baselines/reference/genericCallWithObjectLiteralArgs.types b/tests/baselines/reference/genericCallWithObjectLiteralArgs.types deleted file mode 100644 index d23445ecbca..00000000000 --- a/tests/baselines/reference/genericCallWithObjectLiteralArgs.types +++ /dev/null @@ -1,49 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts === -function foo(x: { bar: T; baz: T }) { ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->T : T ->x : { bar: T; baz: T; } ->bar : T ->T : T ->baz : T ->T : T - - return x; ->x : { bar: T; baz: T; } -} - -var r = foo({ bar: 1, baz: '' }); // T = {} ->r : { bar: {}; baz: {}; } ->foo({ bar: 1, baz: '' }) : { bar: {}; baz: {}; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->{ bar: 1, baz: '' } : { bar: number; baz: string; } ->bar : number ->baz : string - -var r2 = foo({ bar: 1, baz: 1 }); // T = number ->r2 : { bar: number; baz: number; } ->foo({ bar: 1, baz: 1 }) : { bar: number; baz: number; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->{ bar: 1, baz: 1 } : { bar: number; baz: number; } ->bar : number ->baz : number - -var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo ->r3 : { bar: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; baz: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; } ->foo({ bar: foo, baz: foo }) : { bar: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; baz: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->{ bar: foo, baz: foo } : { bar: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; baz: (x: { bar: T; baz: T; }) => { bar: T; baz: T; }; } ->bar : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->baz : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } - -var r4 = foo({ bar: 1, baz: '' }); // T = Object ->r4 : { bar: Object; baz: Object; } ->foo({ bar: 1, baz: '' }) : { bar: Object; baz: Object; } ->foo : (x: { bar: T; baz: T; }) => { bar: T; baz: T; } ->Object : Object ->{ bar: 1, baz: '' } : { bar: number; baz: string; } ->bar : number ->baz : string - diff --git a/tests/baselines/reference/genericCallWithObjectLiteralArguments1.errors.txt b/tests/baselines/reference/genericCallWithObjectLiteralArguments1.errors.txt index 3b3f8d43ff9..4ac64500bd1 100644 --- a/tests/baselines/reference/genericCallWithObjectLiteralArguments1.errors.txt +++ b/tests/baselines/reference/genericCallWithObjectLiteralArguments1.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts(2,9): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts(4,22): error TS2345: Argument of type '{ x: number; y: string; }' is not assignable to parameter of type '{ x: number; y: number; }'. Types of property 'y' are incompatible: Type 'string' is not assignable to type 'number'. @@ -12,9 +13,11 @@ tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts(7,22): error TS23 Type 'number' is not assignable to type 'string'. -==== tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts (4 errors) ==== +==== tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts (5 errors) ==== function foo(n: { x: T; y: T }, m: T) { return m; } var x = foo({ x: 3, y: "" }, 4); // no error, x is Object, the best common type + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. // these are all errors var x2 = foo({ x: 3, y: "" }, 4); ~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt b/tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt new file mode 100644 index 00000000000..dce9562a8f5 --- /dev/null +++ b/tests/baselines/reference/genericCallWithObjectTypeArgs.errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs.ts(20,9): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs.ts (1 errors) ==== + class C { + private x: string; + } + + class D { + private x: string; + } + + class X { + x: T; + } + + function foo(t: X, t2: X) { + var x: T; + return x; + } + + var c1 = new X(); + var d1 = new X(); + var r = foo(c1, d1); // error + ~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r2 = foo(c1, c1); // ok \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgs.types b/tests/baselines/reference/genericCallWithObjectTypeArgs.types deleted file mode 100644 index ddbd7d83054..00000000000 --- a/tests/baselines/reference/genericCallWithObjectTypeArgs.types +++ /dev/null @@ -1,68 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs.ts === -class C { ->C : C - - private x: string; ->x : string -} - -class D { ->D : D - - private x: string; ->x : string -} - -class X { ->X : X ->T : T - - x: T; ->x : T ->T : T -} - -function foo(t: X, t2: X) { ->foo : (t: X, t2: X) => T ->T : T ->t : X ->X : X ->T : T ->t2 : X ->X : X ->T : T - - var x: T; ->x : T ->T : T - - return x; ->x : T -} - -var c1 = new X(); ->c1 : X ->new X() : X ->X : typeof X ->C : C - -var d1 = new X(); ->d1 : X ->new X() : X ->X : typeof X ->D : D - -var r = foo(c1, d1); // error ->r : {} ->foo(c1, d1) : {} ->foo : (t: X, t2: X) => T ->c1 : X ->d1 : X - -var r2 = foo(c1, c1); // ok ->r2 : C ->foo(c1, c1) : C ->foo : (t: X, t2: X) => T ->c1 : X ->c1 : X - diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgs2.types b/tests/baselines/reference/genericCallWithObjectTypeArgs2.types index 0065811fdc1..3e178a7062d 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgs2.types +++ b/tests/baselines/reference/genericCallWithObjectTypeArgs2.types @@ -22,7 +22,7 @@ class Derived2 extends Base { // returns {}[] function f(a: { x: T; y: U }) { ->f : (a: { x: T; y: U; }) => {}[] +>f : (a: { x: T; y: U; }) => (T | U)[] >T : T >Base : Base >U : U @@ -34,7 +34,7 @@ function f(a: { x: T; y: U }) { >U : U return [a.x, a.y]; ->[a.x, a.y] : {}[] +>[a.x, a.y] : (T | U)[] >a.x : T >a : { x: T; y: U; } >x : T @@ -44,9 +44,9 @@ function f(a: { x: T; y: U }) { } var r = f({ x: new Derived(), y: new Derived2() }); // {}[] ->r : {}[] ->f({ x: new Derived(), y: new Derived2() }) : {}[] ->f : (a: { x: T; y: U; }) => {}[] +>r : (Derived | Derived2)[] +>f({ x: new Derived(), y: new Derived2() }) : (Derived | Derived2)[] +>f : (a: { x: T; y: U; }) => (T | U)[] >{ x: new Derived(), y: new Derived2() } : { x: Derived; y: Derived2; } >x : Derived >new Derived() : Derived @@ -56,9 +56,9 @@ var r = f({ x: new Derived(), y: new Derived2() }); // {}[] >Derived2 : typeof Derived2 var r2 = f({ x: new Base(), y: new Derived2() }); // {}[] ->r2 : {}[] ->f({ x: new Base(), y: new Derived2() }) : {}[] ->f : (a: { x: T; y: U; }) => {}[] +>r2 : Base[] +>f({ x: new Base(), y: new Derived2() }) : (Base | Derived2)[] +>f : (a: { x: T; y: U; }) => (T | U)[] >{ x: new Base(), y: new Derived2() } : { x: Base; y: Derived2; } >x : Base >new Base() : Base diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt b/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt index c41ca0e8875..9cb190ddecd 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt +++ b/tests/baselines/reference/genericCallWithObjectTypeArgsAndConstraints3.errors.txt @@ -1,7 +1,8 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts(18,10): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts(20,29): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts (2 errors) ==== // Generic call with constraints infering type parameter from object member properties class Base { @@ -20,6 +21,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObj } var r1 = f({ x: new Derived(), y: new Derived2() }); // ok, both extend Base + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. function f2(a: U) { ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt new file mode 100644 index 00000000000..3ddb094970a --- /dev/null +++ b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt @@ -0,0 +1,54 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts(36,14): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts (1 errors) ==== + // Function typed arguments with multiple signatures must be passed an implementation that matches all of them + // Inferences are made quadratic-pairwise to and from these overload sets + + module NonGenericParameter { + var a: { + new(x: boolean): boolean; + new(x: string): string; + } + + function foo4(cb: typeof a) { + return new cb(null); + } + + var r = foo4(a); + var b: { new (x: T): T }; + var r2 = foo4(b); + } + + module GenericParameter { + function foo5(cb: { new(x: T): string; new(x: number): T }) { + return cb; + } + + var a: { + new (x: boolean): string; + new (x: number): boolean; + } + var r5 = foo5(a); // new{} => string; new(x:number) => {} + var b: { new(x: T): string; new(x: number): T; } + var r7 = foo5(b); // new any => string; new(x:number) => any + + function foo6(cb: { new(x: T): string; new(x: T, y?: T): string }) { + return cb; + } + + var r8 = foo6(a); // error + ~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string + + function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) { + return cb; + } + + var r13 = foo7(1, b); // new any => string; new(x:any, y?:any) => string + var c: { new (x: T): string; (x: number): T; } + var c2: { new (x: T): string; new(x: number): T; } + var r14 = foo7(1, c); // new any => string; new(x:any, y?:any) => string + var r15 = foo7(1, c2); // new any => string; new(x:any, y?:any) => string + } \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.js b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.js index 9da34ebad86..4f74b043bd9 100644 --- a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.js +++ b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.js @@ -34,7 +34,7 @@ module GenericParameter { return cb; } - var r8 = foo6(a); // new{} => string; new(x:{}, y?:{}) => string + var r8 = foo6(a); // error var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) { @@ -73,7 +73,7 @@ var GenericParameter; function foo6(cb) { return cb; } - var r8 = foo6(a); // new{} => string; new(x:{}, y?:{}) => string + var r8 = foo6(a); // error var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string function foo7(x, cb) { return cb; diff --git a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.types b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.types deleted file mode 100644 index 6c16ad0259c..00000000000 --- a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.types +++ /dev/null @@ -1,173 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts === -// Function typed arguments with multiple signatures must be passed an implementation that matches all of them -// Inferences are made quadratic-pairwise to and from these overload sets - -module NonGenericParameter { ->NonGenericParameter : typeof NonGenericParameter - - var a: { ->a : { new (x: boolean): boolean; new (x: string): string; } - - new(x: boolean): boolean; ->x : boolean - - new(x: string): string; ->x : string - } - - function foo4(cb: typeof a) { ->foo4 : (cb: { new (x: boolean): boolean; new (x: string): string; }) => boolean ->cb : { new (x: boolean): boolean; new (x: string): string; } ->a : { new (x: boolean): boolean; new (x: string): string; } - - return new cb(null); ->new cb(null) : boolean ->cb : { new (x: boolean): boolean; new (x: string): string; } - } - - var r = foo4(a); ->r : boolean ->foo4(a) : boolean ->foo4 : (cb: { new (x: boolean): boolean; new (x: string): string; }) => boolean ->a : { new (x: boolean): boolean; new (x: string): string; } - - var b: { new (x: T): T }; ->b : new (x: T) => T ->T : T ->x : T ->T : T ->T : T - - var r2 = foo4(b); ->r2 : boolean ->foo4(b) : boolean ->foo4 : (cb: { new (x: boolean): boolean; new (x: string): string; }) => boolean ->b : new (x: T) => T -} - -module GenericParameter { ->GenericParameter : typeof GenericParameter - - function foo5(cb: { new(x: T): string; new(x: number): T }) { ->foo5 : (cb: { new (x: T): string; new (x: number): T; }) => { new (x: T): string; new (x: number): T; } ->T : T ->cb : { new (x: T): string; new (x: number): T; } ->x : T ->T : T ->x : number ->T : T - - return cb; ->cb : { new (x: T): string; new (x: number): T; } - } - - var a: { ->a : { new (x: boolean): string; new (x: number): boolean; } - - new (x: boolean): string; ->x : boolean - - new (x: number): boolean; ->x : number - } - var r5 = foo5(a); // new{} => string; new(x:number) => {} ->r5 : { new (x: boolean): string; new (x: number): boolean; } ->foo5(a) : { new (x: boolean): string; new (x: number): boolean; } ->foo5 : (cb: { new (x: T): string; new (x: number): T; }) => { new (x: T): string; new (x: number): T; } ->a : { new (x: boolean): string; new (x: number): boolean; } - - var b: { new(x: T): string; new(x: number): T; } ->b : { new (x: T): string; new (x: number): T; } ->T : T ->x : T ->T : T ->T : T ->x : number ->T : T - - var r7 = foo5(b); // new any => string; new(x:number) => any ->r7 : { new (x: any): string; new (x: number): any; } ->foo5(b) : { new (x: any): string; new (x: number): any; } ->foo5 : (cb: { new (x: T): string; new (x: number): T; }) => { new (x: T): string; new (x: number): T; } ->b : { new (x: T): string; new (x: number): T; } - - function foo6(cb: { new(x: T): string; new(x: T, y?: T): string }) { ->foo6 : (cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->T : T ->cb : { new (x: T): string; new (x: T, y?: T): string; } ->x : T ->T : T ->x : T ->T : T ->y : T ->T : T - - return cb; ->cb : { new (x: T): string; new (x: T, y?: T): string; } - } - - var r8 = foo6(a); // new{} => string; new(x:{}, y?:{}) => string ->r8 : { new (x: {}): string; new (x: {}, y?: {}): string; } ->foo6(a) : { new (x: {}): string; new (x: {}, y?: {}): string; } ->foo6 : (cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->a : { new (x: boolean): string; new (x: number): boolean; } - - var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string ->r9 : { new (x: any): string; new (x: any, y?: any): string; } ->foo6(b) : { new (x: any): string; new (x: any, y?: any): string; } ->foo6 : (cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->b : { new (x: T): string; new (x: number): T; } - - function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) { ->foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->T : T ->x : T ->T : T ->cb : { new (x: T): string; new (x: T, y?: T): string; } ->x : T ->T : T ->x : T ->T : T ->y : T ->T : T - - return cb; ->cb : { new (x: T): string; new (x: T, y?: T): string; } - } - - var r13 = foo7(1, b); // new any => string; new(x:any, y?:any) => string ->r13 : { new (x: any): string; new (x: any, y?: any): string; } ->foo7(1, b) : { new (x: any): string; new (x: any, y?: any): string; } ->foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->b : { new (x: T): string; new (x: number): T; } - - var c: { new (x: T): string; (x: number): T; } ->c : { (x: number): T; new (x: T): string; } ->T : T ->x : T ->T : T ->T : T ->x : number ->T : T - - var c2: { new (x: T): string; new(x: number): T; } ->c2 : { new (x: T): string; new (x: number): T; } ->T : T ->x : T ->T : T ->T : T ->x : number ->T : T - - var r14 = foo7(1, c); // new any => string; new(x:any, y?:any) => string ->r14 : { new (x: any): string; new (x: any, y?: any): string; } ->foo7(1, c) : { new (x: any): string; new (x: any, y?: any): string; } ->foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->c : { (x: number): T; new (x: T): string; } - - var r15 = foo7(1, c2); // new any => string; new(x:any, y?:any) => string ->r15 : { new (x: any): string; new (x: any, y?: any): string; } ->foo7(1, c2) : { new (x: any): string; new (x: any, y?: any): string; } ->foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T): string; }) => { new (x: T): string; new (x: T, y?: T): string; } ->c2 : { new (x: T): string; new (x: number): T; } -} diff --git a/tests/baselines/reference/genericCallWithTupleType.errors.txt b/tests/baselines/reference/genericCallWithTupleType.errors.txt index 7f84cee760c..abfe5087131 100644 --- a/tests/baselines/reference/genericCallWithTupleType.errors.txt +++ b/tests/baselines/reference/genericCallWithTupleType.errors.txt @@ -1,47 +1,65 @@ -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(22,1): error TS2322: Type '[number, string]' is not assignable to type '[string, number]': - Types of property '0' are incompatible: - Type 'number' is not assignable to type 'string'. -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(23,1): error TS2322: Type '[{}, {}]' is not assignable to type '[string, number]': - Types of property '0' are incompatible: - Type '{}' is not assignable to type 'string'. -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(24,1): error TS2322: Type '[{}]' is not assignable to type '[{}, {}]': - Property '1' is missing in type '[{}]'. - - -==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts (3 errors) ==== - interface I { - tuple1: [T, U]; - } - - var i1: I; - var i2: I<{}, {}>; - - // no error - i1.tuple1 = ["foo", 5]; - var e1 = i1.tuple1[0]; // string - var e2 = i1.tuple1[1]; // number - i1.tuple1 = ["foo", 5, false, true]; - var e3 = i1.tuple1[2]; // {} - i1.tuple1[3] = { a: "string" }; - var e4 = i1.tuple1[3]; // {} - i2.tuple1 = ["foo", 5]; - i2.tuple1 = ["foo", "bar"]; - i2.tuple1 = [5, "bar"]; - i2.tuple1 = [{}, {}]; - - // error - i1.tuple1 = [5, "foo"]; - ~~~~~~~~~ -!!! error TS2322: Type '[number, string]' is not assignable to type '[string, number]': -!!! error TS2322: Types of property '0' are incompatible: -!!! error TS2322: Type 'number' is not assignable to type 'string'. - i1.tuple1 = [{}, {}]; - ~~~~~~~~~ -!!! error TS2322: Type '[{}, {}]' is not assignable to type '[string, number]': -!!! error TS2322: Types of property '0' are incompatible: -!!! error TS2322: Type '{}' is not assignable to type 'string'. - i2.tuple1 = [{}]; - ~~~~~~~~~ -!!! error TS2322: Type '[{}]' is not assignable to type '[{}, {}]': -!!! error TS2322: Property '1' is missing in type '[{}]'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(12,1): error TS2322: Type '[string, number, boolean, boolean]' is not assignable to type '[string, number]': + Types of property 'pop' are incompatible: + Type '() => string | number | boolean' is not assignable to type '() => string | number': + Type 'string | number | boolean' is not assignable to type 'string | number': + Type 'boolean' is not assignable to type 'string | number': + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(14,1): error TS2322: Type '{ a: string; }' is not assignable to type 'string | number': + Type '{ a: string; }' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(22,1): error TS2322: Type '[number, string]' is not assignable to type '[string, number]': + Types of property '0' are incompatible: + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(23,1): error TS2322: Type '[{}, {}]' is not assignable to type '[string, number]': + Types of property '0' are incompatible: + Type '{}' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(24,1): error TS2322: Type '[{}]' is not assignable to type '[{}, {}]': + Property '1' is missing in type '[{}]'. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts (5 errors) ==== + interface I { + tuple1: [T, U]; + } + + var i1: I; + var i2: I<{}, {}>; + + // no error + i1.tuple1 = ["foo", 5]; + var e1 = i1.tuple1[0]; // string + var e2 = i1.tuple1[1]; // number + i1.tuple1 = ["foo", 5, false, true]; + ~~~~~~~~~ +!!! error TS2322: Type '[string, number, boolean, boolean]' is not assignable to type '[string, number]': +!!! error TS2322: Types of property 'pop' are incompatible: +!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => string | number': +!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'string | number': +!!! error TS2322: Type 'boolean' is not assignable to type 'string | number': +!!! error TS2322: Type 'boolean' is not assignable to type 'number'. + var e3 = i1.tuple1[2]; // {} + i1.tuple1[3] = { a: "string" }; + ~~~~~~~~~~~~ +!!! error TS2322: Type '{ a: string; }' is not assignable to type 'string | number': +!!! error TS2322: Type '{ a: string; }' is not assignable to type 'number'. + var e4 = i1.tuple1[3]; // {} + i2.tuple1 = ["foo", 5]; + i2.tuple1 = ["foo", "bar"]; + i2.tuple1 = [5, "bar"]; + i2.tuple1 = [{}, {}]; + + // error + i1.tuple1 = [5, "foo"]; + ~~~~~~~~~ +!!! error TS2322: Type '[number, string]' is not assignable to type '[string, number]': +!!! error TS2322: Types of property '0' are incompatible: +!!! error TS2322: Type 'number' is not assignable to type 'string'. + i1.tuple1 = [{}, {}]; + ~~~~~~~~~ +!!! error TS2322: Type '[{}, {}]' is not assignable to type '[string, number]': +!!! error TS2322: Types of property '0' are incompatible: +!!! error TS2322: Type '{}' is not assignable to type 'string'. + i2.tuple1 = [{}]; + ~~~~~~~~~ +!!! error TS2322: Type '[{}]' is not assignable to type '[{}, {}]': +!!! error TS2322: Property '1' is missing in type '[{}]'. \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithTupleType.js b/tests/baselines/reference/genericCallWithTupleType.js index 5ac66f66c3c..296a6dad63b 100644 --- a/tests/baselines/reference/genericCallWithTupleType.js +++ b/tests/baselines/reference/genericCallWithTupleType.js @@ -1,4 +1,4 @@ -//// [genericCallWithTupleType.ts] +//// [genericCallWithTupleType.ts] interface I { tuple1: [T, U]; } @@ -23,24 +23,24 @@ i2.tuple1 = [{}, {}]; i1.tuple1 = [5, "foo"]; i1.tuple1 = [{}, {}]; i2.tuple1 = [{}]; - - -//// [genericCallWithTupleType.js] -var i1; -var i2; -// no error -i1.tuple1 = ["foo", 5]; -var e1 = i1.tuple1[0]; // string -var e2 = i1.tuple1[1]; // number -i1.tuple1 = ["foo", 5, false, true]; -var e3 = i1.tuple1[2]; // {} -i1.tuple1[3] = { a: "string" }; -var e4 = i1.tuple1[3]; // {} -i2.tuple1 = ["foo", 5]; -i2.tuple1 = ["foo", "bar"]; -i2.tuple1 = [5, "bar"]; -i2.tuple1 = [{}, {}]; -// error -i1.tuple1 = [5, "foo"]; -i1.tuple1 = [{}, {}]; -i2.tuple1 = [{}]; + + +//// [genericCallWithTupleType.js] +var i1; +var i2; +// no error +i1.tuple1 = ["foo", 5]; +var e1 = i1.tuple1[0]; // string +var e2 = i1.tuple1[1]; // number +i1.tuple1 = ["foo", 5, false, true]; +var e3 = i1.tuple1[2]; // {} +i1.tuple1[3] = { a: "string" }; +var e4 = i1.tuple1[3]; // {} +i2.tuple1 = ["foo", 5]; +i2.tuple1 = ["foo", "bar"]; +i2.tuple1 = [5, "bar"]; +i2.tuple1 = [{}, {}]; +// error +i1.tuple1 = [5, "foo"]; +i1.tuple1 = [{}, {}]; +i2.tuple1 = [{}]; diff --git a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt new file mode 100644 index 00000000000..30ed4bc431f --- /dev/null +++ b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt @@ -0,0 +1,81 @@ +tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts(57,19): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts(60,19): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts(61,20): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts(62,30): error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts (4 errors) ==== + // Generic functions used as arguments for function typed parameters are not used to make inferences from + // Using function arguments, no errors expected + + module ImmediatelyFix { + class C { + foo(x: (a: T) => T) { + return x(null); + } + } + + var c = new C(); + var r = c.foo((x: U) => ''); // {} + var r2 = c.foo((x: U) => ''); // string + var r3 = c.foo(x => ''); // {} + + class C2 { + foo(x: (a: T) => T) { + return x(null); + } + } + + var c2 = new C2(); + var ra = c2.foo((x: U) => 1); // number + var r3a = c2.foo(x => 1); // number + } + + module WithCandidates { + class C { + foo2(x: T, cb: (a: T) => U) { + return cb(x); + } + } + + var c: C; + var r4 = c.foo2(1, function (a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions + var r5 = c.foo2(1, (a) => ''); // string + var r6 = c.foo2('', (a: Z) => 1); // number + + class C2 { + foo3(x: T, cb: (a: T) => U, y: U) { + return cb(x); + } + } + + var c2: C2; + var r7 = c2.foo3(1, (a: Z) => '', ''); // string + var r8 = c2.foo3(1, function (a) { return '' }, ''); // string + + class C3 { + foo3(x: T, cb: (a: T) => U, y: U) { + return cb(x); + } + } + var c3: C3; + + function other(t: T, u: U) { + var r10 = c.foo2(1, (x: T) => ''); // error + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r10 = c.foo2(1, (x) => ''); // string + + var r11 = c3.foo3(1, (x: T) => '', ''); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r11b = c3.foo3(1, (x: T) => '', 1); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var r12 = c3.foo3(1, function (a) { return '' }, 1); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.js b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.js index 1af5f0ea6e6..7ec25949534 100644 --- a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.js +++ b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.js @@ -55,12 +55,12 @@ module WithCandidates { var c3: C3; function other(t: T, u: U) { - var r10 = c.foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made + var r10 = c.foo2(1, (x: T) => ''); // error var r10 = c.foo2(1, (x) => ''); // string - var r11 = c3.foo3(1, (x: T) => '', ''); // string - var r11b = c3.foo3(1, (x: T) => '', 1); // {} - var r12 = c3.foo3(1, function (a) { return '' }, 1); // {} + var r11 = c3.foo3(1, (x: T) => '', ''); // error + var r11b = c3.foo3(1, (x: T) => '', 1); // error + var r12 = c3.foo3(1, function (a) { return '' }, 1); // error } } @@ -132,12 +132,12 @@ var WithCandidates; })(); var c3; function other(t, u) { - var r10 = c.foo2(1, function (x) { return ''; }); // string, non-generic signature allows inferences to be made + var r10 = c.foo2(1, function (x) { return ''; }); // error var r10 = c.foo2(1, function (x) { return ''; }); // string - var r11 = c3.foo3(1, function (x) { return ''; }, ''); // string - var r11b = c3.foo3(1, function (x) { return ''; }, 1); // {} + var r11 = c3.foo3(1, function (x) { return ''; }, ''); // error + var r11b = c3.foo3(1, function (x) { return ''; }, 1); // error var r12 = c3.foo3(1, function (a) { return ''; - }, 1); // {} + }, 1); // error } })(WithCandidates || (WithCandidates = {})); diff --git a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.types b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.types deleted file mode 100644 index 68b94d81d02..00000000000 --- a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.types +++ /dev/null @@ -1,297 +0,0 @@ -=== tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts === -// Generic functions used as arguments for function typed parameters are not used to make inferences from -// Using function arguments, no errors expected - -module ImmediatelyFix { ->ImmediatelyFix : typeof ImmediatelyFix - - class C { ->C : C ->T : T - - foo(x: (a: T) => T) { ->foo : (x: (a: T) => T) => T ->T : T ->x : (a: T) => T ->a : T ->T : T ->T : T - - return x(null); ->x(null) : T ->x : (a: T) => T - } - } - - var c = new C(); ->c : C ->new C() : C ->C : typeof C - - var r = c.foo((x: U) => ''); // {} ->r : {} ->c.foo((x: U) => '') : {} ->c.foo : (x: (a: T) => T) => T ->c : C ->foo : (x: (a: T) => T) => T ->(x: U) => '' : (x: U) => string ->U : U ->x : U ->U : U - - var r2 = c.foo((x: U) => ''); // string ->r2 : string ->c.foo((x: U) => '') : string ->c.foo : (x: (a: T) => T) => T ->c : C ->foo : (x: (a: T) => T) => T ->(x: U) => '' : (x: U) => string ->U : U ->x : U ->U : U - - var r3 = c.foo(x => ''); // {} ->r3 : {} ->c.foo(x => '') : {} ->c.foo : (x: (a: T) => T) => T ->c : C ->foo : (x: (a: T) => T) => T ->x => '' : (x: {}) => string ->x : {} - - class C2 { ->C2 : C2 ->T : T - - foo(x: (a: T) => T) { ->foo : (x: (a: T) => T) => T ->x : (a: T) => T ->a : T ->T : T ->T : T - - return x(null); ->x(null) : T ->x : (a: T) => T - } - } - - var c2 = new C2(); ->c2 : C2 ->new C2() : C2 ->C2 : typeof C2 - - var ra = c2.foo((x: U) => 1); // number ->ra : number ->c2.foo((x: U) => 1) : number ->c2.foo : (x: (a: number) => number) => number ->c2 : C2 ->foo : (x: (a: number) => number) => number ->(x: U) => 1 : (x: U) => number ->U : U ->x : U ->U : U - - var r3a = c2.foo(x => 1); // number ->r3a : number ->c2.foo(x => 1) : number ->c2.foo : (x: (a: number) => number) => number ->c2 : C2 ->foo : (x: (a: number) => number) => number ->x => 1 : (x: number) => number ->x : number -} - -module WithCandidates { ->WithCandidates : typeof WithCandidates - - class C { ->C : C ->T : T - - foo2(x: T, cb: (a: T) => U) { ->foo2 : (x: T, cb: (a: T) => U) => U ->T : T ->U : U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T - } - } - - var c: C; ->c : C ->C : C - - var r4 = c.foo2(1, function (a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions ->r4 : string ->c.foo2(1, function (a: Z) { return '' }) : string ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->function (a: Z) { return '' } : (a: Z) => string ->Z : Z ->a : Z ->Z : Z - - var r5 = c.foo2(1, (a) => ''); // string ->r5 : string ->c.foo2(1, (a) => '') : string ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->(a) => '' : (a: number) => string ->a : number - - var r6 = c.foo2('', (a: Z) => 1); // number ->r6 : number ->c.foo2('', (a: Z) => 1) : number ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->(a: Z) => 1 : (a: Z) => number ->Z : Z ->a : Z ->Z : Z - - class C2 { ->C2 : C2 ->T : T ->U : U - - foo3(x: T, cb: (a: T) => U, y: U) { ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U ->y : U ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T - } - } - - var c2: C2; ->c2 : C2 ->C2 : C2 - - var r7 = c2.foo3(1, (a: Z) => '', ''); // string ->r7 : string ->c2.foo3(1, (a: Z) => '', '') : string ->c2.foo3 : (x: number, cb: (a: number) => string, y: string) => string ->c2 : C2 ->foo3 : (x: number, cb: (a: number) => string, y: string) => string ->(a: Z) => '' : (a: Z) => string ->Z : Z ->a : Z ->Z : Z - - var r8 = c2.foo3(1, function (a) { return '' }, ''); // string ->r8 : string ->c2.foo3(1, function (a) { return '' }, '') : string ->c2.foo3 : (x: number, cb: (a: number) => string, y: string) => string ->c2 : C2 ->foo3 : (x: number, cb: (a: number) => string, y: string) => string ->function (a) { return '' } : (a: number) => string ->a : number - - class C3 { ->C3 : C3 ->T : T ->U : U - - foo3(x: T, cb: (a: T) => U, y: U) { ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->T : T ->U : U ->x : T ->T : T ->cb : (a: T) => U ->a : T ->T : T ->U : U ->y : U ->U : U - - return cb(x); ->cb(x) : U ->cb : (a: T) => U ->x : T - } - } - var c3: C3; ->c3 : C3 ->C3 : C3 - - function other(t: T, u: U) { ->other : (t: T, u: U) => void ->T : T ->U : U ->t : T ->T : T ->u : U ->U : U - - var r10 = c.foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made ->r10 : string ->c.foo2(1, (x: T) => '') : string ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r10 = c.foo2(1, (x) => ''); // string ->r10 : string ->c.foo2(1, (x) => '') : string ->c.foo2 : (x: T, cb: (a: T) => U) => U ->c : C ->foo2 : (x: T, cb: (a: T) => U) => U ->(x) => '' : (x: number) => string ->x : number - - var r11 = c3.foo3(1, (x: T) => '', ''); // string ->r11 : string ->c3.foo3(1, (x: T) => '', '') : string ->c3.foo3 : (x: T, cb: (a: T) => U, y: U) => U ->c3 : C3 ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r11b = c3.foo3(1, (x: T) => '', 1); // {} ->r11b : {} ->c3.foo3(1, (x: T) => '', 1) : {} ->c3.foo3 : (x: T, cb: (a: T) => U, y: U) => U ->c3 : C3 ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->(x: T) => '' : (x: T) => string ->x : T ->T : T - - var r12 = c3.foo3(1, function (a) { return '' }, 1); // {} ->r12 : {} ->c3.foo3(1, function (a) { return '' }, 1) : {} ->c3.foo3 : (x: T, cb: (a: T) => U, y: U) => U ->c3 : C3 ->foo3 : (x: T, cb: (a: T) => U, y: U) => U ->function (a) { return '' } : (a: number) => string ->a : number - } -} diff --git a/tests/baselines/reference/genericRestArgs.errors.txt b/tests/baselines/reference/genericRestArgs.errors.txt index db36a9a0162..49f61de325f 100644 --- a/tests/baselines/reference/genericRestArgs.errors.txt +++ b/tests/baselines/reference/genericRestArgs.errors.txt @@ -1,10 +1,14 @@ +tests/cases/compiler/genericRestArgs.ts(2,12): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/genericRestArgs.ts(5,34): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. +tests/cases/compiler/genericRestArgs.ts(10,12): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/genericRestArgs.ts(12,30): error TS2345: Argument of type 'number' is not assignable to parameter of type 'any[]'. -==== tests/cases/compiler/genericRestArgs.ts (2 errors) ==== +==== tests/cases/compiler/genericRestArgs.ts (4 errors) ==== function makeArrayG(...items: T[]): T[] { return items; } var a1Ga = makeArrayG(1, ""); // no error + ~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var a1Gb = makeArrayG(1, ""); var a1Gc = makeArrayG(1, ""); var a1Gd = makeArrayG(1, ""); // error @@ -15,6 +19,8 @@ tests/cases/compiler/genericRestArgs.ts(12,30): error TS2345: Argument of type ' return [item1, item2, item3]; } var a2Ga = makeArrayGOpt(1, ""); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var a2Gb = makeArrayG(1, ""); var a2Gc = makeArrayG(1, ""); // error ~ diff --git a/tests/baselines/reference/genericTypeArgumentInference1.types b/tests/baselines/reference/genericTypeArgumentInference1.types index 20a9a0ca8f9..c718ccca620 100644 --- a/tests/baselines/reference/genericTypeArgumentInference1.types +++ b/tests/baselines/reference/genericTypeArgumentInference1.types @@ -42,12 +42,12 @@ declare var _: Underscore.Static; >Static : Underscore.Static var r = _.all([true, 1, null, 'yes'], _.identity); ->r : {} ->_.all([true, 1, null, 'yes'], _.identity) : {} +>r : string | number | boolean +>_.all([true, 1, null, 'yes'], _.identity) : string | number | boolean >_.all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T >_ : Underscore.Static >all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T ->[true, 1, null, 'yes'] : {}[] +>[true, 1, null, 'yes'] : (string | number | boolean)[] >_.identity : (value: T) => T >_ : Underscore.Static >identity : (value: T) => T @@ -69,7 +69,7 @@ var r3 = _.all([], _.identity); >_.all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T >_ : Underscore.Static >all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T ->[] : any[] +>[] : undefined[] >_.identity : (value: T) => T >_ : Underscore.Static >identity : (value: T) => T diff --git a/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types b/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types index 05697f1e1f9..f0cab6e7467 100644 --- a/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types +++ b/tests/baselines/reference/genericWithIndexerOfTypeParameterType1.types @@ -8,7 +8,7 @@ class LazyArray { ><{ [objectId: string]: T; }>{} : { [x: string]: T; } >objectId : string >T : T ->{} : { [x: string]: T; } +>{} : { [x: string]: undefined; } array() { >array : () => { [x: string]: T; } diff --git a/tests/baselines/reference/genericsManyTypeParameters.types b/tests/baselines/reference/genericsManyTypeParameters.types index 65f9a7c115e..cb492c30623 100644 --- a/tests/baselines/reference/genericsManyTypeParameters.types +++ b/tests/baselines/reference/genericsManyTypeParameters.types @@ -1,6 +1,6 @@ === tests/cases/compiler/genericsManyTypeParameters.ts === function Foo< ->Foo : (x1: a1, y1: a21, z1: a31, a1: a41, b1: a51, c1: a61, x2: a119, y2: a22, z2: a32, a2: a42, b2: a52, c2: a62, x3: a219, y3: a23, z3: a33, a3: a43, b3: a53, c3: a63, x4: a319, y4: a24, z4: a34, a4: a44, b4: a54, c4: a64, x5: a419, y5: a25, z5: a35, a5: a45, b5: a55, c5: a65, x6: a519, y6: a26, z6: a36, a6: a46, b6: a56, c6: a66, x7: a619, y7: a27, z7: a37, a7: a47, b7: a57, c7: a67, x8: a71, y8: a28, z8: a38, a8: a48, b8: a58, c8: a68, x9: a81, y9: a29, z9: a39, a9: a49, b9: a59, c9: a69, x10: a91, y12: a210, z10: a310, a10: a410, b10: a510, c10: a610, x11: a111, y13: a211, z11: a311, a11: a411, b11: a511, c11: a611, x12: a112, y14: a212, z12: a312, a12: a412, b12: a512, c12: a612, x13: a113, y15: a213, z13: a313, a13: a413, b13: a513, c13: a613, x14: a114, y16: a214, z14: a314, a14: a414, b14: a514, c14: a614, x15: a115, y17: a215, z15: a315, a15: a415, b15: a515, c15: a615, x16: a116, y18: a216, z16: a316, a16: a416, b16: a516, c16: a616, x17: a117, y19: a217, z17: a317, a17: a417, b17: a517, c17: a617, x18: a118, y10: a218, z18: a318, a18: a418, b18: a518, c18: a618) => {}[] +>Foo : (x1: a1, y1: a21, z1: a31, a1: a41, b1: a51, c1: a61, x2: a119, y2: a22, z2: a32, a2: a42, b2: a52, c2: a62, x3: a219, y3: a23, z3: a33, a3: a43, b3: a53, c3: a63, x4: a319, y4: a24, z4: a34, a4: a44, b4: a54, c4: a64, x5: a419, y5: a25, z5: a35, a5: a45, b5: a55, c5: a65, x6: a519, y6: a26, z6: a36, a6: a46, b6: a56, c6: a66, x7: a619, y7: a27, z7: a37, a7: a47, b7: a57, c7: a67, x8: a71, y8: a28, z8: a38, a8: a48, b8: a58, c8: a68, x9: a81, y9: a29, z9: a39, a9: a49, b9: a59, c9: a69, x10: a91, y12: a210, z10: a310, a10: a410, b10: a510, c10: a610, x11: a111, y13: a211, z11: a311, a11: a411, b11: a511, c11: a611, x12: a112, y14: a212, z12: a312, a12: a412, b12: a512, c12: a612, x13: a113, y15: a213, z13: a313, a13: a413, b13: a513, c13: a613, x14: a114, y16: a214, z14: a314, a14: a414, b14: a514, c14: a614, x15: a115, y17: a215, z15: a315, a15: a415, b15: a515, c15: a615, x16: a116, y18: a216, z16: a316, a16: a416, b16: a516, c16: a616, x17: a117, y19: a217, z17: a317, a17: a417, b17: a517, c17: a617, x18: a118, y10: a218, z18: a318, a18: a418, b18: a518, c18: a618) => (a1 | a21 | a31 | a41 | a51 | a61 | a119 | a22 | a32 | a42 | a52 | a62 | a219 | a23 | a33 | a43 | a53 | a63 | a319 | a24 | a34 | a44 | a54 | a64 | a419 | a25 | a35 | a45 | a55 | a65 | a519 | a26 | a36 | a46 | a56 | a66 | a619 | a27 | a37 | a47 | a57 | a67 | a71 | a28 | a38 | a48 | a58 | a68 | a81 | a29 | a39 | a49 | a59 | a69 | a91 | a210 | a310 | a410 | a510 | a610 | a111 | a211 | a311 | a411 | a511 | a611 | a112 | a212 | a312 | a412 | a512 | a612 | a113 | a213 | a313 | a413 | a513 | a613 | a114 | a214 | a314 | a414 | a514 | a614 | a115 | a215 | a315 | a415 | a515 | a615 | a116 | a216 | a316 | a416 | a516 | a616 | a117 | a217 | a317 | a417 | a517 | a617 | a118 | a218 | a318 | a418 | a518 | a618)[] a1, a21, a31, a41, a51, a61, >a1 : a1 @@ -402,7 +402,7 @@ function Foo< ) { return [x1 , y1 , z1 , a1 , b1 , c1, ->[x1 , y1 , z1 , a1 , b1 , c1, x2 , y2 , z2 , a2 , b2 , c2, x3 , y3 , z3 , a3 , b3 , c3, x4 , y4 , z4 , a4 , b4 , c4, x5 , y5 , z5 , a5 , b5 , c5, x6 , y6 , z6 , a6 , b6 , c6, x7 , y7 , z7 , a7 , b7 , c7, x8 , y8 , z8 , a8 , b8 , c8, x9 , y9 , z9 , a9 , b9 , c9, x10 , y12 , z10 , a10 , b10 , c10, x11 , y13 , z11 , a11 , b11 , c11, x12 , y14 , z12 , a12 , b12 , c12, x13 , y15 , z13 , a13 , b13 , c13, x14 , y16 , z14 , a14 , b14 , c14, x15 , y17 , z15 , a15 , b15 , c15, x16 , y18 , z16 , a16 , b16 , c16, x17 , y19 , z17 , a17 , b17 , c17, x18 , y10 , z18 , a18 , b18 , c18] : {}[] +>[x1 , y1 , z1 , a1 , b1 , c1, x2 , y2 , z2 , a2 , b2 , c2, x3 , y3 , z3 , a3 , b3 , c3, x4 , y4 , z4 , a4 , b4 , c4, x5 , y5 , z5 , a5 , b5 , c5, x6 , y6 , z6 , a6 , b6 , c6, x7 , y7 , z7 , a7 , b7 , c7, x8 , y8 , z8 , a8 , b8 , c8, x9 , y9 , z9 , a9 , b9 , c9, x10 , y12 , z10 , a10 , b10 , c10, x11 , y13 , z11 , a11 , b11 , c11, x12 , y14 , z12 , a12 , b12 , c12, x13 , y15 , z13 , a13 , b13 , c13, x14 , y16 , z14 , a14 , b14 , c14, x15 , y17 , z15 , a15 , b15 , c15, x16 , y18 , z16 , a16 , b16 , c16, x17 , y19 , z17 , a17 , b17 , c17, x18 , y10 , z18 , a18 , b18 , c18] : (a1 | a21 | a31 | a41 | a51 | a61 | a119 | a22 | a32 | a42 | a52 | a62 | a219 | a23 | a33 | a43 | a53 | a63 | a319 | a24 | a34 | a44 | a54 | a64 | a419 | a25 | a35 | a45 | a55 | a65 | a519 | a26 | a36 | a46 | a56 | a66 | a619 | a27 | a37 | a47 | a57 | a67 | a71 | a28 | a38 | a48 | a58 | a68 | a81 | a29 | a39 | a49 | a59 | a69 | a91 | a210 | a310 | a410 | a510 | a610 | a111 | a211 | a311 | a411 | a511 | a611 | a112 | a212 | a312 | a412 | a512 | a612 | a113 | a213 | a313 | a413 | a513 | a613 | a114 | a214 | a314 | a414 | a514 | a614 | a115 | a215 | a315 | a415 | a515 | a615 | a116 | a216 | a316 | a416 | a516 | a616 | a117 | a217 | a317 | a417 | a517 | a617 | a118 | a218 | a318 | a418 | a518 | a618)[] >x1 : a1 >y1 : a21 >z1 : a31 diff --git a/tests/baselines/reference/getEmitOutputExternalModule.baseline b/tests/baselines/reference/getEmitOutputExternalModule.baseline index b5e670c5fd7..33360cbed61 100644 --- a/tests/baselines/reference/getEmitOutputExternalModule.baseline +++ b/tests/baselines/reference/getEmitOutputExternalModule.baseline @@ -1,9 +1,9 @@ EmitOutputStatus : Succeeded Filename : declSingleFile.js -var x = 5; -var Bar = (function () { - function Bar() { - } - return Bar; -})(); +var x = 5; +var Bar = (function () { + function Bar() { + } + return Bar; +})(); diff --git a/tests/baselines/reference/getEmitOutputExternalModule2.baseline b/tests/baselines/reference/getEmitOutputExternalModule2.baseline index 5c03a092257..ede5474d8cc 100644 --- a/tests/baselines/reference/getEmitOutputExternalModule2.baseline +++ b/tests/baselines/reference/getEmitOutputExternalModule2.baseline @@ -1,15 +1,15 @@ EmitOutputStatus : JSGeneratedWithSemanticErrors Filename : declSingleFile.js -var x = 5; -var Bar = (function () { - function Bar() { - } - return Bar; -})(); -var x = "world"; -var Bar2 = (function () { - function Bar2() { - } - return Bar2; -})(); +var x = 5; +var Bar = (function () { + function Bar() { + } + return Bar; +})(); +var x = "world"; +var Bar2 = (function () { + function Bar2() { + } + return Bar2; +})(); diff --git a/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline b/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline new file mode 100644 index 00000000000..be0ac935601 --- /dev/null +++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile.baseline @@ -0,0 +1,11 @@ +EmitOutputStatus : Succeeded + +EmitOutputStatus : Succeeded +Filename : tests/cases/fourslash/inputFile2.js +var x1 = "hello world"; +var Foo = (function () { + function Foo() { + } + return Foo; +})(); + diff --git a/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline b/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline new file mode 100644 index 00000000000..92a1ea1fe7a --- /dev/null +++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile2.baseline @@ -0,0 +1,15 @@ +EmitOutputStatus : Succeeded + +EmitOutputStatus : Succeeded +Filename : tests/cases/fourslash/inputFile2.js +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +exports.Foo = Foo; + +EmitOutputStatus : Succeeded +Filename : tests/cases/fourslash/inputFile3.js +var x = "hello"; + diff --git a/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline b/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline new file mode 100644 index 00000000000..f960a05f151 --- /dev/null +++ b/tests/baselines/reference/getEmitOutputWithDeclarationFile3.baseline @@ -0,0 +1,5 @@ +EmitOutputStatus : Succeeded +Filename : declSingle.js +var x = "hello"; +var x1 = 1000; + diff --git a/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt b/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt index 072d06e8686..15f8f21b8f3 100644 --- a/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt +++ b/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt @@ -1,5 +1,6 @@ -tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'string[]'. - Type '{}' is not assignable to type 'string'. +tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'string[]'. + Type 'string | number' is not assignable to type 'string': + Type 'number' is not assignable to type 'string'. ==== tests/cases/compiler/heterogeneousArrayAndOverloads.ts (1 errors) ==== @@ -13,7 +14,8 @@ tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argu this.test([]); this.test([1, 2, "hi", 5]); // Error ~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'string[]'. -!!! error TS2345: Type '{}' is not assignable to type 'string'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'string[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'string': +!!! error TS2345: Type 'number' is not assignable to type 'string'. } } \ No newline at end of file diff --git a/tests/baselines/reference/heterogeneousArrayLiterals.types b/tests/baselines/reference/heterogeneousArrayLiterals.types index 81770731633..7ea7d4196a6 100644 --- a/tests/baselines/reference/heterogeneousArrayLiterals.types +++ b/tests/baselines/reference/heterogeneousArrayLiterals.types @@ -2,16 +2,16 @@ // type of an array is the best common type of its elements (plus its contextual type if it exists) var a = [1, '']; // {}[] ->a : {}[] ->[1, ''] : {}[] +>a : (string | number)[] +>[1, ''] : (string | number)[] var b = [1, null]; // number[] >b : number[] >[1, null] : number[] var c = [1, '', null]; // {}[] ->c : {}[] ->[1, '', null] : {}[] +>c : (string | number)[] +>[1, '', null] : (string | number)[] var d = [{}, 1]; // {}[] >d : {}[] @@ -31,8 +31,8 @@ var f = [[], [1]]; // number[][] >[1] : number[] var g = [[1], ['']]; // {}[] ->g : {}[] ->[[1], ['']] : {}[] +>g : (string[] | number[])[] +>[[1], ['']] : (string[] | number[])[] >[1] : number[] >[''] : string[] @@ -46,8 +46,8 @@ var h = [{ foo: 1, bar: '' }, { foo: 2 }]; // {foo: number}[] >foo : number var i = [{ foo: 1, bar: '' }, { foo: '' }]; // {}[] ->i : {}[] ->[{ foo: 1, bar: '' }, { foo: '' }] : {}[] +>i : ({ foo: number; bar: string; } | { foo: string; })[] +>[{ foo: 1, bar: '' }, { foo: '' }] : ({ foo: number; bar: string; } | { foo: string; })[] >{ foo: 1, bar: '' } : { foo: number; bar: string; } >foo : number >bar : string @@ -55,36 +55,36 @@ var i = [{ foo: 1, bar: '' }, { foo: '' }]; // {}[] >foo : string var j = [() => 1, () => '']; // {}[] ->j : {}[] ->[() => 1, () => ''] : {}[] +>j : ((() => number) | (() => string))[] +>[() => 1, () => ''] : ((() => number) | (() => string))[] >() => 1 : () => number >() => '' : () => string var k = [() => 1, () => 1]; // { (): number }[] ->k : { (): number; }[] ->[() => 1, () => 1] : { (): number; }[] +>k : (() => number)[] +>[() => 1, () => 1] : (() => number)[] >() => 1 : () => number >() => 1 : () => number var l = [() => 1, () => null]; // { (): any }[] ->l : { (): any; }[] ->[() => 1, () => null] : { (): any; }[] +>l : (() => any)[] +>[() => 1, () => null] : (() => any)[] >() => 1 : () => number >() => null : () => any var m = [() => 1, () => '', () => null]; // { (): any }[] ->m : { (): any; }[] ->[() => 1, () => '', () => null] : { (): any; }[] +>m : (() => any)[] +>[() => 1, () => '', () => null] : (() => any)[] >() => 1 : () => number >() => '' : () => string >() => null : () => any var n = [[() => 1], [() => '']]; // {}[] ->n : {}[] ->[[() => 1], [() => '']] : {}[] ->[() => 1] : { (): number; }[] +>n : ((() => number)[] | (() => string)[])[] +>[[() => 1], [() => '']] : ((() => number)[] | (() => string)[])[] +>[() => 1] : (() => number)[] >() => 1 : () => number ->[() => ''] : { (): string; }[] +>[() => ''] : (() => string)[] >() => '' : () => string class Base { foo: string; } @@ -129,8 +129,8 @@ module Derived { >base : Base var i = [{ foo: base, basear: derived }, { foo: derived }]; // {foo: Derived}[] ->i : {}[] ->[{ foo: base, basear: derived }, { foo: derived }] : {}[] +>i : ({ foo: Base; basear: Derived; } | { foo: Derived; })[] +>[{ foo: base, basear: derived }, { foo: derived }] : ({ foo: Base; basear: Derived; } | { foo: Derived; })[] >{ foo: base, basear: derived } : { foo: Base; basear: Derived; } >foo : Base >base : Base @@ -141,30 +141,30 @@ module Derived { >derived : Derived var j = [() => base, () => derived]; // { {}: Base } ->j : { (): Base; }[] ->[() => base, () => derived] : { (): Base; }[] +>j : (() => Base)[] +>[() => base, () => derived] : (() => Base)[] >() => base : () => Base >base : Base >() => derived : () => Derived >derived : Derived var k = [() => base, () => 1]; // {}[]~ ->k : {}[] ->[() => base, () => 1] : {}[] +>k : ((() => Base) | (() => number))[] +>[() => base, () => 1] : ((() => Base) | (() => number))[] >() => base : () => Base >base : Base >() => 1 : () => number var l = [() => base, () => null]; // { (): any }[] ->l : { (): any; }[] ->[() => base, () => null] : { (): any; }[] +>l : (() => any)[] +>[() => base, () => null] : (() => any)[] >() => base : () => Base >base : Base >() => null : () => any var m = [() => base, () => derived, () => null]; // { (): any }[] ->m : { (): any; }[] ->[() => base, () => derived, () => null] : { (): any; }[] +>m : (() => any)[] +>[() => base, () => derived, () => null] : (() => any)[] >() => base : () => Base >base : Base >() => derived : () => Derived @@ -172,18 +172,18 @@ module Derived { >() => null : () => any var n = [[() => base], [() => derived]]; // { (): Base }[] ->n : { (): Base; }[][] ->[[() => base], [() => derived]] : { (): Base; }[][] ->[() => base] : { (): Base; }[] +>n : (() => Base)[][] +>[[() => base], [() => derived]] : (() => Base)[][] +>[() => base] : (() => Base)[] >() => base : () => Base >base : Base ->[() => derived] : { (): Derived; }[] +>[() => derived] : (() => Derived)[] >() => derived : () => Derived >derived : Derived var o = [derived, derived2]; // {}[] ->o : {}[] ->[derived, derived2] : {}[] +>o : (Derived | Derived2)[] +>[derived, derived2] : (Derived | Derived2)[] >derived : Derived >derived2 : Derived2 @@ -195,12 +195,12 @@ module Derived { >base : Base var q = [[() => derived2], [() => derived]]; // {}[] ->q : {}[] ->[[() => derived2], [() => derived]] : {}[] ->[() => derived2] : { (): Derived2; }[] +>q : ((() => Derived2)[] | (() => Derived)[])[] +>[[() => derived2], [() => derived]] : ((() => Derived2)[] | (() => Derived)[])[] +>[() => derived2] : (() => Derived2)[] >() => derived2 : () => Derived2 >derived2 : Derived2 ->[() => derived] : { (): Derived; }[] +>[() => derived] : (() => Derived)[] >() => derived : () => Derived >derived : Derived } @@ -212,24 +212,24 @@ module WithContextualType { var a: Base[] = [derived, derived2]; >a : Base[] >Base : Base ->[derived, derived2] : Base[] +>[derived, derived2] : (Derived | Derived2)[] >derived : Derived >derived2 : Derived2 var b: Derived[] = [null]; >b : Derived[] >Derived : Derived ->[null] : Derived[] +>[null] : null[] var c: Derived[] = []; >c : Derived[] >Derived : Derived ->[] : Derived[] +>[] : undefined[] var d: { (): Base }[] = [() => derived, () => derived2]; ->d : { (): Base; }[] +>d : (() => Base)[] >Base : Base ->[() => derived, () => derived2] : { (): Base; }[] +>[() => derived, () => derived2] : ((() => Derived) | (() => Derived2))[] >() => derived : () => Derived >derived : Derived >() => derived2 : () => Derived2 @@ -257,27 +257,27 @@ function foo(t: T, u: U) { >t : T var c = [t, u]; // {}[] ->c : {}[] ->[t, u] : {}[] +>c : (T | U)[] +>[t, u] : (T | U)[] >t : T >u : U var d = [t, 1]; // {}[] ->d : {}[] ->[t, 1] : {}[] +>d : (number | T)[] +>[t, 1] : (number | T)[] >t : T var e = [() => t, () => u]; // {}[] ->e : {}[] ->[() => t, () => u] : {}[] +>e : ((() => T) | (() => U))[] +>[() => t, () => u] : ((() => T) | (() => U))[] >() => t : () => T >t : T >() => u : () => U >u : U var f = [() => t, () => u, () => null]; // { (): any }[] ->f : { (): any; }[] ->[() => t, () => u, () => null] : { (): any; }[] +>f : (() => any)[] +>[() => t, () => u, () => null] : (() => any)[] >() => t : () => T >t : T >() => u : () => U @@ -308,27 +308,27 @@ function foo2(t: T, u: U) { >t : T var c = [t, u]; // {}[] ->c : {}[] ->[t, u] : {}[] +>c : (T | U)[] +>[t, u] : (T | U)[] >t : T >u : U var d = [t, 1]; // {}[] ->d : {}[] ->[t, 1] : {}[] +>d : (number | T)[] +>[t, 1] : (number | T)[] >t : T var e = [() => t, () => u]; // {}[] ->e : {}[] ->[() => t, () => u] : {}[] +>e : ((() => T) | (() => U))[] +>[() => t, () => u] : ((() => T) | (() => U))[] >() => t : () => T >t : T >() => u : () => U >u : U var f = [() => t, () => u, () => null]; // { (): any }[] ->f : { (): any; }[] ->[() => t, () => u, () => null] : { (): any; }[] +>f : (() => any)[] +>[() => t, () => u, () => null] : (() => any)[] >() => t : () => T >t : T >() => u : () => U @@ -342,8 +342,8 @@ function foo2(t: T, u: U) { >base : Base var h = [t, derived]; // Derived[] ->h : {}[] ->[t, derived] : {}[] +>h : (Derived | T)[] +>[t, derived] : (Derived | T)[] >t : T >derived : Derived @@ -383,27 +383,27 @@ function foo3(t: T, u: U) { >t : T var c = [t, u]; // {}[] ->c : {}[] ->[t, u] : {}[] +>c : (T | U)[] +>[t, u] : (T | U)[] >t : T >u : U var d = [t, 1]; // {}[] ->d : {}[] ->[t, 1] : {}[] +>d : (number | T)[] +>[t, 1] : (number | T)[] >t : T var e = [() => t, () => u]; // {}[] ->e : {}[] ->[() => t, () => u] : {}[] +>e : ((() => T) | (() => U))[] +>[() => t, () => u] : ((() => T) | (() => U))[] >() => t : () => T >t : T >() => u : () => U >u : U var f = [() => t, () => u, () => null]; // { (): any }[] ->f : { (): any; }[] ->[() => t, () => u, () => null] : { (): any; }[] +>f : (() => any)[] +>[() => t, () => u, () => null] : (() => any)[] >() => t : () => T >t : T >() => u : () => U @@ -458,27 +458,27 @@ function foo4(t: T, u: U) { >t : T var c = [t, u]; // BUG 821629 ->c : {}[] ->[t, u] : {}[] +>c : (T | U)[] +>[t, u] : (T | U)[] >t : T >u : U var d = [t, 1]; // {}[] ->d : {}[] ->[t, 1] : {}[] +>d : (number | T)[] +>[t, 1] : (number | T)[] >t : T var e = [() => t, () => u]; // {}[] ->e : {}[] ->[() => t, () => u] : {}[] +>e : ((() => T) | (() => U))[] +>[() => t, () => u] : ((() => T) | (() => U))[] >() => t : () => T >t : T >() => u : () => U >u : U var f = [() => t, () => u, () => null]; // { (): any }[] ->f : { (): any; }[] ->[() => t, () => u, () => null] : { (): any; }[] +>f : (() => any)[] +>[() => t, () => u, () => null] : (() => any)[] >() => t : () => T >t : T >() => u : () => U @@ -492,8 +492,8 @@ function foo4(t: T, u: U) { >base : Base var h = [t, derived]; // Derived[] ->h : {}[] ->[t, derived] : {}[] +>h : (Derived | T)[] +>[t, derived] : (Derived | T)[] >t : T >derived : Derived @@ -504,15 +504,15 @@ function foo4(t: T, u: U) { >base : Base var j = [u, derived]; // Derived[] ->j : {}[] ->[u, derived] : {}[] +>j : (Derived | U)[] +>[u, derived] : (Derived | U)[] >u : U >derived : Derived var k: Base[] = [t, u]; >k : Base[] >Base : Base ->[t, u] : Base[] +>[t, u] : (T | U)[] >t : T >u : U } diff --git a/tests/baselines/reference/incrementOperatorWithAnyOtherType.types b/tests/baselines/reference/incrementOperatorWithAnyOtherType.types index 165c166941c..930c87274d0 100644 --- a/tests/baselines/reference/incrementOperatorWithAnyOtherType.types +++ b/tests/baselines/reference/incrementOperatorWithAnyOtherType.types @@ -9,7 +9,7 @@ var ANY1; var ANY2: any[] = ["", ""]; >ANY2 : any[] ->["", ""] : any[] +>["", ""] : string[] var obj = {x:1,y:null}; >obj : { x: number; y: any; } diff --git a/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt b/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt new file mode 100644 index 00000000000..9bcf6c7612f --- /dev/null +++ b/tests/baselines/reference/incrementOperatorWithEnumType.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(7,23): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts(12,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + + +==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts (2 errors) ==== + // ++ operator on enum type + + enum ENUM1 { A, B, "" }; + + // expression + var ResultIsNumber1 = ++ENUM1["B"]; + var ResultIsNumber2 = ENUM1.B++; + ~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + + // miss assignment operator + ++ENUM1["B"]; + + ENUM1.B++; + ~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. \ No newline at end of file diff --git a/tests/baselines/reference/incrementOperatorWithEnumType.js b/tests/baselines/reference/incrementOperatorWithEnumType.js index cdea036c335..2baa326f399 100644 --- a/tests/baselines/reference/incrementOperatorWithEnumType.js +++ b/tests/baselines/reference/incrementOperatorWithEnumType.js @@ -1,29 +1,29 @@ //// [incrementOperatorWithEnumType.ts] // ++ operator on enum type -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // expression -var ResultIsNumber1 = ++ENUM1[1]; -var ResultIsNumber2 = ENUM1[1]++; +var ResultIsNumber1 = ++ENUM1["B"]; +var ResultIsNumber2 = ENUM1.B++; // miss assignment operator -++ENUM1[1]; +++ENUM1["B"]; -ENUM1[1]++; +ENUM1.B++; //// [incrementOperatorWithEnumType.js] // ++ operator on enum type var ENUM1; (function (ENUM1) { - ENUM1[ENUM1["1"] = 0] = "1"; - ENUM1[ENUM1["2"] = 1] = "2"; + ENUM1[ENUM1["A"] = 0] = "A"; + ENUM1[ENUM1["B"] = 1] = "B"; ENUM1[ENUM1[""] = 2] = ""; })(ENUM1 || (ENUM1 = {})); ; // expression -var ResultIsNumber1 = ++ENUM1[1]; -var ResultIsNumber2 = ENUM1[1]++; +var ResultIsNumber1 = ++ENUM1["B"]; +var ResultIsNumber2 = 1 /* B */++; // miss assignment operator -++ENUM1[1]; -ENUM1[1]++; +++ENUM1["B"]; +1 /* B */++; diff --git a/tests/baselines/reference/incrementOperatorWithEnumType.types b/tests/baselines/reference/incrementOperatorWithEnumType.types deleted file mode 100644 index 3b13c01d5df..00000000000 --- a/tests/baselines/reference/incrementOperatorWithEnumType.types +++ /dev/null @@ -1,30 +0,0 @@ -=== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts === -// ++ operator on enum type - -enum ENUM1 { 1, 2, "" }; ->ENUM1 : ENUM1 - -// expression -var ResultIsNumber1 = ++ENUM1[1]; ->ResultIsNumber1 : number ->++ENUM1[1] : number ->ENUM1[1] : ENUM1 ->ENUM1 : typeof ENUM1 - -var ResultIsNumber2 = ENUM1[1]++; ->ResultIsNumber2 : number ->ENUM1[1]++ : number ->ENUM1[1] : ENUM1 ->ENUM1 : typeof ENUM1 - -// miss assignment operator -++ENUM1[1]; ->++ENUM1[1] : number ->ENUM1[1] : ENUM1 ->ENUM1 : typeof ENUM1 - -ENUM1[1]++; ->ENUM1[1]++ : number ->ENUM1[1] : ENUM1 ->ENUM1 : typeof ENUM1 - diff --git a/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.errors.txt b/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.errors.txt index 81b091264bb..08a1b8ec460 100644 --- a/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.errors.txt +++ b/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.errors.txt @@ -14,7 +14,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp // ++ operator on enum type enum ENUM { }; - enum ENUM1 { 1, 2, "" }; + enum ENUM1 { A, B, "" }; // enum type var var ResultIsNumber1 = ++ENUM; diff --git a/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.js b/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.js index ed9b33e16bb..3bc43cefa4b 100644 --- a/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.js +++ b/tests/baselines/reference/incrementOperatorWithEnumTypeInvalidOperations.js @@ -2,7 +2,7 @@ // ++ operator on enum type enum ENUM { }; -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsNumber1 = ++ENUM; @@ -30,8 +30,8 @@ var ENUM; ; var ENUM1; (function (ENUM1) { - ENUM1[ENUM1["1"] = 0] = "1"; - ENUM1[ENUM1["2"] = 1] = "2"; + ENUM1[ENUM1["A"] = 0] = "A"; + ENUM1[ENUM1["B"] = 1] = "B"; ENUM1[ENUM1[""] = 2] = ""; })(ENUM1 || (ENUM1 = {})); ; diff --git a/tests/baselines/reference/indexSignaturesInferentialTyping.types b/tests/baselines/reference/indexSignaturesInferentialTyping.types index 3c16db3a2bf..4054ccca227 100644 --- a/tests/baselines/reference/indexSignaturesInferentialTyping.types +++ b/tests/baselines/reference/indexSignaturesInferentialTyping.types @@ -24,10 +24,10 @@ var x1 = foo({ 0: 0, 1: 1 }); // type should be number >{ 0: 0, 1: 1 } : { [x: number]: number; 0: number; 1: number; } var x2 = foo({ zero: 0, one: 1 }); ->x2 : {} ->foo({ zero: 0, one: 1 }) : {} +>x2 : any +>foo({ zero: 0, one: 1 }) : any >foo : (items: { [x: number]: T; }) => T ->{ zero: 0, one: 1 } : { [x: number]: {}; zero: number; one: number; } +>{ zero: 0, one: 1 } : { [x: number]: undefined; zero: number; one: number; } >zero : number >one : number diff --git a/tests/baselines/reference/indexer.types b/tests/baselines/reference/indexer.types index 236113cfaa8..9987fdde0b1 100644 --- a/tests/baselines/reference/indexer.types +++ b/tests/baselines/reference/indexer.types @@ -17,7 +17,7 @@ interface JQuery { var jq:JQuery={ 0: { id : "a" }, 1: { id : "b" } }; >jq : JQuery >JQuery : JQuery ->{ 0: { id : "a" }, 1: { id : "b" } } : { [x: number]: JQueryElement; 0: { id: string; }; 1: { id: string; }; } +>{ 0: { id : "a" }, 1: { id : "b" } } : { [x: number]: { id: string; }; 0: { id: string; }; 1: { id: string; }; } >{ id : "a" } : { id: string; } >id : string >{ id : "b" } : { id: string; } diff --git a/tests/baselines/reference/indexer2.errors.txt b/tests/baselines/reference/indexer2.errors.txt new file mode 100644 index 00000000000..9587bb6bb75 --- /dev/null +++ b/tests/baselines/reference/indexer2.errors.txt @@ -0,0 +1,20 @@ +tests/cases/compiler/indexer2.ts(6,25): error TS2353: Neither type '{ [x: number]: undefined; }' nor type 'IDirectChildrenMap' is assignable to the other: + Types of property 'hasOwnProperty' are incompatible: + Type '(v: string) => boolean' is not assignable to type '(objectId: number) => boolean': + Types of parameters 'v' and 'objectId' are incompatible: + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/compiler/indexer2.ts (1 errors) ==== + interface IHeapObjectProperty {} + interface IDirectChildrenMap { + hasOwnProperty(objectId: number) : boolean; + [objectId: number] : IHeapObjectProperty[]; + } + var directChildrenMap = {}; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2353: Neither type '{ [x: number]: undefined; }' nor type 'IDirectChildrenMap' is assignable to the other: +!!! error TS2353: Types of property 'hasOwnProperty' are incompatible: +!!! error TS2353: Type '(v: string) => boolean' is not assignable to type '(objectId: number) => boolean': +!!! error TS2353: Types of parameters 'v' and 'objectId' are incompatible: +!!! error TS2353: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/indexer2.types b/tests/baselines/reference/indexer2.types deleted file mode 100644 index 498ade679a8..00000000000 --- a/tests/baselines/reference/indexer2.types +++ /dev/null @@ -1,21 +0,0 @@ -=== tests/cases/compiler/indexer2.ts === -interface IHeapObjectProperty {} ->IHeapObjectProperty : IHeapObjectProperty - -interface IDirectChildrenMap { ->IDirectChildrenMap : IDirectChildrenMap - - hasOwnProperty(objectId: number) : boolean; ->hasOwnProperty : (objectId: number) => boolean ->objectId : number - - [objectId: number] : IHeapObjectProperty[]; ->objectId : number ->IHeapObjectProperty : IHeapObjectProperty -} -var directChildrenMap = {}; ->directChildrenMap : IDirectChildrenMap ->{} : IDirectChildrenMap ->IDirectChildrenMap : IDirectChildrenMap ->{} : { [x: number]: IHeapObjectProperty[]; } - diff --git a/tests/baselines/reference/indexer2A.errors.txt b/tests/baselines/reference/indexer2A.errors.txt index adf90fb743f..548ed5e565b 100644 --- a/tests/baselines/reference/indexer2A.errors.txt +++ b/tests/baselines/reference/indexer2A.errors.txt @@ -1,7 +1,12 @@ tests/cases/compiler/indexer2A.ts(4,5): error TS2391: Function implementation is missing or not immediately following the declaration. +tests/cases/compiler/indexer2A.ts(7,25): error TS2353: Neither type '{ [x: number]: undefined; }' nor type 'IDirectChildrenMap' is assignable to the other: + Types of property 'hasOwnProperty' are incompatible: + Type '(v: string) => boolean' is not assignable to type '(objectId: number) => boolean': + Types of parameters 'v' and 'objectId' are incompatible: + Type 'string' is not assignable to type 'number'. -==== tests/cases/compiler/indexer2A.ts (1 errors) ==== +==== tests/cases/compiler/indexer2A.ts (2 errors) ==== class IHeapObjectProperty { } class IDirectChildrenMap { // Decided to enforce a semicolon after declarations @@ -10,4 +15,10 @@ tests/cases/compiler/indexer2A.ts(4,5): error TS2391: Function implementation is !!! error TS2391: Function implementation is missing or not immediately following the declaration. [objectId: number]: IHeapObjectProperty[] } - var directChildrenMap = {}; \ No newline at end of file + var directChildrenMap = {}; + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2353: Neither type '{ [x: number]: undefined; }' nor type 'IDirectChildrenMap' is assignable to the other: +!!! error TS2353: Types of property 'hasOwnProperty' are incompatible: +!!! error TS2353: Type '(v: string) => boolean' is not assignable to type '(objectId: number) => boolean': +!!! error TS2353: Types of parameters 'v' and 'objectId' are incompatible: +!!! error TS2353: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/indexer3.types b/tests/baselines/reference/indexer3.types index 2b23ac85885..7f660ab6aa9 100644 --- a/tests/baselines/reference/indexer3.types +++ b/tests/baselines/reference/indexer3.types @@ -3,7 +3,7 @@ var dateMap: { [x: string]: Date; } = {} >dateMap : { [x: string]: Date; } >x : string >Date : Date ->{} : { [x: string]: Date; } +>{} : { [x: string]: undefined; } var r: Date = dateMap["hello"] // result type includes indexer using BCT >r : Date diff --git a/tests/baselines/reference/indexerA.types b/tests/baselines/reference/indexerA.types index 7b409ecedc0..39f7372c839 100644 --- a/tests/baselines/reference/indexerA.types +++ b/tests/baselines/reference/indexerA.types @@ -17,7 +17,7 @@ class JQuery { var jq:JQuery={ 0: { id : "a" }, 1: { id : "b" } }; >jq : JQuery >JQuery : JQuery ->{ 0: { id : "a" }, 1: { id : "b" } } : { [x: number]: JQueryElement; 0: { id: string; }; 1: { id: string; }; } +>{ 0: { id : "a" }, 1: { id : "b" } } : { [x: number]: { id: string; }; 0: { id: string; }; 1: { id: string; }; } >{ id : "a" } : { id: string; } >id : string >{ id : "b" } : { id: string; } diff --git a/tests/baselines/reference/indexerWithTuple.js b/tests/baselines/reference/indexerWithTuple.js index bc3bee9dd17..fc82716ba05 100644 --- a/tests/baselines/reference/indexerWithTuple.js +++ b/tests/baselines/reference/indexerWithTuple.js @@ -1,4 +1,4 @@ -//// [indexerWithTuple.ts] +//// [indexerWithTuple.ts] var strNumTuple: [string, number] = ["foo", 10]; var numTupleTuple: [number, [string, number]] = [10, ["bar", 20]]; @@ -13,20 +13,20 @@ var ele14 = strNumTuple[idx1]; // {} var ele15 = strNumTuple["0"]; // string var ele16 = strNumTuple["1"]; // number var strNumTuple1 = numTupleTuple[1]; //[string, number]; -var ele17 = numTupleTuple[2]; // {} - -//// [indexerWithTuple.js] -var strNumTuple = ["foo", 10]; -var numTupleTuple = [10, ["bar", 20]]; -// no error -var idx0 = 0; -var idx1 = 1; -var ele10 = strNumTuple[0]; // string -var ele11 = strNumTuple[1]; // number -var ele12 = strNumTuple[2]; // {} -var ele13 = strNumTuple[idx0]; // {} -var ele14 = strNumTuple[idx1]; // {} -var ele15 = strNumTuple["0"]; // string -var ele16 = strNumTuple["1"]; // number -var strNumTuple1 = numTupleTuple[1]; //[string, number]; -var ele17 = numTupleTuple[2]; // {} +var ele17 = numTupleTuple[2]; // {} + +//// [indexerWithTuple.js] +var strNumTuple = ["foo", 10]; +var numTupleTuple = [10, ["bar", 20]]; +// no error +var idx0 = 0; +var idx1 = 1; +var ele10 = strNumTuple[0]; // string +var ele11 = strNumTuple[1]; // number +var ele12 = strNumTuple[2]; // {} +var ele13 = strNumTuple[idx0]; // {} +var ele14 = strNumTuple[idx1]; // {} +var ele15 = strNumTuple["0"]; // string +var ele16 = strNumTuple["1"]; // number +var strNumTuple1 = numTupleTuple[1]; //[string, number]; +var ele17 = numTupleTuple[2]; // {} diff --git a/tests/baselines/reference/indexerWithTuple.types b/tests/baselines/reference/indexerWithTuple.types index 7c22cac407f..28053a33081 100644 --- a/tests/baselines/reference/indexerWithTuple.types +++ b/tests/baselines/reference/indexerWithTuple.types @@ -1,64 +1,64 @@ -=== tests/cases/conformance/types/tuple/indexerWithTuple.ts === -var strNumTuple: [string, number] = ["foo", 10]; ->strNumTuple : [string, number] ->["foo", 10] : [string, number] - -var numTupleTuple: [number, [string, number]] = [10, ["bar", 20]]; ->numTupleTuple : [number, [string, number]] ->[10, ["bar", 20]] : [number, [string, number]] ->["bar", 20] : [string, number] - -// no error -var idx0 = 0; ->idx0 : number - -var idx1 = 1; ->idx1 : number - -var ele10 = strNumTuple[0]; // string ->ele10 : string ->strNumTuple[0] : string ->strNumTuple : [string, number] - -var ele11 = strNumTuple[1]; // number ->ele11 : number ->strNumTuple[1] : number ->strNumTuple : [string, number] - -var ele12 = strNumTuple[2]; // {} ->ele12 : {} ->strNumTuple[2] : {} ->strNumTuple : [string, number] - -var ele13 = strNumTuple[idx0]; // {} ->ele13 : {} ->strNumTuple[idx0] : {} ->strNumTuple : [string, number] ->idx0 : number - -var ele14 = strNumTuple[idx1]; // {} ->ele14 : {} ->strNumTuple[idx1] : {} ->strNumTuple : [string, number] ->idx1 : number - -var ele15 = strNumTuple["0"]; // string ->ele15 : string ->strNumTuple["0"] : string ->strNumTuple : [string, number] - -var ele16 = strNumTuple["1"]; // number ->ele16 : number ->strNumTuple["1"] : number ->strNumTuple : [string, number] - -var strNumTuple1 = numTupleTuple[1]; //[string, number]; ->strNumTuple1 : [string, number] ->numTupleTuple[1] : [string, number] ->numTupleTuple : [number, [string, number]] - -var ele17 = numTupleTuple[2]; // {} ->ele17 : {} ->numTupleTuple[2] : {} ->numTupleTuple : [number, [string, number]] - +=== tests/cases/conformance/types/tuple/indexerWithTuple.ts === +var strNumTuple: [string, number] = ["foo", 10]; +>strNumTuple : [string, number] +>["foo", 10] : [string, number] + +var numTupleTuple: [number, [string, number]] = [10, ["bar", 20]]; +>numTupleTuple : [number, [string, number]] +>[10, ["bar", 20]] : [number, [string, number]] +>["bar", 20] : [string, number] + +// no error +var idx0 = 0; +>idx0 : number + +var idx1 = 1; +>idx1 : number + +var ele10 = strNumTuple[0]; // string +>ele10 : string +>strNumTuple[0] : string +>strNumTuple : [string, number] + +var ele11 = strNumTuple[1]; // number +>ele11 : number +>strNumTuple[1] : number +>strNumTuple : [string, number] + +var ele12 = strNumTuple[2]; // {} +>ele12 : string | number +>strNumTuple[2] : string | number +>strNumTuple : [string, number] + +var ele13 = strNumTuple[idx0]; // {} +>ele13 : string | number +>strNumTuple[idx0] : string | number +>strNumTuple : [string, number] +>idx0 : number + +var ele14 = strNumTuple[idx1]; // {} +>ele14 : string | number +>strNumTuple[idx1] : string | number +>strNumTuple : [string, number] +>idx1 : number + +var ele15 = strNumTuple["0"]; // string +>ele15 : string +>strNumTuple["0"] : string +>strNumTuple : [string, number] + +var ele16 = strNumTuple["1"]; // number +>ele16 : number +>strNumTuple["1"] : number +>strNumTuple : [string, number] + +var strNumTuple1 = numTupleTuple[1]; //[string, number]; +>strNumTuple1 : [string, number] +>numTupleTuple[1] : [string, number] +>numTupleTuple : [number, [string, number]] + +var ele17 = numTupleTuple[2]; // {} +>ele17 : number | [string, number] +>numTupleTuple[2] : number | [string, number] +>numTupleTuple : [number, [string, number]] + diff --git a/tests/baselines/reference/inferentialTypingWithFunctionTypeZip.types b/tests/baselines/reference/inferentialTypingWithFunctionTypeZip.types index 11e017d6661..53a9dff0b48 100644 --- a/tests/baselines/reference/inferentialTypingWithFunctionTypeZip.types +++ b/tests/baselines/reference/inferentialTypingWithFunctionTypeZip.types @@ -34,7 +34,7 @@ var result = zipWith([1, 2], ['a', 'b'], pair); >zipWith([1, 2], ['a', 'b'], pair) : { x: number; y: {}; }[] >zipWith : (a: T[], b: S[], f: (x: T) => (y: S) => U) => U[] >[1, 2] : number[] ->['a', 'b'] : {}[] +>['a', 'b'] : string[] >pair : (x: T) => (y: S) => { x: T; y: S; } var i = result[0].x; // number diff --git a/tests/baselines/reference/inferentiallyTypingAnEmptyArray.types b/tests/baselines/reference/inferentiallyTypingAnEmptyArray.types index c8f51c985e6..451280ee16f 100644 --- a/tests/baselines/reference/inferentiallyTypingAnEmptyArray.types +++ b/tests/baselines/reference/inferentiallyTypingAnEmptyArray.types @@ -25,6 +25,6 @@ foo([]).bar; >foo([]).bar : any >foo([]) : any >foo : (arr: T[]) => T ->[] : any[] +>[] : undefined[] >bar : any diff --git a/tests/baselines/reference/interfaceContextualType.types b/tests/baselines/reference/interfaceContextualType.types index 88ba9dcbc24..3078ecfdfa4 100644 --- a/tests/baselines/reference/interfaceContextualType.types +++ b/tests/baselines/reference/interfaceContextualType.types @@ -27,11 +27,11 @@ class Bug { >ok : () => void this.values = {}; ->this.values = {} : { [x: string]: IOptions; } +>this.values = {} : { [x: string]: undefined; } >this.values : IMap >this : Bug >values : IMap ->{} : { [x: string]: IOptions; } +>{} : { [x: string]: undefined; } this.values['comments'] = { italic: true }; >this.values['comments'] = { italic: true } : { italic: boolean; } @@ -46,11 +46,11 @@ class Bug { >shouldBeOK : () => void this.values = { ->this.values = { comments: { italic: true } } : { [x: string]: IOptions; comments: { italic: boolean; }; } +>this.values = { comments: { italic: true } } : { [x: string]: { italic: boolean; }; comments: { italic: boolean; }; } >this.values : IMap >this : Bug >values : IMap ->{ comments: { italic: true } } : { [x: string]: IOptions; comments: { italic: boolean; }; } +>{ comments: { italic: true } } : { [x: string]: { italic: boolean; }; comments: { italic: boolean; }; } comments: { italic: true } >comments : { italic: boolean; } diff --git a/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt b/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt index 0a4761994dd..3ec718f3b25 100644 --- a/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt +++ b/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt @@ -7,7 +7,7 @@ tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDec tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(40,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'I', but here has type 'C2'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(43,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'f' must be of type '(x: string) => number', but here has type '(x: number) => string'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(46,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. -tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(47,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '{}[]'. +tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(47,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '(C | D)[]'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(50,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'D[]', but here has type 'D[]'. tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts(53,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'm' must be of type 'typeof M', but here has type 'typeof A'. @@ -79,7 +79,7 @@ tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDec !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. var arr = [new C(), new C2(), new D()]; ~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '{}[]'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '(C | D)[]'. var arr2 = [new D()]; var arr2 = new Array>(); diff --git a/tests/baselines/reference/logicalNotOperatorWithEnumType.js b/tests/baselines/reference/logicalNotOperatorWithEnumType.js index 19efcc979ad..69ea283051d 100644 --- a/tests/baselines/reference/logicalNotOperatorWithEnumType.js +++ b/tests/baselines/reference/logicalNotOperatorWithEnumType.js @@ -1,33 +1,33 @@ //// [logicalNotOperatorWithEnumType.ts] // ! operator on enum type -enum ENUM { 1, 2, 3 }; +enum ENUM { A, B, C }; enum ENUM1 { }; // enum type var var ResultIsBoolean1 = !ENUM; // enum type expressions -var ResultIsBoolean2 = !ENUM[1]; -var ResultIsBoolean3 = !(ENUM[1] + ENUM[2]); +var ResultIsBoolean2 = !ENUM["B"]; +var ResultIsBoolean3 = !(ENUM.B + ENUM["C"]); // multiple ! operators var ResultIsBoolean4 = !!ENUM; -var ResultIsBoolean5 = !!!(ENUM[1] + ENUM[2]); +var ResultIsBoolean5 = !!!(ENUM["B"] + ENUM.C); // miss assignment operators !ENUM; !ENUM1; -!ENUM[1]; +!ENUM.B; !ENUM, ENUM1; //// [logicalNotOperatorWithEnumType.js] // ! operator on enum type var ENUM; (function (ENUM) { - ENUM[ENUM["1"] = 0] = "1"; - ENUM[ENUM["2"] = 1] = "2"; - ENUM[ENUM["3"] = 2] = "3"; + ENUM[ENUM["A"] = 0] = "A"; + ENUM[ENUM["B"] = 1] = "B"; + ENUM[ENUM["C"] = 2] = "C"; })(ENUM || (ENUM = {})); ; var ENUM1; @@ -37,13 +37,13 @@ var ENUM1; // enum type var var ResultIsBoolean1 = !ENUM; // enum type expressions -var ResultIsBoolean2 = !ENUM[1]; -var ResultIsBoolean3 = !(ENUM[1] + ENUM[2]); +var ResultIsBoolean2 = !ENUM["B"]; +var ResultIsBoolean3 = !(1 /* B */ + ENUM["C"]); // multiple ! operators var ResultIsBoolean4 = !!ENUM; -var ResultIsBoolean5 = !!!(ENUM[1] + ENUM[2]); +var ResultIsBoolean5 = !!!(ENUM["B"] + 2 /* C */); // miss assignment operators !ENUM; !ENUM1; -!ENUM[1]; +!1 /* B */; !ENUM, ENUM1; diff --git a/tests/baselines/reference/logicalNotOperatorWithEnumType.types b/tests/baselines/reference/logicalNotOperatorWithEnumType.types index 27cbb24d3bb..f3c9d98c95b 100644 --- a/tests/baselines/reference/logicalNotOperatorWithEnumType.types +++ b/tests/baselines/reference/logicalNotOperatorWithEnumType.types @@ -1,8 +1,11 @@ === tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithEnumType.ts === // ! operator on enum type -enum ENUM { 1, 2, 3 }; +enum ENUM { A, B, C }; >ENUM : ENUM +>A : ENUM +>B : ENUM +>C : ENUM enum ENUM1 { }; >ENUM1 : ENUM1 @@ -14,20 +17,21 @@ var ResultIsBoolean1 = !ENUM; >ENUM : typeof ENUM // enum type expressions -var ResultIsBoolean2 = !ENUM[1]; +var ResultIsBoolean2 = !ENUM["B"]; >ResultIsBoolean2 : boolean ->!ENUM[1] : boolean ->ENUM[1] : ENUM +>!ENUM["B"] : boolean +>ENUM["B"] : ENUM >ENUM : typeof ENUM -var ResultIsBoolean3 = !(ENUM[1] + ENUM[2]); +var ResultIsBoolean3 = !(ENUM.B + ENUM["C"]); >ResultIsBoolean3 : boolean ->!(ENUM[1] + ENUM[2]) : boolean ->(ENUM[1] + ENUM[2]) : number ->ENUM[1] + ENUM[2] : number ->ENUM[1] : ENUM +>!(ENUM.B + ENUM["C"]) : boolean +>(ENUM.B + ENUM["C"]) : number +>ENUM.B + ENUM["C"] : number +>ENUM.B : ENUM >ENUM : typeof ENUM ->ENUM[2] : ENUM +>B : ENUM +>ENUM["C"] : ENUM >ENUM : typeof ENUM // multiple ! operators @@ -37,17 +41,18 @@ var ResultIsBoolean4 = !!ENUM; >!ENUM : boolean >ENUM : typeof ENUM -var ResultIsBoolean5 = !!!(ENUM[1] + ENUM[2]); +var ResultIsBoolean5 = !!!(ENUM["B"] + ENUM.C); >ResultIsBoolean5 : boolean ->!!!(ENUM[1] + ENUM[2]) : boolean ->!!(ENUM[1] + ENUM[2]) : boolean ->!(ENUM[1] + ENUM[2]) : boolean ->(ENUM[1] + ENUM[2]) : number ->ENUM[1] + ENUM[2] : number ->ENUM[1] : ENUM +>!!!(ENUM["B"] + ENUM.C) : boolean +>!!(ENUM["B"] + ENUM.C) : boolean +>!(ENUM["B"] + ENUM.C) : boolean +>(ENUM["B"] + ENUM.C) : number +>ENUM["B"] + ENUM.C : number +>ENUM["B"] : ENUM >ENUM : typeof ENUM ->ENUM[2] : ENUM +>ENUM.C : ENUM >ENUM : typeof ENUM +>C : ENUM // miss assignment operators !ENUM; @@ -58,10 +63,11 @@ var ResultIsBoolean5 = !!!(ENUM[1] + ENUM[2]); >!ENUM1 : boolean >ENUM1 : typeof ENUM1 -!ENUM[1]; ->!ENUM[1] : boolean ->ENUM[1] : ENUM +!ENUM.B; +>!ENUM.B : boolean +>ENUM.B : ENUM >ENUM : typeof ENUM +>B : ENUM !ENUM, ENUM1; >!ENUM, ENUM1 : typeof ENUM1 diff --git a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types b/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types index d44b220e818..95c9643c29a 100644 --- a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types +++ b/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types @@ -7,7 +7,7 @@ var r: { a: string } = { a: '', b: 123 } || { a: '', b: true }; >r : { a: string; } >a : string ->{ a: '', b: 123 } || { a: '', b: true } : { a: string; } +>{ a: '', b: 123 } || { a: '', b: true } : { a: string; b: number; } | { a: string; b: boolean; } >{ a: '', b: 123 } : { a: string; b: number; } >a : string >b : number diff --git a/tests/baselines/reference/logicalOrOperatorWithEveryType.types b/tests/baselines/reference/logicalOrOperatorWithEveryType.types index 3cf0399f437..3e3b0dcf37f 100644 --- a/tests/baselines/reference/logicalOrOperatorWithEveryType.types +++ b/tests/baselines/reference/logicalOrOperatorWithEveryType.types @@ -108,38 +108,38 @@ var rb2 = a2 || a2; // boolean || boolean is boolean >a2 : boolean var rb3 = a3 || a2; // number || boolean is {} ->rb3 : {} ->a3 || a2 : {} +>rb3 : number | boolean +>a3 || a2 : number | boolean >a3 : number >a2 : boolean var rb4 = a4 || a2; // string || boolean is {} ->rb4 : {} ->a4 || a2 : {} +>rb4 : string | boolean +>a4 || a2 : string | boolean >a4 : string >a2 : boolean var rb5 = a5 || a2; // void || boolean is {} ->rb5 : {} ->a5 || a2 : {} +>rb5 : boolean | void +>a5 || a2 : boolean | void >a5 : void >a2 : boolean var rb6 = a6 || a2; // enum || boolean is {} ->rb6 : {} ->a6 || a2 : {} +>rb6 : boolean | E +>a6 || a2 : boolean | E >a6 : E >a2 : boolean var rb7 = a7 || a2; // object || boolean is {} ->rb7 : {} ->a7 || a2 : {} +>rb7 : boolean | { a: string; } +>a7 || a2 : boolean | { a: string; } >a7 : { a: string; } >a2 : boolean var rb8 = a8 || a2; // array || boolean is {} ->rb8 : {} ->a8 || a2 : {} +>rb8 : boolean | string[] +>a8 || a2 : boolean | string[] >a8 : string[] >a2 : boolean @@ -161,8 +161,8 @@ var rc1 = a1 || a3; // any || number is any >a3 : number var rc2 = a2 || a3; // boolean || number is {} ->rc2 : {} ->a2 || a3 : {} +>rc2 : number | boolean +>a2 || a3 : number | boolean >a2 : boolean >a3 : number @@ -173,14 +173,14 @@ var rc3 = a3 || a3; // number || number is number >a3 : number var rc4 = a4 || a3; // string || number is {} ->rc4 : {} ->a4 || a3 : {} +>rc4 : string | number +>a4 || a3 : string | number >a4 : string >a3 : number var rc5 = a5 || a3; // void || number is {} ->rc5 : {} ->a5 || a3 : {} +>rc5 : number | void +>a5 || a3 : number | void >a5 : void >a3 : number @@ -191,14 +191,14 @@ var rc6 = a6 || a3; // enum || number is number >a3 : number var rc7 = a7 || a3; // object || number is {} ->rc7 : {} ->a7 || a3 : {} +>rc7 : number | { a: string; } +>a7 || a3 : number | { a: string; } >a7 : { a: string; } >a3 : number var rc8 = a8 || a3; // array || number is {} ->rc8 : {} ->a8 || a3 : {} +>rc8 : number | string[] +>a8 || a3 : number | string[] >a8 : string[] >a3 : number @@ -220,14 +220,14 @@ var rd1 = a1 || a4; // any || string is any >a4 : string var rd2 = a2 || a4; // boolean || string is {} ->rd2 : {} ->a2 || a4 : {} +>rd2 : string | boolean +>a2 || a4 : string | boolean >a2 : boolean >a4 : string var rd3 = a3 || a4; // number || string is {} ->rd3 : {} ->a3 || a4 : {} +>rd3 : string | number +>a3 || a4 : string | number >a3 : number >a4 : string @@ -238,26 +238,26 @@ var rd4 = a4 || a4; // string || string is string >a4 : string var rd5 = a5 || a4; // void || string is {} ->rd5 : {} ->a5 || a4 : {} +>rd5 : string | void +>a5 || a4 : string | void >a5 : void >a4 : string var rd6 = a6 || a4; // enum || string is {} ->rd6 : {} ->a6 || a4 : {} +>rd6 : string | E +>a6 || a4 : string | E >a6 : E >a4 : string var rd7 = a7 || a4; // object || string is {} ->rd7 : {} ->a7 || a4 : {} +>rd7 : string | { a: string; } +>a7 || a4 : string | { a: string; } >a7 : { a: string; } >a4 : string var rd8 = a8 || a4; // array || string is {} ->rd8 : {} ->a8 || a4 : {} +>rd8 : string | string[] +>a8 || a4 : string | string[] >a8 : string[] >a4 : string @@ -279,20 +279,20 @@ var re1 = a1 || a5; // any || void is any >a5 : void var re2 = a2 || a5; // boolean || void is {} ->re2 : {} ->a2 || a5 : {} +>re2 : boolean | void +>a2 || a5 : boolean | void >a2 : boolean >a5 : void var re3 = a3 || a5; // number || void is {} ->re3 : {} ->a3 || a5 : {} +>re3 : number | void +>a3 || a5 : number | void >a3 : number >a5 : void var re4 = a4 || a5; // string || void is {} ->re4 : {} ->a4 || a5 : {} +>re4 : string | void +>a4 || a5 : string | void >a4 : string >a5 : void @@ -303,20 +303,20 @@ var re5 = a5 || a5; // void || void is void >a5 : void var re6 = a6 || a5; // enum || void is {} ->re6 : {} ->a6 || a5 : {} +>re6 : void | E +>a6 || a5 : void | E >a6 : E >a5 : void var re7 = a7 || a5; // object || void is {} ->re7 : {} ->a7 || a5 : {} +>re7 : void | { a: string; } +>a7 || a5 : void | { a: string; } >a7 : { a: string; } >a5 : void var re8 = a8 || a5; // array || void is {} ->re8 : {} ->a8 || a5 : {} +>re8 : void | string[] +>a8 || a5 : void | string[] >a8 : string[] >a5 : void @@ -338,8 +338,8 @@ var rg1 = a1 || a6; // any || enum is any >a6 : E var rg2 = a2 || a6; // boolean || enum is {} ->rg2 : {} ->a2 || a6 : {} +>rg2 : boolean | E +>a2 || a6 : boolean | E >a2 : boolean >a6 : E @@ -350,14 +350,14 @@ var rg3 = a3 || a6; // number || enum is number >a6 : E var rg4 = a4 || a6; // string || enum is {} ->rg4 : {} ->a4 || a6 : {} +>rg4 : string | E +>a4 || a6 : string | E >a4 : string >a6 : E var rg5 = a5 || a6; // void || enum is {} ->rg5 : {} ->a5 || a6 : {} +>rg5 : void | E +>a5 || a6 : void | E >a5 : void >a6 : E @@ -368,14 +368,14 @@ var rg6 = a6 || a6; // enum || enum is E >a6 : E var rg7 = a7 || a6; // object || enum is {} ->rg7 : {} ->a7 || a6 : {} +>rg7 : E | { a: string; } +>a7 || a6 : E | { a: string; } >a7 : { a: string; } >a6 : E var rg8 = a8 || a6; // array || enum is {} ->rg8 : {} ->a8 || a6 : {} +>rg8 : string[] | E +>a8 || a6 : string[] | E >a8 : string[] >a6 : E @@ -397,32 +397,32 @@ var rh1 = a1 || a7; // any || object is any >a7 : { a: string; } var rh2 = a2 || a7; // boolean || object is {} ->rh2 : {} ->a2 || a7 : {} +>rh2 : boolean | { a: string; } +>a2 || a7 : boolean | { a: string; } >a2 : boolean >a7 : { a: string; } var rh3 = a3 || a7; // number || object is {} ->rh3 : {} ->a3 || a7 : {} +>rh3 : number | { a: string; } +>a3 || a7 : number | { a: string; } >a3 : number >a7 : { a: string; } var rh4 = a4 || a7; // string || object is {} ->rh4 : {} ->a4 || a7 : {} +>rh4 : string | { a: string; } +>a4 || a7 : string | { a: string; } >a4 : string >a7 : { a: string; } var rh5 = a5 || a7; // void || object is {} ->rh5 : {} ->a5 || a7 : {} +>rh5 : void | { a: string; } +>a5 || a7 : void | { a: string; } >a5 : void >a7 : { a: string; } var rh6 = a6 || a7; // enum || object is {} ->rh6 : {} ->a6 || a7 : {} +>rh6 : E | { a: string; } +>a6 || a7 : E | { a: string; } >a6 : E >a7 : { a: string; } @@ -433,8 +433,8 @@ var rh7 = a7 || a7; // object || object is object >a7 : { a: string; } var rh8 = a8 || a7; // array || object is {} ->rh8 : {} ->a8 || a7 : {} +>rh8 : string[] | { a: string; } +>a8 || a7 : string[] | { a: string; } >a8 : string[] >a7 : { a: string; } @@ -456,38 +456,38 @@ var ri1 = a1 || a8; // any || array is any >a8 : string[] var ri2 = a2 || a8; // boolean || array is {} ->ri2 : {} ->a2 || a8 : {} +>ri2 : boolean | string[] +>a2 || a8 : boolean | string[] >a2 : boolean >a8 : string[] var ri3 = a3 || a8; // number || array is {} ->ri3 : {} ->a3 || a8 : {} +>ri3 : number | string[] +>a3 || a8 : number | string[] >a3 : number >a8 : string[] var ri4 = a4 || a8; // string || array is {} ->ri4 : {} ->a4 || a8 : {} +>ri4 : string | string[] +>a4 || a8 : string | string[] >a4 : string >a8 : string[] var ri5 = a5 || a8; // void || array is {} ->ri5 : {} ->a5 || a8 : {} +>ri5 : void | string[] +>a5 || a8 : void | string[] >a5 : void >a8 : string[] var ri6 = a6 || a8; // enum || array is {} ->ri6 : {} ->a6 || a8 : {} +>ri6 : string[] | E +>a6 || a8 : string[] | E >a6 : E >a8 : string[] var ri7 = a7 || a8; // object || array is {} ->ri7 : {} ->a7 || a8 : {} +>ri7 : string[] | { a: string; } +>a7 || a8 : string[] | { a: string; } >a7 : { a: string; } >a8 : string[] diff --git a/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types b/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types index ff0e0ce568a..4008fbbff50 100644 --- a/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types +++ b/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types @@ -22,14 +22,14 @@ function fn1(t: T, u: U) { >t : T var r3 = t || u; ->r3 : {} ->t || u : {} +>r3 : T | U +>t || u : T | U >t : T >u : U var r4: {} = t || u; >r4 : {} ->t || u : {} +>t || u : T | U >t : T >u : U } @@ -47,8 +47,8 @@ function fn2(t: T, u: U, v: V) { >V : V var r1 = t || u; ->r1 : {} ->t || u : {} +>r1 : T | U +>t || u : T | U >t : T >u : U @@ -67,14 +67,14 @@ function fn2(t: T, u: U, v: V) { >u : U var r5 = u || v; ->r5 : {} ->u || v : {} +>r5 : U | V +>u || v : U | V >u : U >v : V var r6: {} = u || v; >r6 : {} ->u || v : {} +>u || v : U | V >u : U >v : V @@ -95,14 +95,14 @@ function fn3U : U var r1 = t || u; ->r1 : {} ->t || u : {} +>r1 : T | U +>t || u : T | U >t : T >u : U var r2: {} = t || u; >r2 : {} ->t || u : {} +>t || u : T | U >t : T >u : U @@ -116,7 +116,7 @@ function fn3r4 : { a: string; } >a : string ->t || u : { a: string; } +>t || u : T | U >t : T >u : U } diff --git a/tests/baselines/reference/memberVariableDeclarations1.types b/tests/baselines/reference/memberVariableDeclarations1.types index 10ec78d69dc..4dd68cdeb35 100644 --- a/tests/baselines/reference/memberVariableDeclarations1.types +++ b/tests/baselines/reference/memberVariableDeclarations1.types @@ -20,7 +20,7 @@ class Employee { public reports: Employee[] = []; >reports : Employee[] >Employee : Employee ->[] : Employee[] +>[] : undefined[] } class Employee2 { @@ -57,11 +57,11 @@ class Employee2 { >manager : Employee this.reports = []; ->this.reports = [] : Employee[] +>this.reports = [] : undefined[] >this.reports : Employee[] >this : Employee2 >reports : Employee[] ->[] : Employee[] +>[] : undefined[] } } diff --git a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt index 557f60967a6..cc93b716d2e 100644 --- a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt +++ b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt @@ -1,5 +1,6 @@ -tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,30): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. - Type '{}' is not assignable to type 'number'. +tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,30): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): error TS2346: Supplied parameters do not match any signature of call target. @@ -15,8 +16,9 @@ tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): e var r6 = map([1, ""], (x) => x.toString()); var r7 = map([1, ""], (x) => x.toString()); // error ~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type '{}' is not assignable to type 'number'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number': +!!! error TS2345: Type 'string' is not assignable to type 'number'. var r7b = map([1, ""], (x) => x.toString()); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. diff --git a/tests/baselines/reference/negateOperatorWithAnyOtherType.types b/tests/baselines/reference/negateOperatorWithAnyOtherType.types index 8785ab073b2..85a2d9c9233 100644 --- a/tests/baselines/reference/negateOperatorWithAnyOtherType.types +++ b/tests/baselines/reference/negateOperatorWithAnyOtherType.types @@ -9,7 +9,7 @@ var ANY1; var ANY2: any[] = ["", ""]; >ANY2 : any[] ->["", ""] : any[] +>["", ""] : string[] var obj: () => {} >obj : () => {} diff --git a/tests/baselines/reference/negateOperatorWithEnumType.js b/tests/baselines/reference/negateOperatorWithEnumType.js index a3235a3ccc0..876bed45cc2 100644 --- a/tests/baselines/reference/negateOperatorWithEnumType.js +++ b/tests/baselines/reference/negateOperatorWithEnumType.js @@ -2,19 +2,19 @@ // - operator on enum type enum ENUM { }; -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsNumber1 = -ENUM; // expressions -var ResultIsNumber2 = -ENUM1[1]; -var ResultIsNumber3 = -(ENUM1[1] + ENUM1[2]); +var ResultIsNumber2 = -ENUM1["B"]; +var ResultIsNumber3 = -(ENUM1.B + ENUM1[""]); // miss assignment operators -ENUM; -ENUM1; --ENUM1[1]; +-ENUM1["B"]; -ENUM, ENUM1; //// [negateOperatorWithEnumType.js] @@ -25,18 +25,18 @@ var ENUM; ; var ENUM1; (function (ENUM1) { - ENUM1[ENUM1["1"] = 0] = "1"; - ENUM1[ENUM1["2"] = 1] = "2"; + ENUM1[ENUM1["A"] = 0] = "A"; + ENUM1[ENUM1["B"] = 1] = "B"; ENUM1[ENUM1[""] = 2] = ""; })(ENUM1 || (ENUM1 = {})); ; // enum type var var ResultIsNumber1 = -ENUM; // expressions -var ResultIsNumber2 = -ENUM1[1]; -var ResultIsNumber3 = -(ENUM1[1] + ENUM1[2]); +var ResultIsNumber2 = -ENUM1["B"]; +var ResultIsNumber3 = -(1 /* B */ + ENUM1[""]); // miss assignment operators -ENUM; -ENUM1; --ENUM1[1]; +-ENUM1["B"]; -ENUM, ENUM1; diff --git a/tests/baselines/reference/negateOperatorWithEnumType.types b/tests/baselines/reference/negateOperatorWithEnumType.types index b2e0cb91c51..96a33ff4c6e 100644 --- a/tests/baselines/reference/negateOperatorWithEnumType.types +++ b/tests/baselines/reference/negateOperatorWithEnumType.types @@ -4,8 +4,10 @@ enum ENUM { }; >ENUM : ENUM -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; >ENUM1 : ENUM1 +>A : ENUM1 +>B : ENUM1 // enum type var var ResultIsNumber1 = -ENUM; @@ -14,20 +16,21 @@ var ResultIsNumber1 = -ENUM; >ENUM : typeof ENUM // expressions -var ResultIsNumber2 = -ENUM1[1]; +var ResultIsNumber2 = -ENUM1["B"]; >ResultIsNumber2 : number ->-ENUM1[1] : number ->ENUM1[1] : ENUM1 +>-ENUM1["B"] : number +>ENUM1["B"] : ENUM1 >ENUM1 : typeof ENUM1 -var ResultIsNumber3 = -(ENUM1[1] + ENUM1[2]); +var ResultIsNumber3 = -(ENUM1.B + ENUM1[""]); >ResultIsNumber3 : number ->-(ENUM1[1] + ENUM1[2]) : number ->(ENUM1[1] + ENUM1[2]) : number ->ENUM1[1] + ENUM1[2] : number ->ENUM1[1] : ENUM1 +>-(ENUM1.B + ENUM1[""]) : number +>(ENUM1.B + ENUM1[""]) : number +>ENUM1.B + ENUM1[""] : number +>ENUM1.B : ENUM1 >ENUM1 : typeof ENUM1 ->ENUM1[2] : ENUM1 +>B : ENUM1 +>ENUM1[""] : ENUM1 >ENUM1 : typeof ENUM1 // miss assignment operators @@ -39,9 +42,9 @@ var ResultIsNumber3 = -(ENUM1[1] + ENUM1[2]); >-ENUM1 : number >ENUM1 : typeof ENUM1 --ENUM1[1]; ->-ENUM1[1] : number ->ENUM1[1] : ENUM1 +-ENUM1["B"]; +>-ENUM1["B"] : number +>ENUM1["B"] : ENUM1 >ENUM1 : typeof ENUM1 -ENUM, ENUM1; diff --git a/tests/baselines/reference/nestedRecursiveLambda.types b/tests/baselines/reference/nestedRecursiveLambda.types index 358ebda8abf..864daea3e1f 100644 --- a/tests/baselines/reference/nestedRecursiveLambda.types +++ b/tests/baselines/reference/nestedRecursiveLambda.types @@ -35,7 +35,7 @@ void(r =>(r => r)); >r : any [(r =>(r => r))] ->[(r =>(r => r))] : { (r: any): (r: any) => any; }[] +>[(r =>(r => r))] : ((r: any) => (r: any) => any)[] >(r =>(r => r)) : (r: any) => (r: any) => any >r =>(r => r) : (r: any) => (r: any) => any >r : any diff --git a/tests/baselines/reference/noImplicitAnyFunctionExpressionAssignment.errors.txt b/tests/baselines/reference/noImplicitAnyFunctionExpressionAssignment.errors.txt deleted file mode 100644 index d53f12fd504..00000000000 --- a/tests/baselines/reference/noImplicitAnyFunctionExpressionAssignment.errors.txt +++ /dev/null @@ -1,21 +0,0 @@ -tests/cases/compiler/noImplicitAnyFunctionExpressionAssignment.ts(2,27): error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. -tests/cases/compiler/noImplicitAnyFunctionExpressionAssignment.ts(6,28): error TS7010: 'f', which lacks return-type annotation, implicitly has an 'any' return type. - - -==== tests/cases/compiler/noImplicitAnyFunctionExpressionAssignment.ts (2 errors) ==== - - var x: (a: any) => void = function (x: T) { - ~~~~~~~~~~~~~~~~~~~~ - return null; - ~~~~~~~~~~~~~~~~ - }; - ~ -!!! error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. - - var x2: (a: any) => void = function f(x: T) { - ~~~~~~~~~~~~~~~~~~~~~ - return null; - ~~~~~~~~~~~~~~~~ - }; - ~ -!!! error TS7010: 'f', which lacks return-type annotation, implicitly has an 'any' return type. \ No newline at end of file diff --git a/tests/baselines/reference/noImplicitAnyFunctionExpressionAssignment.types b/tests/baselines/reference/noImplicitAnyFunctionExpressionAssignment.types new file mode 100644 index 00000000000..b07252dac6d --- /dev/null +++ b/tests/baselines/reference/noImplicitAnyFunctionExpressionAssignment.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/noImplicitAnyFunctionExpressionAssignment.ts === + +var x: (a: any) => void = function (x: T) { +>x : (a: any) => void +>a : any +>function (x: T) { return null;} : (x: T) => any +>T : T +>x : T +>T : T + + return null; +}; + +var x2: (a: any) => void = function f(x: T) { +>x2 : (a: any) => void +>a : any +>function f(x: T) { return null;} : (x: T) => any +>f : (x: T) => any +>T : T +>x : T +>T : T + + return null; +}; diff --git a/tests/baselines/reference/nonContextuallyTypedLogicalOr.errors.txt b/tests/baselines/reference/nonContextuallyTypedLogicalOr.errors.txt deleted file mode 100644 index ca4dc9f67e3..00000000000 --- a/tests/baselines/reference/nonContextuallyTypedLogicalOr.errors.txt +++ /dev/null @@ -1,22 +0,0 @@ -tests/cases/compiler/nonContextuallyTypedLogicalOr.ts(16,10): error TS2339: Property 'dummy' does not exist on type '{}'. - - -==== tests/cases/compiler/nonContextuallyTypedLogicalOr.ts (1 errors) ==== - interface Contextual { - dummy; - p?: number; - } - - interface Ellement { - dummy; - p: any; - } - - var c: Contextual; - var e: Ellement; - - // This should error. Even though we are contextually typing e with Contextual, the RHS still - // needs to be a supertype of the LHS to win as the best common type. - (c || e).dummy; - ~~~~~ -!!! error TS2339: Property 'dummy' does not exist on type '{}'. \ No newline at end of file diff --git a/tests/baselines/reference/nonContextuallyTypedLogicalOr.js b/tests/baselines/reference/nonContextuallyTypedLogicalOr.js index a29390bcf7f..e3ec95533fd 100644 --- a/tests/baselines/reference/nonContextuallyTypedLogicalOr.js +++ b/tests/baselines/reference/nonContextuallyTypedLogicalOr.js @@ -12,13 +12,9 @@ interface Ellement { var c: Contextual; var e: Ellement; -// This should error. Even though we are contextually typing e with Contextual, the RHS still -// needs to be a supertype of the LHS to win as the best common type. (c || e).dummy; //// [nonContextuallyTypedLogicalOr.js] var c; var e; -// This should error. Even though we are contextually typing e with Contextual, the RHS still -// needs to be a supertype of the LHS to win as the best common type. (c || e).dummy; diff --git a/tests/baselines/reference/nonContextuallyTypedLogicalOr.types b/tests/baselines/reference/nonContextuallyTypedLogicalOr.types new file mode 100644 index 00000000000..aeb9d1409c6 --- /dev/null +++ b/tests/baselines/reference/nonContextuallyTypedLogicalOr.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/nonContextuallyTypedLogicalOr.ts === +interface Contextual { +>Contextual : Contextual + + dummy; +>dummy : any + + p?: number; +>p : number +} + +interface Ellement { +>Ellement : Ellement + + dummy; +>dummy : any + + p: any; +>p : any +} + +var c: Contextual; +>c : Contextual +>Contextual : Contextual + +var e: Ellement; +>e : Ellement +>Ellement : Ellement + +(c || e).dummy; +>(c || e).dummy : any +>(c || e) : Contextual | Ellement +>c || e : Contextual | Ellement +>c : Contextual +>e : Ellement +>dummy : any + diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt index 1560a284702..9965709713d 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt @@ -4,19 +4,17 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(90,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(93,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(18,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(20,5): error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(21,5): error TS2412: Property '3.0' of type 'MyNumber' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(50,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(55,5): error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(68,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(73,5): error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: number]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': Index signatures are incompatible: - Type '{}' is not assignable to type 'string'. + Type 'string | number' is not assignable to type 'string': + Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(88,9): error TS2304: Cannot find name 'Myn'. -==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts (14 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts (11 errors) ==== // String indexer types constrain the types of named properties in their containing type interface MyNumber extends Number { @@ -39,8 +37,6 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo !!! error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. "3.0": string; // ok "4.0": number; // error - ~~~~~~~~~~~~~~ -!!! error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. 3.0: MyNumber // error ~~~~~~~~~~~~~ !!! error TS2412: Property '3.0' of type 'MyNumber' is not assignable to numeric index type 'string'. @@ -86,8 +82,6 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo foo(): string; // ok "3.0": string; // ok "4.0": number; // error - ~~~~~~~~~~~~~~ -!!! error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. f: MyNumber; // error } @@ -108,17 +102,16 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo foo(): string; // ok "3.0": string; // ok "4.0": number; // error - ~~~~~~~~~~~~~~ -!!! error TS2412: Property '"4.0"' of type 'number' is not assignable to numeric index type 'string'. f: MyNumber; // error } // error var b: { [x: number]: string; } = { ~ -!!! error TS2322: Type '{ [x: number]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': +!!! error TS2322: Type '{ [x: number]: string | number; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo: () => string; }' is not assignable to type '{ [x: number]: string; }': !!! error TS2322: Index signatures are incompatible: -!!! error TS2322: Type '{}' is not assignable to type 'string'. +!!! error TS2322: Type 'string | number' is not assignable to type 'string': +!!! error TS2322: Type 'number' is not assignable to type 'string'. a: '', b: 1, c: () => { }, diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt index 0e9cff15560..327a09d8813 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt @@ -1,16 +1,13 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(16,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(17,5): error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(25,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(26,5): error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(34,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(35,5): error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(39,5): error TS2322: Type '{ [x: number]: {}; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(39,5): error TS2322: Type '{ [x: number]: number | A; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': Index signatures are incompatible: - Type '{}' is not assignable to type 'A': - Property 'foo' is missing in type '{}'. + Type 'number | A' is not assignable to type 'A': + Type 'number' is not assignable to type 'A'. -==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts (7 errors) ==== +==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts (4 errors) ==== // String indexer providing a constraint of a user defined type class A { @@ -30,8 +27,6 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo ~~~~~~~~~~~~ !!! error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. "4.0": string; // error - ~~~~~~~~~~~~~~ -!!! error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. } interface Foo2 { @@ -43,8 +38,6 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo ~~~~~~~~~~~~ !!! error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. "4.0": string; // error - ~~~~~~~~~~~~~~ -!!! error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. } var a: { @@ -56,17 +49,15 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo ~~~~~~~~~~~~ !!! error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. "4.0": string; // error - ~~~~~~~~~~~~~~ -!!! error TS2412: Property '"4.0"' of type 'string' is not assignable to numeric index type 'A'. }; // error var b: { [x: number]: A } = { ~ -!!! error TS2322: Type '{ [x: number]: {}; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': +!!! error TS2322: Type '{ [x: number]: number | A; 1.0: A; 2.0: B; 3.0: number; "2.5": B; "4.0": string; }' is not assignable to type '{ [x: number]: A; }': !!! error TS2322: Index signatures are incompatible: -!!! error TS2322: Type '{}' is not assignable to type 'A': -!!! error TS2322: Property 'foo' is missing in type '{}'. +!!! error TS2322: Type 'number | A' is not assignable to type 'A': +!!! error TS2322: Type 'number' is not assignable to type 'A'. 1.0: new A(), 2.0: new B(), "2.5": new B(), diff --git a/tests/baselines/reference/numericIndexerConstraint4.types b/tests/baselines/reference/numericIndexerConstraint4.types index f0004e52b45..78b57d4179e 100644 --- a/tests/baselines/reference/numericIndexerConstraint4.types +++ b/tests/baselines/reference/numericIndexerConstraint4.types @@ -22,7 +22,7 @@ var x: { >A : A } = { data: new B() } ->{ data: new B() } : { [x: number]: A; data: B; } +>{ data: new B() } : { [x: number]: undefined; data: B; } >data : B >new B() : B >B : typeof B diff --git a/tests/baselines/reference/objectIndexer.types b/tests/baselines/reference/objectIndexer.types index a2a7f99cf5d..7b42ea51b56 100644 --- a/tests/baselines/reference/objectIndexer.types +++ b/tests/baselines/reference/objectIndexer.types @@ -23,11 +23,11 @@ class Emitter { constructor () { this.listeners = {}; ->this.listeners = {} : { [x: string]: Callback; } +>this.listeners = {} : { [x: string]: undefined; } >this.listeners : IMap >this : Emitter >listeners : IMap ->{} : { [x: string]: Callback; } +>{} : { [x: string]: undefined; } } } diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types index ab83b0c78f0..a0603ae0777 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers1.types @@ -50,7 +50,7 @@ var a: { var b: { [x: number]: string; } = { foo: '' }; >b : { [x: number]: string; } >x : number ->{ foo: '' } : { [x: number]: string; foo: string; } +>{ foo: '' } : { [x: number]: undefined; foo: string; } >foo : string function foo1(x: A); diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types index cd8f19b2b7e..9e4ccb5c43b 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers2.types @@ -64,7 +64,7 @@ var b: { [x: number]: Derived; } = { foo: null }; >b : { [x: number]: Derived; } >x : number >Derived : Derived ->{ foo: null } : { [x: number]: Derived; foo: Derived; } +>{ foo: null } : { [x: number]: undefined; foo: Derived; } >foo : Derived >null : Derived >Derived : Derived diff --git a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types index 6a73749fc84..3553f5f7252 100644 --- a/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types +++ b/tests/baselines/reference/objectTypesIdentityWithNumericIndexers3.types @@ -50,7 +50,7 @@ var a: { var b: { [x: number]: string; } = { foo: '' }; >b : { [x: number]: string; } >x : number ->{ foo: '' } : { [x: number]: string; foo: string; } +>{ foo: '' } : { [x: number]: undefined; foo: string; } >foo : string function foo1(x: A); diff --git a/tests/baselines/reference/overloadResolutionOverNonCTObjectLit.types b/tests/baselines/reference/overloadResolutionOverNonCTObjectLit.types index 846190010b4..7ad68cefa4f 100644 --- a/tests/baselines/reference/overloadResolutionOverNonCTObjectLit.types +++ b/tests/baselines/reference/overloadResolutionOverNonCTObjectLit.types @@ -37,7 +37,7 @@ module Bugs { var tokens:IToken[]= []; >tokens : IToken[] >IToken : IToken ->[] : IToken[] +>[] : undefined[] tokens.push({ startIndex: 1, type: '', bracket: 3 }); >tokens.push({ startIndex: 1, type: '', bracket: 3 }) : number diff --git a/tests/baselines/reference/parenthesizedTypes.js b/tests/baselines/reference/parenthesizedTypes.js new file mode 100644 index 00000000000..a80d9d98c31 --- /dev/null +++ b/tests/baselines/reference/parenthesizedTypes.js @@ -0,0 +1,52 @@ +//// [parenthesizedTypes.ts] +var a: string; +var a: (string); +var a: ((string) | string | (((string)))); +var a: ((((((((((((((((((((((((((((((((((((((((string)))))))))))))))))))))))))))))))))))))))); + +var b: (x: string) => string; +var b: ((x: (string)) => (string)); + +var c: string[] | number[]; +var c: (string)[] | (number)[]; +var c: ((string)[]) | ((number)[]); + +var d: (((x: string) => string) | ((x: number) => number))[]; +var d: ({ (x: string): string } | { (x: number): number })[]; +var d: Array<((x: string) => string) | ((x: number) => number)>; +var d: Array<{ (x: string): string } | { (x: number): number }>; +var d: (Array<{ (x: string): string } | { (x: number): number }>); + +var e: typeof a[]; +var e: (typeof a)[]; + +var f: (string) => string; +var f: (string: any) => string; + +var g: [string, string]; +var g: [(string), string]; +var g: [(string), (((typeof a)))]; + + +//// [parenthesizedTypes.js] +var a; +var a; +var a; +var a; +var b; +var b; +var c; +var c; +var c; +var d; +var d; +var d; +var d; +var d; +var e; +var e; +var f; +var f; +var g; +var g; +var g; diff --git a/tests/baselines/reference/parenthesizedTypes.types b/tests/baselines/reference/parenthesizedTypes.types new file mode 100644 index 00000000000..4b7129b3782 --- /dev/null +++ b/tests/baselines/reference/parenthesizedTypes.types @@ -0,0 +1,84 @@ +=== tests/cases/conformance/types/specifyingTypes/typeLiterals/parenthesizedTypes.ts === +var a: string; +>a : string + +var a: (string); +>a : string + +var a: ((string) | string | (((string)))); +>a : string + +var a: ((((((((((((((((((((((((((((((((((((((((string)))))))))))))))))))))))))))))))))))))))); +>a : string + +var b: (x: string) => string; +>b : (x: string) => string +>x : string + +var b: ((x: (string)) => (string)); +>b : (x: string) => string +>x : string + +var c: string[] | number[]; +>c : string[] | number[] + +var c: (string)[] | (number)[]; +>c : string[] | number[] + +var c: ((string)[]) | ((number)[]); +>c : string[] | number[] + +var d: (((x: string) => string) | ((x: number) => number))[]; +>d : (((x: string) => string) | ((x: number) => number))[] +>x : string +>x : number + +var d: ({ (x: string): string } | { (x: number): number })[]; +>d : (((x: string) => string) | ((x: number) => number))[] +>x : string +>x : number + +var d: Array<((x: string) => string) | ((x: number) => number)>; +>d : (((x: string) => string) | ((x: number) => number))[] +>Array : T[] +>x : string +>x : number + +var d: Array<{ (x: string): string } | { (x: number): number }>; +>d : (((x: string) => string) | ((x: number) => number))[] +>Array : T[] +>x : string +>x : number + +var d: (Array<{ (x: string): string } | { (x: number): number }>); +>d : (((x: string) => string) | ((x: number) => number))[] +>Array : T[] +>x : string +>x : number + +var e: typeof a[]; +>e : string[] +>a : string + +var e: (typeof a)[]; +>e : string[] +>a : string + +var f: (string) => string; +>f : (string: any) => string +>string : any + +var f: (string: any) => string; +>f : (string: any) => string +>string : any + +var g: [string, string]; +>g : [string, string] + +var g: [(string), string]; +>g : [string, string] + +var g: [(string), (((typeof a)))]; +>g : [string, string] +>a : string + diff --git a/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt b/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt index ab9bab7890c..237541b40f7 100644 --- a/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt +++ b/tests/baselines/reference/parser15.4.4.14-9-2.errors.txt @@ -1,7 +1,8 @@ +tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(16,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(25,1): error TS2304: Cannot find name 'runTestCase'. -==== tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts (2 errors) ==== /// Copyright (c) 2012 Ecma International. All rights reserved. /// Ecma International makes this code available under the terms and conditions set /// forth on http://hg.ecmascript.org/tests/test262/raw-file/tip/LICENSE (the @@ -18,6 +19,8 @@ tests/cases/conformance/parser/ecmascript5/parser15.4.4.14-9-2.ts(25,1): error T var one = 1; var _float = -(4/3); var a = new Array(false,undefined,null,"0",obj,-1.3333333333333, "str",-0,true,+0, one, 1,0, false, _float, -(4/3)); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. if (a.indexOf(-(4/3)) === 14 && // a[14]=_float===-(4/3) a.indexOf(0) === 7 && // a[7] = +0, 0===+0 a.indexOf(-0) === 7 && // a[7] = +0, -0===+0 diff --git a/tests/baselines/reference/parserEnum5.errors.txt b/tests/baselines/reference/parserEnum5.errors.txt index 6a558dc9500..40c2c933955 100644 --- a/tests/baselines/reference/parserEnum5.errors.txt +++ b/tests/baselines/reference/parserEnum5.errors.txt @@ -1,15 +1,24 @@ tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(2,12): error TS1005: ',' expected. tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,15): error TS1005: ',' expected. tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,24): error TS1005: ',' expected. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(2,14): error TS1151: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,17): error TS1151: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts(3,26): error TS1151: An enum member cannot have a numeric name. -==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts (3 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts (6 errors) ==== enum E2 { a, } enum E3 { a: 1, } ~ !!! error TS1005: ',' expected. + ~ +!!! error TS1151: An enum member cannot have a numeric name. enum E1 { a, b: 1, c, d: 2 = 3 } ~ !!! error TS1005: ',' expected. ~ -!!! error TS1005: ',' expected. \ No newline at end of file +!!! error TS1005: ',' expected. + ~ +!!! error TS1151: An enum member cannot have a numeric name. + ~ +!!! error TS1151: An enum member cannot have a numeric name. \ No newline at end of file diff --git a/tests/baselines/reference/parserEnum7.errors.txt b/tests/baselines/reference/parserEnum7.errors.txt new file mode 100644 index 00000000000..a4a2326546a --- /dev/null +++ b/tests/baselines/reference/parserEnum7.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,3): error TS1151: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,6): error TS1151: An enum member cannot have a numeric name. +tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts(2,9): error TS1151: An enum member cannot have a numeric name. + + +==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts (3 errors) ==== + enum E { + 1, 2, 3 + ~ +!!! error TS1151: An enum member cannot have a numeric name. + ~ +!!! error TS1151: An enum member cannot have a numeric name. + ~ +!!! error TS1151: An enum member cannot have a numeric name. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserEnum7.types b/tests/baselines/reference/parserEnum7.types deleted file mode 100644 index 63a77cb9d23..00000000000 --- a/tests/baselines/reference/parserEnum7.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum7.ts === -enum E { ->E : E - - 1, 2, 3 -} diff --git a/tests/baselines/reference/plusOperatorWithEnumType.js b/tests/baselines/reference/plusOperatorWithEnumType.js index 279f3bc286b..4d6eaad892e 100644 --- a/tests/baselines/reference/plusOperatorWithEnumType.js +++ b/tests/baselines/reference/plusOperatorWithEnumType.js @@ -2,20 +2,20 @@ // + operator on enum type enum ENUM { }; -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsNumber1 = +ENUM; var ResultIsNumber2 = +ENUM1; // enum type expressions -var ResultIsNumber3 = +ENUM1[0]; -var ResultIsNumber4 = +(ENUM[0] + ENUM1[1]); +var ResultIsNumber3 = +ENUM1["A"]; +var ResultIsNumber4 = +(ENUM[0] + ENUM1["B"]); // miss assignment operators +ENUM; +ENUM1; -+ENUM1[1]; ++ENUM1.B; +ENUM, ENUM1; //// [plusOperatorWithEnumType.js] @@ -26,8 +26,8 @@ var ENUM; ; var ENUM1; (function (ENUM1) { - ENUM1[ENUM1["1"] = 0] = "1"; - ENUM1[ENUM1["2"] = 1] = "2"; + ENUM1[ENUM1["A"] = 0] = "A"; + ENUM1[ENUM1["B"] = 1] = "B"; ENUM1[ENUM1[""] = 2] = ""; })(ENUM1 || (ENUM1 = {})); ; @@ -35,10 +35,10 @@ var ENUM1; var ResultIsNumber1 = +ENUM; var ResultIsNumber2 = +ENUM1; // enum type expressions -var ResultIsNumber3 = +ENUM1[0]; -var ResultIsNumber4 = +(ENUM[0] + ENUM1[1]); +var ResultIsNumber3 = +ENUM1["A"]; +var ResultIsNumber4 = +(ENUM[0] + ENUM1["B"]); // miss assignment operators +ENUM; +ENUM1; -+ENUM1[1]; ++1 /* B */; +ENUM, ENUM1; diff --git a/tests/baselines/reference/plusOperatorWithEnumType.types b/tests/baselines/reference/plusOperatorWithEnumType.types index 4ac40a9359d..bc51414e4a5 100644 --- a/tests/baselines/reference/plusOperatorWithEnumType.types +++ b/tests/baselines/reference/plusOperatorWithEnumType.types @@ -4,8 +4,10 @@ enum ENUM { }; >ENUM : ENUM -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; >ENUM1 : ENUM1 +>A : ENUM1 +>B : ENUM1 // enum type var var ResultIsNumber1 = +ENUM; @@ -19,20 +21,20 @@ var ResultIsNumber2 = +ENUM1; >ENUM1 : typeof ENUM1 // enum type expressions -var ResultIsNumber3 = +ENUM1[0]; +var ResultIsNumber3 = +ENUM1["A"]; >ResultIsNumber3 : number ->+ENUM1[0] : number ->ENUM1[0] : string +>+ENUM1["A"] : number +>ENUM1["A"] : ENUM1 >ENUM1 : typeof ENUM1 -var ResultIsNumber4 = +(ENUM[0] + ENUM1[1]); +var ResultIsNumber4 = +(ENUM[0] + ENUM1["B"]); >ResultIsNumber4 : number ->+(ENUM[0] + ENUM1[1]) : number ->(ENUM[0] + ENUM1[1]) : string ->ENUM[0] + ENUM1[1] : string +>+(ENUM[0] + ENUM1["B"]) : number +>(ENUM[0] + ENUM1["B"]) : string +>ENUM[0] + ENUM1["B"] : string >ENUM[0] : string >ENUM : typeof ENUM ->ENUM1[1] : ENUM1 +>ENUM1["B"] : ENUM1 >ENUM1 : typeof ENUM1 // miss assignment operators @@ -44,10 +46,11 @@ var ResultIsNumber4 = +(ENUM[0] + ENUM1[1]); >+ENUM1 : number >ENUM1 : typeof ENUM1 -+ENUM1[1]; ->+ENUM1[1] : number ->ENUM1[1] : ENUM1 ++ENUM1.B; +>+ENUM1.B : number +>ENUM1.B : ENUM1 >ENUM1 : typeof ENUM1 +>B : ENUM1 +ENUM, ENUM1; >+ENUM, ENUM1 : typeof ENUM1 diff --git a/tests/baselines/reference/promisePermutations.errors.txt b/tests/baselines/reference/promisePermutations.errors.txt index ee723821cce..0b2aa01bb5c 100644 --- a/tests/baselines/reference/promisePermutations.errors.txt +++ b/tests/baselines/reference/promisePermutations.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/promisePermutations.ts(74,70): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. tests/cases/compiler/promisePermutations.ts(79,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations.ts(82,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations.ts(83,19): error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. @@ -19,13 +20,20 @@ tests/cases/compiler/promisePermutations.ts(120,19): error TS2345: Argument of t tests/cases/compiler/promisePermutations.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations.ts(122,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations.ts(126,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(129,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/promisePermutations.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations.ts(134,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(137,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations.ts(144,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations.ts(152,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations.ts(156,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(159,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. -==== tests/cases/compiler/promisePermutations.ts (25 errors) ==== +==== tests/cases/compiler/promisePermutations.ts (33 errors) ==== interface Promise { then(success?: (value: T) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; then(success?: (value: T) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; @@ -39,7 +47,7 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -99,7 +107,9 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); - var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); + var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error + ~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -118,7 +128,7 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. - var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); + var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -197,6 +207,8 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -210,7 +222,9 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok - var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok + var s9f = s9.then(testFunction, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); @@ -218,6 +232,8 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -225,17 +241,25 @@ tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of t var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok - var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok + var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; - var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok + var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. - var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok - var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok + var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. + var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/baselines/reference/promisePermutations.js b/tests/baselines/reference/promisePermutations.js index 189ef40335e..e59e49d6f8c 100644 --- a/tests/baselines/reference/promisePermutations.js +++ b/tests/baselines/reference/promisePermutations.js @@ -12,7 +12,7 @@ interface IPromise { then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -72,7 +72,7 @@ var s3: Promise; var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); -var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); +var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -83,7 +83,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -135,7 +135,7 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); @@ -150,15 +150,15 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok @@ -192,7 +192,7 @@ var s3; var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); -var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); +var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error var r4; var sIPromise; var sPromise; @@ -249,7 +249,7 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(function (x) { return x; }); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok @@ -263,14 +263,14 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(function (x) { return x; }); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok var s12 = testFunction12(function (x) { return x; }); diff --git a/tests/baselines/reference/promisePermutations2.errors.txt b/tests/baselines/reference/promisePermutations2.errors.txt index f85a3eb925f..e512ca73277 100644 --- a/tests/baselines/reference/promisePermutations2.errors.txt +++ b/tests/baselines/reference/promisePermutations2.errors.txt @@ -20,15 +20,20 @@ tests/cases/compiler/promisePermutations2.ts(119,19): error TS2345: Argument of tests/cases/compiler/promisePermutations2.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations2.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(128,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/promisePermutations2.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations2.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(136,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations2.ts(143,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations2.ts(151,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations2.ts(155,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(157,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(158,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. -==== tests/cases/compiler/promisePermutations2.ts (28 errors) ==== +==== tests/cases/compiler/promisePermutations2.ts (33 errors) ==== // same as promisePermutations but without the same overloads in Promise interface Promise { @@ -41,7 +46,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -122,7 +127,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. - var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); + var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -200,7 +205,9 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok - var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok + var r9d = r9.then(testFunction, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -214,14 +221,18 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok - var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok + var s9f = s9.then(testFunction, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok - var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok + var r10d = r10.then(testFunction, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -229,11 +240,15 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok - var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok + var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; - var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok + var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok ~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/promisePermutations2.js b/tests/baselines/reference/promisePermutations2.js index 008594ee120..a7b5d8cf835 100644 --- a/tests/baselines/reference/promisePermutations2.js +++ b/tests/baselines/reference/promisePermutations2.js @@ -11,7 +11,7 @@ interface IPromise { then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -82,7 +82,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -126,7 +126,7 @@ var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -134,14 +134,14 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -149,11 +149,11 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok @@ -241,7 +241,7 @@ var r9; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -249,13 +249,13 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(function (x) { return x; }); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(function (x) { return x; }); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -263,10 +263,10 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok diff --git a/tests/baselines/reference/promisePermutations3.errors.txt b/tests/baselines/reference/promisePermutations3.errors.txt index edd5f879043..97d47cc7f7f 100644 --- a/tests/baselines/reference/promisePermutations3.errors.txt +++ b/tests/baselines/reference/promisePermutations3.errors.txt @@ -1,4 +1,5 @@ tests/cases/compiler/promisePermutations3.ts(68,69): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(73,70): error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. tests/cases/compiler/promisePermutations3.ts(78,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations3.ts(81,19): error TS2345: Argument of type '(x: number, y?: string) => IPromise' is not assignable to parameter of type '(value: string) => IPromise'. tests/cases/compiler/promisePermutations3.ts(82,19): error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => Promise'. @@ -20,15 +21,21 @@ tests/cases/compiler/promisePermutations3.ts(119,19): error TS2345: Argument of tests/cases/compiler/promisePermutations3.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations3.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(128,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/promisePermutations3.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations3.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(136,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations3.ts(143,12): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/promisePermutations3.ts(151,12): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/promisePermutations3.ts(155,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(157,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(158,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations3.ts(159,21): error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of type '{ (x: T): IPromise; (x: T, y: T): Promise; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise'. -==== tests/cases/compiler/promisePermutations3.ts (28 errors) ==== +==== tests/cases/compiler/promisePermutations3.ts (35 errors) ==== // same as promisePermutations but without the same overloads in IPromise interface Promise { @@ -41,7 +48,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of interface IPromise { then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -104,6 +111,8 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); + ~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -122,7 +131,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. - var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); + var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -200,7 +209,9 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok - var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok + var r9d = r9.then(testFunction, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -214,14 +225,18 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok - var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok + var s9f = s9.then(testFunction, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok - var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok + var r10d = r10.then(testFunction, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -229,7 +244,9 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok - var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok + var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; @@ -240,8 +257,12 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. - var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok - var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok + var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. + var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/baselines/reference/promisePermutations3.js b/tests/baselines/reference/promisePermutations3.js index d65d8c233f8..eb9c882b971 100644 --- a/tests/baselines/reference/promisePermutations3.js +++ b/tests/baselines/reference/promisePermutations3.js @@ -11,7 +11,7 @@ interface Promise { interface IPromise { then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -82,7 +82,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -126,7 +126,7 @@ var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -134,14 +134,14 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -149,15 +149,15 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok @@ -241,7 +241,7 @@ var r9; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -249,13 +249,13 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(function (x) { return x; }); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(function (x) { return x; }); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -263,14 +263,14 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok var s11; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(function (x) { return x; }); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok var s12 = testFunction12(function (x) { return x; }); diff --git a/tests/baselines/reference/propertiesAndIndexers2.errors.txt b/tests/baselines/reference/propertiesAndIndexers2.errors.txt new file mode 100644 index 00000000000..e1ab8c9d13d --- /dev/null +++ b/tests/baselines/reference/propertiesAndIndexers2.errors.txt @@ -0,0 +1,46 @@ +tests/cases/compiler/propertiesAndIndexers2.ts(2,5): error TS2413: Numeric index type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(8,5): error TS2411: Property 'c' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(9,5): error TS2411: Property '3' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(10,5): error TS2411: Property 'Infinity' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(11,5): error TS2411: Property '"-Infinity"' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(12,5): error TS2411: Property 'NaN' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(13,5): error TS2411: Property '"-NaN"' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(14,5): error TS2411: Property '6' of type '() => string' is not assignable to string index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(14,5): error TS2412: Property '6' of type '() => string' is not assignable to numeric index type 'string'. + + +==== tests/cases/compiler/propertiesAndIndexers2.ts (9 errors) ==== + interface A { + [n: number]: string; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2413: Numeric index type 'string' is not assignable to string index type 'number'. + [s: string]: number; + } + + // All of these should fail. + interface B extends A { + c: string; + ~~~~~~~~~~ +!!! error TS2411: Property 'c' of type 'string' is not assignable to string index type 'number'. + 3: string; + ~~~~~~~~~~ +!!! error TS2411: Property '3' of type 'string' is not assignable to string index type 'number'. + Infinity: string; + ~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property 'Infinity' of type 'string' is not assignable to string index type 'number'. + "-Infinity": string; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '"-Infinity"' of type 'string' is not assignable to string index type 'number'. + NaN: string; + ~~~~~~~~~~~~ +!!! error TS2411: Property 'NaN' of type 'string' is not assignable to string index type 'number'. + "-NaN": string; + ~~~~~~~~~~~~~~~ +!!! error TS2411: Property '"-NaN"' of type 'string' is not assignable to string index type 'number'. + 6(): string; + ~~~~~~~~~~~~ +!!! error TS2411: Property '6' of type '() => string' is not assignable to string index type 'number'. + ~~~~~~~~~~~~ +!!! error TS2412: Property '6' of type '() => string' is not assignable to numeric index type 'string'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/propertiesAndIndexers2.js b/tests/baselines/reference/propertiesAndIndexers2.js new file mode 100644 index 00000000000..74485a89248 --- /dev/null +++ b/tests/baselines/reference/propertiesAndIndexers2.js @@ -0,0 +1,19 @@ +//// [propertiesAndIndexers2.ts] +interface A { + [n: number]: string; + [s: string]: number; +} + +// All of these should fail. +interface B extends A { + c: string; + 3: string; + Infinity: string; + "-Infinity": string; + NaN: string; + "-NaN": string; + 6(): string; +} + + +//// [propertiesAndIndexers2.js] diff --git a/tests/baselines/reference/propertiesAndIndexersForNumericNames.errors.txt b/tests/baselines/reference/propertiesAndIndexersForNumericNames.errors.txt new file mode 100644 index 00000000000..01dcb61c70c --- /dev/null +++ b/tests/baselines/reference/propertiesAndIndexersForNumericNames.errors.txt @@ -0,0 +1,69 @@ +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(6,5): error TS2412: Property '"1"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(7,5): error TS2412: Property '"-1"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(8,5): error TS2412: Property '"-2.5"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(9,5): error TS2412: Property '"3.141592"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(10,5): error TS2412: Property '"1.2e-20"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(11,5): error TS2412: Property '"Infinity"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(12,5): error TS2412: Property '"-Infinity"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(13,5): error TS2412: Property '"NaN"' of type 'string' is not assignable to numeric index type 'number'. + + +==== tests/cases/compiler/propertiesAndIndexersForNumericNames.ts (8 errors) ==== + class C { + [i: number]: number; + + // These all have numeric names; they should error + // because their types are not compatible with the numeric indexer. + public "1": string = "number"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"1"' of type 'string' is not assignable to numeric index type 'number'. + public "-1": string = "negative number"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"-1"' of type 'string' is not assignable to numeric index type 'number'. + public "-2.5": string = "negative number"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"-2.5"' of type 'string' is not assignable to numeric index type 'number'. + public "3.141592": string = "pi-sitive number"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"3.141592"' of type 'string' is not assignable to numeric index type 'number'. + public "1.2e-20": string = "really small number"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"1.2e-20"' of type 'string' is not assignable to numeric index type 'number'. + public "Infinity": string = "A gillion"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"Infinity"' of type 'string' is not assignable to numeric index type 'number'. + public "-Infinity": string = "Negative-a-gillion"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"-Infinity"' of type 'string' is not assignable to numeric index type 'number'. + public "NaN": string = "not a number"; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2412: Property '"NaN"' of type 'string' is not assignable to numeric index type 'number'. + + // These all have *partially* numeric names, + // but should really be treated as plain string literals. + public " 1": string = "leading space"; // No error + public "1 ": string = "trailing space"; // No error + public "": string = "no nothing"; // No error + public " ": string = "just space"; // No error + public "1 0 1": string = "several numbers and spaces"; // No error + public "hunter2": string = "not a password"; // No error + public "+Infinity": string = "A gillion"; // No error + public "+NaN": string = "not a positive number"; // No error + public "-NaN": string = "not a negative number"; // No error + + + // These fall into the above category, however, they are "trickier"; + // these all are *scanned* as numeric literals, but they are not written in + // "canonical" numeric representations. + public "+1": string = "positive number (for the paranoid)"; // No error + public "1e0": string = "just one"; // No error + public "-0": string = "just zero"; // No error + public "-0e0": string = "just zero"; // No error + public "0xF00D": string = "hex food"; // No error + public "0xBEEF": string = "hex beef"; // No error + public "0123": string = "oct 83"; // No error + public "0o123": string = "explicit oct 83"; // No error + public "0b101101001010": string = "explicit binary"; // No error + public "0.000000000000000000012": string = "should've been in exponential form"; // No error + } + \ No newline at end of file diff --git a/tests/baselines/reference/propertiesAndIndexersForNumericNames.js b/tests/baselines/reference/propertiesAndIndexersForNumericNames.js new file mode 100644 index 00000000000..975abdc00ec --- /dev/null +++ b/tests/baselines/reference/propertiesAndIndexersForNumericNames.js @@ -0,0 +1,84 @@ +//// [propertiesAndIndexersForNumericNames.ts] +class C { + [i: number]: number; + + // These all have numeric names; they should error + // because their types are not compatible with the numeric indexer. + public "1": string = "number"; // Error + public "-1": string = "negative number"; // Error + public "-2.5": string = "negative number"; // Error + public "3.141592": string = "pi-sitive number"; // Error + public "1.2e-20": string = "really small number"; // Error + public "Infinity": string = "A gillion"; // Error + public "-Infinity": string = "Negative-a-gillion"; // Error + public "NaN": string = "not a number"; // Error + + // These all have *partially* numeric names, + // but should really be treated as plain string literals. + public " 1": string = "leading space"; // No error + public "1 ": string = "trailing space"; // No error + public "": string = "no nothing"; // No error + public " ": string = "just space"; // No error + public "1 0 1": string = "several numbers and spaces"; // No error + public "hunter2": string = "not a password"; // No error + public "+Infinity": string = "A gillion"; // No error + public "+NaN": string = "not a positive number"; // No error + public "-NaN": string = "not a negative number"; // No error + + + // These fall into the above category, however, they are "trickier"; + // these all are *scanned* as numeric literals, but they are not written in + // "canonical" numeric representations. + public "+1": string = "positive number (for the paranoid)"; // No error + public "1e0": string = "just one"; // No error + public "-0": string = "just zero"; // No error + public "-0e0": string = "just zero"; // No error + public "0xF00D": string = "hex food"; // No error + public "0xBEEF": string = "hex beef"; // No error + public "0123": string = "oct 83"; // No error + public "0o123": string = "explicit oct 83"; // No error + public "0b101101001010": string = "explicit binary"; // No error + public "0.000000000000000000012": string = "should've been in exponential form"; // No error +} + + +//// [propertiesAndIndexersForNumericNames.js] +var C = (function () { + function C() { + // These all have numeric names; they should error + // because their types are not compatible with the numeric indexer. + this["1"] = "number"; // Error + this["-1"] = "negative number"; // Error + this["-2.5"] = "negative number"; // Error + this["3.141592"] = "pi-sitive number"; // Error + this["1.2e-20"] = "really small number"; // Error + this["Infinity"] = "A gillion"; // Error + this["-Infinity"] = "Negative-a-gillion"; // Error + this["NaN"] = "not a number"; // Error + // These all have *partially* numeric names, + // but should really be treated as plain string literals. + this[" 1"] = "leading space"; // No error + this["1 "] = "trailing space"; // No error + this[""] = "no nothing"; // No error + this[" "] = "just space"; // No error + this["1 0 1"] = "several numbers and spaces"; // No error + this["hunter2"] = "not a password"; // No error + this["+Infinity"] = "A gillion"; // No error + this["+NaN"] = "not a positive number"; // No error + this["-NaN"] = "not a negative number"; // No error + // These fall into the above category, however, they are "trickier"; + // these all are *scanned* as numeric literals, but they are not written in + // "canonical" numeric representations. + this["+1"] = "positive number (for the paranoid)"; // No error + this["1e0"] = "just one"; // No error + this["-0"] = "just zero"; // No error + this["-0e0"] = "just zero"; // No error + this["0xF00D"] = "hex food"; // No error + this["0xBEEF"] = "hex beef"; // No error + this["0123"] = "oct 83"; // No error + this["0o123"] = "explicit oct 83"; // No error + this["0b101101001010"] = "explicit binary"; // No error + this["0.000000000000000000012"] = "should've been in exponential form"; // No error + } + return C; +})(); diff --git a/tests/baselines/reference/returnTypeParameterWithModules.types b/tests/baselines/reference/returnTypeParameterWithModules.types index adcc1b4bcee..4be0efcd2a5 100644 --- a/tests/baselines/reference/returnTypeParameterWithModules.types +++ b/tests/baselines/reference/returnTypeParameterWithModules.types @@ -21,7 +21,7 @@ module M1 { >reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >apply : (thisArg: any, argArray?: any) => any >ar : any ->e ? [f, e] : [f] : any +>e ? [f, e] : [f] : any[] >e : any >[f, e] : any[] >f : any diff --git a/tests/baselines/reference/selfReferencingFile.errors.txt b/tests/baselines/reference/selfReferencingFile.errors.txt index 727be1ea0b2..8bf68fde774 100644 --- a/tests/baselines/reference/selfReferencingFile.errors.txt +++ b/tests/baselines/reference/selfReferencingFile.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/selfReferencingFile.ts(1,1): error TS1006: A file cannot have a reference to itself. - - -==== tests/cases/compiler/selfReferencingFile.ts (1 errors) ==== - /// - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1006: A file cannot have a reference to itself. - - class selfReferencingFile { - +tests/cases/compiler/selfReferencingFile.ts(1,1): error TS1006: A file cannot have a reference to itself. + + +==== tests/cases/compiler/selfReferencingFile.ts (1 errors) ==== + /// + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1006: A file cannot have a reference to itself. + + class selfReferencingFile { + } \ No newline at end of file diff --git a/tests/baselines/reference/selfReferencingFile2.errors.txt b/tests/baselines/reference/selfReferencingFile2.errors.txt index 5bd2d75723a..c993616784a 100644 --- a/tests/baselines/reference/selfReferencingFile2.errors.txt +++ b/tests/baselines/reference/selfReferencingFile2.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/selfReferencingFile2.ts(1,1): error TS6053: File 'tests/cases/selfReferencingFile2.ts' not found. - - -==== tests/cases/compiler/selfReferencingFile2.ts (1 errors) ==== - /// - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS6053: File 'selfReferencingFile2.ts' not found. - - class selfReferencingFile2 { - +tests/cases/compiler/selfReferencingFile2.ts(1,1): error TS6053: File 'tests/cases/selfReferencingFile2.ts' not found. + + +==== tests/cases/compiler/selfReferencingFile2.ts (1 errors) ==== + /// + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS6053: File 'selfReferencingFile2.ts' not found. + + class selfReferencingFile2 { + } \ No newline at end of file diff --git a/tests/baselines/reference/selfReferencingFile3.errors.txt b/tests/baselines/reference/selfReferencingFile3.errors.txt index e6e8deb5d47..05cf04ddc4b 100644 --- a/tests/baselines/reference/selfReferencingFile3.errors.txt +++ b/tests/baselines/reference/selfReferencingFile3.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/selfReferencingFile3.ts(1,1): error TS1006: A file cannot have a reference to itself. - - -==== tests/cases/compiler/selfReferencingFile3.ts (1 errors) ==== - /// - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1006: A file cannot have a reference to itself. - - class selfReferencingFile3 { - +tests/cases/compiler/selfReferencingFile3.ts(1,1): error TS1006: A file cannot have a reference to itself. + + +==== tests/cases/compiler/selfReferencingFile3.ts (1 errors) ==== + /// + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1006: A file cannot have a reference to itself. + + class selfReferencingFile3 { + } \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationClasses.types b/tests/baselines/reference/sourceMapValidationClasses.types index d53cdcb9974..4f391c86f65 100644 --- a/tests/baselines/reference/sourceMapValidationClasses.types +++ b/tests/baselines/reference/sourceMapValidationClasses.types @@ -56,7 +56,7 @@ module Foo.Bar { var greeters: Greeter[] = []; /* inline block comment */ >greeters : Greeter[] >Greeter : Greeter ->[] : Greeter[] +>[] : undefined[] greeters[0] = new Greeter(greeting); >greeters[0] = new Greeter(greeting) : Greeter diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt index a731dcca188..8039cdf01f0 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt @@ -24,9 +24,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(71,5): error TS2411: Property 'foo' of type '() => string' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(73,5): error TS2411: Property '"4.0"' of type 'number' is not assignable to string index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(74,5): error TS2411: Property 'f' of type 'MyString' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: string | number | MyString | (() => void); 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': Index signatures are incompatible: - Type '{}' is not assignable to type 'string'. + Type 'string | number | MyString | (() => void)' is not assignable to type 'string': + Type 'number' is not assignable to type 'string'. ==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts (27 errors) ==== @@ -159,9 +160,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon // error var b: { [x: string]: string; } = { ~ -!!! error TS2322: Type '{ [x: string]: {}; 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': +!!! error TS2322: Type '{ [x: string]: string | number | MyString | (() => void); 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: MyString; X: string; foo: () => string; }' is not assignable to type '{ [x: string]: string; }': !!! error TS2322: Index signatures are incompatible: -!!! error TS2322: Type '{}' is not assignable to type 'string'. +!!! error TS2322: Type 'string | number | MyString | (() => void)' is not assignable to type 'string': +!!! error TS2322: Type 'number' is not assignable to type 'string'. a: '', b: 1, c: () => { }, diff --git a/tests/baselines/reference/subtypesOfTypeParameter.errors.txt b/tests/baselines/reference/subtypesOfTypeParameter.errors.txt index a986258bf11..bdb3c9a056f 100644 --- a/tests/baselines/reference/subtypesOfTypeParameter.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameter.errors.txt @@ -1,46 +1,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(7,7): error TS2416: Class 'D1' incorrectly extends base class 'C3': Types of property 'foo' are incompatible: Type 'U' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(12,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(13,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(38,14): error TS2367: No best common type exists between 'number' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(39,14): error TS2367: No best common type exists between 'T' and 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(41,14): error TS2367: No best common type exists between 'string' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(42,14): error TS2367: No best common type exists between 'T' and 'string'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(44,14): error TS2367: No best common type exists between 'boolean' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(45,14): error TS2367: No best common type exists between 'T' and 'boolean'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(47,14): error TS2367: No best common type exists between 'Date' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(48,14): error TS2367: No best common type exists between 'T' and 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(50,14): error TS2367: No best common type exists between 'RegExp' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(51,14): error TS2367: No best common type exists between 'T' and 'RegExp'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(53,14): error TS2367: No best common type exists between '{ foo: number; }' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(54,14): error TS2367: No best common type exists between 'T' and '{ foo: number; }'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(56,14): error TS2367: No best common type exists between '() => void' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(57,14): error TS2367: No best common type exists between 'T' and '() => void'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(59,14): error TS2367: No best common type exists between '(x: T) => T' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(60,15): error TS2367: No best common type exists between 'T' and '(x: T) => T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(63,14): error TS2367: No best common type exists between 'I1' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(64,14): error TS2367: No best common type exists between 'T' and 'I1'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(67,15): error TS2367: No best common type exists between 'C1' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(68,15): error TS2367: No best common type exists between 'T' and 'C1'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(72,15): error TS2367: No best common type exists between 'C2' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(73,15): error TS2367: No best common type exists between 'T' and 'C2'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(76,15): error TS2367: No best common type exists between 'typeof E' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(77,15): error TS2367: No best common type exists between 'T' and 'typeof E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(79,15): error TS2367: No best common type exists between 'E' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(80,15): error TS2367: No best common type exists between 'T' and 'E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(83,15): error TS2367: No best common type exists between 'typeof f' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(84,15): error TS2367: No best common type exists between 'T' and 'typeof f'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(87,15): error TS2367: No best common type exists between 'typeof c' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(88,15): error TS2367: No best common type exists between 'T' and 'typeof c'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(91,19): error TS2367: No best common type exists between 'T' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(92,19): error TS2367: No best common type exists between 'T' and 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(95,21): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(96,19): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(97,19): error TS2367: No best common type exists between 'U' and 'T'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts (38 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts (2 errors) ==== // checking whether other types are subtypes of type parameters class C3 { @@ -57,11 +21,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf function f1(x: T, y: U) { var r = true ? x : y; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? y : x; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. } interface I1 { foo: number; } @@ -87,135 +47,67 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf var r0b = true ? x : u; var r1 = true ? 1 : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'number' and 'T'. var r1 = true ? x : 1; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'number'. var r2 = true ? '' : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'string' and 'T'. var r2 = true ? x : ''; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'string'. var r3 = true ? true : x; - ~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'boolean' and 'T'. var r3 = true ? x : true; - ~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'boolean'. var r4 = true ? new Date() : x; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Date' and 'T'. var r4 = true ? x : new Date(); - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Date'. var r5 = true ? /1/ : x; - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'RegExp' and 'T'. var r5 = true ? x : /1/; - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'RegExp'. var r6 = true ? { foo: 1 } : x; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between '{ foo: number; }' and 'T'. var r6 = true ? x : { foo: 1 }; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and '{ foo: number; }'. var r7 = true ? () => { } : x; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between '() => void' and 'T'. var r7 = true ? x : () => { }; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and '() => void'. var r8 = true ? (x: T) => { return x } : x; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between '(x: T) => T' and 'T'. var r8b = true ? x : (x: T) => { return x }; // type parameters not identical across declarations - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and '(x: T) => T'. var i1: I1; var r9 = true ? i1 : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'I1' and 'T'. var r9 = true ? x : i1; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'I1'. var c1: C1; var r10 = true ? c1 : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'C1' and 'T'. var r10 = true ? x : c1; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'C1'. var c2: C2; var r12 = true ? c2 : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'C2' and 'T'. var r12 = true ? x : c2; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'C2'. var r13 = true ? E : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'typeof E' and 'T'. var r13 = true ? x : E; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'typeof E'. var r14 = true ? E.A : x; - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'E' and 'T'. var r14 = true ? x : E.A; - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'E'. var af: typeof f; var r15 = true ? af : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'typeof f' and 'T'. var r15 = true ? x : af; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'typeof f'. var ac: typeof c; var r16 = true ? ac : x; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'typeof c' and 'T'. var r16 = true ? x : ac; - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'typeof c'. function f17(a: T) { var r17 = true ? x : a; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'T'. var r17 = true ? a : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'T'. } function f18(a: U) { ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r18 = true ? x : a; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r18 = true ? a : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. } var r19 = true ? new Object() : x; // BCT is Object diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt index c2b429c08bb..1a2ced3b6f2 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt @@ -1,46 +1,18 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(3,13): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(4,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(5,13): error TS2367: No best common type exists between 'U' and 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(9,13): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(9,26): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(10,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(11,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(14,14): error TS2367: No best common type exists between 'V' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(15,14): error TS2367: No best common type exists between 'U' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(18,14): error TS2367: No best common type exists between 'V' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(19,14): error TS2367: No best common type exists between 'T' and 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(23,13): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(24,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(25,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(28,14): error TS2367: No best common type exists between 'T' and 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(29,14): error TS2367: No best common type exists between 'Date' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(60,14): error TS2367: No best common type exists between 'number' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(61,14): error TS2367: No best common type exists between 'T' and 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(65,14): error TS2367: No best common type exists between 'string' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(66,14): error TS2367: No best common type exists between 'T' and 'string'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(70,14): error TS2367: No best common type exists between 'boolean' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(71,14): error TS2367: No best common type exists between 'T' and 'boolean'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(118,15): error TS2367: No best common type exists between 'typeof E' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(119,15): error TS2367: No best common type exists between 'T' and 'typeof E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(121,15): error TS2367: No best common type exists between 'E' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(122,15): error TS2367: No best common type exists between 'T' and 'E'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(143,18): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(144,19): error TS2367: No best common type exists between 'T' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(145,19): error TS2367: No best common type exists between 'V' and 'T'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts (29 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts (5 errors) ==== // checking whether other types are subtypes of type parameters with constraints function f1(x: T, y: U) { ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r = true ? x : y; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? y : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. } // V > U > T @@ -50,27 +22,15 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r = true ? x : y; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? y : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. // ok var r2 = true ? z : y; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'U'. var r2 = true ? y : z; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'V'. // ok - var r2 = true ? z : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. - var r2 = true ? x : z; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. + var r2a = true ? z : x; + var r2b = true ? x : z; } // Date > U > T @@ -78,19 +38,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r = true ? x : y; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? y : x; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. // ok var r2 = true ? x : new Date(); - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Date'. var r2 = true ? new Date() : x; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Date' and 'T'. // ok var r3 = true ? y : new Date(); @@ -121,30 +73,18 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf } function f5(x: T) { - var r1 = true ? 1 : x; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'number' and 'T'. - var r1 = true ? x : 1; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'number'. + var r1 = true ? 1 : x; // ok + var r1 = true ? x : 1; // ok } function f6(x: T) { - var r2 = true ? '' : x; // error - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'string' and 'T'. - var r2 = true ? x : ''; // error - ~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'string'. + var r2 = true ? '' : x; // ok + var r2 = true ? x : ''; // ok } function f7(x: T) { - var r3 = true ? true : x; // error - ~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'boolean' and 'T'. - var r3 = true ? x : true; // error - ~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'boolean'. + var r3 = true ? true : x; // ok + var r3 = true ? x : true; // ok } function f8(x: T) { @@ -191,19 +131,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf } function f16(x: T) { - var r13 = true ? E : x; // BUG 831833 - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'typeof E' and 'T'. - var r13 = true ? x : E; // BUG 831833 - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'typeof E'. + var r13 = true ? E : x; // ok + var r13 = true ? x : E; // ok - var r14 = true ? E.A : x; // BUG 831833 - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'E' and 'T'. - var r14 = true ? x : E.A; // BUG 831833 - ~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'E'. + var r14 = true ? E.A : x; // ok + var r14 = true ? x : E.A; // ok } function f17(x: T) { @@ -228,11 +160,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. var r18 = true ? x : a; // ok - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. var r18 = true ? a : x; // ok - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. } } diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js index bf582fe13e5..bd729f36222 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js @@ -16,8 +16,8 @@ function f2(x: T, y: U, z: V) { var r2 = true ? y : z; // ok - var r2 = true ? z : x; - var r2 = true ? x : z; + var r2a = true ? z : x; + var r2b = true ? x : z; } // Date > U > T @@ -58,18 +58,18 @@ function f4(x: T) { } function f5(x: T) { - var r1 = true ? 1 : x; // error - var r1 = true ? x : 1; // error + var r1 = true ? 1 : x; // ok + var r1 = true ? x : 1; // ok } function f6(x: T) { - var r2 = true ? '' : x; // error - var r2 = true ? x : ''; // error + var r2 = true ? '' : x; // ok + var r2 = true ? x : ''; // ok } function f7(x: T) { - var r3 = true ? true : x; // error - var r3 = true ? x : true; // error + var r3 = true ? true : x; // ok + var r3 = true ? x : true; // ok } function f8(x: T) { @@ -116,11 +116,11 @@ function f15>(x: T) { } function f16(x: T) { - var r13 = true ? E : x; // BUG 831833 - var r13 = true ? x : E; // BUG 831833 + var r13 = true ? E : x; // ok + var r13 = true ? x : E; // ok - var r14 = true ? E.A : x; // BUG 831833 - var r14 = true ? x : E.A; // BUG 831833 + var r14 = true ? E.A : x; // ok + var r14 = true ? x : E.A; // ok } function f17(x: T) { @@ -171,8 +171,8 @@ function f2(x, y, z) { var r2 = true ? z : y; var r2 = true ? y : z; // ok - var r2 = true ? z : x; - var r2 = true ? x : z; + var r2a = true ? z : x; + var r2b = true ? x : z; } // Date > U > T function f3(x, y) { @@ -222,16 +222,16 @@ function f4(x) { var r0b = true ? x : u; // ok } function f5(x) { - var r1 = true ? 1 : x; // error - var r1 = true ? x : 1; // error + var r1 = true ? 1 : x; // ok + var r1 = true ? x : 1; // ok } function f6(x) { - var r2 = true ? '' : x; // error - var r2 = true ? x : ''; // error + var r2 = true ? '' : x; // ok + var r2 = true ? x : ''; // ok } function f7(x) { - var r3 = true ? true : x; // error - var r3 = true ? x : true; // error + var r3 = true ? true : x; // ok + var r3 = true ? x : true; // ok } function f8(x) { var r4 = true ? new Date() : x; // ok @@ -275,10 +275,10 @@ function f15(x) { var r12 = true ? x : c2; // ok } function f16(x) { - var r13 = true ? E : x; // BUG 831833 - var r13 = true ? x : E; // BUG 831833 - var r14 = true ? 0 /* A */ : x; // BUG 831833 - var r14 = true ? x : 0 /* A */; // BUG 831833 + var r13 = true ? E : x; // ok + var r13 = true ? x : E; // ok + var r14 = true ? 0 /* A */ : x; // ok + var r14 = true ? x : 0 /* A */; // ok } function f17(x) { var af; diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt index f26389bb2a2..2a5fa5ad362 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt @@ -1,13 +1,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(3,12): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(5,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(6,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(9,14): error TS2367: No best common type exists between 'T' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(10,14): error TS2367: No best common type exists between 'V' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(13,14): error TS2367: No best common type exists between 'V' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts(14,14): error TS2367: No best common type exists between 'U' and 'V'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts (7 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts (1 errors) ==== // checking whether other types are subtypes of type parameters with constraints function f(t: T, u: U, v: V) { @@ -15,25 +9,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. // ok var r = true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? u : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. - // error + // ok var r2 = true ? t : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. var r2 = true ? v : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. - // error + // ok var r3 = true ? v : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'U'. var r3 = true ? u : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'V'. } \ No newline at end of file diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.js b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.js index 229beffd334..790c0fa5b96 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.js +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.js @@ -6,11 +6,11 @@ function f(t: T, u: U, v: V) { var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; } @@ -21,10 +21,10 @@ function f(t, u, v) { // ok var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; } diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt index 082d78d43d5..872cb8ef965 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt @@ -1,11 +1,3 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(6,13): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(7,13): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(10,14): error TS2367: No best common type exists between 'T' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(11,14): error TS2367: No best common type exists between 'V' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(14,14): error TS2367: No best common type exists between 'V' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(15,14): error TS2367: No best common type exists between 'U' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(26,14): error TS2367: No best common type exists between 'V' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(27,14): error TS2367: No best common type exists between 'Foo' and 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(45,7): error TS2416: Class 'D3' incorrectly extends base class 'B1': Types of property 'foo' are incompatible: Type 'V' is not assignable to type 'Foo': @@ -29,34 +21,22 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts (18 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts (10 errors) ==== // checking whether other types are subtypes of type parameters with constraints class Foo { foo: number; } function f(t: T, u: U, v: V) { - // error + // ok var r = true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r = true ? u : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. - // error + // ok var r2 = true ? t : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. var r2 = true ? v : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. - // error + // ok var r3 = true ? v : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'U'. var r3 = true ? u : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'V'. // ok var r4 = true ? t : new Foo(); @@ -66,13 +46,9 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // BUG, should be error + // ok var r6 = true ? v : new Foo(); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'Foo'. var r6 = true ? new Foo() : v; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'V'. } diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.js b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.js index 96983ecf68f..f1cf61d484f 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.js +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.js @@ -3,15 +3,15 @@ class Foo { foo: number; } function f(t: T, u: U, v: V) { - // error + // ok var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; @@ -23,7 +23,7 @@ function f(t: T, u: U, v: V) { var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // BUG, should be error + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; @@ -92,13 +92,13 @@ var Foo = (function () { return Foo; })(); function f(t, u, v) { - // error + // ok var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; // ok @@ -107,7 +107,7 @@ function f(t, u, v) { // ok var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // BUG, should be error + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; } diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt index bf7cbbcae03..f4b1d7ef041 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt @@ -1,30 +1,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(4,12): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(4,30): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(4,48): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(6,14): error TS2367: No best common type exists between 'T' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(7,14): error TS2367: No best common type exists between 'U' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(10,14): error TS2367: No best common type exists between 'T' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(11,14): error TS2367: No best common type exists between 'V' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(14,14): error TS2367: No best common type exists between 'V' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(15,14): error TS2367: No best common type exists between 'U' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(18,14): error TS2367: No best common type exists between 'T' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(19,14): error TS2367: No best common type exists between 'Foo' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(22,14): error TS2367: No best common type exists between 'U' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(23,14): error TS2367: No best common type exists between 'Foo' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(26,14): error TS2367: No best common type exists between 'V' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(27,14): error TS2367: No best common type exists between 'Foo' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(31,14): error TS2367: No best common type exists between 'T' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(32,14): error TS2367: No best common type exists between 'Foo' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(35,14): error TS2367: No best common type exists between 'U' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(36,14): error TS2367: No best common type exists between 'Foo' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(39,14): error TS2367: No best common type exists between 'V' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(40,14): error TS2367: No best common type exists between 'Foo' and 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(44,15): error TS2367: No best common type exists between 'T' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(45,15): error TS2367: No best common type exists between 'Foo' and 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(48,15): error TS2367: No best common type exists between 'U' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(49,15): error TS2367: No best common type exists between 'Foo' and 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(52,15): error TS2367: No best common type exists between 'V' and 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(53,15): error TS2367: No best common type exists between 'Foo' and 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(61,14): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(61,32): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(61,50): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. @@ -111,7 +87,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(153,50): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts (99 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts (75 errors) ==== // checking whether other types are subtypes of type parameters with constraints class Foo { foo: T; } @@ -122,103 +98,55 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. ~~~~~~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. - // error + // ok var r1 = true ? t : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'U'. var r1 = true ? u : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'T'. - // error + // ok var r2 = true ? t : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'V'. var r2 = true ? v : t; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'T'. - // error + // ok var r3 = true ? v : u; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'U'. var r3 = true ? u : v; - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'V'. - // ok? + // ok var r4 = true ? t : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Foo'. var r4 = true ? new Foo() : t; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'T'. - // ok? + // ok var r5 = true ? u : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'Foo'. var r5 = true ? new Foo() : u; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'U'. - // ok? + // ok var r6 = true ? v : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'Foo'. var r6 = true ? new Foo() : v; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'V'. - // ok? + // ok var r7 = true ? t : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Foo'. var r7 = true ? new Foo() : t; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'T'. - // ok? + // ok var r8 = true ? u : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'Foo'. var r8 = true ? new Foo() : u; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'U'. - // ok? + // ok var r9 = true ? v : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'Foo'. var r9 = true ? new Foo() : v; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'V'. - // ok? + // ok var r10 = true ? t : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'T' and 'Foo'. var r10 = true ? new Foo() : t; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'T'. - // ok? + // ok var r11 = true ? u : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'U' and 'Foo'. var r11 = true ? new Foo() : u; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'U'. - // ok? + // ok var r12 = true ? v : new Foo(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'V' and 'Foo'. var r12 = true ? new Foo() : v; - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between 'Foo' and 'V'. } module M1 { diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.js b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.js index e345d746bf7..1caa7d99087 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.js +++ b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.js @@ -3,53 +3,53 @@ class Foo { foo: T; } function f, U extends Foo, V extends Foo>(t: T, u: U, v: V) { - // error + // ok var r1 = true ? t : u; var r1 = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; - // ok? + // ok var r4 = true ? t : new Foo(); var r4 = true ? new Foo() : t; - // ok? + // ok var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // ok? + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; - // ok? + // ok var r7 = true ? t : new Foo(); var r7 = true ? new Foo() : t; - // ok? + // ok var r8 = true ? u : new Foo(); var r8 = true ? new Foo() : u; - // ok? + // ok var r9 = true ? v : new Foo(); var r9 = true ? new Foo() : v; - // ok? + // ok var r10 = true ? t : new Foo(); var r10 = true ? new Foo() : t; - // ok? + // ok var r11 = true ? u : new Foo(); var r11 = true ? new Foo() : u; - // ok? + // ok var r12 = true ? v : new Foo(); var r12 = true ? new Foo() : v; } @@ -171,40 +171,40 @@ var Foo = (function () { return Foo; })(); function f(t, u, v) { - // error + // ok var r1 = true ? t : u; var r1 = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; - // ok? + // ok var r4 = true ? t : new Foo(); var r4 = true ? new Foo() : t; - // ok? + // ok var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // ok? + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; - // ok? + // ok var r7 = true ? t : new Foo(); var r7 = true ? new Foo() : t; - // ok? + // ok var r8 = true ? u : new Foo(); var r8 = true ? new Foo() : u; - // ok? + // ok var r9 = true ? v : new Foo(); var r9 = true ? new Foo() : v; - // ok? + // ok var r10 = true ? t : new Foo(); var r10 = true ? new Foo() : t; - // ok? + // ok var r11 = true ? u : new Foo(); var r11 = true ? new Foo() : u; - // ok? + // ok var r12 = true ? v : new Foo(); var r12 = true ? new Foo() : v; } diff --git a/tests/baselines/reference/subtypingWithCallSignatures2.types b/tests/baselines/reference/subtypingWithCallSignatures2.types index 5006e00d52b..a2669bf6e65 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures2.types +++ b/tests/baselines/reference/subtypingWithCallSignatures2.types @@ -330,14 +330,14 @@ var r1 = foo1(r1arg1); // any, return types are not subtype of first overload >r1arg1 : (x: T) => T[] var r1a = [r1arg2, r1arg1]; // generic signature, subtype in both directions ->r1a : { (x: T): T[]; }[] ->[r1arg2, r1arg1] : { (x: T): T[]; }[] +>r1a : ((x: T) => T[])[] +>[r1arg2, r1arg1] : ((x: T) => T[])[] >r1arg2 : (x: number) => number[] >r1arg1 : (x: T) => T[] var r1b = [r1arg1, r1arg2]; // generic signature, subtype in both directions ->r1b : { (x: T): T[]; }[] ->[r1arg1, r1arg2] : { (x: T): T[]; }[] +>r1b : ((x: T) => T[])[] +>[r1arg1, r1arg2] : ((x: T) => T[])[] >r1arg1 : (x: T) => T[] >r1arg2 : (x: number) => number[] @@ -362,14 +362,14 @@ var r2 = foo2(r2arg1); >r2arg1 : (x: T) => string[] var r2a = [r2arg1, r2arg2]; ->r2a : { (x: T): string[]; }[] ->[r2arg1, r2arg2] : { (x: T): string[]; }[] +>r2a : ((x: T) => string[])[] +>[r2arg1, r2arg2] : ((x: T) => string[])[] >r2arg1 : (x: T) => string[] >r2arg2 : (x: number) => string[] var r2b = [r2arg2, r2arg1]; ->r2b : { (x: number): string[]; }[] ->[r2arg2, r2arg1] : { (x: number): string[]; }[] +>r2b : ((x: T) => string[])[] +>[r2arg2, r2arg1] : ((x: T) => string[])[] >r2arg2 : (x: number) => string[] >r2arg1 : (x: T) => string[] @@ -393,14 +393,14 @@ var r3 = foo3(r3arg1); >r3arg1 : (x: T) => T var r3a = [r3arg1, r3arg2]; ->r3a : { (x: T): T; }[] ->[r3arg1, r3arg2] : { (x: T): T; }[] +>r3a : ((x: T) => T)[] +>[r3arg1, r3arg2] : ((x: T) => T)[] >r3arg1 : (x: T) => T >r3arg2 : (x: number) => void var r3b = [r3arg2, r3arg1]; ->r3b : { (x: number): void; }[] ->[r3arg2, r3arg1] : { (x: number): void; }[] +>r3b : ((x: T) => T)[] +>[r3arg2, r3arg1] : ((x: T) => T)[] >r3arg2 : (x: number) => void >r3arg1 : (x: T) => T @@ -428,14 +428,14 @@ var r4 = foo4(r4arg1); // any >r4arg1 : (x: T, y: U) => T var r4a = [r4arg1, r4arg2]; ->r4a : { (x: T, y: U): T; }[] ->[r4arg1, r4arg2] : { (x: T, y: U): T; }[] +>r4a : ((x: T, y: U) => T)[] +>[r4arg1, r4arg2] : ((x: T, y: U) => T)[] >r4arg1 : (x: T, y: U) => T >r4arg2 : (x: string, y: number) => string var r4b = [r4arg2, r4arg1]; ->r4b : { (x: T, y: U): T; }[] ->[r4arg2, r4arg1] : { (x: T, y: U): T; }[] +>r4b : ((x: T, y: U) => T)[] +>[r4arg2, r4arg1] : ((x: T, y: U) => T)[] >r4arg2 : (x: string, y: number) => string >r4arg1 : (x: T, y: U) => T @@ -464,14 +464,14 @@ var r5 = foo5(r5arg1); // any >r5arg1 : (x: (arg: T) => U) => T var r5a = [r5arg1, r5arg2]; ->r5a : { (x: (arg: T) => U): T; }[] ->[r5arg1, r5arg2] : { (x: (arg: T) => U): T; }[] +>r5a : ((x: (arg: T) => U) => T)[] +>[r5arg1, r5arg2] : ((x: (arg: T) => U) => T)[] >r5arg1 : (x: (arg: T) => U) => T >r5arg2 : (x: (arg: string) => number) => string var r5b = [r5arg2, r5arg1]; ->r5b : { (x: (arg: T) => U): T; }[] ->[r5arg2, r5arg1] : { (x: (arg: T) => U): T; }[] +>r5b : ((x: (arg: T) => U) => T)[] +>[r5arg2, r5arg1] : ((x: (arg: T) => U) => T)[] >r5arg2 : (x: (arg: string) => number) => string >r5arg1 : (x: (arg: T) => U) => T @@ -506,14 +506,14 @@ var r6 = foo6(r6arg1); // any >r6arg1 : (x: (arg: T) => U) => T var r6a = [r6arg1, r6arg2]; ->r6a : { (x: (arg: T) => U): T; }[] ->[r6arg1, r6arg2] : { (x: (arg: T) => U): T; }[] +>r6a : ((x: (arg: T) => U) => T)[] +>[r6arg1, r6arg2] : ((x: (arg: T) => U) => T)[] >r6arg1 : (x: (arg: T) => U) => T >r6arg2 : (x: (arg: Base) => Derived) => Base var r6b = [r6arg2, r6arg1]; ->r6b : { (x: (arg: T) => U): T; }[] ->[r6arg2, r6arg1] : { (x: (arg: T) => U): T; }[] +>r6b : ((x: (arg: T) => U) => T)[] +>[r6arg2, r6arg1] : ((x: (arg: T) => U) => T)[] >r6arg2 : (x: (arg: Base) => Derived) => Base >r6arg1 : (x: (arg: T) => U) => T @@ -554,14 +554,14 @@ var r7 = foo7(r7arg1); // any >r7arg1 : (x: (arg: T) => U) => (r: T) => U var r7a = [r7arg1, r7arg2]; ->r7a : { (x: (arg: T) => U): (r: T) => U; }[] ->[r7arg1, r7arg2] : { (x: (arg: T) => U): (r: T) => U; }[] +>r7a : ((x: (arg: T) => U) => (r: T) => U)[] +>[r7arg1, r7arg2] : ((x: (arg: T) => U) => (r: T) => U)[] >r7arg1 : (x: (arg: T) => U) => (r: T) => U >r7arg2 : (x: (arg: Base) => Derived) => (r: Base) => Derived var r7b = [r7arg2, r7arg1]; ->r7b : { (x: (arg: T) => U): (r: T) => U; }[] ->[r7arg2, r7arg1] : { (x: (arg: T) => U): (r: T) => U; }[] +>r7b : ((x: (arg: T) => U) => (r: T) => U)[] +>[r7arg2, r7arg1] : ((x: (arg: T) => U) => (r: T) => U)[] >r7arg2 : (x: (arg: Base) => Derived) => (r: Base) => Derived >r7arg1 : (x: (arg: T) => U) => (r: T) => U @@ -610,14 +610,14 @@ var r8 = foo8(r8arg1); // any >r8arg1 : (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U var r8a = [r8arg1, r8arg2]; ->r8a : { (x: (arg: T) => U, y: (arg2: T) => U): (r: T) => U; }[] ->[r8arg1, r8arg2] : { (x: (arg: T) => U, y: (arg2: T) => U): (r: T) => U; }[] +>r8a : ((x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U)[] +>[r8arg1, r8arg2] : ((x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U)[] >r8arg1 : (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U >r8arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived var r8b = [r8arg2, r8arg1]; ->r8b : { (x: (arg: T) => U, y: (arg2: T) => U): (r: T) => U; }[] ->[r8arg2, r8arg1] : { (x: (arg: T) => U, y: (arg2: T) => U): (r: T) => U; }[] +>r8b : ((x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U)[] +>[r8arg2, r8arg1] : ((x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U)[] >r8arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived >r8arg1 : (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U @@ -667,14 +667,14 @@ var r9 = foo9(r9arg1); // any >r9arg1 : (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U var r9a = [r9arg1, r9arg2]; ->r9a : { (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): (r: T) => U; }[] ->[r9arg1, r9arg2] : { (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): (r: T) => U; }[] +>r9a : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] +>[r9arg1, r9arg2] : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] >r9arg1 : (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U >r9arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived var r9b = [r9arg2, r9arg1]; ->r9b : { (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): (r: T) => U; }[] ->[r9arg2, r9arg1] : { (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U): (r: T) => U; }[] +>r9b : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] +>[r9arg2, r9arg1] : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] >r9arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived >r9arg1 : (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U @@ -703,14 +703,14 @@ var r10 = foo10(r10arg1); // any >r10arg1 : (...x: T[]) => T var r10a = [r10arg1, r10arg2]; ->r10a : { (...x: T[]): T; }[] ->[r10arg1, r10arg2] : { (...x: T[]): T; }[] +>r10a : ((...x: T[]) => T)[] +>[r10arg1, r10arg2] : ((...x: T[]) => T)[] >r10arg1 : (...x: T[]) => T >r10arg2 : (...x: Derived[]) => Derived var r10b = [r10arg2, r10arg1]; ->r10b : { (...x: T[]): T; }[] ->[r10arg2, r10arg1] : { (...x: T[]): T; }[] +>r10b : ((...x: T[]) => T)[] +>[r10arg2, r10arg1] : ((...x: T[]) => T)[] >r10arg2 : (...x: Derived[]) => Derived >r10arg1 : (...x: T[]) => T @@ -743,14 +743,14 @@ var r11 = foo11(r11arg1); // any >r11arg1 : (x: T, y: T) => T var r11a = [r11arg1, r11arg2]; ->r11a : { (x: T, y: T): T; }[] ->[r11arg1, r11arg2] : { (x: T, y: T): T; }[] +>r11a : ((x: T, y: T) => T)[] +>[r11arg1, r11arg2] : ((x: T, y: T) => T)[] >r11arg1 : (x: T, y: T) => T >r11arg2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base var r11b = [r11arg2, r11arg1]; ->r11b : { (x: T, y: T): T; }[] ->[r11arg2, r11arg1] : { (x: T, y: T): T; }[] +>r11b : ((x: T, y: T) => T)[] +>[r11arg2, r11arg1] : ((x: T, y: T) => T)[] >r11arg2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >r11arg1 : (x: T, y: T) => T @@ -789,14 +789,14 @@ var r12 = foo12(r12arg1); // any >r12arg1 : (x: Base[], y: T) => Derived[] var r12a = [r12arg1, r12arg2]; ->r12a : { (x: Base[], y: T): Derived[]; }[] ->[r12arg1, r12arg2] : { (x: Base[], y: T): Derived[]; }[] +>r12a : ((x: Base[], y: T) => Derived[])[] +>[r12arg1, r12arg2] : ((x: Base[], y: T) => Derived[])[] >r12arg1 : (x: Base[], y: T) => Derived[] >r12arg2 : (x: Base[], y: Derived2[]) => Derived[] var r12b = [r12arg2, r12arg1]; ->r12b : { (x: Base[], y: Derived2[]): Derived[]; }[] ->[r12arg2, r12arg1] : { (x: Base[], y: Derived2[]): Derived[]; }[] +>r12b : ((x: Base[], y: T) => Derived[])[] +>[r12arg2, r12arg1] : ((x: Base[], y: T) => Derived[])[] >r12arg2 : (x: Base[], y: Derived2[]) => Derived[] >r12arg1 : (x: Base[], y: T) => Derived[] @@ -833,14 +833,14 @@ var r13 = foo13(r13arg1); // any >r13arg1 : (x: Base[], y: T) => T var r13a = [r13arg1, r13arg2]; ->r13a : { (x: Base[], y: T): T; }[] ->[r13arg1, r13arg2] : { (x: Base[], y: T): T; }[] +>r13a : ((x: Base[], y: T) => T)[] +>[r13arg1, r13arg2] : ((x: Base[], y: T) => T)[] >r13arg1 : (x: Base[], y: T) => T >r13arg2 : (x: Base[], y: Derived[]) => Derived[] var r13b = [r13arg2, r13arg1]; ->r13b : { (x: Base[], y: T): T; }[] ->[r13arg2, r13arg1] : { (x: Base[], y: T): T; }[] +>r13b : ((x: Base[], y: T) => T)[] +>[r13arg2, r13arg1] : ((x: Base[], y: T) => T)[] >r13arg2 : (x: Base[], y: Derived[]) => Derived[] >r13arg1 : (x: Base[], y: T) => T @@ -873,14 +873,14 @@ var r14 = foo14(r14arg1); // any >r14arg1 : (x: { a: T; b: T; }) => T var r14a = [r14arg1, r14arg2]; ->r14a : { (x: { a: T; b: T; }): T; }[] ->[r14arg1, r14arg2] : { (x: { a: T; b: T; }): T; }[] +>r14a : ((x: { a: T; b: T; }) => T)[] +>[r14arg1, r14arg2] : ((x: { a: T; b: T; }) => T)[] >r14arg1 : (x: { a: T; b: T; }) => T >r14arg2 : (x: { a: string; b: number; }) => Object var r14b = [r14arg2, r14arg1]; ->r14b : { (x: { a: T; b: T; }): T; }[] ->[r14arg2, r14arg1] : { (x: { a: T; b: T; }): T; }[] +>r14b : ((x: { a: T; b: T; }) => T)[] +>[r14arg2, r14arg1] : ((x: { a: T; b: T; }) => T)[] >r14arg2 : (x: { a: string; b: number; }) => Object >r14arg1 : (x: { a: T; b: T; }) => T diff --git a/tests/baselines/reference/subtypingWithCallSignatures3.types b/tests/baselines/reference/subtypingWithCallSignatures3.types index 8c136113464..cc2d47d3a33 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures3.types +++ b/tests/baselines/reference/subtypingWithCallSignatures3.types @@ -218,8 +218,8 @@ module Errors { >U : U var r1a = [(x: number) => [''], (x: T) => null]; ->r1a : { (x: T): U[]; }[] ->[(x: number) => [''], (x: T) => null] : { (x: T): U[]; }[] +>r1a : ((x: T) => U[])[] +>[(x: number) => [''], (x: T) => null] : ((x: T) => U[])[] >(x: number) => [''] : (x: number) => string[] >x : number >[''] : string[] @@ -232,8 +232,8 @@ module Errors { >U : U var r1b = [(x: T) => null, (x: number) => ['']]; ->r1b : { (x: T): U[]; }[] ->[(x: T) => null, (x: number) => ['']] : { (x: T): U[]; }[] +>r1b : ((x: T) => U[])[] +>[(x: T) => null, (x: number) => ['']] : ((x: T) => U[])[] >(x: T) => null : (x: T) => U[] >T : T >U : U @@ -284,14 +284,14 @@ module Errors { >r2arg : (x: (arg: T) => U) => (r: T) => V var r2a = [r2arg2, r2arg]; ->r2a : { (x: (arg: T) => U): (r: T) => V; }[] ->[r2arg2, r2arg] : { (x: (arg: T) => U): (r: T) => V; }[] +>r2a : ((x: (arg: T) => U) => (r: T) => V)[] +>[r2arg2, r2arg] : ((x: (arg: T) => U) => (r: T) => V)[] >r2arg2 : (x: (arg: Base) => Derived) => (r: Base) => Derived2 >r2arg : (x: (arg: T) => U) => (r: T) => V var r2b = [r2arg, r2arg2]; ->r2b : { (x: (arg: T) => U): (r: T) => V; }[] ->[r2arg, r2arg2] : { (x: (arg: T) => U): (r: T) => V; }[] +>r2b : ((x: (arg: T) => U) => (r: T) => V)[] +>[r2arg, r2arg2] : ((x: (arg: T) => U) => (r: T) => V)[] >r2arg : (x: (arg: T) => U) => (r: T) => V >r2arg2 : (x: (arg: Base) => Derived) => (r: Base) => Derived2 @@ -340,14 +340,14 @@ module Errors { >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U var r3a = [r3arg2, r3arg]; ->r3a : {}[] ->[r3arg2, r3arg] : {}[] +>r3a : (((x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] +>[r3arg2, r3arg] : (((x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] >r3arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U var r3b = [r3arg, r3arg2]; ->r3b : {}[] ->[r3arg, r3arg2] : {}[] +>r3b : (((x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] +>[r3arg, r3arg2] : (((x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U >r3arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived @@ -376,14 +376,14 @@ module Errors { >r4arg : (...x: T[]) => T var r4a = [r4arg2, r4arg]; ->r4a : { (...x: T[]): T; }[] ->[r4arg2, r4arg] : { (...x: T[]): T; }[] +>r4a : ((...x: T[]) => T)[] +>[r4arg2, r4arg] : ((...x: T[]) => T)[] >r4arg2 : (...x: Base[]) => Base >r4arg : (...x: T[]) => T var r4b = [r4arg, r4arg2]; ->r4b : { (...x: T[]): T; }[] ->[r4arg, r4arg2] : { (...x: T[]): T; }[] +>r4b : ((...x: T[]) => T)[] +>[r4arg, r4arg2] : ((...x: T[]) => T)[] >r4arg : (...x: T[]) => T >r4arg2 : (...x: Base[]) => Base @@ -417,14 +417,14 @@ module Errors { >r5arg : (x: T, y: T) => T var r5a = [r5arg2, r5arg]; ->r5a : { (x: T, y: T): T; }[] ->[r5arg2, r5arg] : { (x: T, y: T): T; }[] +>r5a : ((x: T, y: T) => T)[] +>[r5arg2, r5arg] : ((x: T, y: T) => T)[] >r5arg2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >r5arg : (x: T, y: T) => T var r5b = [r5arg, r5arg2]; ->r5b : { (x: T, y: T): T; }[] ->[r5arg, r5arg2] : { (x: T, y: T): T; }[] +>r5b : ((x: T, y: T) => T)[] +>[r5arg, r5arg2] : ((x: T, y: T) => T)[] >r5arg : (x: T, y: T) => T >r5arg2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base @@ -463,14 +463,14 @@ module Errors { >r6arg : (x: Base[], y: Derived2[]) => Derived[] var r6a = [r6arg2, r6arg]; ->r6a : { (x: Base[], y: Base[]): T; }[] ->[r6arg2, r6arg] : { (x: Base[], y: Base[]): T; }[] +>r6a : ((x: Base[], y: Base[]) => T)[] +>[r6arg2, r6arg] : ((x: Base[], y: Base[]) => T)[] >r6arg2 : (x: Base[], y: Base[]) => T >r6arg : (x: Base[], y: Derived2[]) => Derived[] var r6b = [r6arg, r6arg2]; ->r6b : { (x: Base[], y: Base[]): T; }[] ->[r6arg, r6arg2] : { (x: Base[], y: Base[]): T; }[] +>r6b : ((x: Base[], y: Base[]) => T)[] +>[r6arg, r6arg2] : ((x: Base[], y: Base[]) => T)[] >r6arg : (x: Base[], y: Derived2[]) => Derived[] >r6arg2 : (x: Base[], y: Base[]) => T @@ -500,14 +500,14 @@ module Errors { >r7arg : (x: { a: T; b: T; }) => T var r7a = [r7arg2, r7arg]; ->r7a : { (x: { a: T; b: T; }): T; }[] ->[r7arg2, r7arg] : { (x: { a: T; b: T; }): T; }[] +>r7a : ((x: { a: T; b: T; }) => T)[] +>[r7arg2, r7arg] : ((x: { a: T; b: T; }) => T)[] >r7arg2 : (x: { a: string; b: number; }) => number >r7arg : (x: { a: T; b: T; }) => T var r7b = [r7arg, r7arg2]; ->r7b : { (x: { a: T; b: T; }): T; }[] ->[r7arg, r7arg2] : { (x: { a: T; b: T; }): T; }[] +>r7b : ((x: { a: T; b: T; }) => T)[] +>[r7arg, r7arg2] : ((x: { a: T; b: T; }) => T)[] >r7arg : (x: { a: T; b: T; }) => T >r7arg2 : (x: { a: string; b: number; }) => number @@ -529,14 +529,14 @@ module Errors { >r7arg3 : (x: { a: T; b: T; }) => number var r7d = [r7arg2, r7arg3]; ->r7d : { (x: { a: string; b: number; }): number; }[] ->[r7arg2, r7arg3] : { (x: { a: string; b: number; }): number; }[] +>r7d : ((x: { a: string; b: number; }) => number)[] +>[r7arg2, r7arg3] : ((x: { a: string; b: number; }) => number)[] >r7arg2 : (x: { a: string; b: number; }) => number >r7arg3 : (x: { a: T; b: T; }) => number var r7e = [r7arg3, r7arg2]; ->r7e : { (x: { a: T; b: T; }): number; }[] ->[r7arg3, r7arg2] : { (x: { a: T; b: T; }): number; }[] +>r7e : ((x: { a: string; b: number; }) => number)[] +>[r7arg3, r7arg2] : ((x: { a: string; b: number; }) => number)[] >r7arg3 : (x: { a: T; b: T; }) => number >r7arg2 : (x: { a: string; b: number; }) => number diff --git a/tests/baselines/reference/subtypingWithCallSignatures4.types b/tests/baselines/reference/subtypingWithCallSignatures4.types index 07b3af3e540..0325552187b 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures4.types +++ b/tests/baselines/reference/subtypingWithCallSignatures4.types @@ -244,14 +244,14 @@ var r1 = foo1(r1arg); >r1arg : (x: T) => T[] var r1a = [r1arg, r1arg2]; ->r1a : { (x: T): T[]; }[] ->[r1arg, r1arg2] : { (x: T): T[]; }[] +>r1a : ((x: T) => T[])[] +>[r1arg, r1arg2] : ((x: T) => T[])[] >r1arg : (x: T) => T[] >r1arg2 : (x: T) => T[] var r1b = [r1arg2, r1arg]; ->r1b : { (x: T): T[]; }[] ->[r1arg2, r1arg] : { (x: T): T[]; }[] +>r1b : ((x: T) => T[])[] +>[r1arg2, r1arg] : ((x: T) => T[])[] >r1arg2 : (x: T) => T[] >r1arg : (x: T) => T[] @@ -278,14 +278,14 @@ var r2 = foo2(r2arg); >r2arg : (x: T) => string[] var r2a = [r2arg, r2arg2]; ->r2a : { (x: T): string[]; }[] ->[r2arg, r2arg2] : { (x: T): string[]; }[] +>r2a : ((x: T) => string[])[] +>[r2arg, r2arg2] : ((x: T) => string[])[] >r2arg : (x: T) => string[] >r2arg2 : (x: T) => string[] var r2b = [r2arg2, r2arg]; ->r2b : { (x: T): string[]; }[] ->[r2arg2, r2arg] : { (x: T): string[]; }[] +>r2b : ((x: T) => string[])[] +>[r2arg2, r2arg] : ((x: T) => string[])[] >r2arg2 : (x: T) => string[] >r2arg : (x: T) => string[] @@ -312,14 +312,14 @@ var r3 = foo3(r3arg); >r3arg : (x: T) => T var r3a = [r3arg, r3arg2]; ->r3a : { (x: T): T; }[] ->[r3arg, r3arg2] : { (x: T): T; }[] +>r3a : ((x: T) => T)[] +>[r3arg, r3arg2] : ((x: T) => T)[] >r3arg : (x: T) => T >r3arg2 : (x: T) => void var r3b = [r3arg2, r3arg]; ->r3b : { (x: T): void; }[] ->[r3arg2, r3arg] : { (x: T): void; }[] +>r3b : ((x: T) => T)[] +>[r3arg2, r3arg] : ((x: T) => T)[] >r3arg2 : (x: T) => void >r3arg : (x: T) => T @@ -350,14 +350,14 @@ var r4 = foo4(r4arg); >r4arg : (x: T, y: U) => string var r4a = [r4arg, r4arg2]; ->r4a : { (x: T, y: U): string; }[] ->[r4arg, r4arg2] : { (x: T, y: U): string; }[] +>r4a : ((x: T, y: U) => string)[] +>[r4arg, r4arg2] : ((x: T, y: U) => string)[] >r4arg : (x: T, y: U) => string >r4arg2 : (x: T, y: U) => string var r4b = [r4arg2, r4arg]; ->r4b : { (x: T, y: U): string; }[] ->[r4arg2, r4arg] : { (x: T, y: U): string; }[] +>r4b : ((x: T, y: U) => string)[] +>[r4arg2, r4arg] : ((x: T, y: U) => string)[] >r4arg2 : (x: T, y: U) => string >r4arg : (x: T, y: U) => string @@ -392,14 +392,14 @@ var r5 = foo5(r5arg); >r5arg : (x: (arg: T) => U) => T var r5a = [r5arg, r5arg2]; ->r5a : { (x: (arg: T) => U): T; }[] ->[r5arg, r5arg2] : { (x: (arg: T) => U): T; }[] +>r5a : ((x: (arg: T) => U) => T)[] +>[r5arg, r5arg2] : ((x: (arg: T) => U) => T)[] >r5arg : (x: (arg: T) => U) => T >r5arg2 : (x: (arg: T) => U) => T var r5b = [r5arg2, r5arg]; ->r5b : { (x: (arg: T) => U): T; }[] ->[r5arg2, r5arg] : { (x: (arg: T) => U): T; }[] +>r5b : ((x: (arg: T) => U) => T)[] +>[r5arg2, r5arg] : ((x: (arg: T) => U) => T)[] >r5arg2 : (x: (arg: T) => U) => T >r5arg : (x: (arg: T) => U) => T @@ -436,14 +436,14 @@ var r6 = foo6(r6arg); >r6arg : (x: (arg: T) => U) => T var r6a = [r6arg, r6arg2]; ->r6a : { (x: (arg: T) => U): T; }[] ->[r6arg, r6arg2] : { (x: (arg: T) => U): T; }[] +>r6a : ((x: (arg: T) => U) => T)[] +>[r6arg, r6arg2] : ((x: (arg: T) => U) => T)[] >r6arg : (x: (arg: T) => U) => T >r6arg2 : (x: (arg: T) => Derived) => T var r6b = [r6arg2, r6arg]; ->r6b : { (x: (arg: T) => Derived): T; }[] ->[r6arg2, r6arg] : { (x: (arg: T) => Derived): T; }[] +>r6b : ((x: (arg: T) => U) => T)[] +>[r6arg2, r6arg] : ((x: (arg: T) => U) => T)[] >r6arg2 : (x: (arg: T) => Derived) => T >r6arg : (x: (arg: T) => U) => T @@ -485,14 +485,14 @@ var r11 = foo11(r11arg); >r11arg : (x: { foo: T; }, y: { foo: U; bar: U; }) => Base var r11a = [r11arg, r11arg2]; ->r11a : { (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] ->[r11arg, r11arg2] : { (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] +>r11a : ((x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] +>[r11arg, r11arg2] : ((x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] >r11arg : (x: { foo: T; }, y: { foo: U; bar: U; }) => Base >r11arg2 : (x: { foo: T; }, y: { foo: T; bar: T; }) => Base var r11b = [r11arg2, r11arg]; ->r11b : { (x: { foo: T; }, y: { foo: T; bar: T; }): Base; }[] ->[r11arg2, r11arg] : { (x: { foo: T; }, y: { foo: T; bar: T; }): Base; }[] +>r11b : ((x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] +>[r11arg2, r11arg] : ((x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] >r11arg2 : (x: { foo: T; }, y: { foo: T; bar: T; }) => Base >r11arg : (x: { foo: T; }, y: { foo: U; bar: U; }) => Base @@ -528,14 +528,14 @@ var r15 = foo15(r15arg); >r15arg : (x: { a: U; b: V; }) => U[] var r15a = [r15arg, r15arg2]; ->r15a : { (x: { a: U; b: V; }): U[]; }[] ->[r15arg, r15arg2] : { (x: { a: U; b: V; }): U[]; }[] +>r15a : ((x: { a: U; b: V; }) => U[])[] +>[r15arg, r15arg2] : ((x: { a: U; b: V; }) => U[])[] >r15arg : (x: { a: U; b: V; }) => U[] >r15arg2 : (x: { a: T; b: T; }) => T[] var r15b = [r15arg2, r15arg]; ->r15b : { (x: { a: T; b: T; }): T[]; }[] ->[r15arg2, r15arg] : { (x: { a: T; b: T; }): T[]; }[] +>r15b : ((x: { a: U; b: V; }) => U[])[] +>[r15arg2, r15arg] : ((x: { a: U; b: V; }) => U[])[] >r15arg2 : (x: { a: T; b: T; }) => T[] >r15arg : (x: { a: U; b: V; }) => U[] @@ -572,14 +572,14 @@ var r16 = foo16(r16arg); >r16arg : (x: { a: T; b: T; }) => T[] var r16a = [r16arg, r16arg2]; ->r16a : { (x: { a: T; b: T; }): T[]; }[] ->[r16arg, r16arg2] : { (x: { a: T; b: T; }): T[]; }[] +>r16a : ((x: { a: T; b: T; }) => T[])[] +>[r16arg, r16arg2] : ((x: { a: T; b: T; }) => T[])[] >r16arg : (x: { a: T; b: T; }) => T[] >r16arg2 : (x: { a: T; b: T; }) => T[] var r16b = [r16arg2, r16arg]; ->r16b : { (x: { a: T; b: T; }): T[]; }[] ->[r16arg2, r16arg] : { (x: { a: T; b: T; }): T[]; }[] +>r16b : ((x: { a: T; b: T; }) => T[])[] +>[r16arg2, r16arg] : ((x: { a: T; b: T; }) => T[])[] >r16arg2 : (x: { a: T; b: T; }) => T[] >r16arg : (x: { a: T; b: T; }) => T[] diff --git a/tests/baselines/reference/subtypingWithConstructSignatures2.types b/tests/baselines/reference/subtypingWithConstructSignatures2.types index fdba6014751..d723a367ecb 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures2.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures2.types @@ -326,14 +326,14 @@ var r1 = foo1(r1arg1); // any, return types are not subtype of first overload >r1arg1 : new (x: T) => T[] var r1a = [r1arg2, r1arg1]; // generic signature, subtype in both directions ->r1a : { new (x: T): T[]; }[] ->[r1arg2, r1arg1] : { new (x: T): T[]; }[] +>r1a : (new (x: T) => T[])[] +>[r1arg2, r1arg1] : (new (x: T) => T[])[] >r1arg2 : new (x: number) => number[] >r1arg1 : new (x: T) => T[] var r1b = [r1arg1, r1arg2]; // generic signature, subtype in both directions ->r1b : { new (x: T): T[]; }[] ->[r1arg1, r1arg2] : { new (x: T): T[]; }[] +>r1b : (new (x: T) => T[])[] +>[r1arg1, r1arg2] : (new (x: T) => T[])[] >r1arg1 : new (x: T) => T[] >r1arg2 : new (x: number) => number[] @@ -354,14 +354,14 @@ var r2 = foo2(r2arg1); >r2arg1 : new (x: T) => string[] var r2a = [r2arg1, r2arg2]; ->r2a : { new (x: T): string[]; }[] ->[r2arg1, r2arg2] : { new (x: T): string[]; }[] +>r2a : (new (x: T) => string[])[] +>[r2arg1, r2arg2] : (new (x: T) => string[])[] >r2arg1 : new (x: T) => string[] >r2arg2 : new (x: number) => string[] var r2b = [r2arg2, r2arg1]; ->r2b : { new (x: number): string[]; }[] ->[r2arg2, r2arg1] : { new (x: number): string[]; }[] +>r2b : (new (x: T) => string[])[] +>[r2arg2, r2arg1] : (new (x: T) => string[])[] >r2arg2 : new (x: number) => string[] >r2arg1 : new (x: T) => string[] @@ -383,14 +383,14 @@ var r3 = foo3(r3arg1); >r3arg1 : new (x: T) => T var r3a = [r3arg1, r3arg2]; ->r3a : { new (x: T): T; }[] ->[r3arg1, r3arg2] : { new (x: T): T; }[] +>r3a : (new (x: T) => T)[] +>[r3arg1, r3arg2] : (new (x: T) => T)[] >r3arg1 : new (x: T) => T >r3arg2 : new (x: number) => void var r3b = [r3arg2, r3arg1]; ->r3b : { new (x: number): void; }[] ->[r3arg2, r3arg1] : { new (x: number): void; }[] +>r3b : (new (x: T) => T)[] +>[r3arg2, r3arg1] : (new (x: T) => T)[] >r3arg2 : new (x: number) => void >r3arg1 : new (x: T) => T @@ -416,14 +416,14 @@ var r4 = foo4(r4arg1); // any >r4arg1 : new (x: T, y: U) => T var r4a = [r4arg1, r4arg2]; ->r4a : { new (x: T, y: U): T; }[] ->[r4arg1, r4arg2] : { new (x: T, y: U): T; }[] +>r4a : (new (x: T, y: U) => T)[] +>[r4arg1, r4arg2] : (new (x: T, y: U) => T)[] >r4arg1 : new (x: T, y: U) => T >r4arg2 : new (x: string, y: number) => string var r4b = [r4arg2, r4arg1]; ->r4b : { new (x: T, y: U): T; }[] ->[r4arg2, r4arg1] : { new (x: T, y: U): T; }[] +>r4b : (new (x: T, y: U) => T)[] +>[r4arg2, r4arg1] : (new (x: T, y: U) => T)[] >r4arg2 : new (x: string, y: number) => string >r4arg1 : new (x: T, y: U) => T @@ -449,14 +449,14 @@ var r5 = foo5(r5arg1); // any >r5arg1 : new (x: new (arg: T) => U) => T var r5a = [r5arg1, r5arg2]; ->r5a : { new (x: new (arg: T) => U): T; }[] ->[r5arg1, r5arg2] : { new (x: new (arg: T) => U): T; }[] +>r5a : (new (x: new (arg: T) => U) => T)[] +>[r5arg1, r5arg2] : (new (x: new (arg: T) => U) => T)[] >r5arg1 : new (x: new (arg: T) => U) => T >r5arg2 : new (x: new (arg: string) => number) => string var r5b = [r5arg2, r5arg1]; ->r5b : { new (x: new (arg: T) => U): T; }[] ->[r5arg2, r5arg1] : { new (x: new (arg: T) => U): T; }[] +>r5b : (new (x: new (arg: T) => U) => T)[] +>[r5arg2, r5arg1] : (new (x: new (arg: T) => U) => T)[] >r5arg2 : new (x: new (arg: string) => number) => string >r5arg1 : new (x: new (arg: T) => U) => T @@ -487,14 +487,14 @@ var r6 = foo6(r6arg1); // any >r6arg1 : new (x: new (arg: T) => U) => T var r6a = [r6arg1, r6arg2]; ->r6a : { new (x: new (arg: T) => U): T; }[] ->[r6arg1, r6arg2] : { new (x: new (arg: T) => U): T; }[] +>r6a : (new (x: new (arg: T) => U) => T)[] +>[r6arg1, r6arg2] : (new (x: new (arg: T) => U) => T)[] >r6arg1 : new (x: new (arg: T) => U) => T >r6arg2 : new (x: new (arg: Base) => Derived) => Base var r6b = [r6arg2, r6arg1]; ->r6b : { new (x: new (arg: T) => U): T; }[] ->[r6arg2, r6arg1] : { new (x: new (arg: T) => U): T; }[] +>r6b : (new (x: new (arg: T) => U) => T)[] +>[r6arg2, r6arg1] : (new (x: new (arg: T) => U) => T)[] >r6arg2 : new (x: new (arg: Base) => Derived) => Base >r6arg1 : new (x: new (arg: T) => U) => T @@ -529,14 +529,14 @@ var r7 = foo7(r7arg1); // any >r7arg1 : new (x: new (arg: T) => U) => new (r: T) => U var r7a = [r7arg1, r7arg2]; ->r7a : { new (x: new (arg: T) => U): new (r: T) => U; }[] ->[r7arg1, r7arg2] : { new (x: new (arg: T) => U): new (r: T) => U; }[] +>r7a : (new (x: new (arg: T) => U) => new (r: T) => U)[] +>[r7arg1, r7arg2] : (new (x: new (arg: T) => U) => new (r: T) => U)[] >r7arg1 : new (x: new (arg: T) => U) => new (r: T) => U >r7arg2 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived var r7b = [r7arg2, r7arg1]; ->r7b : { new (x: new (arg: T) => U): new (r: T) => U; }[] ->[r7arg2, r7arg1] : { new (x: new (arg: T) => U): new (r: T) => U; }[] +>r7b : (new (x: new (arg: T) => U) => new (r: T) => U)[] +>[r7arg2, r7arg1] : (new (x: new (arg: T) => U) => new (r: T) => U)[] >r7arg2 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived >r7arg1 : new (x: new (arg: T) => U) => new (r: T) => U @@ -579,14 +579,14 @@ var r8 = foo8(r8arg1); // any >r8arg1 : new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U var r8a = [r8arg1, r8arg2]; ->r8a : { new (x: new (arg: T) => U, y: new (arg2: T) => U): new (r: T) => U; }[] ->[r8arg1, r8arg2] : { new (x: new (arg: T) => U, y: new (arg2: T) => U): new (r: T) => U; }[] +>r8a : (new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U)[] +>[r8arg1, r8arg2] : (new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U)[] >r8arg1 : new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U >r8arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived var r8b = [r8arg2, r8arg1]; ->r8b : { new (x: new (arg: T) => U, y: new (arg2: T) => U): new (r: T) => U; }[] ->[r8arg2, r8arg1] : { new (x: new (arg: T) => U, y: new (arg2: T) => U): new (r: T) => U; }[] +>r8b : (new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U)[] +>[r8arg2, r8arg1] : (new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U)[] >r8arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived >r8arg1 : new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U @@ -630,14 +630,14 @@ var r9 = foo9(r9arg1); // any >r9arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U var r9a = [r9arg1, r9arg2]; ->r9a : {}[] ->[r9arg1, r9arg2] : {}[] +>r9a : ((new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U) | (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] +>[r9arg1, r9arg2] : ((new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U) | (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] >r9arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U >r9arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived var r9b = [r9arg2, r9arg1]; ->r9b : {}[] ->[r9arg2, r9arg1] : {}[] +>r9b : ((new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U) | (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] +>[r9arg2, r9arg1] : ((new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U) | (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] >r9arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived >r9arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U @@ -662,14 +662,14 @@ var r10 = foo10(r10arg1); // any >r10arg1 : new (...x: T[]) => T var r10a = [r10arg1, r10arg2]; ->r10a : { new (...x: T[]): T; }[] ->[r10arg1, r10arg2] : { new (...x: T[]): T; }[] +>r10a : (new (...x: T[]) => T)[] +>[r10arg1, r10arg2] : (new (...x: T[]) => T)[] >r10arg1 : new (...x: T[]) => T >r10arg2 : new (...x: Derived[]) => Derived var r10b = [r10arg2, r10arg1]; ->r10b : { new (...x: T[]): T; }[] ->[r10arg2, r10arg1] : { new (...x: T[]): T; }[] +>r10b : (new (...x: T[]) => T)[] +>[r10arg2, r10arg1] : (new (...x: T[]) => T)[] >r10arg2 : new (...x: Derived[]) => Derived >r10arg1 : new (...x: T[]) => T @@ -699,14 +699,14 @@ var r11 = foo11(r11arg1); // any >r11arg1 : new (x: T, y: T) => T var r11a = [r11arg1, r11arg2]; ->r11a : { new (x: T, y: T): T; }[] ->[r11arg1, r11arg2] : { new (x: T, y: T): T; }[] +>r11a : (new (x: T, y: T) => T)[] +>[r11arg1, r11arg2] : (new (x: T, y: T) => T)[] >r11arg1 : new (x: T, y: T) => T >r11arg2 : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base var r11b = [r11arg2, r11arg1]; ->r11b : { new (x: T, y: T): T; }[] ->[r11arg2, r11arg1] : { new (x: T, y: T): T; }[] +>r11b : (new (x: T, y: T) => T)[] +>[r11arg2, r11arg1] : (new (x: T, y: T) => T)[] >r11arg2 : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >r11arg1 : new (x: T, y: T) => T @@ -741,14 +741,14 @@ var r12 = foo12(r12arg1); // any >r12arg1 : new (x: Base[], y: T) => Derived[] var r12a = [r12arg1, r12arg2]; ->r12a : { new (x: Base[], y: T): Derived[]; }[] ->[r12arg1, r12arg2] : { new (x: Base[], y: T): Derived[]; }[] +>r12a : (new (x: Base[], y: T) => Derived[])[] +>[r12arg1, r12arg2] : (new (x: Base[], y: T) => Derived[])[] >r12arg1 : new (x: Base[], y: T) => Derived[] >r12arg2 : new (x: Base[], y: Derived2[]) => Derived[] var r12b = [r12arg2, r12arg1]; ->r12b : { new (x: Base[], y: Derived2[]): Derived[]; }[] ->[r12arg2, r12arg1] : { new (x: Base[], y: Derived2[]): Derived[]; }[] +>r12b : (new (x: Base[], y: T) => Derived[])[] +>[r12arg2, r12arg1] : (new (x: Base[], y: T) => Derived[])[] >r12arg2 : new (x: Base[], y: Derived2[]) => Derived[] >r12arg1 : new (x: Base[], y: T) => Derived[] @@ -782,14 +782,14 @@ var r13 = foo13(r13arg1); // any >r13arg1 : new (x: Base[], y: T) => T var r13a = [r13arg1, r13arg2]; ->r13a : { new (x: Base[], y: T): T; }[] ->[r13arg1, r13arg2] : { new (x: Base[], y: T): T; }[] +>r13a : (new (x: Base[], y: T) => T)[] +>[r13arg1, r13arg2] : (new (x: Base[], y: T) => T)[] >r13arg1 : new (x: Base[], y: T) => T >r13arg2 : new (x: Base[], y: Derived[]) => Derived[] var r13b = [r13arg2, r13arg1]; ->r13b : { new (x: Base[], y: T): T; }[] ->[r13arg2, r13arg1] : { new (x: Base[], y: T): T; }[] +>r13b : (new (x: Base[], y: T) => T)[] +>[r13arg2, r13arg1] : (new (x: Base[], y: T) => T)[] >r13arg2 : new (x: Base[], y: Derived[]) => Derived[] >r13arg1 : new (x: Base[], y: T) => T @@ -817,14 +817,14 @@ var r14 = foo14(r14arg1); // any >r14arg1 : new (x: { a: T; b: T; }) => T var r14a = [r14arg1, r14arg2]; ->r14a : { new (x: { a: T; b: T; }): T; }[] ->[r14arg1, r14arg2] : { new (x: { a: T; b: T; }): T; }[] +>r14a : (new (x: { a: T; b: T; }) => T)[] +>[r14arg1, r14arg2] : (new (x: { a: T; b: T; }) => T)[] >r14arg1 : new (x: { a: T; b: T; }) => T >r14arg2 : new (x: { a: string; b: number; }) => Object var r14b = [r14arg2, r14arg1]; ->r14b : { new (x: { a: T; b: T; }): T; }[] ->[r14arg2, r14arg1] : { new (x: { a: T; b: T; }): T; }[] +>r14b : (new (x: { a: T; b: T; }) => T)[] +>[r14arg2, r14arg1] : (new (x: { a: T; b: T; }) => T)[] >r14arg2 : new (x: { a: string; b: number; }) => Object >r14arg1 : new (x: { a: T; b: T; }) => T diff --git a/tests/baselines/reference/subtypingWithConstructSignatures3.types b/tests/baselines/reference/subtypingWithConstructSignatures3.types index cf4db8939fd..b0f0680c7a0 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures3.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures3.types @@ -224,14 +224,14 @@ module Errors { >r1arg1 : new (x: T) => U[] var r1a = [r1arg2, r1arg1]; ->r1a : { new (x: T): U[]; }[] ->[r1arg2, r1arg1] : { new (x: T): U[]; }[] +>r1a : (new (x: T) => U[])[] +>[r1arg2, r1arg1] : (new (x: T) => U[])[] >r1arg2 : new (x: number) => string[] >r1arg1 : new (x: T) => U[] var r1b = [r1arg1, r1arg2]; ->r1b : { new (x: T): U[]; }[] ->[r1arg1, r1arg2] : { new (x: T): U[]; }[] +>r1b : (new (x: T) => U[])[] +>[r1arg1, r1arg2] : (new (x: T) => U[])[] >r1arg1 : new (x: T) => U[] >r1arg2 : new (x: number) => string[] @@ -268,14 +268,14 @@ module Errors { >r2arg1 : new (x: new (arg: T) => U) => new (r: T) => V var r2a = [r2arg2, r2arg1]; ->r2a : { new (x: new (arg: T) => U): new (r: T) => V; }[] ->[r2arg2, r2arg1] : { new (x: new (arg: T) => U): new (r: T) => V; }[] +>r2a : (new (x: new (arg: T) => U) => new (r: T) => V)[] +>[r2arg2, r2arg1] : (new (x: new (arg: T) => U) => new (r: T) => V)[] >r2arg2 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2 >r2arg1 : new (x: new (arg: T) => U) => new (r: T) => V var r2b = [r2arg1, r2arg2]; ->r2b : { new (x: new (arg: T) => U): new (r: T) => V; }[] ->[r2arg1, r2arg2] : { new (x: new (arg: T) => U): new (r: T) => V; }[] +>r2b : (new (x: new (arg: T) => U) => new (r: T) => V)[] +>[r2arg1, r2arg2] : (new (x: new (arg: T) => U) => new (r: T) => V)[] >r2arg1 : new (x: new (arg: T) => U) => new (r: T) => V >r2arg2 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2 @@ -318,14 +318,14 @@ module Errors { >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U var r3a = [r3arg2, r3arg1]; ->r3a : {}[] ->[r3arg2, r3arg1] : {}[] +>r3a : ((new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U) | (new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] +>[r3arg2, r3arg1] : ((new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U) | (new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] >r3arg2 : new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U var r3b = [r3arg1, r3arg2]; ->r3b : {}[] ->[r3arg1, r3arg2] : {}[] +>r3b : ((new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U) | (new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] +>[r3arg1, r3arg2] : ((new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U) | (new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U >r3arg2 : new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived @@ -350,14 +350,14 @@ module Errors { >r4arg1 : new (...x: T[]) => T var r4a = [r4arg2, r4arg1]; ->r4a : { new (...x: T[]): T; }[] ->[r4arg2, r4arg1] : { new (...x: T[]): T; }[] +>r4a : (new (...x: T[]) => T)[] +>[r4arg2, r4arg1] : (new (...x: T[]) => T)[] >r4arg2 : new (...x: Base[]) => Base >r4arg1 : new (...x: T[]) => T var r4b = [r4arg1, r4arg2]; ->r4b : { new (...x: T[]): T; }[] ->[r4arg1, r4arg2] : { new (...x: T[]): T; }[] +>r4b : (new (...x: T[]) => T)[] +>[r4arg1, r4arg2] : (new (...x: T[]) => T)[] >r4arg1 : new (...x: T[]) => T >r4arg2 : new (...x: Base[]) => Base @@ -387,14 +387,14 @@ module Errors { >r5arg1 : new (x: T, y: T) => T var r5a = [r5arg2, r5arg1]; ->r5a : { new (x: T, y: T): T; }[] ->[r5arg2, r5arg1] : { new (x: T, y: T): T; }[] +>r5a : (new (x: T, y: T) => T)[] +>[r5arg2, r5arg1] : (new (x: T, y: T) => T)[] >r5arg2 : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >r5arg1 : new (x: T, y: T) => T var r5b = [r5arg1, r5arg2]; ->r5b : { new (x: T, y: T): T; }[] ->[r5arg1, r5arg2] : { new (x: T, y: T): T; }[] +>r5b : (new (x: T, y: T) => T)[] +>[r5arg1, r5arg2] : (new (x: T, y: T) => T)[] >r5arg1 : new (x: T, y: T) => T >r5arg2 : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base @@ -429,14 +429,14 @@ module Errors { >r6arg1 : new (x: Base[], y: Derived2[]) => Derived[] var r6a = [r6arg2, r6arg1]; ->r6a : { new (x: Base[], y: Base[]): T; }[] ->[r6arg2, r6arg1] : { new (x: Base[], y: Base[]): T; }[] +>r6a : (new (x: Base[], y: Base[]) => T)[] +>[r6arg2, r6arg1] : (new (x: Base[], y: Base[]) => T)[] >r6arg2 : new (x: Base[], y: Base[]) => T >r6arg1 : new (x: Base[], y: Derived2[]) => Derived[] var r6b = [r6arg1, r6arg2]; ->r6b : { new (x: Base[], y: Base[]): T; }[] ->[r6arg1, r6arg2] : { new (x: Base[], y: Base[]): T; }[] +>r6b : (new (x: Base[], y: Base[]) => T)[] +>[r6arg1, r6arg2] : (new (x: Base[], y: Base[]) => T)[] >r6arg1 : new (x: Base[], y: Derived2[]) => Derived[] >r6arg2 : new (x: Base[], y: Base[]) => T @@ -463,14 +463,14 @@ module Errors { >r7arg1 : new (x: { a: T; b: T; }) => T var r7a = [r7arg2, r7arg1]; ->r7a : { new (x: { a: T; b: T; }): T; }[] ->[r7arg2, r7arg1] : { new (x: { a: T; b: T; }): T; }[] +>r7a : (new (x: { a: T; b: T; }) => T)[] +>[r7arg2, r7arg1] : (new (x: { a: T; b: T; }) => T)[] >r7arg2 : new (x: { a: string; b: number; }) => number >r7arg1 : new (x: { a: T; b: T; }) => T var r7b = [r7arg1, r7arg2]; ->r7b : { new (x: { a: T; b: T; }): T; }[] ->[r7arg1, r7arg2] : { new (x: { a: T; b: T; }): T; }[] +>r7b : (new (x: { a: T; b: T; }) => T)[] +>[r7arg1, r7arg2] : (new (x: { a: T; b: T; }) => T)[] >r7arg1 : new (x: { a: T; b: T; }) => T >r7arg2 : new (x: { a: string; b: number; }) => number @@ -491,14 +491,14 @@ module Errors { >r7arg3 : new (x: { a: T; b: T; }) => number var r7d = [r7arg2, r7arg3]; ->r7d : { new (x: { a: string; b: number; }): number; }[] ->[r7arg2, r7arg3] : { new (x: { a: string; b: number; }): number; }[] +>r7d : (new (x: { a: string; b: number; }) => number)[] +>[r7arg2, r7arg3] : (new (x: { a: string; b: number; }) => number)[] >r7arg2 : new (x: { a: string; b: number; }) => number >r7arg3 : new (x: { a: T; b: T; }) => number var r7e = [r7arg3, r7arg2]; ->r7e : { new (x: { a: T; b: T; }): number; }[] ->[r7arg3, r7arg2] : { new (x: { a: T; b: T; }): number; }[] +>r7e : (new (x: { a: string; b: number; }) => number)[] +>[r7arg3, r7arg2] : (new (x: { a: string; b: number; }) => number)[] >r7arg3 : new (x: { a: T; b: T; }) => number >r7arg2 : new (x: { a: string; b: number; }) => number diff --git a/tests/baselines/reference/subtypingWithConstructSignatures4.types b/tests/baselines/reference/subtypingWithConstructSignatures4.types index a9116880df3..21a40ecf7fc 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures4.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures4.types @@ -240,14 +240,14 @@ var r1 = foo1(r1arg); >r1arg : new (x: T) => T[] var r1a = [r1arg, r1arg2]; ->r1a : { new (x: T): T[]; }[] ->[r1arg, r1arg2] : { new (x: T): T[]; }[] +>r1a : (new (x: T) => T[])[] +>[r1arg, r1arg2] : (new (x: T) => T[])[] >r1arg : new (x: T) => T[] >r1arg2 : new (x: T) => T[] var r1b = [r1arg2, r1arg]; ->r1b : { new (x: T): T[]; }[] ->[r1arg2, r1arg] : { new (x: T): T[]; }[] +>r1b : (new (x: T) => T[])[] +>[r1arg2, r1arg] : (new (x: T) => T[])[] >r1arg2 : new (x: T) => T[] >r1arg : new (x: T) => T[] @@ -270,14 +270,14 @@ var r2 = foo2(r2arg); >r2arg : new (x: T) => string[] var r2a = [r2arg, r2arg2]; ->r2a : { new (x: T): string[]; }[] ->[r2arg, r2arg2] : { new (x: T): string[]; }[] +>r2a : (new (x: T) => string[])[] +>[r2arg, r2arg2] : (new (x: T) => string[])[] >r2arg : new (x: T) => string[] >r2arg2 : new (x: T) => string[] var r2b = [r2arg2, r2arg]; ->r2b : { new (x: T): string[]; }[] ->[r2arg2, r2arg] : { new (x: T): string[]; }[] +>r2b : (new (x: T) => string[])[] +>[r2arg2, r2arg] : (new (x: T) => string[])[] >r2arg2 : new (x: T) => string[] >r2arg : new (x: T) => string[] @@ -301,14 +301,14 @@ var r3 = foo3(r3arg); >r3arg : new (x: T) => T var r3a = [r3arg, r3arg2]; ->r3a : { new (x: T): T; }[] ->[r3arg, r3arg2] : { new (x: T): T; }[] +>r3a : (new (x: T) => T)[] +>[r3arg, r3arg2] : (new (x: T) => T)[] >r3arg : new (x: T) => T >r3arg2 : new (x: T) => void var r3b = [r3arg2, r3arg]; ->r3b : { new (x: T): void; }[] ->[r3arg2, r3arg] : { new (x: T): void; }[] +>r3b : (new (x: T) => T)[] +>[r3arg2, r3arg] : (new (x: T) => T)[] >r3arg2 : new (x: T) => void >r3arg : new (x: T) => T @@ -337,14 +337,14 @@ var r4 = foo4(r4arg); >r4arg : new (x: T, y: U) => string var r4a = [r4arg, r4arg2]; ->r4a : { new (x: T, y: U): string; }[] ->[r4arg, r4arg2] : { new (x: T, y: U): string; }[] +>r4a : (new (x: T, y: U) => string)[] +>[r4arg, r4arg2] : (new (x: T, y: U) => string)[] >r4arg : new (x: T, y: U) => string >r4arg2 : new (x: T, y: U) => string var r4b = [r4arg2, r4arg]; ->r4b : { new (x: T, y: U): string; }[] ->[r4arg2, r4arg] : { new (x: T, y: U): string; }[] +>r4b : (new (x: T, y: U) => string)[] +>[r4arg2, r4arg] : (new (x: T, y: U) => string)[] >r4arg2 : new (x: T, y: U) => string >r4arg : new (x: T, y: U) => string @@ -375,14 +375,14 @@ var r5 = foo5(r5arg); >r5arg : new (x: new (arg: T) => U) => T var r5a = [r5arg, r5arg2]; ->r5a : { new (x: new (arg: T) => U): T; }[] ->[r5arg, r5arg2] : { new (x: new (arg: T) => U): T; }[] +>r5a : (new (x: new (arg: T) => U) => T)[] +>[r5arg, r5arg2] : (new (x: new (arg: T) => U) => T)[] >r5arg : new (x: new (arg: T) => U) => T >r5arg2 : new (x: new (arg: T) => U) => T var r5b = [r5arg2, r5arg]; ->r5b : { new (x: new (arg: T) => U): T; }[] ->[r5arg2, r5arg] : { new (x: new (arg: T) => U): T; }[] +>r5b : (new (x: new (arg: T) => U) => T)[] +>[r5arg2, r5arg] : (new (x: new (arg: T) => U) => T)[] >r5arg2 : new (x: new (arg: T) => U) => T >r5arg : new (x: new (arg: T) => U) => T @@ -415,14 +415,14 @@ var r6 = foo6(r6arg); >r6arg : new (x: new (arg: T) => U) => T var r6a = [r6arg, r6arg2]; ->r6a : { new (x: new (arg: T) => U): T; }[] ->[r6arg, r6arg2] : { new (x: new (arg: T) => U): T; }[] +>r6a : (new (x: new (arg: T) => U) => T)[] +>[r6arg, r6arg2] : (new (x: new (arg: T) => U) => T)[] >r6arg : new (x: new (arg: T) => U) => T >r6arg2 : new (x: new (arg: T) => Derived) => T var r6b = [r6arg2, r6arg]; ->r6b : { new (x: new (arg: T) => Derived): T; }[] ->[r6arg2, r6arg] : { new (x: new (arg: T) => Derived): T; }[] +>r6b : (new (x: new (arg: T) => U) => T)[] +>[r6arg2, r6arg] : (new (x: new (arg: T) => U) => T)[] >r6arg2 : new (x: new (arg: T) => Derived) => T >r6arg : new (x: new (arg: T) => U) => T @@ -460,14 +460,14 @@ var r11 = foo11(r11arg); >r11arg : new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base var r11a = [r11arg, r11arg2]; ->r11a : { new (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] ->[r11arg, r11arg2] : { new (x: { foo: T; }, y: { foo: U; bar: U; }): Base; }[] +>r11a : (new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] +>[r11arg, r11arg2] : (new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] >r11arg : new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base >r11arg2 : new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base var r11b = [r11arg2, r11arg]; ->r11b : { new (x: { foo: T; }, y: { foo: T; bar: T; }): Base; }[] ->[r11arg2, r11arg] : { new (x: { foo: T; }, y: { foo: T; bar: T; }): Base; }[] +>r11b : (new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] +>[r11arg2, r11arg] : (new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] >r11arg2 : new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base >r11arg : new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base @@ -499,14 +499,14 @@ var r15 = foo15(r15arg); >r15arg : new (x: { a: U; b: V; }) => U[] var r15a = [r15arg, r15arg2]; ->r15a : { new (x: { a: U; b: V; }): U[]; }[] ->[r15arg, r15arg2] : { new (x: { a: U; b: V; }): U[]; }[] +>r15a : (new (x: { a: U; b: V; }) => U[])[] +>[r15arg, r15arg2] : (new (x: { a: U; b: V; }) => U[])[] >r15arg : new (x: { a: U; b: V; }) => U[] >r15arg2 : new (x: { a: T; b: T; }) => T[] var r15b = [r15arg2, r15arg]; ->r15b : { new (x: { a: T; b: T; }): T[]; }[] ->[r15arg2, r15arg] : { new (x: { a: T; b: T; }): T[]; }[] +>r15b : (new (x: { a: U; b: V; }) => U[])[] +>[r15arg2, r15arg] : (new (x: { a: U; b: V; }) => U[])[] >r15arg2 : new (x: { a: T; b: T; }) => T[] >r15arg : new (x: { a: U; b: V; }) => U[] @@ -539,14 +539,14 @@ var r16 = foo16(r16arg); >r16arg : new (x: { a: T; b: T; }) => T[] var r16a = [r16arg, r16arg2]; ->r16a : { new (x: { a: T; b: T; }): T[]; }[] ->[r16arg, r16arg2] : { new (x: { a: T; b: T; }): T[]; }[] +>r16a : (new (x: { a: T; b: T; }) => T[])[] +>[r16arg, r16arg2] : (new (x: { a: T; b: T; }) => T[])[] >r16arg : new (x: { a: T; b: T; }) => T[] >r16arg2 : new (x: { a: T; b: T; }) => T[] var r16b = [r16arg2, r16arg]; ->r16b : { new (x: { a: T; b: T; }): T[]; }[] ->[r16arg2, r16arg] : { new (x: { a: T; b: T; }): T[]; }[] +>r16b : (new (x: { a: T; b: T; }) => T[])[] +>[r16arg2, r16arg] : (new (x: { a: T; b: T; }) => T[])[] >r16arg2 : new (x: { a: T; b: T; }) => T[] >r16arg : new (x: { a: T; b: T; }) => T[] diff --git a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt index 74d47f12565..ac17303572d 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt +++ b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt @@ -4,10 +4,9 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW Property '1' is optional in type 'S2' but required in type 'T2'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts(26,11): error TS2429: Interface 'S3' incorrectly extends interface 'T3': Property ''1'' is optional in type 'S3' but required in type 'T3'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts(33,9): error TS2367: No best common type exists between '{ Foo: Base; }' and '{ Foo?: Derived; }'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts (4 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts (3 errors) ==== // Derived member is optional but base member is not, should be an error interface Base { foo: string; } @@ -49,6 +48,4 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW // object literal case var a: { Foo: Base; } var b: { Foo?: Derived; } - var r = true ? a : b; // error - ~~~~~~~~~~~~ -!!! error TS2367: No best common type exists between '{ Foo: Base; }' and '{ Foo?: Derived; }'. \ No newline at end of file + var r = true ? a : b; // ok \ No newline at end of file diff --git a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.js b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.js index 186f3ba4544..33c4cc927da 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.js +++ b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.js @@ -31,11 +31,11 @@ interface S3 extends T3 { // object literal case var a: { Foo: Base; } var b: { Foo?: Derived; } -var r = true ? a : b; // error +var r = true ? a : b; // ok //// [subtypingWithObjectMembersOptionality2.js] // Derived member is optional but base member is not, should be an error // object literal case var a; var b; -var r = true ? a : b; // error +var r = true ? a : b; // ok diff --git a/tests/baselines/reference/subtypingWithObjectMembersOptionality3.types b/tests/baselines/reference/subtypingWithObjectMembersOptionality3.types index f4bd9f447a8..055863e0bfa 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersOptionality3.types +++ b/tests/baselines/reference/subtypingWithObjectMembersOptionality3.types @@ -69,8 +69,8 @@ var b: { Foo2: Derived; } >Derived : Derived var r = true ? a : b; // ok ->r : { Foo?: Base; } ->true ? a : b : { Foo?: Base; } +>r : { Foo?: Base; } | { Foo2: Derived; } +>true ? a : b : { Foo?: Base; } | { Foo2: Derived; } >a : { Foo?: Base; } >b : { Foo2: Derived; } diff --git a/tests/baselines/reference/subtypingWithObjectMembersOptionality4.types b/tests/baselines/reference/subtypingWithObjectMembersOptionality4.types index 7ad4580090c..96204004b64 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersOptionality4.types +++ b/tests/baselines/reference/subtypingWithObjectMembersOptionality4.types @@ -69,8 +69,8 @@ var b: { Foo2?: Derived; } >Derived : Derived var r = true ? a : b; // ok ->r : { Foo2?: Derived; } ->true ? a : b : { Foo2?: Derived; } +>r : { Foo: Base; } | { Foo2?: Derived; } +>true ? a : b : { Foo: Base; } | { Foo2?: Derived; } >a : { Foo: Base; } >b : { Foo2?: Derived; } diff --git a/tests/baselines/reference/targetTypeTest2.types b/tests/baselines/reference/targetTypeTest2.types index 795dd7036f7..0000e65b8a7 100644 --- a/tests/baselines/reference/targetTypeTest2.types +++ b/tests/baselines/reference/targetTypeTest2.types @@ -4,7 +4,7 @@ var a : any[] = [1,2,"3"]; >a : any[] ->[1,2,"3"] : any[] +>[1,2,"3"] : (string | number)[] function func1(stuff:any[]) { return stuff; } @@ -21,7 +21,7 @@ function func2(stuff1:string, stuff2:number, stuff3:number) { return func1([stuff1, stuff2, stuff3]); >func1([stuff1, stuff2, stuff3]) : any[] >func1 : (stuff: any[]) => any[] ->[stuff1, stuff2, stuff3] : any[] +>[stuff1, stuff2, stuff3] : (string | number)[] >stuff1 : string >stuff2 : number >stuff3 : number diff --git a/tests/baselines/reference/targetTypeTest3.errors.txt b/tests/baselines/reference/targetTypeTest3.errors.txt index e81cba71a47..41b2d027fb5 100644 --- a/tests/baselines/reference/targetTypeTest3.errors.txt +++ b/tests/baselines/reference/targetTypeTest3.errors.txt @@ -1,5 +1,6 @@ -tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type '{}[]' is not assignable to type 'string[]': - Type '{}' is not assignable to type 'string'. +tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type '(string | number)[]' is not assignable to type 'string[]': + Type 'string | number' is not assignable to type 'string': + Type 'number' is not assignable to type 'string'. ==== tests/cases/compiler/targetTypeTest3.ts (1 errors) ==== @@ -8,8 +9,9 @@ tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type '{}[]' is not a var a : string[] = [1,2,"3"]; // should produce an error ~ -!!! error TS2322: Type '{}[]' is not assignable to type 'string[]': -!!! error TS2322: Type '{}' is not assignable to type 'string'. +!!! error TS2322: Type '(string | number)[]' is not assignable to type 'string[]': +!!! error TS2322: Type 'string | number' is not assignable to type 'string': +!!! error TS2322: Type 'number' is not assignable to type 'string'. function func1(stuff:any[]) { return stuff; } diff --git a/tests/baselines/reference/thisInPropertyBoundDeclarations.types b/tests/baselines/reference/thisInPropertyBoundDeclarations.types index 1ccebef5eaa..196cf4e2ddc 100644 --- a/tests/baselines/reference/thisInPropertyBoundDeclarations.types +++ b/tests/baselines/reference/thisInPropertyBoundDeclarations.types @@ -8,7 +8,7 @@ class Bug { private static func: Function[] = [ >func : Function[] >Function : Function ->[ (that: Bug, name: string) => { that.foo(name); } ] : Function[] +>[ (that: Bug, name: string) => { that.foo(name); } ] : ((that: Bug, name: string) => void)[] (that: Bug, name: string) => { >(that: Bug, name: string) => { that.foo(name); } : (that: Bug, name: string) => void diff --git a/tests/baselines/reference/throwStatements.types b/tests/baselines/reference/throwStatements.types index efc2ff24124..eeef863f6eb 100644 --- a/tests/baselines/reference/throwStatements.types +++ b/tests/baselines/reference/throwStatements.types @@ -219,7 +219,7 @@ throw []; >[] : undefined[] throw ['a', ['b']]; ->['a', ['b']] : {}[] +>['a', ['b']] : (string | string[])[] >['b'] : string[] throw /[a-z]/; diff --git a/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt b/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt index e1681f5cc29..9b068b62e68 100644 --- a/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt +++ b/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt @@ -1,7 +1,9 @@ -tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(5,19): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. - Type '{}' is not assignable to type 'number'. -tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. - Type '{}' is not assignable to type 'number'. +tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(5,19): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. ==== tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts (2 errors) ==== @@ -11,12 +13,14 @@ tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS // these two should give the same error this.test([1, 2, "hi", 5, ]); ~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type '{}' is not assignable to type 'number'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number': +!!! error TS2345: Type 'string' is not assignable to type 'number'. this.test([1, 2, "hi", 5]); ~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type '{}' is not assignable to type 'number'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number': +!!! error TS2345: Type 'string' is not assignable to type 'number'. } } \ No newline at end of file diff --git a/tests/baselines/reference/tupleTypes.errors.txt b/tests/baselines/reference/tupleTypes.errors.txt index fcc65ff5c23..8bf6cca4855 100644 --- a/tests/baselines/reference/tupleTypes.errors.txt +++ b/tests/baselines/reference/tupleTypes.errors.txt @@ -1,16 +1,17 @@ tests/cases/compiler/tupleTypes.ts(1,9): error TS1122: A tuple type element list cannot be empty. -tests/cases/compiler/tupleTypes.ts(14,1): error TS2322: Type '{}[]' is not assignable to type '[number, string]': - Property '0' is missing in type '{}[]'. +tests/cases/compiler/tupleTypes.ts(14,1): error TS2322: Type 'undefined[]' is not assignable to type '[number, string]': + Property '0' is missing in type 'undefined[]'. tests/cases/compiler/tupleTypes.ts(15,1): error TS2322: Type '[number]' is not assignable to type '[number, string]': Property '1' is missing in type '[number]'. tests/cases/compiler/tupleTypes.ts(17,1): error TS2322: Type '[string, number]' is not assignable to type '[number, string]': Types of property '0' are incompatible: Type 'string' is not assignable to type 'number'. -tests/cases/compiler/tupleTypes.ts(41,1): error TS2323: Type '{}[]' is not assignable to type '[number, string]'. +tests/cases/compiler/tupleTypes.ts(41,1): error TS2323: Type 'undefined[]' is not assignable to type '[number, string]'. tests/cases/compiler/tupleTypes.ts(47,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]': Types of property 'pop' are incompatible: - Type '() => {}' is not assignable to type '() => number': - Type '{}' is not assignable to type 'number'. + Type '() => string | number' is not assignable to type '() => number': + Type 'string | number' is not assignable to type 'number': + Type 'string' is not assignable to type 'number'. tests/cases/compiler/tupleTypes.ts(49,1): error TS2322: Type '[number, {}]' is not assignable to type 'number[]': Types of property 'pop' are incompatible: Type '() => {}' is not assignable to type '() => number': @@ -36,13 +37,13 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n var t0: number; var t1 = t[1]; // string var t1: string; - var t2 = t[2]; // {} - var t2: {}; + var t2 = t[2]; // number|string + var t2: number|string; t = []; // Error ~ -!!! error TS2322: Type '{}[]' is not assignable to type '[number, string]': -!!! error TS2322: Property '0' is missing in type '{}[]'. +!!! error TS2322: Type 'undefined[]' is not assignable to type '[number, string]': +!!! error TS2322: Property '0' is missing in type 'undefined[]'. t = [1]; // Error ~ !!! error TS2322: Type '[number]' is not assignable to type '[number, string]': @@ -70,15 +71,15 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n var tt0: number; var tt1 = tt[1]; var tt1: string; - var tt2 = tt[2]; - var tt2: {}; + var tt2 = tt[2]; + var tt2: number | string; tt = tuple2(1, undefined); tt = [1, undefined]; tt = [undefined, undefined]; tt = []; // Error ~~ -!!! error TS2323: Type '{}[]' is not assignable to type '[number, string]'. +!!! error TS2323: Type 'undefined[]' is not assignable to type '[number, string]'. var a: number[]; var a1: [number, string]; @@ -88,8 +89,9 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n ~ !!! error TS2322: Type '[number, string]' is not assignable to type 'number[]': !!! error TS2322: Types of property 'pop' are incompatible: -!!! error TS2322: Type '() => {}' is not assignable to type '() => number': -!!! error TS2322: Type '{}' is not assignable to type 'number'. +!!! error TS2322: Type '() => string | number' is not assignable to type '() => number': +!!! error TS2322: Type 'string | number' is not assignable to type 'number': +!!! error TS2322: Type 'string' is not assignable to type 'number'. a = a2; a = a3; // Error ~ diff --git a/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types b/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types index 584ae0dcb3c..27fcd05bb28 100644 --- a/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types +++ b/tests/baselines/reference/typeAnnotationBestCommonTypeInArrayLiteral.types @@ -23,7 +23,7 @@ interface IMenuItem { var menuData: IMenuItem[] = [ >menuData : IMenuItem[] >IMenuItem : IMenuItem ->[ { "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" }, { "id": "productName", "type": "default", "link": "", "text": "Product Name" }] : IMenuItem[] +>[ { "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" }, { "id": "productName", "type": "default", "link": "", "text": "Product Name" }] : ({ "id": string; "type": string; "link": string; "icon": string; } | { "id": string; "type": string; "link": string; "text": string; })[] { >{ "id": "ourLogo", "type": "image", "link": "", "icon": "modules/menu/logo.svg" } : { "id": string; "type": string; "link": string; "icon": string; } diff --git a/tests/baselines/reference/typeArgInference2.errors.txt b/tests/baselines/reference/typeArgInference2.errors.txt new file mode 100644 index 00000000000..cf188972b7d --- /dev/null +++ b/tests/baselines/reference/typeArgInference2.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/typeArgInference2.ts(12,10): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/compiler/typeArgInference2.ts (1 errors) ==== + interface Item { + name: string; + } + + declare function foo(x?: T, y?: T): T; + + var z1 = foo(null); // any + var z2 = foo(); // Item + var z3 = foo({ name: null }); // { name: any } + var z4 = foo({ name: "abc" }); // { name: string } + var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } + var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgInference2.js b/tests/baselines/reference/typeArgInference2.js index ef76c9b33e7..193345cdeb3 100644 --- a/tests/baselines/reference/typeArgInference2.js +++ b/tests/baselines/reference/typeArgInference2.js @@ -10,7 +10,7 @@ var z2 = foo(); // Item var z3 = foo({ name: null }); // { name: any } var z4 = foo({ name: "abc" }); // { name: string } var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } -var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // Item +var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // error //// [typeArgInference2.js] var z1 = foo(null); // any @@ -18,4 +18,4 @@ var z2 = foo(); // Item var z3 = foo({ name: null }); // { name: any } var z4 = foo({ name: "abc" }); // { name: string } var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } -var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // Item +var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // error diff --git a/tests/baselines/reference/typeArgInference2.types b/tests/baselines/reference/typeArgInference2.types deleted file mode 100644 index 1b94a0638bd..00000000000 --- a/tests/baselines/reference/typeArgInference2.types +++ /dev/null @@ -1,61 +0,0 @@ -=== tests/cases/compiler/typeArgInference2.ts === -interface Item { ->Item : Item - - name: string; ->name : string -} - -declare function foo(x?: T, y?: T): T; ->foo : (x?: T, y?: T) => T ->T : T ->Item : Item ->x : T ->T : T ->y : T ->T : T ->T : T - -var z1 = foo(null); // any ->z1 : any ->foo(null) : any ->foo : (x?: T, y?: T) => T - -var z2 = foo(); // Item ->z2 : Item ->foo() : Item ->foo : (x?: T, y?: T) => T - -var z3 = foo({ name: null }); // { name: any } ->z3 : { name: any; } ->foo({ name: null }) : { name: any; } ->foo : (x?: T, y?: T) => T ->{ name: null } : { name: null; } ->name : null - -var z4 = foo({ name: "abc" }); // { name: string } ->z4 : { name: string; } ->foo({ name: "abc" }) : { name: string; } ->foo : (x?: T, y?: T) => T ->{ name: "abc" } : { name: string; } ->name : string - -var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } ->z5 : { name: string; a: number; } ->foo({ name: "abc", a: 5 }) : { name: string; a: number; } ->foo : (x?: T, y?: T) => T ->{ name: "abc", a: 5 } : { name: string; a: number; } ->name : string ->a : number - -var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // Item ->z6 : Item ->foo({ name: "abc", a: 5 }, { name: "def", b: 5 }) : Item ->foo : (x?: T, y?: T) => T ->{ name: "abc", a: 5 } : { name: string; a: number; } ->name : string ->a : number ->{ name: "def", b: 5 } : { name: string; b: number; } ->name : string ->b : number - diff --git a/tests/baselines/reference/typeArgInference2WithError.errors.txt b/tests/baselines/reference/typeArgInference2WithError.errors.txt index 26259abf37b..83fa81b5524 100644 --- a/tests/baselines/reference/typeArgInference2WithError.errors.txt +++ b/tests/baselines/reference/typeArgInference2WithError.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/typeArgInference2WithError.ts(7,14): error TS2345: Argument of type 'string' is not assignable to parameter of type 'Item'. +tests/cases/compiler/typeArgInference2WithError.ts(7,10): error TS2346: Supplied parameters do not match any signature of call target. ==== tests/cases/compiler/typeArgInference2WithError.ts (1 errors) ==== @@ -9,5 +9,5 @@ tests/cases/compiler/typeArgInference2WithError.ts(7,14): error TS2345: Argument declare function foo(x?: T, y?: T): T; var z7 = foo("abc", 5); // Error - ~~~~~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'Item'. \ No newline at end of file + ~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInference.errors.txt b/tests/baselines/reference/typeArgumentInference.errors.txt new file mode 100644 index 00000000000..dbff8b83854 --- /dev/null +++ b/tests/baselines/reference/typeArgumentInference.errors.txt @@ -0,0 +1,109 @@ +tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts(68,11): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts(82,11): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts (2 errors) ==== + // Generic call with no parameters + function noParams() { } + noParams(); + noParams(); + noParams<{}>(); + + // Generic call with parameters but none use type parameter type + function noGenericParams(n: string) { } + noGenericParams(''); + noGenericParams(''); + noGenericParams<{}>(''); + + // Generic call with multiple type parameters and only one used in parameter type annotation + function someGenerics1(n: T, m: number) { } + someGenerics1(3, 4); + someGenerics1(3, 4); + + // Generic call with argument of function type whose parameter is of type parameter type + function someGenerics2a(n: (x: T) => void) { } + someGenerics2a((n: string) => n); + someGenerics2a((n: string) => n); + someGenerics2a((n) => n.substr(0)); + + function someGenerics2b(n: (x: T, y: U) => void) { } + someGenerics2b((n: string, x: number) => n); + someGenerics2b((n: string, t: number) => n); + someGenerics2b((n, t) => n.substr(t * t)); + + // Generic call with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter + function someGenerics3(producer: () => T) { } + someGenerics3(() => ''); + someGenerics3(() => undefined); + someGenerics3(() => 3); + + // 2 parameter generic call with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type + function someGenerics4(n: T, f: (x: U) => void) { } + someGenerics4(4, () => null); + someGenerics4('', () => 3); + someGenerics4(null, null); + + // 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type + function someGenerics5(n: T, f: (x: U) => void) { } + someGenerics5(4, () => null); + someGenerics5('', () => 3); + someGenerics5(null, null); + + // Generic call with multiple arguments of function types that each have parameters of the same generic type + function someGenerics6(a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } + someGenerics6(n => n, n => n, n => n); + someGenerics6(n => n, n => n, n => n); + someGenerics6((n: number) => n, (n: number) => n, (n: number) => n); + + // Generic call with multiple arguments of function types that each have parameters of different generic type + function someGenerics7(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } + someGenerics7(n => n, n => n, n => n); + someGenerics7(n => n, n => n, n => n); + someGenerics7((n: number) => n, (n: string) => n, (n: number) => n); + + // Generic call with argument of generic function type + function someGenerics8(n: T): T { return n; } + var x = someGenerics8(someGenerics7); + x(null, null, null); + + // Generic call with multiple parameters of generic type passed arguments with no best common type + function someGenerics9(a: T, b: T, c: T): T { + return null; + } + var a9a = someGenerics9('', 0, []); + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var a9a: {}; + var a9b = someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null); + var a9b: { a?: number; b?: string; }; + + // Generic call with multiple parameters of generic type passed arguments with multiple best common types + interface A91 { + x: number; + y?: string; + } + interface A92 { + x: number; + z?: Date; + } + var a9e = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + var a9e: {}; + var a9f = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); + var a9f: A92; + + // Generic call with multiple parameters of generic type passed arguments with a single best common type + var a9d = someGenerics9({ x: 3 }, { x: 6 }, { x: 6 }); + var a9d: { x: number; }; + + // Generic call with multiple parameters of generic type where one argument is of type 'any' + var anyVar: any; + var a = someGenerics9(7, anyVar, 4); + var a: any; + + // Generic call with multiple parameters of generic type where one argument is [] and the other is not 'any' + var arr = someGenerics9([], null, undefined); + var arr: any[]; + + \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInference.types b/tests/baselines/reference/typeArgumentInference.types deleted file mode 100644 index 40136bd10c3..00000000000 --- a/tests/baselines/reference/typeArgumentInference.types +++ /dev/null @@ -1,468 +0,0 @@ -=== tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts === -// Generic call with no parameters -function noParams() { } ->noParams : () => void ->T : T - -noParams(); ->noParams() : void ->noParams : () => void - -noParams(); ->noParams() : void ->noParams : () => void - -noParams<{}>(); ->noParams<{}>() : void ->noParams : () => void - -// Generic call with parameters but none use type parameter type -function noGenericParams(n: string) { } ->noGenericParams : (n: string) => void ->T : T ->n : string - -noGenericParams(''); ->noGenericParams('') : void ->noGenericParams : (n: string) => void - -noGenericParams(''); ->noGenericParams('') : void ->noGenericParams : (n: string) => void - -noGenericParams<{}>(''); ->noGenericParams<{}>('') : void ->noGenericParams : (n: string) => void - -// Generic call with multiple type parameters and only one used in parameter type annotation -function someGenerics1(n: T, m: number) { } ->someGenerics1 : (n: T, m: number) => void ->T : T ->U : U ->n : T ->T : T ->m : number - -someGenerics1(3, 4); ->someGenerics1(3, 4) : void ->someGenerics1 : (n: T, m: number) => void - -someGenerics1(3, 4); ->someGenerics1(3, 4) : void ->someGenerics1 : (n: T, m: number) => void - -// Generic call with argument of function type whose parameter is of type parameter type -function someGenerics2a(n: (x: T) => void) { } ->someGenerics2a : (n: (x: T) => void) => void ->T : T ->n : (x: T) => void ->x : T ->T : T - -someGenerics2a((n: string) => n); ->someGenerics2a((n: string) => n) : void ->someGenerics2a : (n: (x: T) => void) => void ->(n: string) => n : (n: string) => string ->n : string ->n : string - -someGenerics2a((n: string) => n); ->someGenerics2a((n: string) => n) : void ->someGenerics2a : (n: (x: T) => void) => void ->(n: string) => n : (n: string) => string ->n : string ->n : string - -someGenerics2a((n) => n.substr(0)); ->someGenerics2a((n) => n.substr(0)) : void ->someGenerics2a : (n: (x: T) => void) => void ->(n) => n.substr(0) : (n: string) => string ->n : string ->n.substr(0) : string ->n.substr : (from: number, length?: number) => string ->n : string ->substr : (from: number, length?: number) => string - -function someGenerics2b(n: (x: T, y: U) => void) { } ->someGenerics2b : (n: (x: T, y: U) => void) => void ->T : T ->U : U ->n : (x: T, y: U) => void ->x : T ->T : T ->y : U ->U : U - -someGenerics2b((n: string, x: number) => n); ->someGenerics2b((n: string, x: number) => n) : void ->someGenerics2b : (n: (x: T, y: U) => void) => void ->(n: string, x: number) => n : (n: string, x: number) => string ->n : string ->x : number ->n : string - -someGenerics2b((n: string, t: number) => n); ->someGenerics2b((n: string, t: number) => n) : void ->someGenerics2b : (n: (x: T, y: U) => void) => void ->(n: string, t: number) => n : (n: string, t: number) => string ->n : string ->t : number ->n : string - -someGenerics2b((n, t) => n.substr(t * t)); ->someGenerics2b((n, t) => n.substr(t * t)) : void ->someGenerics2b : (n: (x: T, y: U) => void) => void ->(n, t) => n.substr(t * t) : (n: string, t: number) => string ->n : string ->t : number ->n.substr(t * t) : string ->n.substr : (from: number, length?: number) => string ->n : string ->substr : (from: number, length?: number) => string ->t * t : number ->t : number ->t : number - -// Generic call with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter -function someGenerics3(producer: () => T) { } ->someGenerics3 : (producer: () => T) => void ->T : T ->producer : () => T ->T : T - -someGenerics3(() => ''); ->someGenerics3(() => '') : void ->someGenerics3 : (producer: () => T) => void ->() => '' : () => string - -someGenerics3(() => undefined); ->someGenerics3(() => undefined) : void ->someGenerics3 : (producer: () => T) => void ->Date : Date ->() => undefined : () => any ->undefined : undefined - -someGenerics3(() => 3); ->someGenerics3(() => 3) : void ->someGenerics3 : (producer: () => T) => void ->() => 3 : () => number - -// 2 parameter generic call with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type -function someGenerics4(n: T, f: (x: U) => void) { } ->someGenerics4 : (n: T, f: (x: U) => void) => void ->T : T ->U : U ->n : T ->T : T ->f : (x: U) => void ->x : U ->U : U - -someGenerics4(4, () => null); ->someGenerics4(4, () => null) : void ->someGenerics4 : (n: T, f: (x: U) => void) => void ->() => null : () => any - -someGenerics4('', () => 3); ->someGenerics4('', () => 3) : void ->someGenerics4 : (n: T, f: (x: U) => void) => void ->() => 3 : () => number - -someGenerics4(null, null); ->someGenerics4(null, null) : void ->someGenerics4 : (n: T, f: (x: U) => void) => void - -// 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type -function someGenerics5(n: T, f: (x: U) => void) { } ->someGenerics5 : (n: T, f: (x: U) => void) => void ->U : U ->T : T ->n : T ->T : T ->f : (x: U) => void ->x : U ->U : U - -someGenerics5(4, () => null); ->someGenerics5(4, () => null) : void ->someGenerics5 : (n: T, f: (x: U) => void) => void ->() => null : () => any - -someGenerics5('', () => 3); ->someGenerics5('', () => 3) : void ->someGenerics5 : (n: T, f: (x: U) => void) => void ->() => 3 : () => number - -someGenerics5(null, null); ->someGenerics5(null, null) : void ->someGenerics5 : (n: T, f: (x: U) => void) => void - -// Generic call with multiple arguments of function types that each have parameters of the same generic type -function someGenerics6(a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } ->someGenerics6 : (a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) => void ->A : A ->a : (a: A) => A ->a : A ->A : A ->A : A ->b : (b: A) => A ->b : A ->A : A ->A : A ->c : (c: A) => A ->c : A ->A : A ->A : A - -someGenerics6(n => n, n => n, n => n); ->someGenerics6(n => n, n => n, n => n) : void ->someGenerics6 : (a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) => void ->n => n : (n: {}) => {} ->n : {} ->n : {} ->n => n : (n: {}) => {} ->n : {} ->n : {} ->n => n : (n: {}) => {} ->n : {} ->n : {} - -someGenerics6(n => n, n => n, n => n); ->someGenerics6(n => n, n => n, n => n) : void ->someGenerics6 : (a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) => void ->n => n : (n: number) => number ->n : number ->n : number ->n => n : (n: number) => number ->n : number ->n : number ->n => n : (n: number) => number ->n : number ->n : number - -someGenerics6((n: number) => n, (n: number) => n, (n: number) => n); ->someGenerics6((n: number) => n, (n: number) => n, (n: number) => n) : void ->someGenerics6 : (a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) => void ->(n: number) => n : (n: number) => number ->n : number ->n : number ->(n: number) => n : (n: number) => number ->n : number ->n : number ->(n: number) => n : (n: number) => number ->n : number ->n : number - -// Generic call with multiple arguments of function types that each have parameters of different generic type -function someGenerics7(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->A : A ->B : B ->C : C ->a : (a: A) => A ->a : A ->A : A ->A : A ->b : (b: B) => B ->b : B ->B : B ->B : B ->c : (c: C) => C ->c : C ->C : C ->C : C - -someGenerics7(n => n, n => n, n => n); ->someGenerics7(n => n, n => n, n => n) : void ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->n => n : (n: {}) => {} ->n : {} ->n : {} ->n => n : (n: {}) => {} ->n : {} ->n : {} ->n => n : (n: {}) => {} ->n : {} ->n : {} - -someGenerics7(n => n, n => n, n => n); ->someGenerics7(n => n, n => n, n => n) : void ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->n => n : (n: number) => number ->n : number ->n : number ->n => n : (n: string) => string ->n : string ->n : string ->n => n : (n: number) => number ->n : number ->n : number - -someGenerics7((n: number) => n, (n: string) => n, (n: number) => n); ->someGenerics7((n: number) => n, (n: string) => n, (n: number) => n) : void ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->(n: number) => n : (n: number) => number ->n : number ->n : number ->(n: string) => n : (n: string) => string ->n : string ->n : string ->(n: number) => n : (n: number) => number ->n : number ->n : number - -// Generic call with argument of generic function type -function someGenerics8(n: T): T { return n; } ->someGenerics8 : (n: T) => T ->T : T ->n : T ->T : T ->T : T ->n : T - -var x = someGenerics8(someGenerics7); ->x : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->someGenerics8(someGenerics7) : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void ->someGenerics8 : (n: T) => T ->someGenerics7 : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void - -x(null, null, null); ->x(null, null, null) : void ->x : (a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void - -// Generic call with multiple parameters of generic type passed arguments with no best common type -function someGenerics9(a: T, b: T, c: T): T { ->someGenerics9 : (a: T, b: T, c: T) => T ->T : T ->a : T ->T : T ->b : T ->T : T ->c : T ->T : T ->T : T - - return null; -} -var a9a = someGenerics9('', 0, []); ->a9a : {} ->someGenerics9('', 0, []) : {} ->someGenerics9 : (a: T, b: T, c: T) => T ->[] : undefined[] - -var a9a: {}; ->a9a : {} - -var a9b = someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null); ->a9b : { a?: number; b?: string; } ->someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null) : { a?: number; b?: string; } ->someGenerics9 : (a: T, b: T, c: T) => T ->a : number ->b : string ->{ a: 0 } : { a: number; } ->a : number ->{ b: '' } : { b: string; } ->b : string - -var a9b: { a?: number; b?: string; }; ->a9b : { a?: number; b?: string; } ->a : number ->b : string - -// Generic call with multiple parameters of generic type passed arguments with multiple best common types -interface A91 { ->A91 : A91 - - x: number; ->x : number - - y?: string; ->y : string -} -interface A92 { ->A92 : A92 - - x: number; ->x : number - - z?: Date; ->z : Date ->Date : Date -} -var a9e = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); ->a9e : {} ->someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }) : {} ->someGenerics9 : (a: T, b: T, c: T) => T ->undefined : undefined ->{ x: 6, z: new Date() } : { x: number; z: Date; } ->x : number ->z : Date ->new Date() : Date ->Date : { (): string; new (): Date; new (value: number): Date; new (value: string): Date; new (year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date; prototype: Date; parse(s: string): number; UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number; now(): number; } ->{ x: 6, y: '' } : { x: number; y: string; } ->x : number ->y : string - -var a9e: {}; ->a9e : {} - -var a9f = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); ->a9f : A92 ->someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }) : A92 ->someGenerics9 : (a: T, b: T, c: T) => T ->A92 : A92 ->undefined : undefined ->{ x: 6, z: new Date() } : { x: number; z: Date; } ->x : number ->z : Date ->new Date() : Date ->Date : { (): string; new (): Date; new (value: number): Date; new (value: string): Date; new (year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date; prototype: Date; parse(s: string): number; UTC(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): number; now(): number; } ->{ x: 6, y: '' } : { x: number; y: string; } ->x : number ->y : string - -var a9f: A92; ->a9f : A92 ->A92 : A92 - -// Generic call with multiple parameters of generic type passed arguments with a single best common type -var a9d = someGenerics9({ x: 3 }, { x: 6 }, { x: 6 }); ->a9d : { x: number; } ->someGenerics9({ x: 3 }, { x: 6 }, { x: 6 }) : { x: number; } ->someGenerics9 : (a: T, b: T, c: T) => T ->{ x: 3 } : { x: number; } ->x : number ->{ x: 6 } : { x: number; } ->x : number ->{ x: 6 } : { x: number; } ->x : number - -var a9d: { x: number; }; ->a9d : { x: number; } ->x : number - -// Generic call with multiple parameters of generic type where one argument is of type 'any' -var anyVar: any; ->anyVar : any - -var a = someGenerics9(7, anyVar, 4); ->a : any ->someGenerics9(7, anyVar, 4) : any ->someGenerics9 : (a: T, b: T, c: T) => T ->anyVar : any - -var a: any; ->a : any - -// Generic call with multiple parameters of generic type where one argument is [] and the other is not 'any' -var arr = someGenerics9([], null, undefined); ->arr : any[] ->someGenerics9([], null, undefined) : any[] ->someGenerics9 : (a: T, b: T, c: T) => T ->[] : any[] ->undefined : undefined - -var arr: any[]; ->arr : any[] - - diff --git a/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt b/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt index a9de02d4226..4f11cb6135e 100644 --- a/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt @@ -3,12 +3,14 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(61,39): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(71,39): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(x: number) => void'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(81,45): error TS2345: Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'. +tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(106,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(118,9): error TS2304: Cannot find name 'Window'. +tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(120,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(120,51): error TS2304: Cannot find name 'window'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(122,56): error TS2304: Cannot find name 'window'. -==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts (8 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts (10 errors) ==== // Generic call with no parameters interface NoParams { new (); @@ -125,6 +127,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct } var someGenerics9: someGenerics9; var a9a = new someGenerics9('', 0, []); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var a9a: {}; var a9b = new someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null); var a9b: { a?: number; b?: string; }; @@ -141,6 +145,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct !!! error TS2304: Cannot find name 'Window'. } var a9e = new someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' }); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. ~~~~~~ !!! error TS2304: Cannot find name 'window'. var a9e: {}; diff --git a/tests/baselines/reference/typeArgumentInferenceTransitiveConstraints.errors.txt b/tests/baselines/reference/typeArgumentInferenceTransitiveConstraints.errors.txt index e6e59308dd4..08cb5348c27 100644 --- a/tests/baselines/reference/typeArgumentInferenceTransitiveConstraints.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceTransitiveConstraints.errors.txt @@ -1,9 +1,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts(2,29): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts(2,42): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts(7,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'd' must be of type '{}[]', but here has type 'Date[]'. -==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts (3 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiveConstraints.ts (2 errors) ==== function fn(a: A, b: B, c: C) { ~~~~~~~~~~~ @@ -15,6 +14,4 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceTransitiv var d = fn(new Date(), new Date(), new Date()); var d: Date[]; // Should be OK (d should be Date[]) - ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'd' must be of type '{}[]', but here has type 'Date[]'. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt b/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt new file mode 100644 index 00000000000..c0ee4329c8d --- /dev/null +++ b/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/typeArgumentInferenceWithConstraintAsCommonRoot.ts(7,1): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/compiler/typeArgumentInferenceWithConstraintAsCommonRoot.ts (1 errors) ==== + interface Animal { x } + interface Giraffe extends Animal { y } + interface Elephant extends Animal { z } + function f(x: T, y: T): T { return undefined; } + var g: Giraffe; + var e: Elephant; + f(g, e); // valid because both Giraffe and Elephant satisfy the constraint. T is Animal + ~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.types b/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.types deleted file mode 100644 index 35328f72803..00000000000 --- a/tests/baselines/reference/typeArgumentInferenceWithConstraintAsCommonRoot.types +++ /dev/null @@ -1,40 +0,0 @@ -=== tests/cases/compiler/typeArgumentInferenceWithConstraintAsCommonRoot.ts === -interface Animal { x } ->Animal : Animal ->x : any - -interface Giraffe extends Animal { y } ->Giraffe : Giraffe ->Animal : Animal ->y : any - -interface Elephant extends Animal { z } ->Elephant : Elephant ->Animal : Animal ->z : any - -function f(x: T, y: T): T { return undefined; } ->f : (x: T, y: T) => T ->T : T ->Animal : Animal ->x : T ->T : T ->y : T ->T : T ->T : T ->undefined : undefined - -var g: Giraffe; ->g : Giraffe ->Giraffe : Giraffe - -var e: Elephant; ->e : Elephant ->Elephant : Elephant - -f(g, e); // valid because both Giraffe and Elephant satisfy the constraint. T is Animal ->f(g, e) : Animal ->f : (x: T, y: T) => T ->g : Giraffe ->e : Elephant - diff --git a/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt b/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt index 8cf2a2d3503..c0dbf74f66e 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt @@ -8,12 +8,14 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(49,15): error TS2344: Type 'string' does not satisfy the constraint 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(55,41): error TS2345: Argument of type '(n: string) => string' is not assignable to parameter of type '(b: number) => number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(66,31): error TS2345: Argument of type '(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) => void' is not assignable to parameter of type 'string'. +tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(73,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(85,9): error TS2304: Cannot find name 'Window'. +tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(87,11): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(87,47): error TS2304: Cannot find name 'window'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts(89,52): error TS2304: Cannot find name 'window'. -==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts (13 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts (15 errors) ==== // Generic call with no parameters function noParams() { } noParams(); @@ -107,6 +109,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst return null; } var a9a = someGenerics9('', 0, []); + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. var a9a: {}; var a9b = someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null); var a9b: { a?: number; b?: string; }; @@ -123,6 +127,8 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst !!! error TS2304: Cannot find name 'Window'. } var a9e = someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' }); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. ~~~~~~ !!! error TS2304: Cannot find name 'window'. var a9e: {}; diff --git a/tests/baselines/reference/typeInferenceConflictingCandidates.errors.txt b/tests/baselines/reference/typeInferenceConflictingCandidates.errors.txt new file mode 100644 index 00000000000..5f9f980e735 --- /dev/null +++ b/tests/baselines/reference/typeInferenceConflictingCandidates.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/typeInferenceConflictingCandidates.ts(3,1): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/compiler/typeInferenceConflictingCandidates.ts (1 errors) ==== + declare function g(a: T, b: T, c: (t: T) => T): T; + + g("", 3, a => a); + ~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/typeInferenceConflictingCandidates.types b/tests/baselines/reference/typeInferenceConflictingCandidates.types deleted file mode 100644 index 7a77daf4092..00000000000 --- a/tests/baselines/reference/typeInferenceConflictingCandidates.types +++ /dev/null @@ -1,21 +0,0 @@ -=== tests/cases/compiler/typeInferenceConflictingCandidates.ts === -declare function g(a: T, b: T, c: (t: T) => T): T; ->g : (a: T, b: T, c: (t: T) => T) => T ->T : T ->a : T ->T : T ->b : T ->T : T ->c : (t: T) => T ->t : T ->T : T ->T : T ->T : T - -g("", 3, a => a); ->g("", 3, a => a) : {} ->g : (a: T, b: T, c: (t: T) => T) => T ->a => a : (a: {}) => {} ->a : {} ->a : {} - diff --git a/tests/baselines/reference/typeInferenceWithTupleType.js b/tests/baselines/reference/typeInferenceWithTupleType.js index a9d75ad9990..10a18274c73 100644 --- a/tests/baselines/reference/typeInferenceWithTupleType.js +++ b/tests/baselines/reference/typeInferenceWithTupleType.js @@ -1,4 +1,4 @@ -//// [typeInferenceWithTupleType.ts] +//// [typeInferenceWithTupleType.ts] function combine(x: T, y: U): [T, U] { return [x, y]; } @@ -23,26 +23,26 @@ var zipResult = zip(["foo", "bar"], [5, 6]); var zipResultEle = zipResult[0]; // [string, number] var zipResultEleEle = zipResult[0][0]; // string - - -//// [typeInferenceWithTupleType.js] -function combine(x, y) { - return [x, y]; -} -var combineResult = combine("string", 10); -var combineEle1 = combineResult[0]; // string -var combineEle2 = combineResult[1]; // number -function zip(array1, array2) { - if (array1.length != array2.length) { - return [[undefined, undefined]]; - } - var length = array1.length; - var zipResult; - for (var i = 0; i < length; ++i) { - zipResult.push([array1[i], array2[i]]); - } - return zipResult; -} -var zipResult = zip(["foo", "bar"], [5, 6]); -var zipResultEle = zipResult[0]; // [string, number] -var zipResultEleEle = zipResult[0][0]; // string + + +//// [typeInferenceWithTupleType.js] +function combine(x, y) { + return [x, y]; +} +var combineResult = combine("string", 10); +var combineEle1 = combineResult[0]; // string +var combineEle2 = combineResult[1]; // number +function zip(array1, array2) { + if (array1.length != array2.length) { + return [[undefined, undefined]]; + } + var length = array1.length; + var zipResult; + for (var i = 0; i < length; ++i) { + zipResult.push([array1[i], array2[i]]); + } + return zipResult; +} +var zipResult = zip(["foo", "bar"], [5, 6]); +var zipResultEle = zipResult[0]; // [string, number] +var zipResultEleEle = zipResult[0][0]; // string diff --git a/tests/baselines/reference/typeInferenceWithTupleType.types b/tests/baselines/reference/typeInferenceWithTupleType.types index fbf1cd51920..3648c0aba50 100644 --- a/tests/baselines/reference/typeInferenceWithTupleType.types +++ b/tests/baselines/reference/typeInferenceWithTupleType.types @@ -1,114 +1,114 @@ -=== tests/cases/conformance/types/tuple/typeInferenceWithTupleType.ts === -function combine(x: T, y: U): [T, U] { ->combine : (x: T, y: U) => [T, U] ->T : T ->U : U ->x : T ->T : T ->y : U ->U : U ->T : T ->U : U - - return [x, y]; ->[x, y] : [T, U] ->x : T ->y : U -} - -var combineResult = combine("string", 10); ->combineResult : [string, number] ->combine("string", 10) : [string, number] ->combine : (x: T, y: U) => [T, U] - -var combineEle1 = combineResult[0]; // string ->combineEle1 : string ->combineResult[0] : string ->combineResult : [string, number] - -var combineEle2 = combineResult[1]; // number ->combineEle2 : number ->combineResult[1] : number ->combineResult : [string, number] - -function zip(array1: T[], array2: U[]): [[T, U]] { ->zip : (array1: T[], array2: U[]) => [[T, U]] ->T : T ->U : U ->array1 : T[] ->T : T ->array2 : U[] ->U : U ->T : T ->U : U - - if (array1.length != array2.length) { ->array1.length != array2.length : boolean ->array1.length : number ->array1 : T[] ->length : number ->array2.length : number ->array2 : U[] ->length : number - - return [[undefined, undefined]]; ->[[undefined, undefined]] : [[undefined, undefined]] ->[undefined, undefined] : [undefined, undefined] ->undefined : undefined ->undefined : undefined - } - var length = array1.length; ->length : number ->array1.length : number ->array1 : T[] ->length : number - - var zipResult: [[T, U]]; ->zipResult : [[T, U]] ->T : T ->U : U - - for (var i = 0; i < length; ++i) { ->i : number ->i < length : boolean ->i : number ->length : number ->++i : number ->i : number - - zipResult.push([array1[i], array2[i]]); ->zipResult.push([array1[i], array2[i]]) : number ->zipResult.push : (...items: [T, U][]) => number ->zipResult : [[T, U]] ->push : (...items: [T, U][]) => number ->[array1[i], array2[i]] : [T, U] ->array1[i] : T ->array1 : T[] ->i : number ->array2[i] : U ->array2 : U[] ->i : number - } - return zipResult; ->zipResult : [[T, U]] -} - -var zipResult = zip(["foo", "bar"], [5, 6]); ->zipResult : [[string, number]] ->zip(["foo", "bar"], [5, 6]) : [[string, number]] ->zip : (array1: T[], array2: U[]) => [[T, U]] ->["foo", "bar"] : string[] ->[5, 6] : number[] - -var zipResultEle = zipResult[0]; // [string, number] ->zipResultEle : [string, number] ->zipResult[0] : [string, number] ->zipResult : [[string, number]] - -var zipResultEleEle = zipResult[0][0]; // string ->zipResultEleEle : string ->zipResult[0][0] : string ->zipResult[0] : [string, number] ->zipResult : [[string, number]] - - +=== tests/cases/conformance/types/tuple/typeInferenceWithTupleType.ts === +function combine(x: T, y: U): [T, U] { +>combine : (x: T, y: U) => [T, U] +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U +>T : T +>U : U + + return [x, y]; +>[x, y] : [T, U] +>x : T +>y : U +} + +var combineResult = combine("string", 10); +>combineResult : [string, number] +>combine("string", 10) : [string, number] +>combine : (x: T, y: U) => [T, U] + +var combineEle1 = combineResult[0]; // string +>combineEle1 : string +>combineResult[0] : string +>combineResult : [string, number] + +var combineEle2 = combineResult[1]; // number +>combineEle2 : number +>combineResult[1] : number +>combineResult : [string, number] + +function zip(array1: T[], array2: U[]): [[T, U]] { +>zip : (array1: T[], array2: U[]) => [[T, U]] +>T : T +>U : U +>array1 : T[] +>T : T +>array2 : U[] +>U : U +>T : T +>U : U + + if (array1.length != array2.length) { +>array1.length != array2.length : boolean +>array1.length : number +>array1 : T[] +>length : number +>array2.length : number +>array2 : U[] +>length : number + + return [[undefined, undefined]]; +>[[undefined, undefined]] : [[undefined, undefined]] +>[undefined, undefined] : [undefined, undefined] +>undefined : undefined +>undefined : undefined + } + var length = array1.length; +>length : number +>array1.length : number +>array1 : T[] +>length : number + + var zipResult: [[T, U]]; +>zipResult : [[T, U]] +>T : T +>U : U + + for (var i = 0; i < length; ++i) { +>i : number +>i < length : boolean +>i : number +>length : number +>++i : number +>i : number + + zipResult.push([array1[i], array2[i]]); +>zipResult.push([array1[i], array2[i]]) : number +>zipResult.push : (...items: [T, U][]) => number +>zipResult : [[T, U]] +>push : (...items: [T, U][]) => number +>[array1[i], array2[i]] : [T, U] +>array1[i] : T +>array1 : T[] +>i : number +>array2[i] : U +>array2 : U[] +>i : number + } + return zipResult; +>zipResult : [[T, U]] +} + +var zipResult = zip(["foo", "bar"], [5, 6]); +>zipResult : [[string, number]] +>zip(["foo", "bar"], [5, 6]) : [[string, number]] +>zip : (array1: T[], array2: U[]) => [[T, U]] +>["foo", "bar"] : string[] +>[5, 6] : number[] + +var zipResultEle = zipResult[0]; // [string, number] +>zipResultEle : [string, number] +>zipResult[0] : [string, number] +>zipResult : [[string, number]] + +var zipResultEleEle = zipResult[0][0]; // string +>zipResultEleEle : string +>zipResult[0][0] : string +>zipResult[0] : [string, number] +>zipResult : [[string, number]] + + diff --git a/tests/baselines/reference/typeParameterAsElementType.types b/tests/baselines/reference/typeParameterAsElementType.types index 0dbbbf5ac7a..5cbad56c5f1 100644 --- a/tests/baselines/reference/typeParameterAsElementType.types +++ b/tests/baselines/reference/typeParameterAsElementType.types @@ -8,7 +8,7 @@ function fee() { >T : T var arr = [t, ""]; ->arr : {}[] ->[t, ""] : {}[] +>arr : (string | T)[] +>[t, ""] : (string | T)[] >t : T } diff --git a/tests/baselines/reference/typeofOperatorWithEnumType.js b/tests/baselines/reference/typeofOperatorWithEnumType.js index 1ce2170659e..272feacf63d 100644 --- a/tests/baselines/reference/typeofOperatorWithEnumType.js +++ b/tests/baselines/reference/typeofOperatorWithEnumType.js @@ -2,24 +2,24 @@ // typeof operator on enum type enum ENUM { }; -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsString1 = typeof ENUM; var ResultIsString2 = typeof ENUM1; // enum type expressions -var ResultIsString3 = typeof ENUM1[0]; -var ResultIsString4 = typeof (ENUM[0] + ENUM1[1]); +var ResultIsString3 = typeof ENUM1["A"]; +var ResultIsString4 = typeof (ENUM[0] + ENUM1["B"]); // multiple typeof operators var ResultIsString5 = typeof typeof ENUM; -var ResultIsString6 = typeof typeof typeof (ENUM[0] + ENUM1[1]); +var ResultIsString6 = typeof typeof typeof (ENUM[0] + ENUM1.B); // miss assignment operators typeof ENUM; typeof ENUM1; -typeof ENUM1[1]; +typeof ENUM1["B"]; typeof ENUM, ENUM1; // use typeof in type query @@ -35,8 +35,8 @@ var ENUM; ; var ENUM1; (function (ENUM1) { - ENUM1[ENUM1["1"] = 0] = "1"; - ENUM1[ENUM1["2"] = 1] = "2"; + ENUM1[ENUM1["A"] = 0] = "A"; + ENUM1[ENUM1["B"] = 1] = "B"; ENUM1[ENUM1[""] = 2] = ""; })(ENUM1 || (ENUM1 = {})); ; @@ -44,15 +44,15 @@ var ENUM1; var ResultIsString1 = typeof ENUM; var ResultIsString2 = typeof ENUM1; // enum type expressions -var ResultIsString3 = typeof ENUM1[0]; -var ResultIsString4 = typeof (ENUM[0] + ENUM1[1]); +var ResultIsString3 = typeof ENUM1["A"]; +var ResultIsString4 = typeof (ENUM[0] + ENUM1["B"]); // multiple typeof operators var ResultIsString5 = typeof typeof ENUM; -var ResultIsString6 = typeof typeof typeof (ENUM[0] + ENUM1[1]); +var ResultIsString6 = typeof typeof typeof (ENUM[0] + 1 /* B */); // miss assignment operators typeof ENUM; typeof ENUM1; -typeof ENUM1[1]; +typeof ENUM1["B"]; typeof ENUM, ENUM1; // use typeof in type query var z; diff --git a/tests/baselines/reference/typeofOperatorWithEnumType.types b/tests/baselines/reference/typeofOperatorWithEnumType.types index cbcc49bd9dc..2a3ccc6a3da 100644 --- a/tests/baselines/reference/typeofOperatorWithEnumType.types +++ b/tests/baselines/reference/typeofOperatorWithEnumType.types @@ -4,8 +4,10 @@ enum ENUM { }; >ENUM : ENUM -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; >ENUM1 : ENUM1 +>A : ENUM1 +>B : ENUM1 // enum type var var ResultIsString1 = typeof ENUM; @@ -19,20 +21,20 @@ var ResultIsString2 = typeof ENUM1; >ENUM1 : typeof ENUM1 // enum type expressions -var ResultIsString3 = typeof ENUM1[0]; +var ResultIsString3 = typeof ENUM1["A"]; >ResultIsString3 : string ->typeof ENUM1[0] : string ->ENUM1[0] : string +>typeof ENUM1["A"] : string +>ENUM1["A"] : ENUM1 >ENUM1 : typeof ENUM1 -var ResultIsString4 = typeof (ENUM[0] + ENUM1[1]); +var ResultIsString4 = typeof (ENUM[0] + ENUM1["B"]); >ResultIsString4 : string ->typeof (ENUM[0] + ENUM1[1]) : string ->(ENUM[0] + ENUM1[1]) : string ->ENUM[0] + ENUM1[1] : string +>typeof (ENUM[0] + ENUM1["B"]) : string +>(ENUM[0] + ENUM1["B"]) : string +>ENUM[0] + ENUM1["B"] : string >ENUM[0] : string >ENUM : typeof ENUM ->ENUM1[1] : ENUM1 +>ENUM1["B"] : ENUM1 >ENUM1 : typeof ENUM1 // multiple typeof operators @@ -42,17 +44,18 @@ var ResultIsString5 = typeof typeof ENUM; >typeof ENUM : string >ENUM : typeof ENUM -var ResultIsString6 = typeof typeof typeof (ENUM[0] + ENUM1[1]); +var ResultIsString6 = typeof typeof typeof (ENUM[0] + ENUM1.B); >ResultIsString6 : string ->typeof typeof typeof (ENUM[0] + ENUM1[1]) : string ->typeof typeof (ENUM[0] + ENUM1[1]) : string ->typeof (ENUM[0] + ENUM1[1]) : string ->(ENUM[0] + ENUM1[1]) : string ->ENUM[0] + ENUM1[1] : string +>typeof typeof typeof (ENUM[0] + ENUM1.B) : string +>typeof typeof (ENUM[0] + ENUM1.B) : string +>typeof (ENUM[0] + ENUM1.B) : string +>(ENUM[0] + ENUM1.B) : string +>ENUM[0] + ENUM1.B : string >ENUM[0] : string >ENUM : typeof ENUM ->ENUM1[1] : ENUM1 +>ENUM1.B : ENUM1 >ENUM1 : typeof ENUM1 +>B : ENUM1 // miss assignment operators typeof ENUM; @@ -63,9 +66,9 @@ typeof ENUM1; >typeof ENUM1 : string >ENUM1 : typeof ENUM1 -typeof ENUM1[1]; ->typeof ENUM1[1] : string ->ENUM1[1] : ENUM1 +typeof ENUM1["B"]; +>typeof ENUM1["B"] : string +>ENUM1["B"] : ENUM1 >ENUM1 : typeof ENUM1 typeof ENUM, ENUM1; diff --git a/tests/baselines/reference/undefinedInferentialTyping.types b/tests/baselines/reference/undefinedInferentialTyping.types index b5741e4d40f..61737ac6b6c 100644 --- a/tests/baselines/reference/undefinedInferentialTyping.types +++ b/tests/baselines/reference/undefinedInferentialTyping.types @@ -15,5 +15,5 @@ var a = f([], 3); // should be number >a : number >f([], 3) : number >f : (arr: T[], elemnt: T) => T ->[] : number[] +>[] : undefined[] diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index 115bc09195d..752c39b5e51 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -104,7 +104,7 @@ var flat = _.reduceRight(list, (a, b) => a.concat(b), []); >a : number[] >concat : { (...items: U[]): number[]; (...items: number[]): number[]; } >b : number[] ->[] : number[] +>[] : undefined[] var even = _.find([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0); >even : number @@ -176,7 +176,7 @@ _.all([true, 1, null, 'yes'], _.identity); >_.all : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } >_ : Underscore.Static >all : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } ->[true, 1, null, 'yes'] : {}[] +>[true, 1, null, 'yes'] : (string | number | boolean)[] >_.identity : (value: T) => T >_ : Underscore.Static >identity : (value: T) => T @@ -186,7 +186,7 @@ _.any([null, 0, 'yes', false]); >_.any : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } >_ : Underscore.Static >any : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } ->[null, 0, 'yes', false] : {}[] +>[null, 0, 'yes', false] : (string | number | boolean)[] _.contains([1, 2, 3], 3); >_.contains([1, 2, 3], 3) : boolean @@ -200,7 +200,7 @@ _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); >_.invoke : { (list: any[], methodName: string, ...args: any[]): any[]; (list: Dictionary, methodName: string, ...args: any[]): any[]; } >_ : Underscore.Static >invoke : { (list: any[], methodName: string, ...args: any[]): any[]; (list: Dictionary, methodName: string, ...args: any[]): any[]; } ->[[5, 1, 7], [3, 2, 1]] : any[] +>[[5, 1, 7], [3, 2, 1]] : number[][] >[5, 1, 7] : number[] >[3, 2, 1] : number[] @@ -309,7 +309,7 @@ _.countBy([1, 2, 3, 4, 5], (num) => num % 2 == 0 ? 'even' : 'odd'); >[1, 2, 3, 4, 5] : number[] >(num) => num % 2 == 0 ? 'even' : 'odd' : (num: number) => string >num : number ->num % 2 == 0 ? 'even' : 'odd' : any +>num % 2 == 0 ? 'even' : 'odd' : string >num % 2 == 0 : boolean >num % 2 : number >num : number @@ -364,25 +364,25 @@ _.rest([5, 4, 3, 2, 1]); >[5, 4, 3, 2, 1] : number[] _.compact([0, 1, false, 2, '', 3]); ->_.compact([0, 1, false, 2, '', 3]) : {}[] +>_.compact([0, 1, false, 2, '', 3]) : (string | number | boolean)[] >_.compact : (list: T[]) => T[] >_ : Underscore.Static >compact : (list: T[]) => T[] ->[0, 1, false, 2, '', 3] : {}[] +>[0, 1, false, 2, '', 3] : (string | number | boolean)[] _.flatten([1, 2, 3, 4]); >_.flatten([1, 2, 3, 4]) : {}[] >_.flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >_ : Underscore.Static >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } ->[1, 2, 3, 4] : any[] +>[1, 2, 3, 4] : number[] _.flatten([1, [2]]); >_.flatten([1, [2]]) : {}[] >_.flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >_ : Underscore.Static >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } ->[1, [2]] : any[] +>[1, [2]] : (number | number[])[] >[2] : number[] // typescript doesn't like the elements being different @@ -391,9 +391,9 @@ _.flatten([1, [2], [3, [[4]]]]); >_.flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >_ : Underscore.Static >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } ->[1, [2], [3, [[4]]]] : any[] +>[1, [2], [3, [[4]]]] : (number | (number | number[][])[])[] >[2] : number[] ->[3, [[4]]] : {}[] +>[3, [[4]]] : (number | number[][])[] >[[4]] : number[][] >[4] : number[] @@ -402,9 +402,9 @@ _.flatten([1, [2], [3, [[4]]]], true); >_.flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } >_ : Underscore.Static >flatten : { (list: T[][]): T[]; (array: any[], shallow?: boolean): T[]; } ->[1, [2], [3, [[4]]]] : any[] +>[1, [2], [3, [[4]]]] : (number | (number | number[][])[])[] >[2] : number[] ->[3, [[4]]] : {}[] +>[3, [[4]]] : (number | number[][])[] >[[4]] : number[][] >[4] : number[] @@ -463,17 +463,17 @@ _.object(['moe', 'larry', 'curly'], [30, 40, 50]); >_ : Underscore.Static >object : { (list: any[][]): any; (keys: string[], values: any[]): any; } >['moe', 'larry', 'curly'] : string[] ->[30, 40, 50] : any[] +>[30, 40, 50] : number[] _.object([['moe', 30], ['larry', 40], ['curly', 50]]); >_.object([['moe', 30], ['larry', 40], ['curly', 50]]) : any >_.object : { (list: any[][]): any; (keys: string[], values: any[]): any; } >_ : Underscore.Static >object : { (list: any[][]): any; (keys: string[], values: any[]): any; } ->[['moe', 30], ['larry', 40], ['curly', 50]] : any[][] ->['moe', 30] : any[] ->['larry', 40] : any[] ->['curly', 50] : any[] +>[['moe', 30], ['larry', 40], ['curly', 50]] : (string | number)[][] +>['moe', 30] : (string | number)[] +>['larry', 40] : (string | number)[] +>['curly', 50] : (string | number)[] _.indexOf([1, 2, 3], 2); >_.indexOf([1, 2, 3], 2) : number diff --git a/tests/baselines/reference/validMultipleVariableDeclarations.types b/tests/baselines/reference/validMultipleVariableDeclarations.types index 89d3702a702..4bbd46bab2b 100644 --- a/tests/baselines/reference/validMultipleVariableDeclarations.types +++ b/tests/baselines/reference/validMultipleVariableDeclarations.types @@ -117,11 +117,11 @@ var a = ['a', 'b'] var a = []; >a : string[] >[] : string[] ->[] : string[] +>[] : undefined[] var a: string[] = []; >a : string[] ->[] : string[] +>[] : undefined[] var a = new Array(); >a : string[] diff --git a/tests/baselines/reference/varArgParamTypeCheck.types b/tests/baselines/reference/varArgParamTypeCheck.types index 1b5b20adbec..9cd2fad7aca 100644 --- a/tests/baselines/reference/varArgParamTypeCheck.types +++ b/tests/baselines/reference/varArgParamTypeCheck.types @@ -1,7 +1,7 @@ === tests/cases/compiler/varArgParamTypeCheck.ts === function sequence(...sequences:{():void;}[]) { ->sequence : (...sequences: { (): void; }[]) => void ->sequences : { (): void; }[] +>sequence : (...sequences: (() => void)[]) => void +>sequences : (() => void)[] } function callback(clb:()=>void) { @@ -11,7 +11,7 @@ function callback(clb:()=>void) { sequence( >sequence( function bar() { }, function foo() { callback(()=>{ this(); }); }, function baz() { callback(()=>{ this(); }); }) : void ->sequence : (...sequences: { (): void; }[]) => void +>sequence : (...sequences: (() => void)[]) => void function bar() { >function bar() { } : () => void diff --git a/tests/baselines/reference/varArgsOnConstructorTypes.types b/tests/baselines/reference/varArgsOnConstructorTypes.types index 17993a32fda..5ac9babd426 100644 --- a/tests/baselines/reference/varArgsOnConstructorTypes.types +++ b/tests/baselines/reference/varArgsOnConstructorTypes.types @@ -45,14 +45,14 @@ export interface I1 { >I1 : I1 register(inputClass: new(...params: any[]) => A); ->register : { (inputClass: new (...params: any[]) => A): any; (inputClass: { new (...params: any[]): A; }[]): any; } +>register : { (inputClass: new (...params: any[]) => A): any; (inputClass: (new (...params: any[]) => A)[]): any; } >inputClass : new (...params: any[]) => A >params : any[] >A : A register(inputClass: { new (...params: any[]): A; }[]); ->register : { (inputClass: new (...params: any[]) => A): any; (inputClass: { new (...params: any[]): A; }[]): any; } ->inputClass : { new (...params: any[]): A; }[] +>register : { (inputClass: new (...params: any[]) => A): any; (inputClass: (new (...params: any[]) => A)[]): any; } +>inputClass : (new (...params: any[]) => A)[] >params : any[] >A : A } @@ -64,8 +64,8 @@ var reg: I1; reg.register(B); >reg.register(B) : any ->reg.register : { (inputClass: new (...params: any[]) => A): any; (inputClass: { new (...params: any[]): A; }[]): any; } +>reg.register : { (inputClass: new (...params: any[]) => A): any; (inputClass: (new (...params: any[]) => A)[]): any; } >reg : I1 ->register : { (inputClass: new (...params: any[]) => A): any; (inputClass: { new (...params: any[]): A; }[]): any; } +>register : { (inputClass: new (...params: any[]) => A): any; (inputClass: (new (...params: any[]) => A)[]): any; } >B : typeof B diff --git a/tests/baselines/reference/vardecl.js b/tests/baselines/reference/vardecl.js index 326a639ca91..5ce8e095020 100644 --- a/tests/baselines/reference/vardecl.js +++ b/tests/baselines/reference/vardecl.js @@ -213,9 +213,7 @@ declare var d2: { }; }; declare var n2: () => void; -declare var n4: { - (): void; -}[]; +declare var n4: (() => void)[]; declare var d4: { foo(n: string, x: { x: number; diff --git a/tests/baselines/reference/vardecl.types b/tests/baselines/reference/vardecl.types index f757562c103..25257e57d78 100644 --- a/tests/baselines/reference/vardecl.types +++ b/tests/baselines/reference/vardecl.types @@ -107,7 +107,7 @@ var n2: { (): void; } var n4: { ->n4 : { (): void; }[] +>n4 : (() => void)[] (): void; }[]; diff --git a/tests/baselines/reference/voidOperatorWithEnumType.js b/tests/baselines/reference/voidOperatorWithEnumType.js index a168acaa1b6..8d20842ea7b 100644 --- a/tests/baselines/reference/voidOperatorWithEnumType.js +++ b/tests/baselines/reference/voidOperatorWithEnumType.js @@ -2,24 +2,24 @@ // void operator on enum type enum ENUM { }; -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsAny1 = void ENUM; var ResultIsAny2 = void ENUM1; // enum type expressions -var ResultIsAny3 = void ENUM1[0]; -var ResultIsAny4 = void (ENUM[0] + ENUM1[1]); +var ResultIsAny3 = void ENUM1["A"]; +var ResultIsAny4 = void (ENUM[0] + ENUM1["B"]); // multiple void operators var ResultIsAny5 = void void ENUM; -var ResultIsAny6 = void void void (ENUM[0] + ENUM1[1]); +var ResultIsAny6 = void void void (ENUM[0] + ENUM1.B); // miss assignment operators void ENUM; void ENUM1; -void ENUM1[1]; +void ENUM1["B"]; void ENUM, ENUM1; //// [voidOperatorWithEnumType.js] @@ -30,8 +30,8 @@ var ENUM; ; var ENUM1; (function (ENUM1) { - ENUM1[ENUM1["1"] = 0] = "1"; - ENUM1[ENUM1["2"] = 1] = "2"; + ENUM1[ENUM1["A"] = 0] = "A"; + ENUM1[ENUM1["B"] = 1] = "B"; ENUM1[ENUM1[""] = 2] = ""; })(ENUM1 || (ENUM1 = {})); ; @@ -39,13 +39,13 @@ var ENUM1; var ResultIsAny1 = void ENUM; var ResultIsAny2 = void ENUM1; // enum type expressions -var ResultIsAny3 = void ENUM1[0]; -var ResultIsAny4 = void (ENUM[0] + ENUM1[1]); +var ResultIsAny3 = void ENUM1["A"]; +var ResultIsAny4 = void (ENUM[0] + ENUM1["B"]); // multiple void operators var ResultIsAny5 = void void ENUM; -var ResultIsAny6 = void void void (ENUM[0] + ENUM1[1]); +var ResultIsAny6 = void void void (ENUM[0] + 1 /* B */); // miss assignment operators void ENUM; void ENUM1; -void ENUM1[1]; +void ENUM1["B"]; void ENUM, ENUM1; diff --git a/tests/baselines/reference/voidOperatorWithEnumType.types b/tests/baselines/reference/voidOperatorWithEnumType.types index 2433a00ca44..82f4108bee3 100644 --- a/tests/baselines/reference/voidOperatorWithEnumType.types +++ b/tests/baselines/reference/voidOperatorWithEnumType.types @@ -4,8 +4,10 @@ enum ENUM { }; >ENUM : ENUM -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; >ENUM1 : ENUM1 +>A : ENUM1 +>B : ENUM1 // enum type var var ResultIsAny1 = void ENUM; @@ -19,20 +21,20 @@ var ResultIsAny2 = void ENUM1; >ENUM1 : typeof ENUM1 // enum type expressions -var ResultIsAny3 = void ENUM1[0]; +var ResultIsAny3 = void ENUM1["A"]; >ResultIsAny3 : any ->void ENUM1[0] : undefined ->ENUM1[0] : string +>void ENUM1["A"] : undefined +>ENUM1["A"] : ENUM1 >ENUM1 : typeof ENUM1 -var ResultIsAny4 = void (ENUM[0] + ENUM1[1]); +var ResultIsAny4 = void (ENUM[0] + ENUM1["B"]); >ResultIsAny4 : any ->void (ENUM[0] + ENUM1[1]) : undefined ->(ENUM[0] + ENUM1[1]) : string ->ENUM[0] + ENUM1[1] : string +>void (ENUM[0] + ENUM1["B"]) : undefined +>(ENUM[0] + ENUM1["B"]) : string +>ENUM[0] + ENUM1["B"] : string >ENUM[0] : string >ENUM : typeof ENUM ->ENUM1[1] : ENUM1 +>ENUM1["B"] : ENUM1 >ENUM1 : typeof ENUM1 // multiple void operators @@ -42,17 +44,18 @@ var ResultIsAny5 = void void ENUM; >void ENUM : undefined >ENUM : typeof ENUM -var ResultIsAny6 = void void void (ENUM[0] + ENUM1[1]); +var ResultIsAny6 = void void void (ENUM[0] + ENUM1.B); >ResultIsAny6 : any ->void void void (ENUM[0] + ENUM1[1]) : undefined ->void void (ENUM[0] + ENUM1[1]) : undefined ->void (ENUM[0] + ENUM1[1]) : undefined ->(ENUM[0] + ENUM1[1]) : string ->ENUM[0] + ENUM1[1] : string +>void void void (ENUM[0] + ENUM1.B) : undefined +>void void (ENUM[0] + ENUM1.B) : undefined +>void (ENUM[0] + ENUM1.B) : undefined +>(ENUM[0] + ENUM1.B) : string +>ENUM[0] + ENUM1.B : string >ENUM[0] : string >ENUM : typeof ENUM ->ENUM1[1] : ENUM1 +>ENUM1.B : ENUM1 >ENUM1 : typeof ENUM1 +>B : ENUM1 // miss assignment operators void ENUM; @@ -63,9 +66,9 @@ void ENUM1; >void ENUM1 : undefined >ENUM1 : typeof ENUM1 -void ENUM1[1]; ->void ENUM1[1] : undefined ->ENUM1[1] : ENUM1 +void ENUM1["B"]; +>void ENUM1["B"] : undefined +>ENUM1["B"] : ENUM1 >ENUM1 : typeof ENUM1 void ENUM, ENUM1; diff --git a/tests/cases/compiler/arrayBestCommonTypes.ts b/tests/cases/compiler/arrayBestCommonTypes.ts index ee09c4d07f6..c7466b5181e 100644 --- a/tests/cases/compiler/arrayBestCommonTypes.ts +++ b/tests/cases/compiler/arrayBestCommonTypes.ts @@ -1,52 +1,106 @@ -interface iface { } -class base implements iface { } -class base2 implements iface { } -class derived extends base { } +module EmptyTypes { + interface iface { } + class base implements iface { } + class base2 implements iface { } + class derived extends base { } -class f { - public voidIfAny(x: boolean, y?: boolean): number; - public voidIfAny(x: string, y?: boolean): number; - public voidIfAny(x: number, y?: boolean): number; - public voidIfAny(x: any, y =false): any { return null; } - - public x() { - (this.voidIfAny([4, 2][0])); - (this.voidIfAny([4, 2, undefined][0])); - (this.voidIfAny([undefined, 2, 4][0])); - (this.voidIfAny([null, 2, 4][0])); - (this.voidIfAny([2, 4, null][0])); - (this.voidIfAny([undefined, 4, null][0])); + class f { + public voidIfAny(x: boolean, y?: boolean): number; + public voidIfAny(x: string, y?: boolean): number; + public voidIfAny(x: number, y?: boolean): number; + public voidIfAny(x: any, y = false): any { return null; } - (this.voidIfAny(['', "q"][0])); - (this.voidIfAny(['', "q", undefined][0])); - (this.voidIfAny([undefined, "q", ''][0])); - (this.voidIfAny([null, "q", ''][0])); - (this.voidIfAny(["q", '', null][0])); - (this.voidIfAny([undefined, '', null][0])); + public x() { + (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); - (this.voidIfAny([[3,4],[null]][0][0])); - - - var t1: { x: number; y: base; }[] = [ { x: 7, y: new derived() }, { x: 5, y: new base() } ]; - var t2: { x: boolean; y: base; }[] = [ { x: true, y: new derived() }, { x: false, y: new base() } ]; - var t3: { x: string; y: base; }[] = [ { x: undefined, y: new base() }, { x: '', y: new derived() } ]; + (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny([undefined, '', null][0])); - var anyObj: any = null; - // Order matters here so test all the variants - var a1 = [ {x: 0, y: 'a'}, {x: 'a', y: 'a'}, {x: anyObj, y: 'a'} ]; - var a2 = [ {x: anyObj, y: 'a'}, {x: 0, y: 'a'}, {x: 'a', y: 'a'} ]; - var a3 = [ {x: 0, y: 'a'}, {x: anyObj, y: 'a'}, {x: 'a', y: 'a'} ]; - - var ifaceObj: iface = null; - var baseObj = new base(); - var base2Obj = new base2(); + (this.voidIfAny([[3, 4], [null]][0][0])); - var b1 = [ baseObj, base2Obj, ifaceObj ]; - var b2 = [ base2Obj, baseObj, ifaceObj ]; - var b3 = [ baseObj, ifaceObj, base2Obj ]; - var b4 = [ ifaceObj, baseObj, base2Obj ]; + + var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; + var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }]; + var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; + + var anyObj: any = null; + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; + + var ifaceObj: iface = null; + var baseObj = new base(); + var base2Obj = new base2(); + + var b1 = [baseObj, base2Obj, ifaceObj]; + var b2 = [base2Obj, baseObj, ifaceObj]; + var b3 = [baseObj, ifaceObj, base2Obj]; + var b4 = [ifaceObj, baseObj, base2Obj]; + } } } +module NonEmptyTypes { + interface iface { x: string; } + class base implements iface { x: string; y: string; } + class base2 implements iface { x: string; z: string; } + class derived extends base { a: string; } + + + class f { + public voidIfAny(x: boolean, y?: boolean): number; + public voidIfAny(x: string, y?: boolean): number; + public voidIfAny(x: number, y?: boolean): number; + public voidIfAny(x: any, y = false): any { return null; } + + public x() { + (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); + + (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny([undefined, '', null][0])); + + (this.voidIfAny([[3, 4], [null]][0][0])); + + + var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }]; + var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }]; + var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }]; + + var anyObj: any = null; + // Order matters here so test all the variants + var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }]; + var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }]; + var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }]; + + var ifaceObj: iface = null; + var baseObj = new base(); + var base2Obj = new base2(); + + var b1 = [baseObj, base2Obj, ifaceObj]; + var b2 = [base2Obj, baseObj, ifaceObj]; + var b3 = [baseObj, ifaceObj, base2Obj]; + var b4 = [ifaceObj, baseObj, base2Obj]; + } + } +} diff --git a/tests/cases/compiler/arrayLiteralContextualType.ts b/tests/cases/compiler/arrayLiteralContextualType.ts index 1518d2e4ac0..be05929e8e7 100644 --- a/tests/cases/compiler/arrayLiteralContextualType.ts +++ b/tests/cases/compiler/arrayLiteralContextualType.ts @@ -25,5 +25,5 @@ bar([ ]); // Legal because of the contextual type IAnimal provided by the parameter var arr = [new Giraffe(), new Elephant()]; -foo(arr); // Error because of no contextual type -bar(arr); // Error because of no contextual type \ No newline at end of file +foo(arr); // ok because arr is Array not {}[] +bar(arr); // ok because arr is Array not {}[] \ No newline at end of file diff --git a/tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts b/tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts index bd1f22f44dc..1ea001057a9 100644 --- a/tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts +++ b/tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts @@ -1,3 +1,3 @@ var f10: (x: T, b: () => (a: T) => void, y: T) => T; -f10('', () => a => a.foo, ''); // a is string, fixed by first parameter -var r9 = f10('', () => (a => a.foo), 1); // now a should be any \ No newline at end of file +f10('', () => a => a.foo, ''); // a is string +var r9 = f10('', () => (a => a.foo), 1); // error \ No newline at end of file diff --git a/tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts b/tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts index b9fecdc6ffc..254197bf309 100644 --- a/tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts +++ b/tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts @@ -1,18 +1,14 @@ - var obj1: {}; - obj1.length; - - var obj2: Object; - obj2.length; - - function concat(x: T, y: T): T { return null; } +var result = concat(1, ""); // error +var elementCount = result.length; -var result = concat(1, ""); +function concat2(x: T, y: U) { return null; } +var result2 = concat2(1, ""); // result2 will be number|string +var elementCount2 = result.length; -var elementCount = result.length; // would like to get an error by now diff --git a/tests/cases/compiler/enumIdenticalIdentifierValues.ts b/tests/cases/compiler/enumIdenticalIdentifierValues.ts deleted file mode 100644 index 2b5bc78650b..00000000000 --- a/tests/cases/compiler/enumIdenticalIdentifierValues.ts +++ /dev/null @@ -1,4 +0,0 @@ -enum Enum { - 1, - 1.0 -} \ No newline at end of file diff --git a/tests/cases/compiler/nonContextuallyTypedLogicalOr.ts b/tests/cases/compiler/nonContextuallyTypedLogicalOr.ts index f77ad5105ab..cadd60ea398 100644 --- a/tests/cases/compiler/nonContextuallyTypedLogicalOr.ts +++ b/tests/cases/compiler/nonContextuallyTypedLogicalOr.ts @@ -11,6 +11,4 @@ interface Ellement { var c: Contextual; var e: Ellement; -// This should error. Even though we are contextually typing e with Contextual, the RHS still -// needs to be a supertype of the LHS to win as the best common type. (c || e).dummy; \ No newline at end of file diff --git a/tests/cases/compiler/promisePermutations.ts b/tests/cases/compiler/promisePermutations.ts index c5091aaa630..0ce62be8181 100644 --- a/tests/cases/compiler/promisePermutations.ts +++ b/tests/cases/compiler/promisePermutations.ts @@ -11,7 +11,7 @@ interface IPromise { then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -71,7 +71,7 @@ var s3: Promise; var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); -var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); +var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -82,7 +82,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -134,7 +134,7 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); @@ -149,15 +149,15 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/cases/compiler/promisePermutations2.ts b/tests/cases/compiler/promisePermutations2.ts index 66f9806de00..05a60860929 100644 --- a/tests/cases/compiler/promisePermutations2.ts +++ b/tests/cases/compiler/promisePermutations2.ts @@ -10,7 +10,7 @@ interface IPromise { then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -81,7 +81,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -125,7 +125,7 @@ var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -133,14 +133,14 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -148,11 +148,11 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok diff --git a/tests/cases/compiler/promisePermutations3.ts b/tests/cases/compiler/promisePermutations3.ts index 78d6b17c9ec..3aab00b0ed0 100644 --- a/tests/cases/compiler/promisePermutations3.ts +++ b/tests/cases/compiler/promisePermutations3.ts @@ -10,7 +10,7 @@ interface Promise { interface IPromise { then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -81,7 +81,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -125,7 +125,7 @@ var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -133,14 +133,14 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -148,15 +148,15 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/cases/compiler/propertiesAndIndexers2.ts b/tests/cases/compiler/propertiesAndIndexers2.ts new file mode 100644 index 00000000000..188635bf1dd --- /dev/null +++ b/tests/cases/compiler/propertiesAndIndexers2.ts @@ -0,0 +1,15 @@ +interface A { + [n: number]: string; + [s: string]: number; +} + +// All of these should fail. +interface B extends A { + c: string; + 3: string; + Infinity: string; + "-Infinity": string; + NaN: string; + "-NaN": string; + 6(): string; +} diff --git a/tests/cases/compiler/propertiesAndIndexersForNumericNames.ts b/tests/cases/compiler/propertiesAndIndexersForNumericNames.ts new file mode 100644 index 00000000000..3a6f4afd52b --- /dev/null +++ b/tests/cases/compiler/propertiesAndIndexersForNumericNames.ts @@ -0,0 +1,41 @@ +class C { + [i: number]: number; + + // These all have numeric names; they should error + // because their types are not compatible with the numeric indexer. + public "1": string = "number"; // Error + public "-1": string = "negative number"; // Error + public "-2.5": string = "negative number"; // Error + public "3.141592": string = "pi-sitive number"; // Error + public "1.2e-20": string = "really small number"; // Error + public "Infinity": string = "A gillion"; // Error + public "-Infinity": string = "Negative-a-gillion"; // Error + public "NaN": string = "not a number"; // Error + + // These all have *partially* numeric names, + // but should really be treated as plain string literals. + public " 1": string = "leading space"; // No error + public "1 ": string = "trailing space"; // No error + public "": string = "no nothing"; // No error + public " ": string = "just space"; // No error + public "1 0 1": string = "several numbers and spaces"; // No error + public "hunter2": string = "not a password"; // No error + public "+Infinity": string = "A gillion"; // No error + public "+NaN": string = "not a positive number"; // No error + public "-NaN": string = "not a negative number"; // No error + + + // These fall into the above category, however, they are "trickier"; + // these all are *scanned* as numeric literals, but they are not written in + // "canonical" numeric representations. + public "+1": string = "positive number (for the paranoid)"; // No error + public "1e0": string = "just one"; // No error + public "-0": string = "just zero"; // No error + public "-0e0": string = "just zero"; // No error + public "0xF00D": string = "hex food"; // No error + public "0xBEEF": string = "hex beef"; // No error + public "0123": string = "oct 83"; // No error + public "0o123": string = "explicit oct 83"; // No error + public "0b101101001010": string = "explicit binary"; // No error + public "0.000000000000000000012": string = "should've been in exponential form"; // No error +} diff --git a/tests/cases/compiler/tupleTypes.ts b/tests/cases/compiler/tupleTypes.ts index 3b22c284cb1..80181f8b332 100644 --- a/tests/cases/compiler/tupleTypes.ts +++ b/tests/cases/compiler/tupleTypes.ts @@ -8,8 +8,8 @@ var t0 = t[0]; // number var t0: number; var t1 = t[1]; // string var t1: string; -var t2 = t[2]; // {} -var t2: {}; +var t2 = t[2]; // number|string +var t2: number|string; t = []; // Error t = [1]; // Error @@ -32,8 +32,8 @@ var tt0 = tt[0]; var tt0: number; var tt1 = tt[1]; var tt1: string; -var tt2 = tt[2]; -var tt2: {}; +var tt2 = tt[2]; +var tt2: number | string; tt = tuple2(1, undefined); tt = [1, undefined]; diff --git a/tests/cases/compiler/typeArgInference2.ts b/tests/cases/compiler/typeArgInference2.ts index 523d1eab506..5bf8599996e 100644 --- a/tests/cases/compiler/typeArgInference2.ts +++ b/tests/cases/compiler/typeArgInference2.ts @@ -1,12 +1,12 @@ -interface Item { - name: string; -} - -declare function foo(x?: T, y?: T): T; - -var z1 = foo(null); // any -var z2 = foo(); // Item -var z3 = foo({ name: null }); // { name: any } -var z4 = foo({ name: "abc" }); // { name: string } -var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } -var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // Item \ No newline at end of file +interface Item { + name: string; +} + +declare function foo(x?: T, y?: T): T; + +var z1 = foo(null); // any +var z2 = foo(); // Item +var z3 = foo({ name: null }); // { name: any } +var z4 = foo({ name: "abc" }); // { name: string } +var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } +var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // error \ No newline at end of file diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts index b4b85573755..41c5a0b8100 100644 --- a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts +++ b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts @@ -1,28 +1,21 @@ // Empty array literal with no contextual type has type Undefined[] var arr1= [[], [1], ['']]; -var arr1: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK var arr2 = [[null], [1], ['']]; -var arr2: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK // Array literal with elements of only EveryType E has type E[] var stringArrArr = [[''], [""]]; -var stringArrArr: string[][]; var stringArr = ['', ""]; -var stringArr: string[]; var numberArr = [0, 0.0, 0x00, 1e1]; -var numberArr: number[]; var boolArr = [false, true, false, true]; -var boolArr: boolean[]; class C { private p; } var classArr = [new C(), new C()]; -var classArr: C[]; // Should be OK var classTypeArray = [C, C, C]; var classTypeArray: Array; // Should OK, not be a parse error @@ -30,7 +23,6 @@ var classTypeArray: Array; // Should OK, not be a parse error // Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[] var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; -var context2: Array<{}>; // Should be OK // Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] class Base { private p; } diff --git a/tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts b/tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts index 34ef4b3ca8c..feaa3c5a280 100644 --- a/tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts +++ b/tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts @@ -1,21 +1,20 @@ -//Cond ? Expr1 : Expr2, Expr1 and Expr2 have no identical best common type -class X { propertyX: any; propertyX1: number; propertyX2: string }; -class A extends X { propertyA: number }; -class B extends X { propertyB: string }; - -var x: X; -var a: A; -var b: B; - -//Expect to have compiler errors -//Be not contextually typed -true ? a : b; -var result1 = true ? a : b; - -//Be contextually typed and and bct is not identical -var result2: A = true ? a : b; -var result3: B = true ? a : b; - -var result4: (t: X) => number = true ? (m) => m.propertyX1 : (n) => n.propertyX2; -var result5: (t: X) => string = true ? (m) => m.propertyX1 : (n) => n.propertyX2; +//Cond ? Expr1 : Expr2, Expr1 and Expr2 have no identical best common type +class X { propertyX: any; propertyX1: number; propertyX2: string }; +class A extends X { propertyA: number }; +class B extends X { propertyB: string }; + +var x: X; +var a: A; +var b: B; + +// No errors anymore, uses union types +true ? a : b; +var result1 = true ? a : b; + +//Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target +var result2: A = true ? a : b; +var result3: B = true ? a : b; + +var result4: (t: X) => number = true ? (m) => m.propertyX1 : (n) => n.propertyX2; +var result5: (t: X) => string = true ? (m) => m.propertyX1 : (n) => n.propertyX2; var result6: (t: X) => boolean = true ? (m) => m.propertyX1 : (n) => n.propertyX2; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithEnumType.ts b/tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithEnumType.ts index 8dac812d702..60370469692 100644 --- a/tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithEnumType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/bitwiseNotOperator/bitwiseNotOperatorWithEnumType.ts @@ -1,18 +1,18 @@ // ~ operator on enum type -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsNumber1 = ~ENUM1; // enum type expressions -var ResultIsNumber2 = ~ENUM1[1]; -var ResultIsNumber3 = ~(ENUM1[1] + ENUM1[2]); +var ResultIsNumber2 = ~ENUM1["A"]; +var ResultIsNumber3 = ~(ENUM1.A + ENUM1["B"]); // multiple ~ operators -var ResultIsNumber4 = ~~~(ENUM1[1] + ENUM1[2]); +var ResultIsNumber4 = ~~~(ENUM1["A"] + ENUM1.B); // miss assignment operators ~ENUM1; -~ENUM1[1]; -~ENUM1[1], ~ENUM1[2]; \ No newline at end of file +~ENUM1["A"]; +~ENUM1.A, ~ENUM1["B"]; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts index 9af7d33dbe7..022ed405a0b 100644 --- a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumType.ts @@ -1,12 +1,12 @@ // -- operator on enum type -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // expression -var ResultIsNumber1 = --ENUM1[1]; -var ResultIsNumber2 = ENUM1[1]--; +var ResultIsNumber1 = --ENUM1["A"]; +var ResultIsNumber2 = ENUM1.A--; // miss assignment operator ---ENUM1[1]; +--ENUM1["A"]; -ENUM1[1]--; \ No newline at end of file +ENUM1[A]--; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts index 97b9bd48841..fca19d38daa 100644 --- a/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts +++ b/tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithEnumTypeInvalidOperations.ts @@ -1,7 +1,7 @@ // -- operator on enum type enum ENUM { }; -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsNumber1 = --ENUM; @@ -11,8 +11,8 @@ var ResultIsNumber3 = ENUM--; var ResultIsNumber4 = ENUM1--; // enum type expressions -var ResultIsNumber5 = --(ENUM[1] + ENUM[2]); -var ResultIsNumber6 = (ENUM[1] + ENUM[2])--; +var ResultIsNumber5 = --(ENUM["A"] + ENUM.B); +var ResultIsNumber6 = (ENUM.A + ENUM["B"])--; // miss assignment operator --ENUM; diff --git a/tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithEnumType.ts b/tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithEnumType.ts index 522e62a2748..a4c8020fdfe 100644 --- a/tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithEnumType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorWithEnumType.ts @@ -1,22 +1,22 @@ // delete operator on enum type enum ENUM { }; -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsBoolean1 = delete ENUM; var ResultIsBoolean2 = delete ENUM1; // enum type expressions -var ResultIsBoolean3 = delete ENUM1[0]; -var ResultIsBoolean4 = delete (ENUM[0] + ENUM1[1]); +var ResultIsBoolean3 = delete ENUM1["A"]; +var ResultIsBoolean4 = delete (ENUM[0] + ENUM1["B"]); // multiple delete operators var ResultIsBoolean5 = delete delete ENUM; -var ResultIsBoolean6 = delete delete delete (ENUM[0] + ENUM1[1]); +var ResultIsBoolean6 = delete delete delete (ENUM[0] + ENUM1["B"]); // miss assignment operators delete ENUM; delete ENUM1; -delete ENUM1[1]; +delete ENUM1.B; delete ENUM, ENUM1; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts index a58941feca9..6b116a7ca3d 100644 --- a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumType.ts @@ -1,12 +1,12 @@ // ++ operator on enum type -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // expression -var ResultIsNumber1 = ++ENUM1[1]; -var ResultIsNumber2 = ENUM1[1]++; +var ResultIsNumber1 = ++ENUM1["B"]; +var ResultIsNumber2 = ENUM1.B++; // miss assignment operator -++ENUM1[1]; +++ENUM1["B"]; -ENUM1[1]++; \ No newline at end of file +ENUM1.B++; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts index 5eab1420f98..78726cb152a 100644 --- a/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts +++ b/tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithEnumTypeInvalidOperations.ts @@ -1,7 +1,7 @@ // ++ operator on enum type enum ENUM { }; -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsNumber1 = ++ENUM; diff --git a/tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithEnumType.ts b/tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithEnumType.ts index 69b9566937a..a7a6f12b99d 100644 --- a/tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithEnumType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/logicalNotOperator/logicalNotOperatorWithEnumType.ts @@ -1,21 +1,21 @@ // ! operator on enum type -enum ENUM { 1, 2, 3 }; +enum ENUM { A, B, C }; enum ENUM1 { }; // enum type var var ResultIsBoolean1 = !ENUM; // enum type expressions -var ResultIsBoolean2 = !ENUM[1]; -var ResultIsBoolean3 = !(ENUM[1] + ENUM[2]); +var ResultIsBoolean2 = !ENUM["B"]; +var ResultIsBoolean3 = !(ENUM.B + ENUM["C"]); // multiple ! operators var ResultIsBoolean4 = !!ENUM; -var ResultIsBoolean5 = !!!(ENUM[1] + ENUM[2]); +var ResultIsBoolean5 = !!!(ENUM["B"] + ENUM.C); // miss assignment operators !ENUM; !ENUM1; -!ENUM[1]; +!ENUM.B; !ENUM, ENUM1; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithEnumType.ts b/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithEnumType.ts index a5e277f2b6e..6545588913c 100644 --- a/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithEnumType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorWithEnumType.ts @@ -1,17 +1,17 @@ // - operator on enum type enum ENUM { }; -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsNumber1 = -ENUM; // expressions -var ResultIsNumber2 = -ENUM1[1]; -var ResultIsNumber3 = -(ENUM1[1] + ENUM1[2]); +var ResultIsNumber2 = -ENUM1["B"]; +var ResultIsNumber3 = -(ENUM1.B + ENUM1[""]); // miss assignment operators -ENUM; -ENUM1; --ENUM1[1]; +-ENUM1["B"]; -ENUM, ENUM1; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithEnumType.ts b/tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithEnumType.ts index 47a6991d8ce..288d716e231 100644 --- a/tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithEnumType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/plusOperator/plusOperatorWithEnumType.ts @@ -1,18 +1,18 @@ // + operator on enum type enum ENUM { }; -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsNumber1 = +ENUM; var ResultIsNumber2 = +ENUM1; // enum type expressions -var ResultIsNumber3 = +ENUM1[0]; -var ResultIsNumber4 = +(ENUM[0] + ENUM1[1]); +var ResultIsNumber3 = +ENUM1["A"]; +var ResultIsNumber4 = +(ENUM[0] + ENUM1["B"]); // miss assignment operators +ENUM; +ENUM1; -+ENUM1[1]; ++ENUM1.B; +ENUM, ENUM1; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithEnumType.ts b/tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithEnumType.ts index 0d1ddd67f31..9abb602db06 100644 --- a/tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithEnumType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithEnumType.ts @@ -1,24 +1,24 @@ // typeof operator on enum type enum ENUM { }; -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsString1 = typeof ENUM; var ResultIsString2 = typeof ENUM1; // enum type expressions -var ResultIsString3 = typeof ENUM1[0]; -var ResultIsString4 = typeof (ENUM[0] + ENUM1[1]); +var ResultIsString3 = typeof ENUM1["A"]; +var ResultIsString4 = typeof (ENUM[0] + ENUM1["B"]); // multiple typeof operators var ResultIsString5 = typeof typeof ENUM; -var ResultIsString6 = typeof typeof typeof (ENUM[0] + ENUM1[1]); +var ResultIsString6 = typeof typeof typeof (ENUM[0] + ENUM1.B); // miss assignment operators typeof ENUM; typeof ENUM1; -typeof ENUM1[1]; +typeof ENUM1["B"]; typeof ENUM, ENUM1; // use typeof in type query diff --git a/tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithEnumType.ts b/tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithEnumType.ts index debbc65f148..038aaed6483 100644 --- a/tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithEnumType.ts +++ b/tests/cases/conformance/expressions/unaryOperators/voidOperator/voidOperatorWithEnumType.ts @@ -1,22 +1,22 @@ // void operator on enum type enum ENUM { }; -enum ENUM1 { 1, 2, "" }; +enum ENUM1 { A, B, "" }; // enum type var var ResultIsAny1 = void ENUM; var ResultIsAny2 = void ENUM1; // enum type expressions -var ResultIsAny3 = void ENUM1[0]; -var ResultIsAny4 = void (ENUM[0] + ENUM1[1]); +var ResultIsAny3 = void ENUM1["A"]; +var ResultIsAny4 = void (ENUM[0] + ENUM1["B"]); // multiple void operators var ResultIsAny5 = void void ENUM; -var ResultIsAny6 = void void void (ENUM[0] + ENUM1[1]); +var ResultIsAny6 = void void void (ENUM[0] + ENUM1.B); // miss assignment operators void ENUM; void ENUM1; -void ENUM1[1]; +void ENUM1["B"]; void ENUM, ENUM1; \ No newline at end of file diff --git a/tests/cases/conformance/types/specifyingTypes/typeLiterals/parenthesizedTypes.ts b/tests/cases/conformance/types/specifyingTypes/typeLiterals/parenthesizedTypes.ts new file mode 100644 index 00000000000..92959698885 --- /dev/null +++ b/tests/cases/conformance/types/specifyingTypes/typeLiterals/parenthesizedTypes.ts @@ -0,0 +1,27 @@ +var a: string; +var a: (string); +var a: ((string) | string | (((string)))); +var a: ((((((((((((((((((((((((((((((((((((((((string)))))))))))))))))))))))))))))))))))))))); + +var b: (x: string) => string; +var b: ((x: (string)) => (string)); + +var c: string[] | number[]; +var c: (string)[] | (number)[]; +var c: ((string)[]) | ((number)[]); + +var d: (((x: string) => string) | ((x: number) => number))[]; +var d: ({ (x: string): string } | { (x: number): number })[]; +var d: Array<((x: string) => string) | ((x: number) => number)>; +var d: Array<{ (x: string): string } | { (x: number): number }>; +var d: (Array<{ (x: string): string } | { (x: number): number }>); + +var e: typeof a[]; +var e: (typeof a)[]; + +var f: (string) => string; +var f: (string: any) => string; + +var g: [string, string]; +var g: [(string), string]; +var g: [(string), (((typeof a)))]; diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts index 68ac4cff026..9edf4f5f417 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts @@ -15,8 +15,8 @@ function f2(x: T, y: U, z: V) { var r2 = true ? y : z; // ok - var r2 = true ? z : x; - var r2 = true ? x : z; + var r2a = true ? z : x; + var r2b = true ? x : z; } // Date > U > T @@ -57,18 +57,18 @@ function f4(x: T) { } function f5(x: T) { - var r1 = true ? 1 : x; // error - var r1 = true ? x : 1; // error + var r1 = true ? 1 : x; // ok + var r1 = true ? x : 1; // ok } function f6(x: T) { - var r2 = true ? '' : x; // error - var r2 = true ? x : ''; // error + var r2 = true ? '' : x; // ok + var r2 = true ? x : ''; // ok } function f7(x: T) { - var r3 = true ? true : x; // error - var r3 = true ? x : true; // error + var r3 = true ? true : x; // ok + var r3 = true ? x : true; // ok } function f8(x: T) { @@ -115,11 +115,11 @@ function f15>(x: T) { } function f16(x: T) { - var r13 = true ? E : x; // BUG 831833 - var r13 = true ? x : E; // BUG 831833 + var r13 = true ? E : x; // ok + var r13 = true ? x : E; // ok - var r14 = true ? E.A : x; // BUG 831833 - var r14 = true ? x : E.A; // BUG 831833 + var r14 = true ? E.A : x; // ok + var r14 = true ? x : E.A; // ok } function f17(x: T) { diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts index 10021cdcc06..96218dce43e 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts @@ -5,11 +5,11 @@ function f(t: T, u: U, v: V) { var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; } \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts index a4e691edbb4..0dc53908ea3 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts @@ -2,15 +2,15 @@ class Foo { foo: number; } function f(t: T, u: U, v: V) { - // error + // ok var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; @@ -22,7 +22,7 @@ function f(t: T, u: U, v: V) { var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // BUG, should be error + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts index dc3f2917ec1..f63b63432e5 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts @@ -2,53 +2,53 @@ class Foo { foo: T; } function f, U extends Foo, V extends Foo>(t: T, u: U, v: V) { - // error + // ok var r1 = true ? t : u; var r1 = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; - // ok? + // ok var r4 = true ? t : new Foo(); var r4 = true ? new Foo() : t; - // ok? + // ok var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // ok? + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; - // ok? + // ok var r7 = true ? t : new Foo(); var r7 = true ? new Foo() : t; - // ok? + // ok var r8 = true ? u : new Foo(); var r8 = true ? new Foo() : u; - // ok? + // ok var r9 = true ? v : new Foo(); var r9 = true ? new Foo() : v; - // ok? + // ok var r10 = true ? t : new Foo(); var r10 = true ? new Foo() : t; - // ok? + // ok var r11 = true ? u : new Foo(); var r11 = true ? new Foo() : u; - // ok? + // ok var r12 = true ? v : new Foo(); var r12 = true ? new Foo() : v; } diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts index 601d85704eb..ac8f5642f70 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts @@ -30,4 +30,4 @@ interface S3 extends T3 { // object literal case var a: { Foo: Base; } var b: { Foo?: Derived; } -var r = true ? a : b; // error \ No newline at end of file +var r = true ? a : b; // ok \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/contextualSignatureInstantiation.ts b/tests/cases/conformance/types/typeRelationships/typeInference/contextualSignatureInstantiation.ts new file mode 100644 index 00000000000..393d0e10d37 --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/typeInference/contextualSignatureInstantiation.ts @@ -0,0 +1,28 @@ +// TypeScript Spec, section 4.12.2: +// If e is an expression of a function type that contains exactly one generic call signature and no other members, +// and T is a function type with exactly one non - generic call signature and no other members, then any inferences +// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed +// to a function type with e's call signature instantiated in the context of T's call signature (section 3.8.5). + +declare function foo(cb: (x: number, y: string) => T): T; +declare function bar(x: T, y: U, cb: (x: T, y: U) => V): V; +declare function baz(x: T, y: T, cb: (x: T, y: T) => U): U; + +declare function g(x: T, y: T): T; +declare function h(x: T, y: U): T[] | U[]; + +var a: number; +var a = bar(1, 1, g); // Should be number +var a = baz(1, 1, g); // Should be number + +var b: number | string; +var b = foo(g); // Should be number | string +var b = bar(1, "one", g); // Should be number | string +var b = bar("one", 1, g); // Should be number | string +var b = baz(b, b, g); // Should be number | string + +var d: number[] | string[]; +var d = foo(h); // Should be number[] | string[] +var d = bar(1, "one", h); // Should be number[] | string[] +var d = bar("one", 1, h); // Should be number[] | string[] +var d = baz(d, d, g); // Should be number[] | string[] diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts index 3f2e17c6b05..97359cde959 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts @@ -23,14 +23,14 @@ function foo3(x: T, cb: (a: T) => U, y: U) { var r7 = foo3(1, (a: Z) => '', ''); // string -var r8 = foo3(1, function (a) { return '' }, 1); // {} +var r8 = foo3(1, function (a) { return '' }, 1); // error var r9 = foo3(1, (a) => '', ''); // string function other(t: T, u: U) { - var r10 = foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made + var r10 = foo2(1, (x: T) => ''); // error var r10 = foo2(1, (x) => ''); // string - var r11 = foo3(1, (x: T) => '', ''); // string - var r11b = foo3(1, (x: T) => '', 1); // {} - var r12 = foo3(1, function (a) { return '' }, 1); // {} + var r11 = foo3(1, (x: T) => '', ''); // error + var r11b = foo3(1, (x: T) => '', 1); // error + var r12 = foo3(1, function (a) { return '' }, 1); // error } \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts index f313d638bfb..0d02afe9c88 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts @@ -26,7 +26,7 @@ function foo2(x: T, cb: new(a: T) => U) { return new cb(x); } -var r4 = foo2(1, i2); // string, instantiated generic +var r4 = foo2(1, i2); // error var r4b = foo2(1, a); // any var r5 = foo2(1, i); // any var r6 = foo2('', i2); // string @@ -37,5 +37,5 @@ function foo3(x: T, cb: new(a: T) => U, y: U) { var r7 = foo3(null, i, ''); // any var r7b = foo3(null, a, ''); // any -var r8 = foo3(1, i2, 1); // {} +var r8 = foo3(1, i2, 1); // error var r9 = foo3('', i2, ''); // string \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts index 54a7cf7ebc6..c37b2e31333 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts @@ -1,36 +1,73 @@ // When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, // the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. -function foo(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; +module onlyT { + function foo(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); + + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); // T => T + // BUG 835518 + var r9 = r7(new Date()); // should be ok + var r10 = r7(1); // error + } + + function foo2(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + function other3(x: T) { + var r7 = foo2((a: T) => a, (b: T) => b); // error + var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date + } + + enum E { A } + enum F { A } + + function foo3(x: T, a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error } -var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); +module TU { + function foo(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } -function other2(x: T) { - var r7 = foo((a: T) => a, (b: T) => b); // T => T - // BUG 835518 - var r9 = r7(new Date()); // should be ok - var r10 = r7(1); // error -} + var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => ''); -function foo2(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; -} + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); + var r9 = r7(new Date()); + var r10 = r7(1); + } -function other3(x: T) { - var r7 = foo2((a: T) => a, (b: T) => b); // error - var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date -} + function foo2(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } -enum E { A } -enum F { A } + function other3(x: T) { + var r7 = foo2((a: T) => a, (b: T) => b); + var r7b = foo2((a) => a, (b) => b); + } -function foo3(x: T, a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; -} + enum E { A } + enum F { A } -var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error \ No newline at end of file + function foo3(x: T, a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } + + var r7 = foo3(E.A, (x) => E.A, (x) => F.A); +} \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts index 65f22a3fd3f..82b917efa3e 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts @@ -29,5 +29,5 @@ var r9 = foo2(null, (x) => '', (x) => ''); // any => any var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object var x: (a: string) => boolean; -var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // {} => {} -var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // (string => boolean) => {} \ No newline at end of file +var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // error +var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // error \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts index 1e5976b33e5..75b0462b689 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts @@ -2,7 +2,7 @@ function foo(x: { bar: T; baz: T }) { return x; } -var r = foo({ bar: 1, baz: '' }); // T = {} +var r = foo({ bar: 1, baz: '' }); // error var r2 = foo({ bar: 1, baz: 1 }); // T = number var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo var r4 = foo({ bar: 1, baz: '' }); // T = Object \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts index 8bb5d234bb5..527286e6ee2 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts @@ -33,7 +33,7 @@ module GenericParameter { return cb; } - var r8 = foo6(a); // new{} => string; new(x:{}, y?:{}) => string + var r8 = foo6(a); // error var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) { diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts index a3b02eaf4e4..f429cd5169d 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts @@ -54,11 +54,11 @@ module WithCandidates { var c3: C3; function other(t: T, u: U) { - var r10 = c.foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made + var r10 = c.foo2(1, (x: T) => ''); // error var r10 = c.foo2(1, (x) => ''); // string - var r11 = c3.foo3(1, (x: T) => '', ''); // string - var r11b = c3.foo3(1, (x: T) => '', 1); // {} - var r12 = c3.foo3(1, function (a) { return '' }, 1); // {} + var r11 = c3.foo3(1, (x: T) => '', ''); // error + var r11b = c3.foo3(1, (x: T) => '', 1); // error + var r12 = c3.foo3(1, function (a) { return '' }, 1); // error } } \ No newline at end of file diff --git a/tests/cases/fourslash/bestCommonTypeObjectLiterals1.ts b/tests/cases/fourslash/bestCommonTypeObjectLiterals1.ts index 1632fff5df8..79d3174b542 100644 --- a/tests/cases/fourslash/bestCommonTypeObjectLiterals1.ts +++ b/tests/cases/fourslash/bestCommonTypeObjectLiterals1.ts @@ -28,10 +28,19 @@ goTo.marker('2'); verify.quickInfoIs('(var) c1: {\n name: string;\n age: number;\n}[]'); goTo.marker('3'); -verify.quickInfoIs('(var) c2: {}[]'); +verify.quickInfoIs('(var) c2: ({\n\ + name: string;\n\ + age: number;\n\ + address: string;\n\ +} | {\n\ + name: string;\n\ + age: number;\n\ + dob: Date;\n\ +})[]'); goTo.marker('4'); verify.quickInfoIs('(var) c2a: {\n name: string;\n age: number;\n}[]'); goTo.marker('5'); -verify.quickInfoIs('(var) c3: I[]'); \ No newline at end of file +verify.quickInfoIs('(var) c3: I[]'); + diff --git a/tests/cases/fourslash/commentsExternalModules.ts b/tests/cases/fourslash/commentsExternalModules.ts index 154d87535c6..ad0440a3218 100644 --- a/tests/cases/fourslash/commentsExternalModules.ts +++ b/tests/cases/fourslash/commentsExternalModules.ts @@ -69,10 +69,10 @@ verify.memberListContains("i", "(var) m1.m2.i: m1.m2.c", "i"); goTo.file("commentsExternalModules_file1.ts"); goTo.marker('9'); -verify.quickInfoIs('(alias) extMod', "This is on import declaration"); +verify.quickInfoIs('import extMod = require("commentsExternalModules_file0")', "This is on import declaration"); goTo.marker('10'); -verify.completionListContains("extMod", "(alias) extMod", "This is on import declaration"); +verify.completionListContains("extMod", 'import extMod = require("commentsExternalModules_file0")', "This is on import declaration"); goTo.marker('11'); verify.memberListContains("m1", "module extMod.m1"); diff --git a/tests/cases/fourslash/commentsImportDeclaration.ts b/tests/cases/fourslash/commentsImportDeclaration.ts index 7b34d2fade2..88abbed8618 100644 --- a/tests/cases/fourslash/commentsImportDeclaration.ts +++ b/tests/cases/fourslash/commentsImportDeclaration.ts @@ -28,7 +28,7 @@ goTo.marker('2'); verify.quickInfoIs("module m1", "ModuleComment"); goTo.marker('3'); -verify.quickInfoIs("(alias) extMod", "Import declaration"); +verify.quickInfoIs('import extMod = require("commentsImportDeclaration_file0")', "Import declaration"); goTo.marker('6'); verify.memberListContains("m1", "module extMod.m1"); diff --git a/tests/cases/fourslash/completionEntryForUnionProperty.ts b/tests/cases/fourslash/completionEntryForUnionProperty.ts new file mode 100644 index 00000000000..bc0f9405a1b --- /dev/null +++ b/tests/cases/fourslash/completionEntryForUnionProperty.ts @@ -0,0 +1,20 @@ +/// + +////interface One { +//// commonProperty: number; +//// commonFunction(): number; +////} +//// +////interface Two { +//// commonProperty: string +//// commonFunction(): number; +////} +//// +////var x : One | Two; +//// +////x./**/ + +goTo.marker(); +verify.memberListContains("commonProperty", "(property) commonProperty: string | number"); +verify.memberListContains("commonFunction", "(method) commonFunction(): number"); +verify.memberListCount(2); \ No newline at end of file diff --git a/tests/cases/fourslash/completionEntryForUnionProperty2.ts b/tests/cases/fourslash/completionEntryForUnionProperty2.ts new file mode 100644 index 00000000000..b32e6d05345 --- /dev/null +++ b/tests/cases/fourslash/completionEntryForUnionProperty2.ts @@ -0,0 +1,19 @@ +/// + +////interface One { +//// commonProperty: number; +//// commonFunction(): number; +////} +//// +////interface Two { +//// commonProperty: string +//// commonFunction(): number; +////} +//// +////var x : One | Two; +//// +////x.commonProperty./**/ + +goTo.marker(); +verify.memberListContains("toString", "(method) toString(): string"); +verify.memberListCount(1); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListOnAliases.ts b/tests/cases/fourslash/completionListOnAliases.ts index 68c25d3608e..3d9026c3036 100644 --- a/tests/cases/fourslash/completionListOnAliases.ts +++ b/tests/cases/fourslash/completionListOnAliases.ts @@ -9,7 +9,7 @@ ////} goTo.marker("1"); -verify.memberListContains("x", "(alias) x", undefined); +verify.memberListContains("x", "import x = M", undefined); goTo.marker("2"); verify.memberListContains("value"); diff --git a/tests/cases/fourslash/contextualTyping.ts b/tests/cases/fourslash/contextualTyping.ts index dad6ee8b587..13fb4dc2450 100644 --- a/tests/cases/fourslash/contextualTyping.ts +++ b/tests/cases/fourslash/contextualTyping.ts @@ -242,7 +242,7 @@ verify.quickInfoIs("(var) c3t9: number[][]"); goTo.marker('23'); verify.quickInfoIs("(var) c3t10: IFoo[]"); goTo.marker('24'); -verify.quickInfoIs("(var) c3t11: {\n (n: number, s: string): string;\n}[]"); +verify.quickInfoIs("(var) c3t11: ((n: number, s: string) => string)[]"); goTo.marker('25'); verify.quickInfoIs("(parameter) n: number"); goTo.marker('26'); @@ -314,7 +314,7 @@ verify.quickInfoIs("(property) t9: number[][]"); goTo.marker('59'); verify.quickInfoIs("(property) t10: IFoo[]"); goTo.marker('60'); -verify.quickInfoIs("(property) t11: {\n (n: number, s: string): string;\n}[]"); +verify.quickInfoIs("(property) t11: ((n: number, s: string) => string)[]"); goTo.marker('61'); verify.quickInfoIs("(parameter) n: number"); goTo.marker('62'); @@ -374,7 +374,7 @@ verify.quickInfoIs("(var) c12t9: number[][]"); goTo.marker('89'); verify.quickInfoIs("(var) c12t10: IFoo[]"); goTo.marker('90'); -verify.quickInfoIs("(var) c12t11: {\n (n: number, s: string): string;\n}[]"); +verify.quickInfoIs("(var) c12t11: ((n: number, s: string) => string)[]"); goTo.marker('91'); verify.quickInfoIs("(parameter) n: number"); goTo.marker('92'); diff --git a/tests/cases/fourslash/contextualTypingOfArrayLiterals1.ts b/tests/cases/fourslash/contextualTypingOfArrayLiterals1.ts index 9e59d21c53b..128f801300b 100644 --- a/tests/cases/fourslash/contextualTypingOfArrayLiterals1.ts +++ b/tests/cases/fourslash/contextualTypingOfArrayLiterals1.ts @@ -43,7 +43,7 @@ goTo.marker('4'); verify.quickInfoIs('(var) r4: C'); goTo.marker('5'); -verify.quickInfoIs('(var) x5: {\n name: string;\n age: number;\n}[]'); +verify.quickInfoIs('(var) x5: C[]'); goTo.marker('6'); -verify.quickInfoIs('(var) r5: {\n name: string;\n age: number;\n}'); \ No newline at end of file +verify.quickInfoIs('(var) r5: C'); \ No newline at end of file diff --git a/tests/cases/fourslash/exportEqualTypes.ts b/tests/cases/fourslash/exportEqualTypes.ts index 47a266f7f39..8cfe931d87b 100644 --- a/tests/cases/fourslash/exportEqualTypes.ts +++ b/tests/cases/fourslash/exportEqualTypes.ts @@ -15,7 +15,7 @@ ////var /*3*/r2 = t./*4*/foo; // t should have 'foo' in dropdown list and be of type 'string' goTo.marker('1'); -verify.quickInfoIs('(alias) test'); +verify.quickInfoIs("import test = require('exportEqualTypes_file0')"); goTo.marker('2'); verify.quickInfoIs('(var) r1: Date'); goTo.marker('3'); diff --git a/tests/cases/fourslash/externalModuleWithExportAssignment.ts b/tests/cases/fourslash/externalModuleWithExportAssignment.ts index 1cbaf4f518c..4d5f600317d 100644 --- a/tests/cases/fourslash/externalModuleWithExportAssignment.ts +++ b/tests/cases/fourslash/externalModuleWithExportAssignment.ts @@ -30,7 +30,7 @@ goTo.file("externalModuleWithExportAssignment_file1.ts"); goTo.marker('1'); -verify.quickInfoIs("(alias) a1"); +verify.quickInfoIs('import a1 = require("externalModuleWithExportAssignment_file0")'); goTo.marker('2'); verify.quickInfoIs("(var) a: {\n (): a1.connectExport;\n test1: a1.connectModule;\n test2(): a1.connectModule;\n}", undefined); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 7be7dd63c92..c71f8987bdf 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -80,6 +80,10 @@ module FourSlashInterface { return FourSlash.currentTestState.getMarkers(); } + public marker(name?: string): Marker { + return FourSlash.currentTestState.getMarkerByName(name); + } + public ranges(): Range[] { return FourSlash.currentTestState.getRanges(); } @@ -401,11 +405,17 @@ module FourSlashInterface { FourSlash.currentTestState.verifyCompletionEntryDetails(entryName, text, documentation, kind); } + /** + * This method *requires* a contiguous, complete, and ordered stream of classifications for a file. + */ public syntacticClassificationsAre(...classifications: { classificationType: string; text: string }[]) { FourSlash.currentTestState.verifySyntacticClassifications(classifications); } - public semanticClassificationsAre(...classifications: { classificationType: string; text: string }[]) { + /** + * This method *requires* an ordered stream of classifications for a file, and spans are highly recommended. + */ + public semanticClassificationsAre(...classifications: { classificationType: string; text: string; textSpan?: TextSpan }[]) { FourSlash.currentTestState.verifySemanticClassifications(classifications); } @@ -563,61 +573,69 @@ module FourSlashInterface { } } - export class classification { - public static comment(text: string): { classificationType: string; text: string } { - return { classificationType: "comment", text: text }; + export module classification { + export function comment(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("comment", text, position); } - public static identifier(text: string): { classificationType: string; text: string } { - return { classificationType: "identifier", text: text }; + export function identifier(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("identifier", text, position); } - public static keyword(text: string): { classificationType: string; text: string } { - return { classificationType: "keyword", text: text }; + export function keyword(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("keyword", text, position); } - public static numericLiteral(text: string): { classificationType: string; text: string } { - return { classificationType: "numericLiteral", text: text }; + export function numericLiteral(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("numericLiteral", text, position); } - public static operator(text: string): { classificationType: string; text: string } { - return { classificationType: "operator", text: text }; + export function operator(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("operator", text, position); } - public static stringLiteral(text: string): { classificationType: string; text: string } { - return { classificationType: "stringLiteral", text: text }; + export function stringLiteral(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("stringLiteral", text, position); } - public static whiteSpace(text: string): { classificationType: string; text: string } { - return { classificationType: "whiteSpace", text: text }; + export function whiteSpace(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("whiteSpace", text, position); } - public static text(text: string): { classificationType: string; text: string } { - return { classificationType: "text", text: text }; + export function text(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("text", text, position); } - public static punctuation(text: string): { classificationType: string; text: string } { - return { classificationType: "punctuation", text: text }; + export function punctuation(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("punctuation", text, position); } - public static className(text: string): { classificationType: string; text: string } { - return { classificationType: "className", text: text }; + export function className(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("className", text, position); } - public static enumName(text: string): { classificationType: string; text: string } { - return { classificationType: "enumName", text: text }; + export function enumName(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("enumName", text, position); } - public static interfaceName(text: string): { classificationType: string; text: string } { - return { classificationType: "interfaceName", text: text }; + export function interfaceName(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("interfaceName", text, position); } - public static moduleName(text: string): { classificationType: string; text: string } { - return { classificationType: "moduleName", text: text }; + export function moduleName(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("moduleName", text, position); } - public static typeParameterName(text: string): { classificationType: string; text: string } { - return { classificationType: "typeParameterName", text: text }; + export function typeParameterName(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("typeParameterName", text, position); + } + + function getClassification(type: string, text: string, position?: number) { + return { + classificationType: type, + text: text, + textSpan: position === undefined ? undefined : { start: position, end: position + text.length } + }; } } } @@ -635,6 +653,7 @@ module fs { function verifyOperationIsCancelled(f) { FourSlash.verifyOperationIsCancelled(f); } + var test = new FourSlashInterface.test_(); var goTo = new FourSlashInterface.goTo(); var verify = new FourSlashInterface.verify(); diff --git a/tests/cases/fourslash/genericParameterHelp.ts b/tests/cases/fourslash/genericParameterHelp.ts index a1df1cc2f32..17882485fd7 100644 --- a/tests/cases/fourslash/genericParameterHelp.ts +++ b/tests/cases/fourslash/genericParameterHelp.ts @@ -6,26 +6,12 @@ //// return null; ////} //// -////class testClass { -//// constructor(a:T, b:U, c:M){ } -////} ////// Function calls ////testFunction(/*3*/ ////testFunction(null, null, null); ////testFunction<, ,/*5*/>(null, null, null); -////// Constructor calls -////new testClass(null, null, null) -////new testClass<,,/*construcor4*/>(null, null, null) -////new testClass(null, null, null) -////// Generic types -////testClass extends testClass; // goTo.marker("1"); // verify.currentSignatureParamterCountIs(3); @@ -38,56 +24,14 @@ // verify.currentParameterHelpArgumentNameIs("U"); // verify.currentParameterSpanIs("U"); - goTo.marker("3"); - verify.currentParameterHelpArgumentNameIs("a"); - verify.currentParameterSpanIs("a: T"); +goTo.marker("3"); +verify.currentParameterHelpArgumentNameIs("a"); +verify.currentParameterSpanIs("a: T"); - // goTo.marker("4"); - // verify.currentParameterHelpArgumentNameIs("M"); - // verify.currentParameterSpanIs("M extends IFoo"); +goTo.marker("4"); +verify.currentParameterHelpArgumentNameIs("M"); +verify.currentParameterSpanIs("M extends IFoo"); - // goTo.marker("5"); - // verify.currentParameterHelpArgumentNameIs("M"); - // verify.currentParameterSpanIs("M extends IFoo"); - - // goTo.marker("construcor1"); - // verify.currentSignatureHelpIs("testClass(a: T, b: U, c: M): testClass"); - // verify.currentParameterHelpArgumentNameIs("T"); - // verify.currentParameterSpanIs("T extends IFoo"); - - // goTo.marker("construcor2"); - // verify.currentParameterHelpArgumentNameIs("U"); - // verify.currentParameterSpanIs("U"); - - //goTo.marker("construcor3"); - //verify.currentParameterHelpArgumentNameIs("T"); - //verify.currentParameterSpanIs("T extends IFoo"); - - // goTo.marker("construcor4"); - // verify.currentParameterHelpArgumentNameIs("M"); - // verify.currentParameterSpanIs("M extends IFoo"); - - // goTo.marker("construcor5"); - // verify.currentParameterHelpArgumentNameIs("U"); - // verify.currentParameterSpanIs("U"); - - // goTo.marker("type1"); - // verify.signatureHelpCountIs(1); - // verify.currentSignatureHelpIs("testClass"); - // verify.currentParameterHelpArgumentNameIs("T"); - // verify.currentParameterSpanIs("T extends IFoo"); - - // goTo.marker("type2"); - // verify.signatureHelpCountIs(1); - // verify.currentParameterHelpArgumentNameIs("T"); - // verify.currentParameterSpanIs("T extends IFoo"); - - // goTo.marker("type3"); - // verify.signatureHelpCountIs(1); - // verify.currentParameterHelpArgumentNameIs("T"); - // verify.currentParameterSpanIs("T extends IFoo"); - - // goTo.marker("type4"); - // verify.signatureHelpCountIs(1); - // verify.currentParameterHelpArgumentNameIs("M"); - // verify.currentParameterSpanIs("M extends IFoo"); \ No newline at end of file +goTo.marker("5"); +verify.currentParameterHelpArgumentNameIs("M"); +verify.currentParameterSpanIs("M extends IFoo"); \ No newline at end of file diff --git a/tests/cases/fourslash/genericParameterHelpConstructorCalls.ts b/tests/cases/fourslash/genericParameterHelpConstructorCalls.ts new file mode 100644 index 00000000000..4cbe141fcce --- /dev/null +++ b/tests/cases/fourslash/genericParameterHelpConstructorCalls.ts @@ -0,0 +1,35 @@ +/// + +////interface IFoo { } +//// +////class testClass { +//// constructor(a:T, b:U, c:M){ } +////} +//// +////// Constructor calls +////new testClass(null, null, null) +////new testClass<,,/*construcor4*/>(null, null, null) +////new testClass(null, null, null) + + // goTo.marker("construcor1"); + // verify.currentSignatureHelpIs("testClass(a: T, b: U, c: M): testClass"); + // verify.currentParameterHelpArgumentNameIs("T"); + // verify.currentParameterSpanIs("T extends IFoo"); + + // goTo.marker("construcor2"); + // verify.currentParameterHelpArgumentNameIs("U"); + // verify.currentParameterSpanIs("U"); + +goTo.marker("construcor3"); +verify.currentParameterHelpArgumentNameIs("T"); +verify.currentParameterSpanIs("T extends IFoo"); + +goTo.marker("construcor4"); +verify.currentParameterHelpArgumentNameIs("M"); +verify.currentParameterSpanIs("M extends IFoo"); + +goTo.marker("construcor5"); +verify.currentParameterHelpArgumentNameIs("U"); +verify.currentParameterSpanIs("U"); diff --git a/tests/cases/fourslash/genericParameterHelpTypeReferences.ts b/tests/cases/fourslash/genericParameterHelpTypeReferences.ts new file mode 100644 index 00000000000..346cf7191c1 --- /dev/null +++ b/tests/cases/fourslash/genericParameterHelpTypeReferences.ts @@ -0,0 +1,34 @@ +/// + +////interface IFoo { } +//// +////class testClass { +//// constructor(a:T, b:U, c:M){ } +////} +//// +////// Generic types +////testClass extends testClass; + + // goTo.marker("type1"); + // verify.signatureHelpCountIs(1); + // verify.currentSignatureHelpIs("testClass"); + // verify.currentParameterHelpArgumentNameIs("T"); + // verify.currentParameterSpanIs("T extends IFoo"); + + // goTo.marker("type2"); + // verify.signatureHelpCountIs(1); + // verify.currentParameterHelpArgumentNameIs("T"); + // verify.currentParameterSpanIs("T extends IFoo"); + + // goTo.marker("type3"); + // verify.signatureHelpCountIs(1); + // verify.currentParameterHelpArgumentNameIs("T"); + // verify.currentParameterSpanIs("T extends IFoo"); + + // goTo.marker("type4"); + // verify.signatureHelpCountIs(1); + // verify.currentParameterHelpArgumentNameIs("M"); + // verify.currentParameterSpanIs("M extends IFoo"); \ No newline at end of file diff --git a/tests/cases/fourslash/genericTypeArgumentInference1.ts b/tests/cases/fourslash/genericTypeArgumentInference1.ts index 96d603b939c..5c30363d35c 100644 --- a/tests/cases/fourslash/genericTypeArgumentInference1.ts +++ b/tests/cases/fourslash/genericTypeArgumentInference1.ts @@ -18,9 +18,9 @@ ////var /*4*/r4 = _./*41*/all([true], _.identity); goTo.marker('1'); -verify.quickInfoIs('(var) r: {}'); +verify.quickInfoIs('(var) r: string | number | boolean'); goTo.marker('11'); -verify.quickInfoIs('(method) Underscore.Static.all<{}>(list: {}[], iterator?: Underscore.Iterator<{}, boolean>, context?: any): {}'); +verify.quickInfoIs('(method) Underscore.Static.all(list: (string | number | boolean)[], iterator?: Underscore.Iterator, context?: any): string | number | boolean'); goTo.marker('2'); verify.quickInfoIs('(var) r2: boolean'); @@ -37,4 +37,4 @@ verify.quickInfoIs('(var) r4: any'); goTo.marker('41'); verify.quickInfoIs('(method) Underscore.Static.all(list: any[], iterator?: Underscore.Iterator, context?: any): any'); -verify.numberOfErrorsInCurrentFile(0); +verify.numberOfErrorsInCurrentFile(0); \ No newline at end of file diff --git a/tests/cases/fourslash/genericTypeArgumentInference2.ts b/tests/cases/fourslash/genericTypeArgumentInference2.ts index 0ae5114b133..bb59cc8eed6 100644 --- a/tests/cases/fourslash/genericTypeArgumentInference2.ts +++ b/tests/cases/fourslash/genericTypeArgumentInference2.ts @@ -18,9 +18,9 @@ ////var /*4*/r4 = _./*41*/all([true], _.identity); goTo.marker('1'); -verify.quickInfoIs('(var) r: {}'); +verify.quickInfoIs('(var) r: string | number | boolean'); goTo.marker('11'); -verify.quickInfoIs('(method) Underscore.Static.all<{}>(list: {}[], iterator?: Underscore.Iterator<{}, boolean>, context?: any): {}'); +verify.quickInfoIs('(method) Underscore.Static.all(list: (string | number | boolean)[], iterator?: Underscore.Iterator, context?: any): string | number | boolean'); goTo.marker('2'); verify.quickInfoIs('(var) r2: boolean'); diff --git a/tests/cases/fourslash/getEmitOutputWithDeclarationFile.ts b/tests/cases/fourslash/getEmitOutputWithDeclarationFile.ts new file mode 100644 index 00000000000..b45b2eff467 --- /dev/null +++ b/tests/cases/fourslash/getEmitOutputWithDeclarationFile.ts @@ -0,0 +1,18 @@ +/// + +// @BaselineFile: getEmitOutputWithDeclarationFile.baseline + +// @Filename: decl.d.ts +// @emitThisFile: true +//// interface I { a: string; } + +// @Filename: inputFile2.ts +// @emitThisFile: true +//// var x1: string = "hello world"; +//// class Foo{ +//// x : string; +//// y : number; +//// } + +debugger; +verify.baselineGetEmitOutput(); \ No newline at end of file diff --git a/tests/cases/fourslash/getEmitOutputWithDeclarationFile2.ts b/tests/cases/fourslash/getEmitOutputWithDeclarationFile2.ts new file mode 100644 index 00000000000..a36ac606189 --- /dev/null +++ b/tests/cases/fourslash/getEmitOutputWithDeclarationFile2.ts @@ -0,0 +1,18 @@ +/// + +// @BaselineFile: getEmitOutputWithDeclarationFile2.baseline + +// @Filename: decl.d.ts +// @emitThisFile: true +//// interface I { a: string; } + +// @Filename: inputFile2.ts +// @emitThisFile: true +//// export class Foo { } + +// @Filename: inputFile3.ts +// @emitThisFile: true +//// var x:string = "hello"; + +debugger; +verify.baselineGetEmitOutput(); \ No newline at end of file diff --git a/tests/cases/fourslash/getEmitOutputWithDeclarationFile3.ts b/tests/cases/fourslash/getEmitOutputWithDeclarationFile3.ts new file mode 100644 index 00000000000..1fce5434c1f --- /dev/null +++ b/tests/cases/fourslash/getEmitOutputWithDeclarationFile3.ts @@ -0,0 +1,23 @@ +/// + +// @BaselineFile: getEmitOutputWithDeclarationFile3.baseline +// @out: declSingle.js + +// @Filename: decl.d.ts +//// interface I { a: string; } + +// @Filename: inputFile2.ts +//// export class Foo { } + +// @Filename: inputFile3.ts +// @emitThisFile: true +//// var x:string = "hello"; + +// @Filename: inputFile4.ts +//// var x1:number = 1000; + +// @Filename: inputFile5.js +//// var x2 = 1000; + +debugger; +verify.baselineGetEmitOutput(); \ No newline at end of file diff --git a/tests/cases/fourslash/goToDefinitionUnionTypeProperty.ts b/tests/cases/fourslash/goToDefinitionUnionTypeProperty.ts new file mode 100644 index 00000000000..74b5e2aad8a --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionUnionTypeProperty.ts @@ -0,0 +1,24 @@ +/// + +////interface One { +//// /*propertyDefinition1*/commonProperty: number; +//// commonFunction(): number; +////} +//// +////interface Two { +//// /*propertyDefinition2*/commonProperty: string +//// commonFunction(): number; +////} +//// +////var x : One | Two; +//// +////x./*propertyReference*/commonProperty; +////x./*3*/commonFunction; + +goTo.marker("propertyReference"); +goTo.definition(0); +verify.caretAtMarker("propertyDefinition1"); + +goTo.marker("propertyReference"); +goTo.definition(1); +verify.caretAtMarker("propertyDefinition2"); diff --git a/tests/cases/fourslash/goToDefinitionUnionTypeProperty2.ts b/tests/cases/fourslash/goToDefinitionUnionTypeProperty2.ts new file mode 100644 index 00000000000..6536bb76e7d --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionUnionTypeProperty2.ts @@ -0,0 +1,25 @@ +/// +////interface HasAOrB { +//// /*propertyDefinition1*/a: string; +//// b: string; +////} +//// +////interface One { +//// common: { /*propertyDefinition2*/a : number; }; +////} +//// +////interface Two { +//// common: HasAOrB; +////} +//// +////var x : One | Two; +//// +////x.common./*propertyReference*/a; + +goTo.marker("propertyReference"); +goTo.definition(0); +verify.caretAtMarker("propertyDefinition1"); + +goTo.marker("propertyReference"); +goTo.definition(1); +verify.caretAtMarker("propertyDefinition2"); diff --git a/tests/cases/fourslash/mergedDeclarationsWithExportAssignment1.ts b/tests/cases/fourslash/mergedDeclarationsWithExportAssignment1.ts index be5376d5de5..3198b6e9243 100644 --- a/tests/cases/fourslash/mergedDeclarationsWithExportAssignment1.ts +++ b/tests/cases/fourslash/mergedDeclarationsWithExportAssignment1.ts @@ -19,7 +19,7 @@ edit.insert(''); goTo.marker('1'); -verify.quickInfoIs('(alias) Foo'); +verify.quickInfoIs("import Foo = require('mergedDeclarationsWithExportAssignment1_file0')"); goTo.marker('2'); verify.completionListContains('Foo'); diff --git a/tests/cases/fourslash/quickInfoInWithBlock.ts b/tests/cases/fourslash/quickInfoInWithBlock.ts index 9a765251f6f..c58ffa56560 100644 --- a/tests/cases/fourslash/quickInfoInWithBlock.ts +++ b/tests/cases/fourslash/quickInfoInWithBlock.ts @@ -7,10 +7,10 @@ goTo.marker('1'); -verify.quickInfoIs(""); +verify.quickInfoIs("any"); goTo.marker('2'); -verify.quickInfoIs(""); +verify.quickInfoIs("any"); goTo.marker('3'); -verify.quickInfoIs(""); \ No newline at end of file +verify.quickInfoIs("any"); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoOnArgumentsInsideFunction.ts b/tests/cases/fourslash/quickInfoOnArgumentsInsideFunction.ts new file mode 100644 index 00000000000..6f08b15da7b --- /dev/null +++ b/tests/cases/fourslash/quickInfoOnArgumentsInsideFunction.ts @@ -0,0 +1,8 @@ +/// + +////function foo(x: string) { +//// return /*1*/arguments; +////} + +goTo.marker('1'); +verify.quickInfoIs('(local var) arguments: IArguments'); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoOnInternalAliases.ts b/tests/cases/fourslash/quickInfoOnInternalAliases.ts new file mode 100644 index 00000000000..b1c562df494 --- /dev/null +++ b/tests/cases/fourslash/quickInfoOnInternalAliases.ts @@ -0,0 +1,59 @@ +/// + +/////** Module comment*/ +////export module m1 { +//// /** m2 comments*/ +//// export module m2 { +//// /** class comment;*/ +//// export class /*1*/c { +//// }; +//// } +//// export function foo() { +//// } +////} +/////**This is on import declaration*/ +////import /*2*/internalAlias = m1.m2./*3*/c; +////var /*4*/newVar = new /*5*/internalAlias(); +////var /*6*/anotherAliasVar = /*7*/internalAlias; +////import /*8*/internalFoo = m1./*9*/foo; +////var /*10*/callVar = /*11*/internalFoo(); +////var /*12*/anotherAliasFoo = /*13*/internalFoo; + +goTo.marker('1'); +verify.quickInfoIs("class m1.m2.c", "class comment;"); + +goTo.marker('2'); +verify.quickInfoIs('import internalAlias = m1.m2.c', "This is on import declaration"); + +goTo.marker('3'); +verify.quickInfoIs("class m1.m2.c", "class comment;"); + +goTo.marker('4'); +verify.quickInfoIs("(var) newVar: internalAlias", ""); + +goTo.marker('5'); +verify.quickInfoIs("(alias) new internalAlias(): internalAlias\nimport internalAlias = m1.m2.c", ""); + +goTo.marker('6'); +verify.quickInfoIs("(var) anotherAliasVar: typeof internalAlias", ""); + +goTo.marker('7'); +verify.quickInfoIs("import internalAlias = m1.m2.c", "This is on import declaration"); + +goTo.marker('8'); +verify.quickInfoIs('import internalFoo = m1.foo', ""); + +goTo.marker('9'); +verify.quickInfoIs("(function) m1.foo(): void", ""); + +goTo.marker('10'); +verify.quickInfoIs("(var) callVar: void", ""); + +goTo.marker('11'); +verify.quickInfoIs("(alias) internalFoo(): void\nimport internalFoo = m1.foo", ""); + +goTo.marker('12'); +verify.quickInfoIs("(var) anotherAliasFoo: () => void", ""); + +goTo.marker('13'); +verify.quickInfoIs("import internalFoo = m1.foo", ""); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoOnMergedInterfacesWithIncrementalEdits.ts b/tests/cases/fourslash/quickInfoOnMergedInterfacesWithIncrementalEdits.ts index e14d08ccd69..5f6b3483084 100644 --- a/tests/cases/fourslash/quickInfoOnMergedInterfacesWithIncrementalEdits.ts +++ b/tests/cases/fourslash/quickInfoOnMergedInterfacesWithIncrementalEdits.ts @@ -18,7 +18,7 @@ goTo.marker('1'); verify.quickInfoIs("(property) B.bar: string", undefined); edit.deleteAtCaret(1); edit.insert('z'); -verify.quickInfoIs(""); +verify.quickInfoIs("any"); verify.numberOfErrorsInCurrentFile(1); edit.backspace(1); edit.insert('a'); diff --git a/tests/cases/fourslash/quickInfoOnThis.ts b/tests/cases/fourslash/quickInfoOnThis.ts index daf34fd5764..c4eecfca5d5 100644 --- a/tests/cases/fourslash/quickInfoOnThis.ts +++ b/tests/cases/fourslash/quickInfoOnThis.ts @@ -12,4 +12,4 @@ ////} goTo.marker(); -verify.quickInfoIs(''); +verify.quickInfoIs('any'); diff --git a/tests/cases/fourslash/quickInfoOnUndefined.ts b/tests/cases/fourslash/quickInfoOnUndefined.ts index 252da49d4fe..1bb516d2c18 100644 --- a/tests/cases/fourslash/quickInfoOnUndefined.ts +++ b/tests/cases/fourslash/quickInfoOnUndefined.ts @@ -3,6 +3,13 @@ ////function foo(a: string) { ////} ////foo(/*1*/undefined); +////var x = { +//// undefined: 10 +////}; +////x./*2*/undefined = 30; goTo.marker('1'); -verify.quickInfoIs('(var) undefined'); \ No newline at end of file +verify.quickInfoIs('(var) undefined'); + +goTo.marker('2'); +verify.quickInfoIs('(property) undefined: number'); \ No newline at end of file diff --git a/tests/cases/fourslash/quickinfoForUnionProperty.ts b/tests/cases/fourslash/quickinfoForUnionProperty.ts new file mode 100644 index 00000000000..b5c7dc0a01c --- /dev/null +++ b/tests/cases/fourslash/quickinfoForUnionProperty.ts @@ -0,0 +1,27 @@ +/// + +////interface One { +//// commonProperty: number; +//// commonFunction(): number; +////} +//// +////interface Two { +//// commonProperty: string +//// commonFunction(): number; +////} +//// +////var /*1*/x : One | Two; +//// +////x./*2*/commonProperty; +////x./*3*/commonFunction; + + +goTo.marker("1"); +verify.quickInfoIs('(var) x: One | Two'); + + +goTo.marker("2"); +verify.quickInfoIs('(property) commonProperty: string | number'); + +goTo.marker("3"); +verify.quickInfoIs('(method) commonFunction(): number'); diff --git a/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts b/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts index f21f6cc3936..15dd5720019 100644 --- a/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts +++ b/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts @@ -1,5 +1,5 @@ -/// - +/// + ////interface IFoo { /*1*/xy: number; } //// ////// Assignment @@ -23,10 +23,10 @@ ////var w: IFoo = { /*4*/xy: undefined }; //// ////// Untped -- should not be included -////var u = { xy: 0 }; - - -test.markers().forEach((m) => { - goTo.position(m.position, m.fileName); - verify.referencesCountIs(9); -}); +////var u = { xy: 0 }; + + +test.markers().forEach((m) => { + goTo.position(m.position, m.fileName); + verify.referencesCountIs(9); +}); diff --git a/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts new file mode 100644 index 00000000000..f9c479de769 --- /dev/null +++ b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts @@ -0,0 +1,40 @@ +/// + +////interface A { +//// a: number; +//// common: string; +////} +//// +////interface B { +//// b: number; +//// common: number; +////} +//// +////// Assignment +////var v1: A | B = { a: 0, /*1*/common: "" }; +////var v2: A | B = { b: 0, /*2*/common: 3 }; +//// +////// Function call +////function consumer(f: A | B) { } +////consumer({ a: 0, b: 0, /*3*/common: 1 }); +//// +////// Type cast +////var c = { /*4*/common: 0, b: 0 }; +//// +////// Array literal +////var ar: Array = [{ a: 0, /*5*/common: "" }, { b: 0, /*6*/common: 0 }]; +//// +////// Nested object literal +////var ob: { aorb: A|B } = { aorb: { b: 0, /*7*/common: 0 } }; +//// +////// Widened type +////var w: A|B = { a:0, /*8*/common: undefined }; +//// +////// Untped -- should not be included +////var u1 = { a: 0, b: 0, common: "" }; +////var u2 = { b: 0, common: 0 }; + +test.markers().forEach((m) => { + goTo.position(m.position, m.fileName); + verify.referencesCountIs(10); // 8 contextually typed common, and 2 in definition (A.common, B.common) +}); diff --git a/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts new file mode 100644 index 00000000000..bbcc482a6e7 --- /dev/null +++ b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts @@ -0,0 +1,40 @@ +/// + +////interface A { +//// a: number; +//// common: string; +////} +//// +////interface B { +//// /*1*/b: number; +//// common: number; +////} +//// +////// Assignment +////var v1: A | B = { a: 0, common: "" }; +////var v2: A | B = { /*2*/b: 0, common: 3 }; +//// +////// Function call +////function consumer(f: A | B) { } +////consumer({ a: 0, /*3*/b: 0, common: 1 }); +//// +////// Type cast +////var c = { common: 0, /*4*/b: 0 }; +//// +////// Array literal +////var ar: Array = [{ a: 0, common: "" }, { /*5*/b: 0, common: 0 }]; +//// +////// Nested object literal +////var ob: { aorb: A|B } = { aorb: { /*6*/b: 0, common: 0 } }; +//// +////// Widened type +////var w: A|B = { /*7*/b:undefined, common: undefined }; +//// +////// Untped -- should not be included +////var u1 = { a: 0, b: 0, common: "" }; +////var u2 = { b: 0, common: 0 }; + +test.markers().forEach((m) => { + goTo.position(m.position, m.fileName); + verify.referencesCountIs(7); +}); diff --git a/tests/cases/fourslash/referencesForUnionProperties.ts b/tests/cases/fourslash/referencesForUnionProperties.ts new file mode 100644 index 00000000000..f4ef85e8e4e --- /dev/null +++ b/tests/cases/fourslash/referencesForUnionProperties.ts @@ -0,0 +1,35 @@ +/// + +////interface One { +//// common: { /*1*/a: number; }; +////} +//// +////interface Base { +//// /*2*/a: string; +//// b: string; +////} +//// +////interface HasAOrB extends Base { +//// /*3*/a: string; +//// b: string; +////} +//// +////interface Two { +//// common: HasAOrB; +////} +//// +////var x : One | Two; +//// +////x.common./*4*/a; + +goTo.marker("1"); +verify.referencesCountIs(2); // One.common.a, x.common.a + +goTo.marker("2"); +verify.referencesCountIs(3); // Base.a, HasAOrB.a, x.common.a + +goTo.marker("3"); +verify.referencesCountIs(3); // Base.a, HasAOrB.a, x.common.a + +goTo.marker("4"); +verify.referencesCountIs(4); // One.common.a, Base.a, HasAOrB.a, x.common.a \ No newline at end of file diff --git a/tests/cases/fourslash/selfReferencedExternalModule.ts b/tests/cases/fourslash/selfReferencedExternalModule.ts index ec312ccb1e5..f5e955839c7 100644 --- a/tests/cases/fourslash/selfReferencedExternalModule.ts +++ b/tests/cases/fourslash/selfReferencedExternalModule.ts @@ -5,5 +5,5 @@ ////A./**/I goTo.marker(); -verify.completionListContains("A", "(alias) A"); +verify.completionListContains("A", "import A = require('app')"); verify.completionListContains("I", "(var) I: number"); \ No newline at end of file diff --git a/tests/cases/fourslash/semanticClassification1.ts b/tests/cases/fourslash/semanticClassification1.ts index ad9e88ea842..4eb7f2a32ed 100644 --- a/tests/cases/fourslash/semanticClassification1.ts +++ b/tests/cases/fourslash/semanticClassification1.ts @@ -1,11 +1,15 @@ /// -//// module M { -//// export interface I { +//// module /*0*/M { +//// export interface /*1*/I { //// } //// } -//// interface X extends M.I { } +//// interface /*2*/X extends /*3*/M./*4*/I { } var c = classification; verify.semanticClassificationsAre( - c.moduleName("M"), c.interfaceName("I"), c.interfaceName("X"), c.moduleName("M"), c.interfaceName("I")); + c.moduleName("M", test.marker("0").position), + c.interfaceName("I", test.marker("1").position), + c.interfaceName("X", test.marker("2").position), + c.moduleName("M", test.marker("3").position), + c.interfaceName("I", test.marker("4").position)); diff --git a/tests/cases/fourslash/semanticClassification2.ts b/tests/cases/fourslash/semanticClassification2.ts index 810636dba3e..f7f6340e5bd 100644 --- a/tests/cases/fourslash/semanticClassification2.ts +++ b/tests/cases/fourslash/semanticClassification2.ts @@ -1,6 +1,6 @@ /// -//// interface Thing { +//// interface /*0*/Thing { //// toExponential(): number; //// } //// @@ -8,4 +8,4 @@ //// Thing.toExponential(); var c = classification; -verify.semanticClassificationsAre(c.interfaceName("Thing")); \ No newline at end of file +verify.semanticClassificationsAre(c.interfaceName("Thing", test.marker("0").position)); \ No newline at end of file diff --git a/tests/cases/fourslash/semanticClassificationInstantiatedModuleWithVariableOfSameName1.ts b/tests/cases/fourslash/semanticClassificationInstantiatedModuleWithVariableOfSameName1.ts new file mode 100644 index 00000000000..2b8b6824558 --- /dev/null +++ b/tests/cases/fourslash/semanticClassificationInstantiatedModuleWithVariableOfSameName1.ts @@ -0,0 +1,24 @@ +/// + +////module /*0*/M { +//// export interface /*1*/I { +//// } +//// var x = 10; +////} +//// +////var /*2*/M = { +//// foo: 10, +//// bar: 20 +////} +//// +////var v: /*3*/M./*4*/I; +//// +////var x = /*5*/M; + +var c = classification; +verify.semanticClassificationsAre( + c.moduleName("M", test.marker("0").position), + c.interfaceName("I", test.marker("1").position), + c.moduleName("M", test.marker("3").position), + c.interfaceName("I", test.marker("4").position), + c.moduleName("M", test.marker("5").position)); diff --git a/tests/cases/fourslash/semanticClassificationInstantiatedModuleWithVariableOfSameName2.ts b/tests/cases/fourslash/semanticClassificationInstantiatedModuleWithVariableOfSameName2.ts new file mode 100644 index 00000000000..5d2ed9844cc --- /dev/null +++ b/tests/cases/fourslash/semanticClassificationInstantiatedModuleWithVariableOfSameName2.ts @@ -0,0 +1,28 @@ +/// + +////module /*0*/M { +//// export interface /*1*/I { +//// } +////} +//// +////module /*2*/M { +//// var x = 10; +////} +//// +////var /*3*/M = { +//// foo: 10, +//// bar: 20 +////} +//// +////var v: /*4*/M./*5*/I; +//// +////var x = /*6*/M; + +var c = classification; +verify.semanticClassificationsAre( + c.moduleName("M", test.marker("0").position), + c.interfaceName("I", test.marker("1").position), + c.moduleName("M", test.marker("2").position), + c.moduleName("M", test.marker("4").position), + c.interfaceName("I", test.marker("5").position), + c.moduleName("M", test.marker("6").position)); diff --git a/tests/cases/fourslash/semanticClassificationModules.ts b/tests/cases/fourslash/semanticClassificationModules.ts new file mode 100644 index 00000000000..86c2819983a --- /dev/null +++ b/tests/cases/fourslash/semanticClassificationModules.ts @@ -0,0 +1,19 @@ +/// + +////module /*0*/M { +//// export var v; +//// export interface /*1*/I { +//// } +////} +//// +////var x: /*2*/M./*3*/I = /*4*/M.v; +////var y = /*5*/M; + +var c = classification; +verify.semanticClassificationsAre( + c.moduleName("M", test.marker("0").position), + c.interfaceName("I", test.marker("1").position), + c.moduleName("M", test.marker("2").position), + c.interfaceName("I", test.marker("3").position), + c.moduleName("M", test.marker("4").position), + c.moduleName("M", test.marker("5").position)); \ No newline at end of file diff --git a/tests/cases/fourslash/semanticClassificationUninstantiatedModuleWithVariableOfSameName1.ts b/tests/cases/fourslash/semanticClassificationUninstantiatedModuleWithVariableOfSameName1.ts new file mode 100644 index 00000000000..e7486c2c0cb --- /dev/null +++ b/tests/cases/fourslash/semanticClassificationUninstantiatedModuleWithVariableOfSameName1.ts @@ -0,0 +1,14 @@ +/// + +////declare module /*0*/M { +//// interface /*1*/I { +//// +//// } +////} +//// +////var M = { I: 10 }; + +var c = classification; +verify.semanticClassificationsAre( + c.moduleName("M", test.marker("0").position), + c.interfaceName("I", test.marker("1").position)); \ No newline at end of file diff --git a/tests/cases/fourslash/semanticClassificationUninstantiatedModuleWithVariableOfSameName2.ts b/tests/cases/fourslash/semanticClassificationUninstantiatedModuleWithVariableOfSameName2.ts new file mode 100644 index 00000000000..f90efd7518d --- /dev/null +++ b/tests/cases/fourslash/semanticClassificationUninstantiatedModuleWithVariableOfSameName2.ts @@ -0,0 +1,22 @@ +/// + +////module /*0*/M { +//// export interface /*1*/I { +//// } +////} +//// +////var /*2*/M = { +//// foo: 10, +//// bar: 20 +////} +//// +////var v: /*3*/M./*4*/I; +//// +////var x = /*5*/M; + +var c = classification; +verify.semanticClassificationsAre( + c.moduleName("M", test.marker("0").position), + c.interfaceName("I", test.marker("1").position), + c.moduleName("M", test.marker("3").position), + c.interfaceName("I", test.marker("4").position)); diff --git a/tests/cases/fourslash/semanticClassificationWithUnionTypes.ts b/tests/cases/fourslash/semanticClassificationWithUnionTypes.ts new file mode 100644 index 00000000000..40a7f409685 --- /dev/null +++ b/tests/cases/fourslash/semanticClassificationWithUnionTypes.ts @@ -0,0 +1,24 @@ +////module /*0*/M { +//// export interface /*1*/I { +//// } +////} +//// +////interface /*2*/I { +////} +////class /*3*/C { +////} +//// +////var M: /*4*/M./*5*/I | /*6*/I | /*7*/C; +////var I: typeof M | typeof /*8*/C; + +var c = classification; +verify.semanticClassificationsAre( + c.moduleName("M", test.marker("0").position), + c.interfaceName("I", test.marker("1").position), + c.interfaceName("I", test.marker("2").position), + c.className("C", test.marker("3").position), + c.moduleName("M", test.marker("4").position), + c.interfaceName("I", test.marker("5").position), + c.interfaceName("I", test.marker("6").position), + c.className("C", test.marker("7").position), + c.className("C", test.marker("8").position)); \ No newline at end of file diff --git a/tests/cases/fourslash/signatureHelpOnNestedOverloads.ts b/tests/cases/fourslash/signatureHelpOnNestedOverloads.ts index 476d79a8243..e657000c113 100644 --- a/tests/cases/fourslash/signatureHelpOnNestedOverloads.ts +++ b/tests/cases/fourslash/signatureHelpOnNestedOverloads.ts @@ -15,6 +15,6 @@ verify.currentParameterSpanIs("x: string"); edit.insert("'',"); verify.signatureHelpCountIs(2); -// verify.currentSignatureHelpIs("fn2(x: string, y: number): any"); -// verify.currentParameterHelpArgumentNameIs("y"); -// verify.currentParameterSpanIs("y: number"); +verify.currentSignatureHelpIs("fn2(x: string, y: number): any"); +verify.currentParameterHelpArgumentNameIs("y"); +verify.currentParameterSpanIs("y: number"); diff --git a/tests/cases/fourslash/symbolNameAtUnparseableFunctionOverload.ts b/tests/cases/fourslash/symbolNameAtUnparseableFunctionOverload.ts index cda1084bf79..2ad60dbb6bc 100644 --- a/tests/cases/fourslash/symbolNameAtUnparseableFunctionOverload.ts +++ b/tests/cases/fourslash/symbolNameAtUnparseableFunctionOverload.ts @@ -10,4 +10,4 @@ //// goTo.marker(); -verify.not.quickInfoExists(); +verify.quickInfoExists(); \ No newline at end of file diff --git a/tests/cases/fourslash/syntacticClassifications1.ts b/tests/cases/fourslash/syntacticClassifications1.ts index e70a4b672ff..88f655683a3 100644 --- a/tests/cases/fourslash/syntacticClassifications1.ts +++ b/tests/cases/fourslash/syntacticClassifications1.ts @@ -18,7 +18,6 @@ //// } //// } -debugger; var c = classification; verify.syntacticClassificationsAre( c.comment("// comment"), diff --git a/tests/cases/fourslash/syntacticClassificationsFunctionWithComments.ts b/tests/cases/fourslash/syntacticClassificationsFunctionWithComments.ts new file mode 100644 index 00000000000..eeaf4a7033f --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationsFunctionWithComments.ts @@ -0,0 +1,25 @@ +/// + +/////** +//// * This is my function. +//// * There are many like it, but this one is mine. +//// */ +////function myFunction(/* x */ x: any) { +//// var y = x ? x++ : ++x; +////} +////// end of file + +var firstCommentText = +"\ +/**\n\ + * This is my function.\n\ + * There are many like it, but this one is mine.\n\ + */"; + +var c = classification; +verify.syntacticClassificationsAre( + c.comment(firstCommentText), + c.keyword("function"), c.text("myFunction"), c.punctuation("("), c.comment("/* x */"), c.text("x"), c.punctuation(":"), c.keyword("any"), c.punctuation(")"), c.punctuation("{"), + c.keyword("var"), c.text("y"), c.operator("="), c.text("x"), c.operator("?"), c.text("x"), c.operator("++"), c.operator(":"), c.operator("++"), c.text("x"), c.punctuation(";"), + c.punctuation("}"), + c.comment("// end of file")); \ No newline at end of file diff --git a/tests/cases/fourslash/syntacticClassificationsObjectLiteral.ts b/tests/cases/fourslash/syntacticClassificationsObjectLiteral.ts new file mode 100644 index 00000000000..a7e8f7b7b07 --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationsObjectLiteral.ts @@ -0,0 +1,25 @@ +/// + +////var v = 10e0; +////var x = { +//// p1: 1, +//// p2: 2, +//// any: 3, +//// function: 4, +//// var: 5, +//// void: void 0, +//// v: v += v, +////}; + +var c = classification; +verify.syntacticClassificationsAre( + c.keyword("var"), c.text("v"), c.operator("="), c.numericLiteral("10e0"), c.punctuation(";"), + c.keyword("var"), c.text("x"), c.operator("="), c.punctuation("{"), + c.text("p1"), c.punctuation(":"), c.numericLiteral("1"), c.punctuation(","), + c.text("p2"), c.punctuation(":"), c.numericLiteral("2"), c.punctuation(","), + c.text("any"), c.punctuation(":"), c.numericLiteral("3"), c.punctuation(","), + c.text("function"), c.punctuation(":"), c.numericLiteral("4"), c.punctuation(","), + c.text("var"), c.punctuation(":"), c.numericLiteral("5"), c.punctuation(","), + c.text("void"), c.punctuation(":"), c.keyword("void"), c.numericLiteral("0"), c.punctuation(","), + c.text("v"), c.punctuation(":"), c.text("v"), c.operator("+="), c.text("v"), c.punctuation(","), + c.punctuation("}"), c.punctuation(";")); \ No newline at end of file diff --git a/tests/cases/unittests/services/colorization.ts b/tests/cases/unittests/services/colorization.ts index ee5350a25eb..3031cefb56c 100644 --- a/tests/cases/unittests/services/colorization.ts +++ b/tests/cases/unittests/services/colorization.ts @@ -1,4 +1,7 @@ -interface Classification { +/// +/// + +interface Classification { position: number; length: number; class: ts.TokenClass; @@ -66,7 +69,7 @@ describe('Colorization', function () { function numberLiteral(text: string) { return { value: text, class: ts.TokenClass.NumberLiteral }; } function stringLiteral(text: string) { return { value: text, class: ts.TokenClass.StringLiteral }; } function regExpLiteral(text: string) { return { value: text, class: ts.TokenClass.RegExpLiteral }; } - function finalEndOfLineState(value: number) { return { value: value, class: undefined }; } + function finalEndOfLineState(value: number) { return { value: value, class: undefined }; } function test(text: string, initialEndOfLineState: ts.EndOfLineState, ...expectedEntries: ClassificationEntry[]): void { var result = getClassifications(text, initialEndOfLineState); @@ -253,7 +256,7 @@ describe('Colorization', function () { identifier("Foo"), operator("<"), identifier("Foo"), - punctuation(","), + operator(","), identifier("Foo"), operator("<"), identifier("number"), @@ -265,8 +268,8 @@ describe('Colorization', function () { identifier("Foo"), operator("<"), identifier("Foo"), - operator(">" - identifier("keyword"), + operator(">"), + keyword("number"), finalEndOfLineState(ts.EndOfLineState.Start)); }); }); diff --git a/tests/cases/unittests/services/documentRegistry.ts b/tests/cases/unittests/services/documentRegistry.ts index a7ed030f44c..88503149715 100644 --- a/tests/cases/unittests/services/documentRegistry.ts +++ b/tests/cases/unittests/services/documentRegistry.ts @@ -5,8 +5,8 @@ describe("DocumentRegistry", () => { var documentRegistry = ts.createDocumentRegistry(); var defaultCompilerOptions = ts.getDefaultCompilerOptions(); - var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false); - var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false); + var f1 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false); + var f2 = documentRegistry.acquireDocument("file1.ts", defaultCompilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false); assert(f1 === f2, "DocumentRegistry should return the same document for the same name"); }); @@ -17,21 +17,21 @@ describe("DocumentRegistry", () => { // change compilation setting that doesn't affect parsing - should have the same document compilerOptions.declaration = true; - var f1 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false); + var f1 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false); compilerOptions.declaration = false; - var f2 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false); + var f2 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false); assert(f1 === f2, "Expected to have the same document instance"); // change value of compilation setting that is used during production of AST - new document is required compilerOptions.target = ts.ScriptTarget.ES3; - var f3 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false); + var f3 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false); assert(f1 !== f3, "Changed target: Expected to have different instances of document"); compilerOptions.module = ts.ModuleKind.CommonJS; - var f4 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), 1, false); + var f4 = documentRegistry.acquireDocument("file1.ts", compilerOptions, TypeScript.ScriptSnapshot.fromString("var x = 1;"), "1", false); assert(f1 !== f4, "Changed module: Expected to have different instances of document"); });