diff --git a/.gitignore b/.gitignore index 3147b8e8724..58a45545939 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ tests/baselines/reference/projectOutput/* tests/baselines/local/projectOutput/* tests/services/baselines/prototyping/local/* tests/services/browser/typescriptServices.js +scripts/configureNightly.js scripts/processDiagnosticMessages.d.ts scripts/processDiagnosticMessages.js scripts/importDefinitelyTypedTests.js diff --git a/AUTHORS.md b/AUTHORS.md new file mode 100644 index 00000000000..0ade4c31221 --- /dev/null +++ b/AUTHORS.md @@ -0,0 +1,70 @@ +TypeScript is authored by: + +* Adam Freidin +* Ahmad Farid +* Anders Hejlsberg +* Arnav Singh +* Arthur Ozga +* Basarat Ali Syed +* Ben Duffield +* Bill Ticehurst +* Bryan Forbes +* Caitlin Potter +* Chris Bubernak +* Colby Russell +* Colin Snover +* Cyrus Najmabadi +* Dan Quirk +* Daniel Rosenwasser +* David Li +* Dick van den Brink +* Dirk Bäumer +* Frank Wallis +* Gabriel Isenberg +* Gilad Peleg +* Guillaume Salles +* Harald Niesche +* Ingvar Stepanyan +* Ivo Gabe de Wolff +* James Whitney +* Jason Freeman +* Jason Ramsay +* Jed Mao +* Johannes Rieken +* Jonathan Bond-Caron +* Jonathan Park +* Jonathan Turner +* Josh Kalderimis +* Kagami Sascha Rosylight +* Keith Mashinter +* Kenji Imamula +* Lorant Pinter +* Masahiro Wakame +* Max Deepfield +* Micah Zoltu +* Mohamed Hegazy +* Oleg Mihailik +* Oleksandr Chekhovskyi +* Paul van Brenk +* Pedro Maltez +* Philip Bulley +* piloopin +* Ron Buckton +* Ryan Cavanaugh +* Sheetal Nandi +* Shengping Zhong +* Shyyko Serhiy +* Simon Hürlimann +* Solal Pirelli +* Stan Thomas +* Steve Lucco +* Tien Hoanhtien +* Tingan Ho +* togru +* Tomas Grubliauskas +* TruongSinh Tran-Nguyen +* Vladimir Matveev +* Wesley Wigham +* Yui Tanglertsampan +* Zev Spitz +* Zhengbo Li \ No newline at end of file diff --git a/Jakefile.js b/Jakefile.js index bd5074b43d6..52df2d15e47 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -17,7 +17,7 @@ var docDirectory = "doc/"; var builtDirectory = "built/"; var builtLocalDirectory = "built/local/"; -var LKGDirectory = "bin/"; +var LKGDirectory = "lib/"; var copyright = "CopyrightNotice.txt"; var thirdParty = "ThirdPartyNoticeText.txt"; @@ -138,6 +138,7 @@ var harnessSources = harnessCoreSources.concat([ "services/documentRegistry.ts", "services/preProcessFile.ts", "services/patternMatcher.ts", + "session.ts", "versionCache.ts", "convertToBase64.ts", "transpile.ts" @@ -217,7 +218,7 @@ var compilerFilename = "tsc.js"; function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, outDir, preserveConstEnums, keepComments, noResolve, stripInternal, callback) { file(outFile, prereqs, function() { var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory; - var options = "--module commonjs -noImplicitAny"; + var options = "--module commonjs --noImplicitAny --noEmitOnError"; // Keep comments when specifically requested // or when in debug mode. @@ -313,7 +314,7 @@ var processDiagnosticMessagesTs = path.join(scriptsDirectory, "processDiagnostic var diagnosticMessagesJson = path.join(compilerDirectory, "diagnosticMessages.json"); var diagnosticInfoMapTs = path.join(compilerDirectory, "diagnosticInformationMap.generated.ts"); -file(processDiagnosticMessagesTs) +file(processDiagnosticMessagesTs); // processDiagnosticMessages script compileFile(processDiagnosticMessagesJs, @@ -338,12 +339,50 @@ file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson], complete(); }); ex.run(); -}, {async: true}) +}, {async: true}); desc("Generates a diagnostic file in TypeScript based on an input JSON file"); -task("generate-diagnostics", [diagnosticInfoMapTs]) +task("generate-diagnostics", [diagnosticInfoMapTs]); +// Publish nightly +var configureNightlyJs = path.join(scriptsDirectory, "configureNightly.js"); +var configureNightlyTs = path.join(scriptsDirectory, "configureNightly.ts"); +var packageJson = "package.json"; +var programTs = path.join(compilerDirectory, "program.ts"); + +file(configureNightlyTs); + +compileFile(/*outfile*/configureNightlyJs, + /*sources*/ [configureNightlyTs], + /*prereqs*/ [configureNightlyTs], + /*prefixes*/ [], + /*useBuiltCompiler*/ false, + /*noOutFile*/ false, + /*generateDeclarations*/ false, + /*outDir*/ undefined, + /*preserveConstEnums*/ undefined, + /*keepComments*/ false, + /*noResolve*/ false, + /*stripInternal*/ false); + +task("setDebugMode", function() { + useDebugMode = true; +}); + +task("configure-nightly", [configureNightlyJs], function() { + var cmd = "node " + configureNightlyJs + " " + packageJson + " " + programTs; + console.log(cmd); + exec(cmd); +}, { async: true }); + +desc("Configure, build, test, and publish the nightly release."); +task("publish-nightly", ["configure-nightly", "LKG", "clean", "setDebugMode", "runtests"], function () { + var cmd = "npm publish --tag next"; + console.log(cmd); + exec(cmd); +}); + // Local target to build the compiler and services var tscFile = path.join(builtLocalDirectory, compilerFilename); compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false); @@ -440,11 +479,11 @@ file(specMd, [word2mdJs, specWord], function () { child_process.exec(cmd, function () { complete(); }); -}, {async: true}) +}, {async: true}); desc("Generates a Markdown version of the Language Specification"); -task("generate-spec", [specMd]) +task("generate-spec", [specMd]); // Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory @@ -576,7 +615,7 @@ task("runtests", ["tests", builtLocalDirectory], function() { exec(cmd, deleteTemporaryProjectOutput); }, {async: true}); -desc("Generates code coverage data via instanbul") +desc("Generates code coverage data via instanbul"); task("generate-code-coverage", ["tests", builtLocalDirectory], function () { var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run; console.log(cmd); @@ -619,7 +658,7 @@ task("runtests-browser", ["tests", "browserify", builtLocalDirectory], function( function getDiffTool() { var program = process.env['DIFF'] if (!program) { - fail("Add the 'DIFF' environment variable to the path of the program you want to use.") + fail("Add the 'DIFF' environment variable to the path of the program you want to use."); } return program; } @@ -628,14 +667,14 @@ function getDiffTool() { desc("Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable"); task('diff', function () { var cmd = '"' + getDiffTool() + '" ' + refBaseline + ' ' + localBaseline; - console.log(cmd) + console.log(cmd); exec(cmd); }, {async: true}); desc("Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable"); task('diff-rwc', function () { var cmd = '"' + getDiffTool() + '" ' + refRwcBaseline + ' ' + localRwcBaseline; - console.log(cmd) + console.log(cmd); exec(cmd); }, {async: true}); @@ -736,9 +775,9 @@ task("lint", [], function() { function failure(f) { return function() { console.log('FAILURE: Please fix linting errors in ' + f + '\n') }}; var lintTargets = compilerSources.concat(harnessCoreSources); - for(var i in lintTargets) { + for (var i in lintTargets) { var f = lintTargets[i]; - var cmd = 'tslint -f ' + f; + var cmd = 'tslint -c tslint.json ' + f; exec(cmd, success(f), failure(f)); } }, { async: true }); diff --git a/README.md b/README.md index 57dfe06c67c..c8bc5936c24 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,19 @@ [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). +## Installing + +For the latest stable version: + +``` +npm install -g typescript +``` + +For our nightly builds: + +``` +npm install -g typescript@next +``` ## Contribute @@ -63,7 +76,8 @@ jake runtests # Run tests using the built compiler and test infrastructu # Use host= or tests=. jake runtests-browser # Runs the tests using the built run.js file. Syntax is jake runtests. Optional parameters 'host=', 'tests=[regex], reporter=[list|spec|json|]'. -jake baseline-accept # This replaces the baseline test results with the results obtained from jake runtests. +jake baseline-accept # This replaces the baseline test results with the results obtained from jake runtests. +jake lint # Runs tslint on the TypeScript source. jake -T # List the above commands. ``` diff --git a/bin/tsc b/bin/tsc index 3c0dab574f2..19c62bf7a00 100755 --- a/bin/tsc +++ b/bin/tsc @@ -1,2 +1,2 @@ #!/usr/bin/env node -require('./tsc.js') +require('../lib/tsc.js') diff --git a/bin/tsserver b/bin/tsserver old mode 100644 new mode 100755 index 003eb0d22af..7143b6a73ab --- a/bin/tsserver +++ b/bin/tsserver @@ -1,2 +1,2 @@ #!/usr/bin/env node -require('./tsserver.js') +require('../lib/tsserver.js') diff --git a/doc/TypeScript Language Specification (Change Markup).docx b/doc/TypeScript Language Specification (Change Markup).docx index fd2688234c3..893f2e7ed22 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 7cb0009047b..1b4faab62e1 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 62604fa5bc4..4aaa3bf92fe 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 e28d6f2d7f4..277fcecf2de 100644 Binary files a/doc/TypeScript Language Specification.pdf and b/doc/TypeScript Language Specification.pdf differ diff --git a/doc/spec.md b/doc/spec.md index cff436d5fc0..fe2147be477 100644 --- a/doc/spec.md +++ b/doc/spec.md @@ -1,12 +1,12 @@ # TypeScript Language Specification -Version 1.5 +Version 1.6 -February, 2015 +August, 2015
-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](http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0). TypeScript is a trademark of Microsoft Corporation. @@ -24,10 +24,14 @@ TypeScript is a trademark of Microsoft Corporation. * [1.7 Enum Types](#1.7) * [1.8 Overloading on String Parameters](#1.8) * [1.9 Generic Types and Functions](#1.9) - * [1.10 Modules](#1.10) + * [1.10 Namespaces](#1.10) + * [1.11 Modules](#1.11) * [2 Basic Concepts](#2) * [2.1 Grammar Conventions](#2.1) - * [2.2 Namespaces and Named Types](#2.2) + * [2.2 Names](#2.2) + * [2.2.1 Reserved Words](#2.2.1) + * [2.2.2 Property Names](#2.2.2) + * [2.2.3 Computed Property Names](#2.2.3) * [2.3 Declarations](#2.3) * [2.4 Scopes](#2.4) * [3 Types](#3) @@ -36,11 +40,12 @@ TypeScript is a trademark of Microsoft Corporation. * [3.2.1 The Number Type](#3.2.1) * [3.2.2 The Boolean Type](#3.2.2) * [3.2.3 The String Type](#3.2.3) - * [3.2.4 The Void Type](#3.2.4) - * [3.2.5 The Null Type](#3.2.5) - * [3.2.6 The Undefined Type](#3.2.6) - * [3.2.7 Enum Types](#3.2.7) - * [3.2.8 String Literal Types](#3.2.8) + * [3.2.4 The Symbol Type](#3.2.4) + * [3.2.5 The Void Type](#3.2.5) + * [3.2.6 The Null Type](#3.2.6) + * [3.2.7 The Undefined Type](#3.2.7) + * [3.2.8 Enum Types](#3.2.8) + * [3.2.9 String Literal Types](#3.2.9) * [3.3 Object Types](#3.3) * [3.3.1 Named Type References](#3.3.1) * [3.3.2 Array Types](#3.3.2) @@ -49,38 +54,40 @@ TypeScript is a trademark of Microsoft Corporation. * [3.3.5 Constructor Types](#3.3.5) * [3.3.6 Members](#3.3.6) * [3.4 Union Types](#3.4) - * [3.4.1 Contextual Union Types](#3.4.1) - * [3.5 Type Parameters](#3.5) - * [3.5.1 Type Parameter Lists](#3.5.1) - * [3.5.2 Type Argument Lists](#3.5.2) - * [3.6 Named Types](#3.6) - * [3.6.1 Instance Types](#3.6.1) - * [3.7 Specifying Types](#3.7) - * [3.7.1 Predefined Types](#3.7.1) - * [3.7.2 Type References](#3.7.2) - * [3.7.3 Object Type Literals](#3.7.3) - * [3.7.4 Array Type Literals](#3.7.4) - * [3.7.5 Tuple Type Literals](#3.7.5) - * [3.7.6 Union Type Literals](#3.7.6) - * [3.7.7 Function Type Literals](#3.7.7) - * [3.7.8 Constructor Type Literals](#3.7.8) - * [3.7.9 Type Queries](#3.7.9) - * [3.8 Specifying Members](#3.8) - * [3.8.1 Property Signatures](#3.8.1) - * [3.8.2 Call Signatures](#3.8.2) - * [3.8.3 Construct Signatures](#3.8.3) - * [3.8.4 Index Signatures](#3.8.4) - * [3.8.5 Method Signatures](#3.8.5) - * [3.9 Type Aliases](#3.9) - * [3.10 Type Relationships](#3.10) - * [3.10.1 Apparent Members](#3.10.1) - * [3.10.2 Type and Member Identity](#3.10.2) - * [3.10.3 Subtypes and Supertypes](#3.10.3) - * [3.10.4 Assignment Compatibility](#3.10.4) - * [3.10.5 Contextual Signature Instantiation](#3.10.5) - * [3.10.6 Type Inference](#3.10.6) - * [3.10.7 Recursive Types](#3.10.7) - * [3.11 Widened Types](#3.11) + * [3.5 Intersection Types](#3.5) + * [3.6 Type Parameters](#3.6) + * [3.6.1 Type Parameter Lists](#3.6.1) + * [3.6.2 Type Argument Lists](#3.6.2) + * [3.7 Named Types](#3.7) + * [3.7.1 Instance Types](#3.7.1) + * [3.8 Specifying Types](#3.8) + * [3.8.1 Predefined Types](#3.8.1) + * [3.8.2 Type References](#3.8.2) + * [3.8.3 Object Type Literals](#3.8.3) + * [3.8.4 Array Type Literals](#3.8.4) + * [3.8.5 Tuple Type Literals](#3.8.5) + * [3.8.6 Union Type Literals](#3.8.6) + * [3.8.7 Intersection Type Literals](#3.8.7) + * [3.8.8 Function Type Literals](#3.8.8) + * [3.8.9 Constructor Type Literals](#3.8.9) + * [3.8.10 Type Queries](#3.8.10) + * [3.9 Specifying Members](#3.9) + * [3.9.1 Property Signatures](#3.9.1) + * [3.9.2 Call Signatures](#3.9.2) + * [3.9.3 Construct Signatures](#3.9.3) + * [3.9.4 Index Signatures](#3.9.4) + * [3.9.5 Method Signatures](#3.9.5) + * [3.10 Type Aliases](#3.10) + * [3.11 Type Relationships](#3.11) + * [3.11.1 Apparent Members](#3.11.1) + * [3.11.2 Type and Member Identity](#3.11.2) + * [3.11.3 Subtypes and Supertypes](#3.11.3) + * [3.11.4 Assignment Compatibility](#3.11.4) + * [3.11.5 Excess Properties](#3.11.5) + * [3.11.6 Contextual Signature Instantiation](#3.11.6) + * [3.11.7 Type Inference](#3.11.7) + * [3.11.8 Recursive Types](#3.11.8) + * [3.12 Widened Types](#3.12) * [4 Expressions](#4) * [4.1 Values and References](#4.1) * [4.2 The this Keyword](#4.2) @@ -88,57 +95,61 @@ TypeScript is a trademark of Microsoft Corporation. * [4.4 Literals](#4.4) * [4.5 Object Literals](#4.5) * [4.6 Array Literals](#4.6) - * [4.7 Parentheses](#4.7) - * [4.8 The super Keyword](#4.8) - * [4.8.1 Super Calls](#4.8.1) - * [4.8.2 Super Property Access](#4.8.2) - * [4.9 Function Expressions](#4.9) - * [4.9.1 Standard Function Expressions](#4.9.1) - * [4.9.2 Arrow Function Expressions](#4.9.2) - * [4.9.3 Contextually Typed Function Expressions](#4.9.3) - * [4.10 Property Access](#4.10) - * [4.11 The new Operator](#4.11) - * [4.12 Function Calls](#4.12) - * [4.12.1 Overload Resolution](#4.12.1) - * [4.12.2 Type Argument Inference](#4.12.2) - * [4.12.3 Grammar Ambiguities](#4.12.3) - * [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.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.2 The + operator](#4.15.2) - * [4.15.3 The <, >, <=, >=, ==, !=, ===, and !== operators](#4.15.3) - * [4.15.4 The instanceof operator](#4.15.4) - * [4.15.5 The in operator](#4.15.5) - * [4.15.6 The && operator](#4.15.6) - * [4.15.7 The || operator](#4.15.7) - * [4.16 The Conditional Operator](#4.16) - * [4.17 Assignment Operators](#4.17) - * [4.17.1 Destructuring Assignment](#4.17.1) - * [4.18 The Comma Operator](#4.18) - * [4.19 Contextually Typed Expressions](#4.19) - * [4.20 Type Guards](#4.20) + * [4.7 Template Literals](#4.7) + * [4.8 Parentheses](#4.8) + * [4.9 The super Keyword](#4.9) + * [4.9.1 Super Calls](#4.9.1) + * [4.9.2 Super Property Access](#4.9.2) + * [4.10 Function Expressions](#4.10) + * [4.11 Arrow Functions](#4.11) + * [4.12 Class Expressions](#4.12) + * [4.13 Property Access](#4.13) + * [4.14 The new Operator](#4.14) + * [4.15 Function Calls](#4.15) + * [4.15.1 Overload Resolution](#4.15.1) + * [4.15.2 Type Argument Inference](#4.15.2) + * [4.15.3 Grammar Ambiguities](#4.15.3) + * [4.16 Type Assertions](#4.16) + * [4.17 JSX Expressions](#4.17) + * [4.18 Unary Operators](#4.18) + * [4.18.1 The ++ and -- operators](#4.18.1) + * [4.18.2 The +, –, and ~ operators](#4.18.2) + * [4.18.3 The ! operator](#4.18.3) + * [4.18.4 The delete Operator](#4.18.4) + * [4.18.5 The void Operator](#4.18.5) + * [4.18.6 The typeof Operator](#4.18.6) + * [4.19 Binary Operators](#4.19) + * [4.19.1 The *, /, %, –, <<, >>, >>>, &, ^, and | operators](#4.19.1) + * [4.19.2 The + operator](#4.19.2) + * [4.19.3 The <, >, <=, >=, ==, !=, ===, and !== operators](#4.19.3) + * [4.19.4 The instanceof operator](#4.19.4) + * [4.19.5 The in operator](#4.19.5) + * [4.19.6 The && operator](#4.19.6) + * [4.19.7 The || operator](#4.19.7) + * [4.20 The Conditional Operator](#4.20) + * [4.21 Assignment Operators](#4.21) + * [4.21.1 Destructuring Assignment](#4.21.1) + * [4.22 The Comma Operator](#4.22) + * [4.23 Contextually Typed Expressions](#4.23) + * [4.24 Type Guards](#4.24) * [5 Statements](#5) - * [5.1 Variable Statements](#5.1) - * [5.1.1 Simple Variable Declarations](#5.1.1) - * [5.1.2 Destructuring Variable Declarations](#5.1.2) - * [5.1.3 Implied Type](#5.1.3) - * [5.2 If, Do, and While Statements](#5.2) - * [5.3 For Statements](#5.3) - * [5.4 For-In Statements](#5.4) - * [5.5 Continue Statements](#5.5) - * [5.6 Break Statements](#5.6) - * [5.7 Return Statements](#5.7) - * [5.8 With Statements](#5.8) - * [5.9 Switch Statements](#5.9) - * [5.10 Throw Statements](#5.10) - * [5.11 Try Statements](#5.11) + * [5.1 Blocks](#5.1) + * [5.2 Variable Statements](#5.2) + * [5.2.1 Simple Variable Declarations](#5.2.1) + * [5.2.2 Destructuring Variable Declarations](#5.2.2) + * [5.2.3 Implied Type](#5.2.3) + * [5.3 Let and Const Declarations](#5.3) + * [5.4 If, Do, and While Statements](#5.4) + * [5.5 For Statements](#5.5) + * [5.6 For-In Statements](#5.6) + * [5.7 For-Of Statements](#5.7) + * [5.8 Continue Statements](#5.8) + * [5.9 Break Statements](#5.9) + * [5.10 Return Statements](#5.10) + * [5.11 With Statements](#5.11) + * [5.12 Switch Statements](#5.12) + * [5.13 Throw Statements](#5.13) + * [5.14 Try Statements](#5.14) * [6 Functions](#6) * [6.1 Function Declarations](#6.1) * [6.2 Function Overloads](#6.2) @@ -146,6 +157,8 @@ TypeScript is a trademark of Microsoft Corporation. * [6.4 Destructuring Parameter Declarations](#6.4) * [6.5 Generic Functions](#6.5) * [6.6 Code Generation](#6.6) + * [6.7 Generator Functions](#6.7) + * [6.8 Type Guard Functions](#6.8) * [7 Interfaces](#7) * [7.1 Interface Declarations](#7.1) * [7.2 Declaration Merging](#7.2) @@ -169,6 +182,7 @@ TypeScript is a trademark of Microsoft Corporation. * [8.4.1 Member Variable Declarations](#8.4.1) * [8.4.2 Member Function Declarations](#8.4.2) * [8.4.3 Member Accessor Declarations](#8.4.3) + * [8.4.4 Dynamic Property Declarations](#8.4.4) * [8.5 Index Member Declarations](#8.5) * [8.6 Code Generation](#8.6) * [8.6.1 Classes Without Extends Clauses](#8.6.1) @@ -179,31 +193,33 @@ TypeScript is a trademark of Microsoft Corporation. * [9.3 Declaration Merging](#9.3) * [9.4 Constant Enum Declarations](#9.4) * [9.5 Code Generation](#9.5) -* [10 Internal Modules](#10) - * [10.1 Module Declarations](#10.1) - * [10.2 Module Body](#10.2) - * [10.3 Import Declarations](#10.3) +* [10 Namespaces](#10) + * [10.1 Namespace Declarations](#10.1) + * [10.2 Namespace Body](#10.2) + * [10.3 Import Alias Declarations](#10.3) * [10.4 Export Declarations](#10.4) * [10.5 Declaration Merging](#10.5) * [10.6 Code Generation](#10.6) -* [11 Source Files and External Modules](#11) - * [11.1 Source Files](#11.1) +* [11 Scripts and Modules](#11) + * [11.1 Programs and Source Files](#11.1) * [11.1.1 Source Files Dependencies](#11.1.1) - * [11.2 External Modules](#11.2) - * [11.2.1 External Module Names](#11.2.1) - * [11.2.2 External Import Declarations](#11.2.2) - * [11.2.3 Export Declarations](#11.2.3) - * [11.2.4 Export Assignments](#11.2.4) - * [11.2.5 CommonJS Modules](#11.2.5) - * [11.2.6 AMD Modules](#11.2.6) + * [11.2 Scripts](#11.2) + * [11.3 Modules](#11.3) + * [11.3.1 Module Names](#11.3.1) + * [11.3.2 Import Declarations](#11.3.2) + * [11.3.3 Import Require Declarations](#11.3.3) + * [11.3.4 Export Declarations](#11.3.4) + * [11.3.5 Export Assignments](#11.3.5) + * [11.3.6 CommonJS Modules](#11.3.6) + * [11.3.7 AMD Modules](#11.3.7) * [12 Ambients](#12) * [12.1 Ambient Declarations](#12.1) * [12.1.1 Ambient Variable Declarations](#12.1.1) * [12.1.2 Ambient Function Declarations](#12.1.2) * [12.1.3 Ambient Class Declarations](#12.1.3) * [12.1.4 Ambient Enum Declarations](#12.1.4) - * [12.1.5 Ambient Module Declarations](#12.1.5) - * [12.2 Ambient External Module Declarations](#12.2) + * [12.1.5 Ambient Namespace Declarations](#12.1.5) + * [12.2 Ambient Module Declarations](#12.2) * [A Grammar](#A) * [A.1 Types](#A.1) * [A.2 Expressions](#A.2) @@ -212,8 +228,8 @@ TypeScript is a trademark of Microsoft Corporation. * [A.5 Interfaces](#A.5) * [A.6 Classes](#A.6) * [A.7 Enums](#A.7) - * [A.8 Internal Modules](#A.8) - * [A.9 Source Files and External Modules](#A.9) + * [A.8 Namespaces](#A.8) + * [A.9 Scripts and Modules](#A.9) * [A.10 Ambients](#A.10)
@@ -222,9 +238,11 @@ TypeScript is a trademark of Microsoft Corporation. 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. +TypeScript is a syntactic sugar for JavaScript. TypeScript syntax is a superset of ECMAScript 6 (ES6) 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. -TypeScript syntax includes several proposed features of Ecmascript 6 (ES6), including classes and modules. Classes enable programmers to express common object-oriented patterns in a standard way, making features like inheritance more readable and interoperable. Modules enable programmers to organize their code into components while avoiding naming conflicts. The TypeScript compiler provides module code generation options that support either static or dynamic loading of module contents. +TypeScript syntax includes all features of ECMAScript 6 (ES6), including classes and modules, and provides the ability to translate these features into ECMAScript 3 or 5 compliant code. + +Classes enable programmers to express common object-oriented patterns in a standard way, making features like inheritance more readable and interoperable. Modules enable programmers to organize their code into components while avoiding naming conflicts. The TypeScript compiler provides module code generation options that support either static or dynamic loading of module contents. 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. @@ -314,7 +332,7 @@ In this example, the second parameter to 'vote' has the function type which means the second parameter is a function returning type 'any' that has a single parameter of type 'string' named 'result'. -Section [3.8.2](#3.8.2) provides additional information about function types. +Section [3.9.2](#3.9.2) provides additional information about function types. ## 1.3 Object Types @@ -426,7 +444,7 @@ getX({ x: 0, y: 0, color: "red" }); // Extra fields Ok getX({ x: 0 }); // Error: supplied parameter does not match ``` -See section [3.10](#3.10) for more information about type comparisons. +See section [3.11](#3.11) for more information about type comparisons. ## 1.5 Contextual Typing @@ -452,13 +470,13 @@ $.get("http://mysite.org/divContent", Contextual typing is also useful for writing out object literals. As the programmer types the object literal, the contextual type provides information that enables tools to provide completion for object member names. -Section [4.19](#4.19) provides additional information about contextually typed expressions. +Section [4.23](#4.23) provides additional information about contextually typed expressions. ## 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 two very 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. TypeScript's namespaces are a formalization of the module pattern. (The term "module pattern" is somewhat unfortunate now that ECMAScript 6 formally supports modules in a manner different from what the module pattern prescribes. For this reason, TypeScript uses the term "namespace" for its formalization of the module pattern.) -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 namespace section below will show how TypeScript emits consistent, idiomatic JavaScript when emitting ECMAScript 3 or 5 compliant code for classes and namespaces. The goal of TypeScript's translation is to emit exactly what a programmer would type when implementing a class or namespace 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 { @@ -556,7 +574,7 @@ Section [8](#8) provides additional information about classes. TypeScript enables programmers to summarize a set of numeric constants as an *enum type*. The example below creates an enum type to represent operators in a calculator application. ```TypeScript -enum Operator { +const enum Operator { ADD, DIV, MUL, @@ -571,7 +589,7 @@ 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. -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. +When enums are declared with the `const` modifier, 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. @@ -622,7 +640,7 @@ In the following screen shot, a programming tool combines information from overl / -Section [3.8.2.4](#3.8.2.4) provides details on how to use string literals in function signatures. +Section [3.9.2.4](#3.9.2.4) provides details on how to use string literals in function signatures. ## 1.9 Generic Types and Functions @@ -686,13 +704,13 @@ class List { } ``` -Section [3.6](#3.6) provides further information about generic types. +Section [3.7](#3.7) provides further information about generic types. -## 1.10 Modules +## 1.10 Namespaces 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. +In JavaScript, a very common 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. The module pattern can also provide the ability to introduce namespaces, avoiding use of the global namespace for most software components. The following example illustrates the JavaScript module pattern. @@ -710,12 +728,12 @@ This example illustrates the two essential elements of the module pattern: a *mo 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. +TypeScript namespaces provide a mechanism for succinctly expressing the module pattern. In TypeScript, programmers can combine the module pattern with the class pattern by nesting namespaces and classes within an outer namespace. -The following example shows the definition and use of a simple module. +The following example shows the definition and use of a simple namespace. ```TypeScript -module M { +namespace M { var s = "hello"; export function f() { return s; @@ -726,7 +744,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 namespace, but function 'f' is exported from the namespace and accessible to code outside of the namespace. If we were to describe the effect of namespace 'M' in terms of interfaces and variables, we would write ```TypeScript interface M { @@ -736,9 +754,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 namespace '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. +The TypeScript compiler emits the following JavaScript code for the namespace: ```TypeScript var M; @@ -751,110 +769,200 @@ 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 namespace object resides in global variable 'M', which may or may not have been initialized to the desired namespace 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. +## 1.11 Modules + +TypeScript also supports ECMAScript 6 modules, which are files that contain top-level *export* and *import* directives. For this type of module the TypeScript compiler can emit both ECMAScript 6 compliant code and down-level ECMAScript 3 or 5 compliant code for a variety of module loading systems, including CommonJS, Asynchronous Module Definition (AMD), and Universal Module Definition (UMD).
#
2 Basic Concepts -The remainder of this document is the formal specification of the TypeScript programming language and is intended to be read as an adjunct to the ECMAScript Language Specification (specifically, the ECMA-262 Standard, 5th Edition). This document describes the syntactic grammar added by TypeScript along with the compile-time processing and type checking performed by the TypeScript compiler, but it only minimally discusses the run-time behavior of programs since that is covered by the ECMAScript specification. +The remainder of this document is the formal specification of the TypeScript programming language and is intended to be read as an adjunct to the [ECMAScript Language Specification](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf) (specifically, the ECMA-262 Standard, 6th Edition). This document describes the syntactic grammar added by TypeScript along with the compile-time processing and type checking performed by the TypeScript compiler, but it only minimally discusses the run-time behavior of programs since that is covered by the ECMAScript specification. ## 2.1 Grammar Conventions 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 )* +  *Declaration:* *( Modified )*    … -   `super` `(` *ArgumentListopt* `)` -   `super` `.` *IdentifierName* +   *InterfaceDeclaration* +   *TypeAliasDeclaration* +   *EnumDeclaration* 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. -## 2.2 Namespaces and Named Types +## 2.2 Names -TypeScript supports ***named types*** that can be organized in hierarchical ***namespaces***. Namespaces are introduced by module declarations and named types are introduced by class, interface, and enum declarations. Named types are denoted by qualified names that extend from some root module (possibly the global module) to the point of their declaration. The example +A core purpose of the TypeScript compiler is to track the named entities in a program and validate that they are used according to their designated meaning. Names in TypeScript can be written in several ways, depending on context. Specifically, a name can be written as + +* an *IdentifierName*, +* a *StringLiteral* in a property name, +* a *NumericLiteral* in a property name, or +* a *ComputedPropertyName* that denotes a well-known symbol ([2.2.3](#2.2.3)). + +Most commonly, names are written to conform with the *Identifier* production, which is any *IdentifierName* that isn't a reserved word. + +### 2.2.1 Reserved Words + +The following keywords are reserved and cannot be used as an *Identifier*: ```TypeScript -module X { - export module Y { - export interface Z { } - } - export interface Y { } +break case catch class +const continue debugger default +delete do else enum +export extends false finally +for function if import +in instanceof new null +return super switch this +throw true try typeof +var void while with +``` + +The following keywords cannot be used as identifiers in strict mode code, but are otherwise not restricted: + +```TypeScript +implements interface let package +private protected public static +yield +``` + +The following keywords cannot be used as user defined type names, but are otherwise not restricted: + +```TypeScript +any boolean number string +symbol +``` + +The following keywords have special meaning in certain contexts, but are valid identifiers: + +```TypeScript +abstract as async await +constructor declare from get +is module namespace of +require set type +``` + +### 2.2.2 Property Names + +The *PropertyName* production from the ECMAScript grammar is reproduced below: + +  *PropertyName:* +   *LiteralPropertyName* +   *ComputedPropertyName* + +  *LiteralPropertyName:* +   *IdentifierName* +   *StringLiteral* +   *NumericLiteral* + +  *ComputedPropertyName:* +   `[` *AssignmentExpression* `]` + +A property name can be any identifier (including a reserved word), a string literal, a numeric literal, or a computed property name. String literals may be used to give properties names that are not valid identifiers, such as names containing blanks. Numeric literal property names are equivalent to string literal property names with the string representation of the numeric literal, as defined in the ECMAScript specification. + +### 2.2.3 Computed Property Names + +ECMAScript 6 permits object literals and classes to declare members with computed property names. A computed property name specifies an expression that computes the actual property name at run-time. Because the final property name isn't known at compile-time, TypeScript can only perform limited checks for entities declared with computed property names. However, a subset of computed property names known as ***well-known symbols*** can be used anywhere a *PropertyName* is expected, including property names within types. A computed property name is a well-known symbol if it is of the form + +```TypeScript +[ Symbol . xxx ] +``` + +In a well-known symbol, the identifier to the right of the dot must denote a property of the primitive type `symbol` in the type of the global variable 'Symbol', or otherwise an error occurs. + +In a *PropertyName* that specifies a *ComputedPropertyName*, the computed property name is required to denote a well-known symbol unless the property name occurs in a property assignment of an object literal ([4.5](#4.5)) or a property member declaration in a non-ambient class ([8.4](#8.4)). + +Below is an example of an interface that declares a property with a well-known symbol name: + +```TypeScript +interface Iterable { + [Symbol.iterator](): Iterator; } ``` -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. - -The hierarchy formed by namespace and named type names partially mirrors that formed by module instances and members. The example - -```TypeScript -module A { - export module B { - export class C { } - } -} -``` - -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. - ## 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 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 function declaration (including constructor, member function, and member accessor declarations) and each function expression has a declaration space for locals (introduced by parameter, variable, and function declarations) 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. - -Top-level declarations in a source file with no top-level import or export declarations belong to the ***global module***. Top-level declarations in a source file with one or more top-level import or export declarations belong to the ***external module*** represented by that source file. - -An internal module declaration contributes a namespace name (representing a container of types) and possibly a member name (representing the module instance) to the containing module. A class declaration contributes both a member name (representing the constructor function) and a type name (representing the class type) to the containing module. An interface declaration contributes a type name to the containing module. An enum declaration contributes both a member name (representing the enum object) and a type name (representing the enum type) to the containing module. Any other declaration contributes a member name to the declaration space to which it belongs. - -The ***parent module*** of an entity is defined as follows: - -* The parent module of an entity declared in an internal module is that internal module. -* The parent module of an entity declared in an external module is that external module. -* The parent module of an entity declared in the global module is the global module. -* The parent module of an external module is the global module. - -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. - -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). - -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: +Declarations introduce names in their associated ***declaration spaces***. A name must be unique in its declaration space and can denote a ***value***, a ***type***, or a ***namespace***, or some combination thereof. Effectively, a single name can have as many as three distinct meanings. For example: ```TypeScript -module M { - module X { ... } // Namespace - interface X { ... } // Type - var X; // Member +var X: string; // Value named X + +type X = number; // Type named X + +namespace X { // Namespace named X + type Y = string; } ``` -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. +A name that denotes a value has an associated type (section [3](#3)) and can be referenced in expressions (section [4.3](#4.3)). A name that denotes a type can be used by itself in a type reference or on the right hand side of a dot in a type reference ([3.8.2](#3.8.2)). A name that denotes a namespace can be used one the left hand side of a dot in a type reference. -Instance and static members in a class are likewise in separate declaration spaces. Thus the following is permitted: +When a name with multiple meanings is referenced, the context in which the reference occurs determines the meaning. For example: + +```TypeScript +var n: X; // X references type +var s: X.Y = X; // First X references namespace, second X references value +``` + +In the first line, X references the type X because it occurs in a type position. In the second line, the first X references the namespace X because it occurs before a dot in a type name, and the second X references the variable X because it occurs in an expression. + +Declarations introduce the following meanings for the name they declare: + +* A variable, parameter, function, generator, member variable, member function, member accessor, or enum member declaration introduces a value meaning. +* An interface, type alias, or type parameter declaration introduces a type meaning. +* A class declaration introduces a value meaning (the constructor function) and a type meaning (the class instance type). +* An enum declaration introduces a value meaning (the enum instance) and a type meaning (the enum type). +* A namespace declaration introduces a namespace meaning (the type and namespace container) and, if the namespace is instantiated (section [10.1](#10.1)), a value meaning (the namespace instance). +* An import or export declaration introduces the meaning(s) of the imported or exported entity. + +Below are some examples of declarations that introduce multiple meanings for a name: + +```TypeScript +class C { // Value and type named C + x: string; +} + +namespace N { // Value and namespace named N + export var x: string; +} +``` + +Declaration spaces exist as follows: + +* The global namespace, each module, and each declared namespace has a declaration space for its contained entities (whether local or exported). +* Each module has a declaration space for its exported entities. All export declarations in the module contribute to this declaration space. +* Each declared namespace has a declaration space for its exported entities. All export declarations in the namespace contribute to this declaration space. A declared namespace’s declaration space is shared with other declared namespaces that have the same root container and the same qualified name starting from that root container. +* Each class declaration has a declaration space for instance members and type parameters, and a declaration space for static members. +* Each interface declaration has a declaration space for members and type parameters. An interface's declaration space is shared with other interfaces that have the same root container and the same qualified name starting from that root container. +* 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 container and the same qualified name starting from that root container. +* Each type alias declaration has a declaration space for its type parameters. +* Each function-like declaration (including function declarations, constructor declarations, member function declarations, member accessor declarations, function expressions, and arrow functions) has a declaration space for locals and type parameters. This declaration space includes parameter declarations, all local var and function declarations, and local let, const, class, interface, type alias, and enum declarations that occur immediately within the function body and are not further nested in blocks. +* Each statement block has a declaration space for local let, const, class, interface, type alias, and enum declarations that occur immediately within that block. +* Each object literal has a declaration space for its properties. +* Each object type literal has a declaration space for its members. + +Top-level declarations in a source file with no top-level import or export declarations belong to the ***global namespace***. Top-level declarations in a source file with one or more top-level import or export declarations belong to the ***module*** represented by that source file. + +The ***container*** of an entity is defined as follows: + +* The container of an entity declared in a namespace declaration is that namespace declaration. +* The container of an entity declared in a module is that module. +* The container of an entity declared in the global namespace is the global namespace. +* The container of a module is the global namespace. + +The ***root container*** of an entity is defined as follows: + +* The root container of a non-exported entity is the entity’s container. +* The root container of an exported entity is the root container of the entity's container. + +Intuitively, the root container of an entity is the outermost module or namespace body from within which the entity is reachable. + +Interfaces, enums, and namespaces are "open ended," meaning that interface, enum, and namespace 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). + +Instance and static members in a class are in separate declaration spaces. Thus the following is permitted: ```TypeScript class C { @@ -867,37 +975,41 @@ class C { The ***scope*** of a name is the region of program text within which it is possible to refer to the entity declared by that name without qualification of the name. The scope of a name depends on the context in which the name is declared. The contexts are listed below in order from outermost to innermost: -* The scope of an entity declared in the global module is the entire program text. -* The scope of an entity declared in an external module is the source file of that external module. -* The scope of an exported entity declared in an internal module is the body of that module and every internal module with the same root and the same qualified name relative to that root. -* The scope of a non-exported entity declared within an internal module declaration is the body of that internal module declaration. -* The scope of a type parameter declared in a class or interface declaration is that entire declaration, including constraints, extends clause, implements clause, and declaration body, but not including static member declarations. -* The scope of a member declared in an enum declaration is the body of that declaration and every enum declaration with the same root and the same qualified name relative to that root. -* The scope of a type parameter declared in a call or construct signature is that entire signature declaration, including constraints, parameter list, and return type. If the signature is part of a function implementation, the scope includes the function body. -* The scope of a local entity (parameter, variable, or function) declared within a function declaration (including a constructor, member function, or member accessor declaration) or function expression is the body of that function declaration or function expression. +* The scope of a name declared in the global namespace is the entire program text. +* The scope of a name declared in a module is the source file of that module. +* The scope of an exported name declared within a namespace declaration is the body of that namespace declaration and every namespace declaration with the same root and the same qualified name relative to that root. +* The scope of a non-exported name declared within a namespace declaration is the body of that namespace declaration. +* The scope of a type parameter name declared in a class or interface declaration is that entire declaration, including constraints, extends clause, implements clause, and declaration body, but not including static member declarations. +* The scope of a type parameter name declared in a type alias declaration is that entire type alias declaration. +* The scope of a member name declared in an enum declaration is the body of that declaration and every enum declaration with the same root and the same qualified name relative to that root. +* The scope of a type parameter name declared in a call or construct signature is that entire signature declaration, including constraints, parameter list, and return type. If the signature is part of a function implementation, the scope includes the function body. +* The scope of a parameter name declared in a call or construct signature is the remainder of the signature declaration. If the signature is part of a function-like declaration with a body (including a function declaration, constructor declaration, member function declaration, member accessor declaration, function expression, or arrow function), the scope includes the body of that function-like declaration. +* The scope of a local var or function name declared anywhere in the body of a function-like declaration is the body of that function-like declaration. +* The scope of a local let, const, class, interface, type alias, or enum declaration declared immediately within the body of a function-like declaration is the body of that function-like declaration. +* The scope of a local let, const, class, interface, type alias, or enum declaration declared immediately within a statement block is the body of that statement block. -Scopes may overlap, for example through nesting of modules and functions. When the scopes of two entities with the same name overlap, the entity with the innermost declaration takes precedence and access to the outer entity is either not possible or only possible by qualifying its name. +Scopes may overlap, for example through nesting of namespaces and functions. When the scopes of two names overlap, the name with the innermost declaration takes precedence and access to the outer name is either not possible or only possible by qualification. -When an identifier is resolved as a *TypeName* (section [3.7.2](#3.7.2)), only classes, interfaces, enums, and type parameters are considered and other entities in scope are ignored. +When an identifier is resolved as a *PrimaryExpression* (section [4.3](#4.3)), only names in scope with a value meaning are considered and other names are ignored. -When an identifier is resolved as a *ModuleName* (section [3.7.2](#3.7.2)), only modules are considered and other entities in scope are ignored. +When an identifier is resolved as a *TypeName* (section [3.8.2](#3.8.2)), only names in scope with a type meaning are considered and other names are ignored. -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. +When an identifier is resolved as a *NamespaceName* (section [3.8.2](#3.8.2)), only names in scope with a namespace meaning are considered and other names 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 members are never directly in scope—they can only be accessed by applying the dot ('.') operator to a class instance. 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: +As the rules above imply, locally declared entities in a namespace are closer in scope than exported entities declared in other namespace declarations for the same namespace. For example: ```TypeScript var x = 1; -module M { +namespace M { export var x = 2; console.log(x); // 2 } -module M { +namespace M { console.log(x); // 2 } -module M { +namespace M { var x = 3; console.log(x); // 3 } @@ -909,15 +1021,15 @@ module M { 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***, ***union types***, or ***type parameters***. These types introduce various static constraints on their values. +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***, ***union types***, ***intersection 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, Symbol, Void, Null, and Undefined types along with user defined enum types. The `number`, `boolean`, `string`, `symbol`, and `void` keywords reference the Number, Boolean, String, Symbol, 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, tuple, function, and constructor 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. -Union types represent values that can have one of multiple types. +Union types represent values that have one of multiple types, and intersection types represent values that simultaneously have more than one type. -Declarations of modules, classes, properties, functions, variables and other language entities associate types with those entities. The mechanism by which a type is formed and associated with a language entity depends on the particular kind of entity. For example, a module declaration associates the module with an anonymous type containing a set of properties corresponding to the exported variables and functions in the module, and a function declaration associates the function with an anonymous type containing a call signature corresponding to the parameters and return type of the function. Types can be associated with variables through explicit ***type annotations***, such as +Declarations of classes, properties, functions, variables and other language entities associate types with those entities. The mechanism by which a type is formed and associated with a language entity depends on the particular kind of entity. For example, a namespace declaration associates the namespace with an anonymous type containing a set of properties corresponding to the exported variables and functions in the namespace, and a function declaration associates the function with an anonymous type containing a call signature corresponding to the parameters and return type of the function. Types can be associated with variables through explicit ***type annotations***, such as ```TypeScript var x: number; @@ -953,7 +1065,7 @@ function f(x) { // Same as f(x: any): void ## 3.2 Primitive Types -The primitive types are the Number, Boolean, String, Void, Null, and Undefined types and all user defined enum types. +The primitive types are the Number, Boolean, String, Symbol, Void, Null, and Undefined types and all user defined enum types. ### 3.2.1 The Number Type @@ -961,7 +1073,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.10](#3.10)) 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.11](#3.11)) and accessing properties (section [4.13](#4.13)), the Number primitive type behaves as an object type with the same properties as the global interface type 'Number'. Some examples: @@ -978,7 +1090,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.10](#3.10)) 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.11](#3.11)) and accessing properties (section [4.13](#4.13)), the Boolean primitive type behaves as an object type with the same properties as the global interface type 'Boolean'. Some examples: @@ -994,7 +1106,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.10](#3.10)) 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.11](#3.11)) and accessing properties (section [4.13](#4.13)), the String primitive type behaves as an object type with the same properties as the global interface type 'String'. Some examples: @@ -1005,7 +1117,24 @@ var abc = 'abc'; // Same as abc: string = "abc" var c = abc.charAt(2); // Property of String interface ``` -### 3.2.4 The Void Type +### 3.2.4 The Symbol Type + +The Symbol primitive type corresponds to the similarly named JavaScript primitive type and represents unique tokens that may be used as keys for object properties. + +The `symbol` keyword references the Symbol primitive type. Symbol values are obtained using the global object 'Symbol' which has a number of methods and properties and can be invoked as a function. In particular, the global object 'Symbol' defines a number of well-known symbols ([2.2.3](#2.2.3)) that can be used in a manner similar to identifiers. Note that the 'Symbol' object is available only in ECMAScript 6 environments. + +For purposes of determining type relationships (section [3.11](#3.11)) and accessing properties (section [4.13](#4.13)), the Symbol primitive type behaves as an object type with the same properties as the global interface type 'Symbol'. + +Some examples: + +```TypeScript +var secretKey = Symbol(); +var obj = {}; +obj[secretKey] = "secret message"; // Use symbol as property key +obj[Symbol.toStringTag] = "test"; // Use of well-known symbol +``` + +### 3.2.5 The Void Type The Void type, referenced by the `void` keyword, represents the absence of a value and is used as the return type of functions with no return value. @@ -1013,13 +1142,13 @@ The only possible values for the Void type are `null` and `undefined`. The Void *NOTE: We might consider disallowing declaring variables of type Void as they serve no useful purpose. However, because Void is permitted as a type argument to a generic type or function it is not feasible to disallow Void properties or parameters*. -### 3.2.5 The Null Type +### 3.2.6 The Null Type The Null type corresponds to the similarly named JavaScript primitive type and is the type of the `null` literal. The `null` literal references the one and only value of the Null type. It is not possible to directly reference the Null type itself. -The Null type is a subtype of all types, except the Undefined type. This means that `null` is considered a valid value for all primitive types, object types, union types, and type parameters, including even the Number and Boolean primitive types. +The Null type is a subtype of all types, except the Undefined type. This means that `null` is considered a valid value for all primitive types, object types, union types, intersection types, and type parameters, including even the Number and Boolean primitive types. Some examples: @@ -1029,13 +1158,13 @@ var x = null; // Same as x: any = null var e: Null; // Error, can't reference Null type ``` -### 3.2.6 The Undefined Type +### 3.2.7 The Undefined Type The Undefined type corresponds to the similarly named JavaScript primitive type and is the type of the `undefined` literal. The `undefined` literal denotes the value given to all uninitialized variables and is the one and only value of the Undefined type. It is not possible to directly reference the Undefined type itself. -The undefined type is a subtype of all types. This means that `undefined` is considered a valid value for all primitive types, object types, union types, and type parameters. +The undefined type is a subtype of all types. This means that `undefined` is considered a valid value for all primitive types, object types, union types, intersection types, and type parameters. Some examples: @@ -1045,15 +1174,15 @@ var x = undefined; // Same as x: any = undefined var e: Undefined; // Error, can't reference Undefined type ``` -### 3.2.7 Enum Types +### 3.2.8 Enum Types -Enum types are distinct user defined subtypes of the Number primitive type. Enum types are declared using enum declarations (section [9.1](#9.1)) and referenced using type references (section [3.7.2](#3.7.2)). +Enum types are distinct user defined subtypes of the Number primitive type. Enum types are declared using enum declarations (section [9.1](#9.1)) and referenced using type references (section [3.8.2](#3.8.2)). Enum types are assignable to the Number primitive type, and vice versa, but different enum types are not assignable to each other. -### 3.2.8 String Literal Types +### 3.2.9 String Literal Types -Specialized signatures (section [3.8.2.4](#3.8.2.4)) permit string literals to be used as types in parameter type annotations. String literal types are permitted only in that context and nowhere else. +Specialized signatures (section [3.9.2.4](#3.9.2.4)) permit string literals to be used as types in parameter type annotations. String literal types are permitted only in that context and nowhere else. All string literal types are subtypes of the String primitive type. @@ -1061,26 +1190,26 @@ 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, union 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, 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.7.3](#3.7.3)). -* Array type literals (section [3.7.4](#3.7.4)). -* Tuple type literals (section [3.7.5](#3.7.5)). -* Function type literals (section [3.7.7](#3.7.7)). -* Constructor type literals (section [3.7.8](#3.7.8)). +* Object type literals (section [3.8.3](#3.8.3)). +* Array type literals (section [3.8.4](#3.8.4)). +* Tuple type literals (section [3.8.5](#3.8.5)). +* Function type literals (section [3.8.8](#3.8.8)). +* Constructor type literals (section [3.8.9](#3.8.9)). * 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)). +* Function expressions (section [4.10](#4.10)) and function declarations ([6.1](#6.1)). * Constructor function types created by class declarations (section [8.2.5](#8.2.5)). -* Module instance types created by module declarations (section [10.3](#10.3)). +* Namespace instance types created by namespace declarations (section [10.3](#10.3)). ### 3.3.1 Named Type References -Type references (section [3.7.2](#3.7.2)) to class and interface types are classified as object types. Type references to generic class and interface types include type arguments that are substituted for the type parameters of the class or interface to produce an actual object type. +Type references (section [3.8.2](#3.8.2)) to class and interface types are classified as object types. Type references to generic class and interface types include type arguments that are substituted for the type parameters of the class or interface to produce an actual object type. ### 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.7.4](#3.7.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 namespace with the array element type as a type argument. Array type literals (section [3.8.4](#3.8.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: @@ -1098,11 +1227,11 @@ Array literals (section [4.6](#4.6)) may be used to create values of array types var a: string[] = ["hello", "world"]; ``` -A type is said to be an ***array-like type*** if it is assignable (section [3.10.4](#3.10.4)) to the type `any[]`. +A type is said to be an ***array-like type*** if it is assignable (section [3.11.4](#3.11.4)) to the type `any[]`. ### 3.3.3 Tuple Types -***Tuple types*** represent JavaScript arrays with individually tracked element types. Tuple types are written using tuple type literals (section [3.7.5](#3.7.5)). A tuple type combines a set of numerically named properties with the members of an array type. Specifically, a tuple type +***Tuple types*** represent JavaScript arrays with individually tracked element types. Tuple types are written using tuple type literals (section [3.8.5](#3.8.5)). A tuple type combines a set of numerically named properties with the members of an array type. Specifically, a tuple type ```TypeScript [ T0, T1, ..., Tn ] @@ -1143,11 +1272,11 @@ A type is said to be a ***tuple-like type*** if it has a property with the numer ### 3.3.4 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.7.7](#3.7.7)) or by including call signatures in object type literals. +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.8.8](#3.8.8)) or by including call signatures in object type literals. ### 3.3.5 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.7.8](#3.7.8)) or by including construct signatures in object type literals. +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.8.9](#3.8.9)) or by including construct signatures in object type literals. ### 3.3.6 Members @@ -1160,22 +1289,16 @@ Every object type is composed from zero or more of the following kinds of member Properties are either ***public***, ***private***, or ***protected*** and are either ***required*** or ***optional***: -* Properties in a class declaration may be designated public, private, or protected, while properties declared in other contexts are always considered public. Private members are only accessible within their declaring class, as described in section [8.2.2](#8.2.2), and private properties match only themselves in subtype and assignment compatibility checks, as described in section [3.10](#3.10). Protected members are only accessible within their declaring class and classes derived from it, as described in section [8.2.2](#8.2.2), and protected properties match only themselves and overrides in subtype and assignment compatibility checks, as described in section [3.10](#3.10). -* Properties in an object type literal or interface declaration may be designated required or optional, while properties declared in other contexts are always considered required. Properties that are optional in the target type of an assignment may be omitted from source objects, as described in section [3.10.4](#3.10.4). +* Properties in a class declaration may be designated public, private, or protected, while properties declared in other contexts are always considered public. Private members are only accessible within their declaring class, as described in section [8.2.2](#8.2.2), and private properties match only themselves in subtype and assignment compatibility checks, as described in section [3.11](#3.11). Protected members are only accessible within their declaring class and classes derived from it, as described in section [8.2.2](#8.2.2), and protected properties match only themselves and overrides in subtype and assignment compatibility checks, as described in section [3.11](#3.11). +* Properties in an object type literal or interface declaration may be designated required or optional, while properties declared in other contexts are always considered required. Properties that are optional in the target type of an assignment may be omitted from source objects, as described in section [3.11.4](#3.11.4). -Call and construct signatures may be ***specialized*** (section [3.8.2.4](#3.8.2.4)) by including parameters with string literal types. Specialized signatures are used to express patterns where specific string values for some parameters cause the types of other parameters or the function result to become further specialized. +Call and construct signatures may be ***specialized*** (section [3.9.2.4](#3.9.2.4)) by including parameters with string literal types. Specialized signatures are used to express patterns where specific string values for some parameters cause the types of other parameters or the function result to become further specialized. ## 3.4 Union Types -***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.7.6](#3.7.6)). +***Union types*** represent values that may have one of several distinct 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.8.6](#3.8.6)). -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: - -* *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*. - -Union types are reduced to the smallest possible set of constituent types using these rules. +A union type encompasses an ordered set of constituent types. While it is generally true that *A* | *B* is equivalent to *B* | *A*, the order of the constituent types may matter when determining the call and construct signatures of the union type. Union types have the following subtype relationships: @@ -1187,9 +1310,9 @@ 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*. -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. +The || and conditional operators (section [4.19.7](#4.19.7) and [4.20](#4.20)) 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. +Type guards (section [4.24](#4.24)) 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 @@ -1209,7 +1332,7 @@ it is possible to assign 'x' a value of type `string`, `number`, or the union ty var n = typeof x === "string" ? x.length : x; // Type of n is number ``` -For purposes of property access and function calls, the apparent members (section [3.10.1](#3.10.1)) of a union type *U* are those that are present in every one of its constituent types, with types that are unions of the respective apparent members in the constituent types. The following example illustrates the merging of member types that occurs when union types are created from object types. +For purposes of property access and function calls, the apparent members (section [3.11.1](#3.11.1)) of a union type are those that are present in every one of its constituent types, with types that are unions of the respective apparent members in the constituent types. The following example illustrates the merging of member types that occurs when union types are created from object types. ```TypeScript interface A { @@ -1231,25 +1354,71 @@ 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.4.1 Contextual Union Types +When used as a contextual type (section [4.23](#4.23)), a union type 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, a union type used as a contextual type has the apparent members defined in section [3.11.1](#3.11.1), except that a particular member need only be present in one or more constituent types instead of all constituent types. -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: +## 3.5 Intersection Types -* 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*. +***Intersection types*** represent values that simultaneously have multiple types. A value of an intersection type *A* & *B* is a value that is *both* of type *A* and type *B*. Intersection types are written using intersection type literals (section [3.8.7](#3.8.7)). -## 3.5 Type Parameters +An intersection type encompasses an ordered set of constituent types. While it is generally true that *A* & *B* is equivalent to *B* & *A*, the order of the constituent types may matter when determining the call and construct signatures of the intersection type. + +Intersection types have the following subtype relationships: + +* An intersection type *I* is a subtype of a type *T* if any type in *I* is a subtype of *T*. +* A type *T* is a subtype of an intersection type *I* if *T* is a subtype of each type in *I*. + +Similarly, intersection types have the following assignability relationships: + +* An intersection type *I* is assignable to a type *T* if any type in *I* is assignable to *T*. +* A type *T* is assignable to an intersection type *I* if *T* is assignable to each type in *I*. + +For purposes of property access and function calls, the apparent members (section [3.11.1](#3.11.1)) of an intersection type are those that are present in one or more of its constituent types, with types that are intersections of the respective apparent members in the constituent types. The following examples illustrate the merging of member types that occurs when intersection types are created from object types. + +```TypeScript +interface A { a: number } +interface B { b: number } + +var ab: A & B = { a: 1, b: 1 }; +var a: A = ab; // A & B assignable to A +var b: B = ab; // A & B assignable to B + +interface X { p: A } +interface Y { p: B } + +var xy: X & Y = { p: ab }; // X & Y has property p of type A & B + +type F1 = (a: string, b: string) => void; +type F2 = (a: number, b: number) => void; + +var f: F1 & F2 = (a: string | number, b: string | number) => { }; +f("hello", "world"); // Ok +f(1, 2); // Ok +f(1, "test"); // Error +``` + +The union and intersection type operators can be applied to type parameters. This capability can for example be used to model functions that merge objects: + +```TypeScript +function extend(first: T, second: U): T & U { + // Extend first with properties of second +} + +var x = extend({ a: "hello" }, { b: 42 }); +var s = x.a; +var n = x.b; +``` + +It is possible to create intersection types for which no values other than null or undefined are possible. For example, intersections of primitive types such as `string & number` fall into this category. + +## 3.6 Type Parameters A type parameter represents an actual type that the parameter is bound to in a generic type reference or a generic function call. Type parameters have constraints that establish upper bounds for their actual type arguments. Since a type parameter represents a multitude of different type arguments, type parameters have certain restrictions compared to other types. In particular, a type parameter cannot be used as a base class or interface. -### 3.5.1 Type Parameter Lists +### 3.6.1 Type Parameter Lists -Class, interface, and function declarations may optionally include lists of type parameters enclosed in < and > brackets. Type parameters are also permitted in call signatures of object, function, and constructor type literals. +Class, interface, type alias, and function declarations may optionally include lists of type parameters enclosed in < and > brackets. Type parameters are also permitted in call signatures of object, function, and constructor type literals.   *TypeParameters:*    `<` *TypeParameterList* `>` @@ -1259,7 +1428,7 @@ Class, interface, and function declarations may optionally include lists of type    *TypeParameterList* `,` *TypeParameter*   *TypeParameter:* -   *Identifier* *Constraintopt* +   *BindingIdentifier* *Constraintopt*   *Constraint:*    `extends` *Type* @@ -1268,7 +1437,7 @@ Type parameter names must be unique. A compile-time error occurs if two or more The scope of a type parameter extends over the entire declaration with which the type parameter list is associated, with the exception of static member declarations in classes. -Each type parameter has an associated type parameter ***constraint*** that establishes an upper bound for type arguments. Omitting a constraint corresponds to specifying the empty object type `{}`. Type parameters declared in a particular type parameter list may not be referenced in constraints in that type parameter list. +Each type parameter has an associated type parameter ***constraint*** that establishes an upper bound for type arguments. Omitting a constraint or specifying type `any` as the constraint corresponds to specifying the empty object type `{}`. Type parameters declared in a particular type parameter list may not be referenced in constraints in that type parameter list. The ***base constraint*** of a type parameter *T* is defined as follows: @@ -1286,11 +1455,11 @@ interface G { 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.10](#3.10)), 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. +For purposes of determining type relationships (section [3.11](#3.11)), type parameters appear to be subtypes of their base constraint. Likewise, in property accesses (section [4.13](#4.13)), `new` operations (section [4.14](#4.14)), and function calls (section [4.15](#4.15)), type parameters appear to have the members of their base constraint, but no other members. -### 3.5.2 Type Argument Lists +### 3.6.2 Type Argument Lists -A type reference (section [3.7.2](#3.7.2)) to a generic type must include a list of type arguments enclosed in angle brackets and separated by commas. Similarly, a call (section [4.12](#4.12)) to a generic function may explicitly include a type argument list instead of relying on type inference. +A type reference (section [3.8.2](#3.8.2)) to a generic type must include a list of type arguments enclosed in angle brackets and separated by commas. Similarly, a call (section [4.15](#4.15)) to a generic function may explicitly include a type argument list instead of relying on type inference.   *TypeArguments:*    `<` *TypeArgumentList* `>` @@ -1302,7 +1471,7 @@ A type reference (section [3.7.2](#3.7.2)) to a generic type must include a list   *TypeArgument:*    *Type* -Type arguments correspond one-to-one with type parameters of the generic type or function being referenced. A type argument list is required to specify exactly one type argument for each corresponding type parameter, and each type argument is required to ***satisfy*** the constraint of its corresponding type parameter. A type argument satisfies a type parameter constraint if the type argument is assignable to (section [3.10.4](#3.10.4)) the constraint type once type arguments are substituted for type parameters. +Type arguments correspond one-to-one with type parameters of the generic type or function being referenced. A type argument list is required to specify exactly one type argument for each corresponding type parameter, and each type argument is required to ***satisfy*** the constraint of its corresponding type parameter. A type argument satisfies a type parameter constraint if the type argument is assignable to (section [3.11.4](#3.11.4)) the constraint type once type arguments are substituted for type parameters. Given the declaration @@ -1314,13 +1483,13 @@ a type reference of the form 'G<A, B>' places no requirements on 'A' but requ 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. -## 3.6 Named Types +## 3.7 Named Types -Classes, interfaces, enums, and type aliases are ***named types*** that are introduced through class declarations (section [8.1](#8.1)), interface declarations (section [7.1](#7.1)), enum declarations ([9.1](#9.1)), and type alias declarations (section [3.9](#3.9)). 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***. +Classes, interfaces, enums, and type aliases are ***named types*** that are introduced through class declarations (section [8.1](#8.1)), interface declarations (section [7.1](#7.1)), enum declarations ([9.1](#9.1)), and type alias declarations (section [3.10](#3.10)). Classes, interfaces, and type aliases 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. -Named types are referenced through ***type references*** (section [3.7.2](#3.7.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 referenced through ***type references*** (section [3.8.2](#3.8.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. @@ -1342,7 +1511,7 @@ is indistinguishable from the type { first: string; second: Entity; } ``` -### 3.6.1 Instance Types +### 3.7.1 Instance Types Each class and interface has an associated actual type known as the ***instance type***. For a non-generic class or interface, the instance type is simply a type reference to the class or interface. For a generic class or interface, 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 class or interface. Within the constructor and instance member functions of a class, the type of `this` is the instance type of the class. @@ -1357,18 +1526,22 @@ class G { // Introduce type parameter T } ``` -## 3.7 Specifying Types +## 3.8 Specifying Types 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* +   *UnionOrIntersectionOrPrimaryType*    *FunctionType*    *ConstructorType* -  *PrimaryOrUnionType:* -   *PrimaryType* -   *UnionType* +  *UnionOrIntersectionOrPrimaryType:* +   *UnionType* +   *IntersectionOrPrimaryType* + +  *IntersectionOrPrimaryType:* +   *IntersectionType* +   *PrimaryType*   *PrimaryType:*    *ParenthesizedType* @@ -1382,29 +1555,31 @@ Types are specified either by referencing their keyword or name, or by writing o   *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: +Parentheses are required around union, intersection, function, or constructor types when they are used as array element types; around union, function, or constructor types in intersection types; and around function or constructor types in union types. For example: ```TypeScript (string | number)[] -((x: string) => string) | ((x: number) => number) +((x: string) => string) | ((x: number) => number) +(A | B) & (C | D) ``` The different forms of type notations are described in the following sections. -### 3.7.1 Predefined Types +### 3.8.1 Predefined Types -The `any`, `number`, `boolean`, `string`, and `void` keywords reference the Any type and the Number, Boolean, String, and Void primitive types respectively. +The `any`, `number`, `boolean`, `string`, `symbol` and `void` keywords reference the Any type and the Number, Boolean, String, Symbol, and Void primitive types respectively.   *PredefinedType:*    `any`    `number`    `boolean`    `string` +   `symbol`    `void` The predefined type keywords are reserved and cannot be used as names of user defined types. -### 3.7.2 Type References +### 3.8.2 Type References A type reference references a named type or type parameter through its name and, in the case of a generic type, supplies a type argument list. @@ -1412,24 +1587,26 @@ A type reference references a named type or type parameter through its name and,    *TypeName* *[no LineTerminator here]* *TypeArgumentsopt*   *TypeName:* -   *Identifier* -   *ModuleName* `.` *Identifier* +   *IdentifierReference* +   *NamespaceName* `.` *IdentifierReference* -  *ModuleName:* -   *Identifier* -   *ModuleName* `.` *Identifier* +  *NamespaceName:* +   *IdentifierReference* +   *NamespaceName* `.` *IdentifierReference* -A *TypeReference* consists of a *TypeName* that a references a named type or type parameter. A reference to a generic type must be followed by a list of *TypeArguments* (section [3.5.2](#3.5.2)). +A *TypeReference* consists of a *TypeName* that a references a named type or type parameter. A reference to a generic type must be followed by a list of *TypeArguments* (section [3.6.2](#3.6.2)). + +A *TypeName* is either a single identifier or a sequence of identifiers separated by dots. In a type name, all identifiers but the last one refer to namespaces and the last identifier refers to a named type. Resolution of a *TypeName* consisting of a single identifier is described in section [2.4](#2.4). -Resolution of a *TypeName* of the form *M.N*, where *M* is a *ModuleName* and *N* is an *Identifier*, proceeds by first resolving the module name *M*. If the resolution of *M* is successful and the resulting module contains an exported named type *N*, then *M.N* refers to that member. Otherwise, *M.N* is undefined. +Resolution of a *TypeName* of the form *N.X*, where *N* is a *NamespaceName* and *X* is an *IdentifierReference*, proceeds by first resolving the namespace name *N*. If the resolution of *N* is successful and the export member set (sections [10.4](#10.4) and [11.3.4.4](#11.3.4.4)) of the resulting namespace contains a named type *X*, then *N.X* refers to that member. Otherwise, *N.X* is undefined. -Resolution of a *ModuleName* consisting of a single identifier is described in section [2.4](#2.4). +Resolution of a *NamespaceName* consisting of a single identifier is described in section [2.4](#2.4). Identifiers declared in namespace declarations (section [10.1](#10.1)) or import declarations (sections [10.3](#10.3), [11.3.2](#11.3.2), and [11.3.3](#11.3.3)) may be classified as namespaces. -Resolution of a *ModuleName* of the form *M.N*, where *M* is a *ModuleName* and *N* is an *Identifier*, proceeds by first resolving the module name *M*. If the resolution of *M* is successful and the resulting module contains an exported module member *N*, then *M.N* refers to that member. Otherwise, *M.N* is undefined. +Resolution of a *NamespaceName* of the form *N.X*, where *N* is a *NamespaceName* and *X* is an *IdentifierReference*, proceeds by first resolving the namespace name *N*. If the resolution of *N* is successful and the export member set (sections [10.4](#10.4) and [11.3.4.4](#11.3.4.4)) of the resulting namespace contains an exported namespace member *X*, then *N.X* refers to that member. Otherwise, *N.X* is undefined. -A type reference to a generic type is required to specify exactly one type argument for each type parameter of the referenced generic type, and each type argument must be assignable to (section [3.10.4](#3.10.4)) the constraint of the corresponding type parameter or otherwise an error occurs. An example: +A type reference to a generic type is required to specify exactly one type argument for each type parameter of the referenced generic type, and each type argument must be assignable to (section [3.11.4](#3.11.4)) the constraint of the corresponding type parameter or otherwise an error occurs. An example: ```TypeScript interface A { a: string; } @@ -1454,7 +1631,7 @@ 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. -As described in section [3.6](#3.6), 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.7](#3.7), 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: { @@ -1463,7 +1640,7 @@ var v1: { }; ``` -### 3.7.3 Object Type Literals +### 3.8.3 Object Type Literals An object type literal defines an object type by specifying the set of members that are statically considered to be present in instances of the type. Object type literals can be given names using interface declarations but are otherwise anonymous. @@ -1471,11 +1648,13 @@ An object type literal defines an object type by specifying the set of members t    `{` *TypeBodyopt* `}`   *TypeBody:* -   *TypeMemberList* `;`*opt* +   *TypeMemberList* `;`*opt* +   *TypeMemberList* `,`*opt*   *TypeMemberList:*    *TypeMember* -   *TypeMemberList* `;` *TypeMember* +   *TypeMemberList* `;` *TypeMember* +   *TypeMemberList* `,` *TypeMember*   *TypeMember:*    *PropertySignature* @@ -1484,18 +1663,18 @@ An object type literal defines an object type by specifying the set of members t    *IndexSignature*    *MethodSignature* -The members of an object type literal are specified as a combination of property, call, construct, index, and method signatures. Object type members are described in section [3.8](#3.8). +The members of an object type literal are specified as a combination of property, call, construct, index, and method signatures. Object type members are described in section [3.9](#3.9). -### 3.7.4 Array Type Literals +### 3.8.4 Array Type Literals An array type literal is written as an element type followed by an open and close square bracket.   *ArrayType:*    *PrimaryType* *[no LineTerminator here]* `[` `]` -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 namespace with the element type as a type argument. -When union, function, or constructor types are used as array element types they must be enclosed in parentheses. For example: +When union, intersection, function, or constructor types are used as array element types they must be enclosed in parentheses. For example: ```TypeScript (string | number)[] @@ -1509,7 +1688,7 @@ Array Array<() => string> ``` -### 3.7.5 Tuple Type Literals +### 3.8.5 Tuple Type Literals A tuple type literal is written as a sequence of element types, separated by commas and enclosed in square brackets. @@ -1525,28 +1704,25 @@ 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.7.6 Union Type Literals +### 3.8.6 Union Type Literals A union type literal is written as a sequence of types separated by vertical bars.   *UnionType:* -   *PrimaryOrUnionType* `|` *PrimaryType* +   *UnionOrIntersectionOrPrimaryType* `|` *IntersectionOrPrimaryType* A union typle literal references a union type (section [3.4](#3.4)). -When function or constructor types are included in union types they must be enclosed in parentheses. For example: +### 3.8.7 Intersection Type Literals -```TypeScript -((x: string) => string) | ((x: number) => number) -``` +An intersection type literal is written as a sequence of types separated by ampersands. -Alternatively, function or constructor types in union types can be written using object literals: +  *IntersectionType:* +   *IntersectionOrPrimaryType* `&` *PrimaryType* -```TypeScript -{ (x: string): string } | { (x: number): number } -``` +An intersection typle literal references an intersection type (section [3.5](#3.5)). -### 3.7.7 Function Type Literals +### 3.8.8 Function Type Literals A function type literal specifies the type parameters, regular parameters, and return type of a call signature. @@ -1567,7 +1743,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.7.8 Constructor Type Literals +### 3.8.9 Constructor Type Literals A constructor type literal specifies the type parameters, regular parameters, and return type of a construct signature. @@ -1588,7 +1764,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.7.9 Type Queries +### 3.8.10 Type Queries A type query obtains the type of an expression. @@ -1596,12 +1772,12 @@ A type query obtains the type of an expression.    `typeof` *TypeQueryExpression*   *TypeQueryExpression:* -   *Identifier* +   *IdentifierReference*    *TypeQueryExpression* `.` *IdentifierName* -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. The expression is processed as an identifier expression (section [4.3](#4.3)) or property access expression (section [4.10](#4.10)), the widened type (section [3.11](#3.11)) of which becomes the result. Similar to other static typing constructs, type queries are erased from the generated JavaScript code and add no run-time overhead. +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. The expression is processed as an identifier expression (section [4.3](#4.3)) or property access expression (section [4.13](#4.13)), the widened type (section [3.12](#3.12)) of which becomes the result. Similar to other static typing constructs, type queries are erased from the generated JavaScript code and add no run-time overhead. -Type queries are useful for capturing anonymous types that are generated by various constructs such as object literals, function declarations, and module declarations. For example: +Type queries are useful for capturing anonymous types that are generated by various constructs such as object literals, function declarations, and namespace declarations. For example: ```TypeScript var a = { x: 10, y: 20 }; @@ -1628,48 +1804,44 @@ var h: () => typeof h; Here, 'g' and 'g.x' have the same recursive type, and likewise 'h' and 'h()' have the same recursive type. -## 3.8 Specifying Members +## 3.9 Specifying Members -The members of an object type literal (section [3.7.3](#3.7.3)) are specified as a combination of property, call, construct, index, and method signatures. +The members of an object type literal (section [3.8.3](#3.8.3)) are specified as a combination of property, call, construct, index, and method signatures. -### 3.8.1 Property Signatures +### 3.9.1 Property Signatures A property signature declares the name and type of a property member.   *PropertySignature:*    *PropertyName* `?`*opt* *TypeAnnotationopt* -  *PropertyName:* -   *IdentifierName* -   *StringLiteral* -   *NumericLiteral* +  *TypeAnnotation:* +   `:` *Type* -The *PropertyName* production, reproduced above from the ECMAScript grammar, permits a property name to be any identifier (including a reserved word), a string literal, or a numeric literal. String literals can be used to give properties names that are not valid identifiers, such as names containing blanks. Numeric literal property names are equivalent to string literal property names with the string representation of the numeric literal, as defined in the ECMAScript specification. - -The *PropertyName* of a property signature must be unique within its containing type. If the property name is followed by a question mark, the property is optional. Otherwise, the property is required. +The *PropertyName* ([2.2.2](#2.2.2)) of a property signature must be unique within its containing type, and must denote a well-known symbol if it is a computed property name ([2.2.3](#2.2.3)). If the property name is followed by a question mark, the property is optional. Otherwise, the property is required. If a property signature omits a *TypeAnnotation*, the Any type is assumed. -### 3.8.2 Call Signatures +### 3.9.2 Call Signatures -A call signature defines the type parameters, parameter list, and return type associated with applying a call operation (section [4.12](#4.12)) to an instance of the containing type. A type may ***overload*** call operations by defining multiple different call signatures. +A call signature defines the type parameters, parameter list, and return type associated with applying a call operation (section [4.15](#4.15)) to an instance of the containing type. A type may ***overload*** call operations by defining multiple different call signatures.   *CallSignature:*    *TypeParametersopt* `(` *ParameterListopt* `)` *TypeAnnotationopt* -A call signature that includes *TypeParameters* (section [3.5.1](#3.5.1)) is called a ***generic call signature***. Conversely, a call signature with no *TypeParameters* is called a non-generic call signature. +A call signature that includes *TypeParameters* (section [3.6.1](#3.6.1)) is called a ***generic call signature***. Conversely, a call signature with no *TypeParameters* is called a non-generic call signature. -As well as being members of object type literals, call signatures occur in method signatures (section [3.8.5](#3.8.5)), function expressions (section [4.9](#4.9)), and function declarations (section [6.1](#6.1)). +As well as being members of object type literals, call signatures occur in method signatures (section [3.9.5](#3.9.5)), function expressions (section [4.10](#4.10)), and function declarations (section [6.1](#6.1)). An object type containing call signatures is said to be a ***function type***. -#### 3.8.2.1 Type Parameters +#### 3.9.2.1 Type Parameters -Type parameters (section [3.5.1](#3.5.1)) in call signatures provide a mechanism for expressing the relationships of parameter and return types in call operations. For example, a signature might introduce a type parameter and use it as both a parameter type and a return type, in effect describing a function that returns a value of the same type as its argument. +Type parameters (section [3.6.1](#3.6.1)) in call signatures provide a mechanism for expressing the relationships of parameter and return types in call operations. For example, a signature might introduce a type parameter and use it as both a parameter type and a return type, in effect describing a function that returns a value of the same type as its argument. Type parameters may be referenced in parameter types and return type annotations, but not in type parameter constraints, of the call signature in which they are introduced. -Type arguments (section [3.5.2](#3.5.2)) for call signature type parameters 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. An ***instantiation*** of a generic call signature for a particular set of type arguments is the call signature formed by replacing each type parameter with its corresponding type argument. +Type arguments (section [3.6.2](#3.6.2)) for call signature type parameters may be explicitly specified in a call operation or may, when possible, be inferred (section [4.15.2](#4.15.2)) from the types of the regular arguments in the call. An ***instantiation*** of a generic call signature for a particular set of type arguments is the call signature formed by replacing each type parameter with its corresponding type argument. Some examples of call signatures with type parameters follow below. @@ -1697,7 +1869,7 @@ A function taking an array of one type and a function argument, returning an arr (a: T[], f: (x: T) => U): U[] ``` -#### 3.8.2.2 Parameter List +#### 3.9.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. @@ -1715,16 +1887,16 @@ A signature's parameter list consists of zero or more required parameters, follo    *RequiredParameterList* `,` *RequiredParameter*   *RequiredParameter:* -   *AccessibilityModifieropt* *IdentifierOrPattern* *TypeAnnotationopt* -   *Identifier* `:` *StringLiteral* +   *AccessibilityModifieropt* *BindingIdentifierOrPattern* *TypeAnnotationopt* +   *BindingIdentifier* `:` *StringLiteral*   *AccessibilityModifier:*    `public`    `private`    `protected` -  *IdentifierOrPattern:* -   *Identifier* +  *BindingIdentifierOrPattern:* +   *BindingIdentifier*    *BindingPattern*   *OptionalParameterList:* @@ -1732,20 +1904,20 @@ A signature's parameter list consists of zero or more required parameters, follo    *OptionalParameterList* `,` *OptionalParameter*   *OptionalParameter:* -   *AccessibilityModifieropt* *IdentifierOrPattern* `?` *TypeAnnotationopt* -   *AccessibilityModifieropt* *IdentifierOrPattern* *TypeAnnotationopt* *Initialiser* -   *Identifier* `?` `:` *StringLiteral* +   *AccessibilityModifieropt* *BindingIdentifierOrPattern* `?` *TypeAnnotationopt* +   *AccessibilityModifieropt* *BindingIdentifierOrPattern* *TypeAnnotationopt* *Initializer* +   *BindingIdentifier* `?` `:` *StringLiteral*   *RestParameter:* -   `...` *Identifier* *TypeAnnotationopt* +   `...` *BindingIdentifier* *TypeAnnotationopt* -A parameter declaration may specify either an identifier or a binding pattern ([5.1.2](#5.1.2)). The identifiers specified in parameter declarations and binding patterns in a parameter list must be unique within that parameter list. +A parameter declaration may specify either an identifier or a binding pattern ([5.2.2](#5.2.2)). The identifiers specified in parameter declarations and binding patterns in a parameter list must be unique within that parameter list. The type of a parameter in a signature is determined as follows: * If the declaration includes a type annotation, the parameter is of that type. -* Otherwise, if the declaration includes an initializer expression (which is permitted only when the parameter list occurs in conjunction with a function body), the parameter type is the widened form (section [3.11](#3.11)) of the type of the initializer expression. -* Otherwise, if the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section [5.1.3](#5.1.3)). +* Otherwise, if the declaration includes an initializer expression (which is permitted only when the parameter list occurs in conjunction with a function body), the parameter type is the widened form (section [3.12](#3.12)) of the type of the initializer expression. +* Otherwise, if the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section [5.2.3](#5.2.3)). * Otherwise, if the parameter is a rest parameter, the parameter type is `any[]`. * Otherwise, the parameter type is `any`. @@ -1753,11 +1925,13 @@ A parameter is permitted to include a `public`, `private`, or `protected` modifi A type annotation for a rest parameter must denote an array type. -When a parameter type annotation specifies a string literal type, the containing signature is a specialized signature (section [3.8.2.4](#3.8.2.4)). Specialized signatures are not permitted in conjunction with a function body, i.e. the *FunctionExpression*, *FunctionImplementation*, *MemberFunctionImplementation*, and *ConstructorImplementation* grammar productions do not permit parameters with string literal types. +When a parameter type annotation specifies a string literal type, the containing signature is a specialized signature (section [3.9.2.4](#3.9.2.4)). Specialized signatures are not permitted in conjunction with a function body, i.e. the *FunctionExpression*, *FunctionImplementation*, *MemberFunctionImplementation*, and *ConstructorImplementation* grammar productions do not permit parameters with string literal types. A parameter can be marked optional by following its name or binding pattern with a question mark (`?`) or by including an initializer. Initializers (including binding property or element initializers) are permitted only when the parameter list occurs in conjunction with a function body, i.e. only in a *FunctionExpression*, *FunctionImplementation*, *MemberFunctionImplementation*, or *ConstructorImplementation* grammar production. -#### 3.8.2.3 Return Type +*TODO: Update to reflect [binding parameter cannot be optional in implementation signature](https://github.com/Microsoft/TypeScript/issues/2797)*. + +#### 3.9.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. @@ -1765,9 +1939,9 @@ When a call signature with no return type annotation occurs in a context without When a call signature with no return type annotation occurs in a context that has a function body (specifically, a function implementation, a member function implementation, or a member accessor declaration), the return type is inferred from the function body as described in section [6.3](#6.3). -#### 3.8.2.4 Specialized Signatures +#### 3.9.2.4 Specialized Signatures -When a parameter type annotation specifies a string literal type (section [3.2.8](#3.2.8)), the containing signature is considered a specialized signature. Specialized signatures are used to express patterns where specific string values for some parameters cause the types of other parameters or the function result to become further specialized. For example, the declaration +When a parameter type annotation specifies a string literal type (section [3.2.9](#3.2.9)), the containing signature is considered a specialized signature. Specialized signatures are used to express patterns where specific string values for some parameters cause the types of other parameters or the function result to become further specialized. For example, the declaration ```TypeScript interface Document { @@ -1780,13 +1954,13 @@ 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'. -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. +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.15.1](#4.15.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. -### 3.8.3 Construct Signatures +### 3.9.3 Construct Signatures -A construct signature defines the parameter list and return type associated with applying the `new` operator (section [4.11](#4.11)) to an instance of the containing type. A type may overload `new` operations by defining multiple construct signatures with different parameter lists. +A construct signature defines the parameter list and return type associated with applying the `new` operator (section [4.14](#4.14)) to an instance of the containing type. A type may overload `new` operations by defining multiple construct signatures with different parameter lists.   *ConstructSignature:*    `new` *TypeParametersopt* `(` *ParameterListopt* `)` *TypeAnnotationopt* @@ -1795,33 +1969,33 @@ The type parameters, parameter list, and return type of a construct signature ar A type containing construct signatures is said to be a ***constructor type***. -### 3.8.4 Index Signatures +### 3.9.4 Index Signatures An index signature defines a type constraint for properties in the containing type.   *IndexSignature:* -   `[` *Identifier* `:` `string` `]` *TypeAnnotation* -   `[` *Identifier* `:` `number` `]` *TypeAnnotation* +   `[` *BindingIdentifier* `:` `string` `]` *TypeAnnotation* +   `[` *BindingIdentifier* `:` `number` `]` *TypeAnnotation* There are two kinds of index signatures: * ***String index signatures***, specified using index type `string`, define type constraints for all properties and numeric index signatures in the containing type. Specifically, in a type with a string index signature of type *T*, all properties and numeric index signatures must have types that are assignable to *T*. * ***Numeric index signatures***, specified using index type `number`, define type constraints for all numerically named properties in the containing type. Specifically, in a type with a numeric index signature of type *T*, all numerically named properties must have types that are assignable to *T*. -A ***numerically named property*** is a property whose name is a valid numeric literal. Specifically, a property with a name *N* for which ToNumber(*N*) is not NaN, where ToNumber is the abstract operation defined in ECMAScript specification. +A ***numerically named property*** is a property whose name is a valid numeric literal. Specifically, a property with a name *N* for which ToString(ToNumber(*N*)) is identical to *N*, where ToString and ToNumber are the abstract operations defined in ECMAScript specification. An object type can contain at most one string index signature and one numeric index signature. -Index signatures affect the determination of the type that results from applying a bracket notation property access to an instance of the containing type, as described in section [4.10](#4.10). +Index signatures affect the determination of the type that results from applying a bracket notation property access to an instance of the containing type, as described in section [4.13](#4.13). -### 3.8.5 Method Signatures +### 3.9.5 Method Signatures A method signature is shorthand for declaring a property of a function type.   *MethodSignature:*    *PropertyName* `?`*opt* *CallSignature* -If the identifier is followed by a question mark, the property is optional. Otherwise, the property is required. Only object type literals and interfaces can declare optional properties. +If the *PropertyName* is a computed property name ([2.2.3](#2.2.3)), it must specify a well-known symbol. If the *PropertyName* is followed by a question mark, the property is optional. Otherwise, the property is required. Only object type literals and interfaces can declare optional properties. A method signature of the form @@ -1878,24 +2052,26 @@ the properties 'func1', 'func2', and 'func3' are all of the same type, namely an 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.9 Type Aliases +## 3.10 Type Aliases -A type alias declaration introduces a ***type alias*** in the containing module. +A type alias declaration introduces a ***type alias*** in the containing declaration space.   *TypeAliasDeclaration:* -   `type` *Identifier* `=` *Type* `;` +   `type` *BindingIdentifier* *TypeParametersopt* `=` *Type* `;` -A type alias serves as an alias for the type specified in the type alias declaration. Unlike an interface declaration, which always introduces a named object type, a type alias declaration can introduce a name for any kind of type, including primitive types and union types. +A type alias serves as an alias for the type specified in the type alias declaration. Unlike an interface declaration, which always introduces a named object type, a type alias declaration can introduce a name for any kind of type, including primitive, union, and intersection types. -Type aliases are referenced using type references ([3.7.2](#3.7.2)). Writing a reference to a type alias has ***exactly*** the same effect as writing the aliased type itself. +A type alias may optionally have type parameters (section [3.6.1](#3.6.1)) that serve as placeholders for actual types to be provided when the type alias is referenced in type references. A type alias with type parameters is called a ***generic type alias***. The type parameters of a generic type alias declaration are in scope and may be referenced in the aliased *Type*. -The *Identifier* of a type alias declaration may not be one of the predefined type names (section [3.7.1](#3.7.1)). +Type aliases are referenced using type references ([3.8.2](#3.8.2)). Type references to generic type aliases produce instantiations of the aliased type with the given type arguments. Writing a reference to a non-generic type alias has exactly the same effect as writing the aliased type itself, and writing a reference to a generic type alias has exactly the same effect as writing the resulting instantiation of the aliased type. + +The *BindingIdentifier* of a type alias declaration may not be one of the predefined type names (section [3.8.1](#3.8.1)). It is an error for the type specified in a type alias to depend on that type alias. Types have the following dependencies: * A type alias *directly depends on* the type it aliases. * A type reference *directly depends on* the referenced type and each of the type arguments, if any. -* A union type *directly depends on* each of the constituent types. +* A union or intersection type *directly depends on* each of the constituent types. * An array type *directly depends on* its element type. * A tuple type *directly depends on* each of its element types. * A type query *directly depends on* the type of the referenced entity. @@ -1907,11 +2083,12 @@ Some examples of type alias declarations: ```TypeScript type StringOrNumber = string | number; type Text = string | { text: string }; -type Coordinates = [number, number]; type NameLookup = Dictionary; -type Callback = (data: string) => void; -type RecFunc = () => RecFunc; -type ObjectStatics = typeof Object; +type ObjectStatics = typeof Object; +type Callback = (data: T) => void; +type Pair = [T, T]; +type Coordinates = Pair; +type Tree = T | { left: Tree, right: Tree }; ``` Interface types have many similarities to type aliases for object type literals, but since interface types offer more capabilities they are generally preferred to type aliases. For example, the interface type @@ -1936,29 +2113,34 @@ However, doing so means the following capabilities are lost: * An interface can be named in an extends or implements clause, but a type alias for an object type literal cannot. * An interface can have multiple merged declarations, but a type alias for an object type literal cannot. -* An interface can have type parameters, but a type alias for an object type literal cannot. -## 3.10 Type Relationships +## 3.11 Type Relationships Types in TypeScript have identity, subtype, supertype, and assignment compatibility relationships as defined in the following sections. -### 3.10.1 Apparent Members +### 3.11.1 Apparent Members -The ***apparent members*** of a type are the members observed in 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 members of a type are determined as follows: +The ***apparent members*** of a type are the members observed in subtype, supertype, and assignment compatibility relationships, as well as in the type checking of property accesses (section [4.13](#4.13)), `new` operations (section [4.14](#4.14)), and function calls (section [4.15](#4.15)). The apparent members of a type are determined as follows: * The apparent members of the primitive types Number, Boolean, and String are the apparent members of the global interface types 'Number', 'Boolean', and 'String' respectively. * The apparent members of an enum type are the apparent members of the global interface type 'Number'. -* The apparent members of a type parameter are the apparent members of the base constraint (section [3.5.1](#3.5.1)) of that type parameter. +* The apparent members of a type parameter are the apparent members of the constraint (section [3.6.1](#3.6.1)) of that type parameter. * The apparent members of an object type *T* are the combination of the following: * The declared and/or inherited members of *T*. * The properties of the global interface type 'Object' that aren't hidden by properties with the same name in *T*. * If *T* has one or more call or construct signatures, the properties of the global interface type 'Function' that aren't hidden by properties with the same name in *T*. * The apparent members of a union type *U* are determined as follows: - * If each type in *U* has an apparent property *P*, *U* has an apparent property *P* of a union type of the types of *P* from each type in *U*. - * If each type in *U* has apparent call signatures and the sets of apparent 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 apparent call signatures from each type in *U*. - * If each type in *U* has apparent construct signatures and the sets of apparent 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 apparent construct signatures from each type in *U*. - * If each type in *U* has an apparent string index signature, *U* has a string index signature of a union type of the types of the apparent string index signatures from each type in *U*. - * If each type in *U* has an apparent numeric index signature, *U* has a numeric index signature of a union type of the types of the apparent numeric index signatures from each type in *U*. + * When all constituent types of *U* have an apparent property named *N*, *U* has an apparent property named *N* of a union type of the respective property types. + * When all constituent types of *U* have an apparent call signature with a parameter list *P*, *U* has an apparent call signature with the parameter list *P* and a return type that is a union of the respective return types. The call signatures appear in the same order as in the first constituent type. + * When all constituent types of *U* have an apparent construct signature with a parameter list *P*, *U* has an apparent construct signature with the parameter list *P* and a return type that is a union of the respective return types. The construct signatures appear in the same order as in the first constituent type. + * When all constituent types of *U* have an apparent string index signature, *U* has an apparent string index signature of a union type of the respective string index signature types. + * When all constituent types of *U* have an apparent numeric index signature, *U* has an apparent numeric index signature of a union type of the respective numeric index signature types. +* The apparent members of an intersection type *I* are determined as follows: + * When one of more constituent types of *I* have an apparent property named *N*, *I* has an apparent property named *N* of an intersection type of the respective property types. + * When one or more constituent types of *I* have a call signature *S*, *I* has the apparent call signature *S*. The signatures are ordered as a concatenation of the signatures of each constituent type in the order of the constituent types within *I*. + * When one or more constituent types of *I* have a construct signature *S*, *I* has the apparent construct signature *S*. The signatures are ordered as a concatenation of the signatures of each constituent type in the order of the constituent types within *I*. + * When one or more constituent types of *I* have an apparent string index signature, *I* has an apparent string index signature of an intersection type of the respective string index signature types. + * When one or more constituent types of *I* have an apparent numeric index signature, *I* has an apparent numeric index signature of an intersection type of the respective numeric index signature types. If a type is not one of the above, it is considered to have no apparent members. @@ -1974,7 +2156,7 @@ var err: Object = { toString: 0 }; // Error The last assignment is an error because the object literal has a 'toString' method that isn't compatible with that of 'Object'. -### 3.10.2 Type and Member Identity +### 3.11.2 Type and Member Identity Two types are considered ***identical*** when @@ -1982,6 +2164,7 @@ Two types are considered ***identical*** when * they are the same primitive type, * they are the same type parameter, * they are union types with identical sets of constituent types, or +* they are intersection types with identical sets of constituent types, or * they are object types with identical sets of members. Two members are considered identical when @@ -2011,9 +2194,9 @@ 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. -### 3.10.3 Subtypes and Supertypes +### 3.11.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: +*S* is a ***subtype*** of a type *T*, and *T* is a ***supertype*** of *S*, if *S* has no excess properties with respect to *T* ([3.11.5](#3.11.5)) and one of the following is true: * *S* and *T* are identical types. * *T* is the Any type. @@ -2021,10 +2204,12 @@ the variables 'a' and 'b' are of identical types because the two type references * *S* is the Null type and *T* is not the Undefined type. * *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* is a union type and each constituent type of *S* is a subtype of *T*. +* *S* is an intersection type and at least one 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* is an object type, a type parameter, or the Number, Boolean, or String primitive type, *T* is an object type, and for each member *M* in *T*, one of the following is true: +* *T* is an intersection type and *S* is a subtype of each constituent type of *T*. +* *S* is a type parameter and the constraint of *S* is a subtype of *T*. +* *S* is an object type, an intersection type, an enum type, or the Number, Boolean, or String primitive type, *T* is an object type, and for each member *M* in *T*, one of the following is true: * *M* is a property and *S* has an apparent property *N* where * *M* and *N* have the same name, * the type of *N* is a subtype of that of *M*, @@ -2035,20 +2220,20 @@ the variables 'a' and 'b' are of identical types because the two type references * *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* has an apparent string index signature of a type that is a subtype of *U*. - * *M* is a numeric index signature of type *U* and *S* has an apparent string or numeric index signature of a type that is a subtype of *U*. + * *M* is a string index signature of type *U*, and *U* is the Any type or *S* has an apparent string index signature of a type that is a subtype of *U*. + * *M* is a numeric index signature of type *U*, and *U* is the Any type or *S* has an apparent 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. -Note that specialized call and construct signatures (section [3.8.2.4](#3.8.2.4)) are not significant when determining subtype and supertype relationships. +Note that specialized call and construct signatures (section [3.9.2.4](#3.9.2.4)) are not significant when determining subtype and supertype relationships. Also note that type parameters are not considered object types. Thus, the only subtypes of a type parameter *T* are *T* itself and other type parameters that are directly or indirectly constrained to *T*. -### 3.10.4 Assignment Compatibility +### 3.11.4 Assignment Compatibility 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: +*S* is ***assignable to*** a type *T*, and *T* is ***assignable from*** *S*, if *S* has no excess properties with respect to *T* ([3.11.5](#3.11.5)) and one of the following is true: * *S* and *T* are identical types. * *S* or *T* is the Any type. @@ -2056,10 +2241,12 @@ Types are required to be assignment compatible in certain circumstances, such as * *S* is the Null type and *T* is not the Undefined type. * *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* is a union type and each constituent type of *S* is assignable to *T*. +* *S* is an intersection type and at least one 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* is an object type, a type parameter, or the Number, Boolean, or String primitive type, *T* is an object type, and for each member *M* in *T*, one of the following is true: +* *T* is an intersection type and *S* is assignable to each constituent type of *T*. +* *S* is a type parameter and the constraint of *S* is assignable to *T*. +* *S* is an object type, an intersection type, an enum type, or the Number, Boolean, or String primitive type, *T* is an object type, and for each member *M* in *T*, one of the following is true: * *M* is a property and *S* has an apparent property *N* where * *M* and *N* have the same name, * the type of *N* is assignable to that of *M*, @@ -2076,7 +2263,7 @@ Types are required to be assignment compatible in certain circumstances, such as 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. -Note that specialized call and construct signatures (section [3.8.2.4](#3.8.2.4)) are not significant when determining assignment compatibility. +Note that specialized call and construct signatures (section [3.9.2.4](#3.9.2.4)) are not significant when determining assignment compatibility. The assignment compatibility and subtyping rules differ only in that @@ -2095,23 +2282,80 @@ foo({ id: 1234, name: false }); // Error, name of wrong type foo({ name: "hello" }); // Error, id required but missing ``` -### 3.10.5 Contextual Signature Instantiation +### 3.11.5 Excess Properties -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: +The subtype and assignment compatibility relationships require that source types have no excess properties with respect to their target types. The purpose of this check is to detect excess or misspelled properties in object literals. -* Using the process described in [3.10.6](#3.10.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. +A source type *S* is considered to have excess properties with respect to a target type *T* if + +* *S* is a fresh object literal type, as defined below, and +* *S* has one or more properties that aren't expected in *T*. + +A property *P* is said to be expected in a type *T* if one of the following is true: + +* *T* is not an object, union, or intersection type. +* *T* is an object type and + * *T* has a property with the same name as *P*, + * *T* has a string or numeric index signature, + * *T* has no properties, or + * *T* is the global type 'Object'. +* *T* is a union or intersection type and *P* is expected in at least one of the constituent types of *T*. + +The type inferred for an object literal (as described in section [4.5](#4.5)) is considered a ***fresh object literal type***. The freshness disappears when an object literal type is widened ([3.12](#3.12)) or is the type of the expression in a type assertion ([4.16](#4.16)). + +Consider the following example: + +```TypeScript +interface CompilerOptions { + strict?: boolean; + sourcePath?: string; + targetPath?: string; +} + +var options: CompilerOptions = { + strict: true, + sourcepath: "./src", // Error, excess or misspelled property + targetpath: "./bin" // Error, excess or misspelled property +}; +``` + +The 'CompilerOptions' type contains only optional properties, so without the excess property check, *any* object literal would be assignable to the 'options' variable (because a misspelled property would just be considered an excess property of a different name). + +In cases where excess properties are expected, an index signature can be added to the target type as an indicator of intent: + +```TypeScript +interface InputElement { + name: string; + visible?: boolean; + [x: string]: any; // Allow additional properties of any type +} + +var address: InputElement = { + name: "Address", + visible: true, + help: "Enter address here", // Allowed because of index signature + shortcut: "Alt-A" // Allowed because of index signature +}; +``` + +### 3.11.6 Contextual Signature Instantiation + +During type argument inference in a function call (section [4.15.2](#4.15.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.11.7](#3.11.7), 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.10.6 Type Inference +### 3.11.7 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: +* Otherwise, if *S* and *T* are tuple types with the same number of elements, inferences are made from each element type in *S* to each corresponding element type in *T*. +* Otherwise, if *T* is a union or intersection 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*. + * If the first step produced no inferences then if T is a union type 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 or intersection 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*. @@ -2122,7 +2366,7 @@ In certain contexts, inferences for a given set of type parameters are made *fro When comparing call or construct signatures, signatures in *S* correspond to signatures of the same kind in *T* pairwise in declaration order. If *S* and *T* have different numbers of a given kind of signature, the excess *first* signatures in declaration order of the longer list are ignored. -### 3.10.7 Recursive Types +### 3.11.8 Recursive Types Classes and interfaces can reference themselves in their internal structure, in effect creating recursive types with infinite nesting. For example, the type @@ -2156,7 +2400,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. -## 3.11 Widened Types +## 3.12 Widened Types In several situations TypeScript infers types from context, alleviating the need for the programmer to explicitly specify types that appear obvious. For example @@ -2171,7 +2415,7 @@ The following example shows the results of widening types to produce inferred va ```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 c = { x: 0, y: null }; // var c: { x: number, y: any } var d = [ null, undefined ]; // var d: any[] ``` @@ -2185,17 +2429,15 @@ TypeScript's typing rules define a type for every expression construct. For exam In addition to type inference and type checking, TypeScript augments JavaScript expressions with the following constructs: -* Optional parameter and return type annotations in function expressions. -* Default parameter values and rest parameters in function expressions. -* Arrow function expressions. -* Super calls and member access. +* Optional parameter and return type annotations in function expressions and arrow functions. +* Type arguments in function calls. * Type assertions. Unless otherwise noted in the sections that follow, TypeScript expressions and the JavaScript expressions generated from them are identical. ## 4.1 Values and References -Expressions are classified as ***values*** or ***references***. References are the subset of expressions that are permitted as the target of an assignment. Specifically, references are combinations of identifiers (section [4.3](#4.3)), parentheses (section [4.7](#4.7)), and property accesses (section [4.10](#4.10)). All other expression constructs described in this chapter are classified as values. +Expressions are classified as ***values*** or ***references***. References are the subset of expressions that are permitted as the target of an assignment. Specifically, references are combinations of identifiers (section [4.3](#4.3)), parentheses (section [4.8](#4.8)), and property accesses (section [4.13](#4.13)). All other expression constructs described in this chapter are classified as values. ## 4.2 The this Keyword @@ -2203,18 +2445,18 @@ The type of `this` in an expression depends on the location in which the referen * In a constructor, instance member function, instance member accessor, or instance member variable initializer, `this` is of the class instance type of the containing class. * In a static member function or static member accessor, the type of `this` is the constructor function type of the containing class. -* In a function declaration or a standard function expression, `this` is of type Any. -* In the global module, `this` is of type Any. +* In a function declaration or a function expression, `this` is of type Any. +* In the global namespace, `this` is of type Any. In all other contexts it is a compile-time error to reference `this`. -In the body of an arrow function expression, references to `this` are rewritten in the generated JavaScript code, as described in section [4.9.2](#4.9.2). +Note that an arrow function (section [4.11](#4.11)) has no `this` parameter but rather preserves the `this` of its enclosing context. ## 4.3 Identifiers -When an expression is an *Identifier*, the expression refers to the most nested module, class, enum, function, variable, or parameter with that name whose scope (section [2.4](#2.4)) includes the location of the reference. The type of such an expression is the type associated with the referenced entity: +When an expression is an *IdentifierReference*, the expression refers to the most nested namespace, class, enum, function, variable, or parameter with that name whose scope (section [2.4](#2.4)) includes the location of the reference. The type of such an expression is the type associated with the referenced entity: -* For a module, the object type associated with the module instance. +* For a namespace, the object type associated with the namespace instance. * For a class, the constructor type associated with the constructor function object. * For an enum, the object type associated with the enum object. * For a function, the function type associated with the function object. @@ -2235,9 +2477,11 @@ Literals are typed as follows: ## 4.5 Object Literals -Object literals are extended to support type annotations in get and set accessors. +Object literals are extended to support type annotations in methods and get and set accessors. -  *PropertyAssignment:* *( Modified )* +  *PropertyDefinition:* *( Modified )* +   *IdentifierReference* +   *CoverInitializedName*    *PropertyName* `:` *AssignmentExpression*    *PropertyName* *CallSignature* `{` *FunctionBody* `}`    *GetAccessor* @@ -2247,17 +2491,29 @@ Object literals are extended to support type annotations in get and set accessor    `get` *PropertyName* `(` `)` *TypeAnnotationopt* `{` *FunctionBody* `}`   *SetAccessor:* -   `set` *PropertyName* `(` *Identifier* *TypeAnnotationopt* `)` `{` *FunctionBody* `}` +   `set` *PropertyName* `(` *BindingIdentifierOrPattern* *TypeAnnotationopt* `)` `{` *FunctionBody* `}` The type of an object literal is an object type with the set of properties specified by the property assignments in the object literal. A get and set accessor may specify the same property name, but otherwise it is an error to specify multiple property assignments for the same property. -A property assignment of the form +A shorthand property assignment of the form + +```TypeScript +prop +``` + +is equivalent to + +```TypeScript +prop : prop +``` + +Likewise, a property assignment of the form ```TypeScript f ( ... ) { ... } ``` -is simply shorthand for +is equivalent to ```TypeScript f : function ( ... ) { ... } @@ -2280,20 +2536,15 @@ 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, 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.8.4](#3.8.4)) declared in the object literal, or the Undefined type if the object literal declares no numerically named properties. +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.9.4](#3.9.4)) declared in the object literal, or the Undefined type if the object literal declares no numerically named properties. -## 4.6 Array Literals +If the *PropertyName* of a property assignment is a computed property name that doesn't denote a well-known symbol ([2.2.3](#2.2.3)), the construct is considered a ***dynamic property assignment***. The following rules apply to dynamic property assignments: -Array literals are extended to support the spread (`...`) operator. +* A dynamic property assignment does not introduce a property in the type of the object literal. +* The property name expression of a dynamic property assignment must be of type Any or the String, Number, or Symbol primitive type. +* The name associated with a dynamic property assignment is considered to be a numeric property name if the property name expression is of type Any or the Number primitive type. -  *ElementList:* *( Modified )* -   *Elisionopt* *AssignmentExpression* -   *Elisionopt* *SpreadElement* -   *ElementList* `,` *Elisionopt* *AssignmentExpression* -   *ElementList* `,` *Elisionopt* *SpreadElement* - -  *SpreadElement:* -   `...` *AssignmentExpression* +## 4.6 Array Literals An array literal @@ -2305,7 +2556,7 @@ denotes a value of an array type (section [3.3.2](#3.3.2)) or a tuple type (sect Each element expression in a non-empty array literal is processed as follows: -* If the array literal contains no spread elements, and if the array literal is contextually typed (section [4.19](#4.19)) by a type *T* and *T* has a property with the numeric name *N*, where *N* is the index of the element expression in the array literal, the element expression is contextually typed by the type of that property. +* If the array literal contains no spread elements, and if the array literal is contextually typed (section [4.23](#4.23)) by a type *T* and *T* has a property with the numeric name *N*, where *N* is the index of the element expression in the array literal, the element expression is contextually typed by the type of that property. * 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. @@ -2313,11 +2564,13 @@ The resulting type an array literal expression is determined as follows: * If the array literal is empty, the resulting type is an array type with the element type Undefined. * Otherwise, if the array literal contains no spread elements and is contextually typed by a tuple-like type (section [3.3.3](#3.3.3)), the resulting type is a tuple type constructed from the types of the element expressions. -* Otherwise, if the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section [4.17.1](#4.17.1)), the resulting type is a tuple type constructed from the types of the element expressions. +* Otherwise, if the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section [4.21.1](#4.21.1)), 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 non-spread element expressions and the numeric index signature types of the spread element expressions. A spread element must specify an expression of an array-like type (section [3.3.2](#3.3.2)), or otherwise an error occurs. +*TODO: Document spreading an [iterator](https://github.com/Microsoft/TypeScript/pull/2498) into an array literal*. + The rules above mean that an array literal is always of an array type, unless it is contextually typed by a tuple-like type. For example ```TypeScript @@ -2340,7 +2593,11 @@ var a = [2, 3, 4]; var b = [0, 1].concat(a, [5, 6]); ``` -## 4.7 Parentheses +## 4.7 Template Literals + +*TODO: [Template literals](https://github.com/Microsoft/TypeScript/pull/960)*. + +## 4.8 Parentheses A parenthesized expression @@ -2350,72 +2607,78 @@ A parenthesized expression has the same type and classification as the contained expression itself. Specifically, if the contained expression is classified as a reference, so is the parenthesized expression. -## 4.8 The super Keyword +## 4.9 The super Keyword The `super` keyword can be used in expressions to reference base class properties and the base class constructor. -  *CallExpression:* *( Modified )* -   … -   `super` `(` *ArgumentListopt* `)` -   `super` `.` *IdentifierName* - -### 4.8.1 Super Calls +### 4.9.1 Super Calls Super calls consist of the keyword `super` followed by an argument list enclosed in parentheses. Super calls are only permitted in constructors of derived classes, as described in section [8.3.2](#8.3.2). -A super call invokes the constructor of the base class on the instance referenced by `this`. A super call is processed as a function call (section [4.12](#4.12)) using the construct signatures of the base class constructor function type as the initial set of candidate signatures for overload resolution. Type arguments cannot be explicitly specified in a super call. If the base class is a generic class, the type arguments used to process a super call are always those specified in the `extends` clause that references the base class. +A super call invokes the constructor of the base class on the instance referenced by `this`. A super call is processed as a function call (section [4.15](#4.15)) using the construct signatures of the base class constructor function type as the initial set of candidate signatures for overload resolution. Type arguments cannot be explicitly specified in a super call. If the base class is a generic class, the type arguments used to process a super call are always those specified in the `extends` clause that references the base class. The type of a super call expression is Void. The JavaScript code generated for a super call is specified in section [8.6.2](#8.6.2). -### 4.8.2 Super Property Access +### 4.9.2 Super Property Access A super property access consists of the keyword `super` followed by a dot and an identifier. Super property accesses are used to access base class member functions from derived classes and are permitted in contexts where `this` (section [4.2](#4.2)) references a derived class instance or a derived class constructor function. Specifically: * In a constructor, instance member function, instance member accessor, or instance member variable initializer where `this` references a derived class instance, a super property access is permitted and must specify a public instance member function of the base class. * In a static member function or static member accessor where `this` references the constructor function object of a derived class, a super property access is permitted and must specify a public static member function of the base class. -Super property accesses are not permitted in other contexts, and it is not possible to access other kinds of base class members in a super property access. Note that super property accesses are not permitted inside standard function expressions nested in the above constructs because `this` is of type Any in such function expressions. +Super property accesses are not permitted in other contexts, and it is not possible to access other kinds of base class members in a super property access. Note that super property accesses are not permitted inside function expressions nested in the above constructs because `this` is of type Any in such function expressions. Super property accesses are typically used to access overridden base class member functions from derived class member functions. For an example of this, see section [8.4.2](#8.4.2). The JavaScript code generated for a super property access is specified in section [8.6.2](#8.6.2). -## 4.9 Function Expressions +*TODO: Update section to include [bracket notation in super property access](https://github.com/Microsoft/TypeScript/issues/3970)*. -Function expressions are extended from JavaScript to optionally include parameter and return type annotations, and a new compact form, called arrow function expressions, is introduced. +## 4.10 Function Expressions + +Function expressions are extended from JavaScript to optionally include parameter and return type annotations.   *FunctionExpression:* *( Modified )* -   `function` *Identifieropt* *CallSignature* `{` *FunctionBody* `}` +   `function` *BindingIdentifieropt* *CallSignature* `{` *FunctionBody* `}` -  *AssignmentExpression:* *( Modified )* -   … -   *ArrowFunctionExpression* - -  *ArrowFunctionExpression:* -   *ArrowFormalParameters* `=>` *Block* -   *ArrowFormalParameters* `=>` *AssignmentExpression* - -  *ArrowFormalParameters:* -   *CallSignature* -   *Identifier* - -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 descriptions of function declarations provided in chapter [6](#6) apply to function expressions as well, except that function expressions do not support overloading. 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. +When a function expression with no type parameters and no parameter type annotations is contextually typed (section [4.23](#4.23)) by a type *T* and a contextual signature *S* can be extracted from *T*, the function expression is processed as if it had explicitly specified parameter type annotations as they exist in *S*. Parameters are matched by position and need not have matching names. If the function expression has fewer parameters than *S*, the additional parameters in *S* are ignored. If the function expression has more parameters than *S*, the additional parameters are all considered to have type Any. -### 4.9.1 Standard Function Expressions +Likewise, when a function expression with no return type annotation is contextually typed (section [4.23](#4.23)) by a function type *T* and a contextual signature *S* can be extracted from *T*, expressions in contained return statements (section [5.10](#5.10)) are contextually typed by the return type of *S*. -Standard function expressions are function expressions written with the `function` keyword. The type of `this` in a standard function expression is the Any type. +A contextual signature *S* is extracted from a function type *T* as follows: -Standard function expressions are transformed to JavaScript in the same manner as function declarations (see section [6.6](#6.6)). +* If *T* is a function type with exactly one call signature, and if that call signature is non-generic, *S* is that signature. +* If *T* is a union type, let *U* be the set of element types in *T* that have call signatures. If each type in *U* has exactly one call signature and that call signature is non-generic, and if all of the signatures are identical ignoring return types, then *S* is a signature with the same parameters and a union of the return types. +* Otherwise, no contextual signature can be extracted from *T*. -### 4.9.2 Arrow Function Expressions +In the example -TypeScript supports ***arrow function expressions***, a new feature planned for ECMAScript 6. Arrow function expressions are a compact form of function expressions that omit the `function` keyword and have lexical scoping of `this`. +```TypeScript +var f: (s: string) => string = function (s) { + return s.toLowerCase(); +}; +``` + +the function expression is contextually typed by the type of 'f', and since the function expression has no type parameters or type annotations its parameter type information is extracted from the contextual type, thus inferring the type of 's' to be the String primitive type. + +## 4.11 Arrow Functions + +Arrow functions are extended from JavaScript to optionally include parameter and return type annotations. + +  *ArrowFormalParameters:* *( Modified )* +   *CallSignature* + +The descriptions of function declarations provided in chapter [6](#6) apply to arrow functions as well, except that arrow functions do not support overloading. + +The type of an arrow function is determined in the same manner as a function expression (section [4.10](#4.10)). Likewise, parameters of an arrow function and return statements in the body of an arrow function are contextually typed in the same manner as for function expressions. + +When an arrow function with an expression body and no return type annotation is contextually typed (section [4.23](#4.23)) by a function type *T* and a contextual signature *S* can be extracted from *T*, the expression body is contextually typed by the return type of *S*. An arrow function expression of the form @@ -2452,7 +2715,7 @@ x => { return Math.sin(x); } x => Math.sin(x) ``` -A function expression using the `function` keyword introduces a new dynamically bound `this`, whereas an arrow function expression preserves the `this` of its enclosing context. Arrow function expressions are particularly useful for writing callbacks, which otherwise often have an undefined or unexpected `this`. +A function expression introduces a new dynamically bound `this`, whereas an arrow function expression preserves the `this` of its enclosing context. Arrow function expressions are particularly useful for writing callbacks, which otherwise often have an undefined or unexpected `this`. In the example @@ -2497,27 +2760,11 @@ could be parsed as an arrow function expression with a type parameter or a type < T > ( ( ... ) => { ... } ) ``` -### 4.9.3 Contextually Typed Function Expressions +## 4.12 Class Expressions -When a function expression with no type parameters and no parameter type annotations is contextually typed (section [4.19](#4.19)) by a type *T* and a contextual signature *S* can be extracted from *T*, the function expression is processed as if it had explicitly specified parameter type annotations as they exist in *S*. Parameters are matched by position and need not have matching names. If the function expression has fewer parameters than *S*, the additional parameters in *S* are ignored. If the function expression has more parameters than *S*, the additional parameters are all considered to have type Any. +*TODO: Document [class expressions](https://github.com/Microsoft/TypeScript/issues/497)*. -Likewise, when a function expression with no return type annotation is contextually typed (section [4.19](#4.19)) by a function type *T* and a contextual signature *S* can be extracted from *T*, expressions in contained return statements (section [5.7](#5.7)) are contextually typed by the return type of *S*. - -A contextual signature *S* is extracted from a function type *T* as follows: - -* If *T* is a function type with exactly one call signature, and if that call signature is non-generic, *S* is that signature. -* If *T* is a union type, let *U* be the set of element types in *T* that have call signatures. If each type in *U* has exactly one call signature and that call signature is non-generic, and if all of the signatures are identical ignoring return types, then *S* is a signature with the same parameters and a union of the return types. -* Otherwise, no contextual signature can be extracted from *T* and *S* is undefined. - -In the example - -```TypeScript -var f: (s: string) => string = s => s.toLowerCase(); -``` - -the function expression is contextually typed by the type of 'f', and since the function expression has no type parameters or type annotations its parameter type information is extracted from the contextual type, thus inferring the type of 's' to be the String primitive type. - -## 4.10 Property Access +## 4.13 Property Access A property access uses either dot notation or bracket notation. A property access expression is always classified as a reference. @@ -2530,7 +2777,7 @@ object . name where *object* is an expression and *name* is an identifier (including, possibly, a reserved word), is used to access the property with the given name on the given object. A dot notation property access is processed as follows at compile-time: * If *object* is of type Any, any *name* is permitted and the property access is of type Any. -* Otherwise, if *name* denotes an accessible apparent property (section [3.10.1](#3.10.1)) in the type of *object*, the property access is of the type of that property. Public members are always accessible, but private and protected members of a class have restricted accessibility, as described in [8.2.2](#8.2.2). +* Otherwise, if *name* denotes an accessible apparent property (section [3.11.1](#3.11.1)) in the type of *object*, the property access is of the type of that property. Public members are always accessible, but private and protected members of a class have restricted accessibility, as described in [8.2.2](#8.2.2). * Otherwise, the property access is invalid and a compile-time error occurs. A bracket notation property access of the form @@ -2541,12 +2788,14 @@ 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* has an apparent property (section [3.10.1](#3.10.1)) 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. +* If *index* is a string literal or a numeric literal and *object* has an apparent property (section [3.11.1](#3.11.1)) 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* has an apparent 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* has an apparent 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. +*TODO: Indexing with [symbols](https://github.com/Microsoft/TypeScript/pull/1978)*. + The rules above mean that properties are strongly typed when accessed using bracket notation with the literal representation of their name. For example: ```TypeScript @@ -2567,7 +2816,7 @@ var s = data[0]; // string var n = data[1]; // number ``` -## 4.11 The new Operator +## 4.14 The new Operator A `new` operation has one of the following forms: @@ -2580,12 +2829,12 @@ 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* has one or more apparent construct signatures (section [3.10.1](#3.10.1)), 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* has one or more apparent construct signatures (section [3.11.1](#3.11.1)), 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* has no apparent construct signatures but one or more apparent 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 +## 4.15 Function Calls -Function calls are extended from JavaScript to optionally include type arguments. +Function calls are extended from JavaScript to support optional type arguments.   *Arguments:* *( Modified )*    *TypeArgumentsopt* `(` *ArgumentListopt* `)` @@ -2597,16 +2846,18 @@ func ( ... ) func < ... > ( ... ) ``` -where *func* is an expression of a function type or of type Any. The function expression is followed by an optional type argument list (section [3.5.2](#3.5.2)) and an argument list. +where *func* is an expression of a function type or of type Any. The function expression is followed by an optional type argument list (section [3.6.2](#3.6.2)) and an argument list. 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* has apparent call signatures (section [3.10.1](#3.10.1)) 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* has apparent call signatures (section [3.11.1](#3.11.1)) 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 +### 4.15.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. +*TODO: Describe use of [wildcard function types](https://github.com/Microsoft/TypeScript/issues/3970) in overload resolution*. + The compile-time processing of a typed function call consists of the following steps: * First, a list of candidate signatures is constructed from the call signatures in the function type in declaration order. For classes and interfaces, inherited signatures are considered to follow explicitly declared signatures in `extends` clause order. @@ -2614,7 +2865,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 for each type parameter, + * type inference (section [4.15.2](#4.15.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, @@ -2628,12 +2879,16 @@ A signature is said to be an ***applicable signature*** with respect to an argum * the number of arguments is not less than the number of required parameters, * the number of arguments is not greater than the number of parameters, and -* for each argument expression *e* and its corresponding parameter *P,* when *e* is contextually typed (section [4.19](#4.19)) by the type of *P*, no errors ensue and the type of *e* is assignable to (section [3.10.4](#3.10.4)) the type of *P*. +* for each argument expression *e* and its corresponding parameter *P,* when *e* is contextually typed (section [4.23](#4.23)) by the type of *P*, no errors ensue and the type of *e* is assignable to (section [3.11.4](#3.11.4)) the type of *P*. -### 4.12.2 Type Argument Inference +*TODO: [Spread operator in function calls](https://github.com/Microsoft/TypeScript/pull/1931) and spreading an [iterator](https://github.com/Microsoft/TypeScript/pull/2498) into a function call*. + +### 4.15.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. +*TODO: Update [type argument inference and overload resolution rules](https://github.com/Microsoft/TypeScript/issues/1186)*. + 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 the set of candidate argument types is empty, the inferred type argument for *T* is *T*'s constraint. @@ -2643,13 +2898,13 @@ Type argument inference produces a set of candidate types for each type paramete In order to compute candidate types, the argument list is processed as follows: * Initially all inferred type arguments are considered ***unfixed*** with an empty set of candidate types. -* Proceeding from left to right, each argument expression *e* is ***inferentially typed*** by its corresponding parameter type *P*, possibly causing some inferred type arguments to become ***fixed***, and candidate type inferences (section [3.10.6](#3.10.6)) are made for unfixed inferred type arguments from the type computed for *e* to *P*. +* Proceeding from left to right, each argument expression *e* is ***inferentially typed*** by its corresponding parameter type *P*, possibly causing some inferred type arguments to become ***fixed***, and candidate type inferences (section [3.11.7](#3.11.7)) are made for unfixed inferred type arguments from the type computed for *e* to *P*. 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. -* 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.10.5](#3.10.5)). +* When a function expression is inferentially typed (section [4.10](#4.10)) 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.11.6](#3.11.6)). An example: @@ -2715,9 +2970,9 @@ var pairs = zip( and the resulting type of 'pairs' is therefore '{ name: string; age: number }[]'. -### 4.12.3 Grammar Ambiguities +### 4.15.3 Grammar Ambiguities -The inclusion of type arguments in the *Arguments* production (section [4.12](#4.12)) gives rise to certain ambiguities in the grammar for expressions. For example, the statement +The inclusion of type arguments in the *Arguments* production (section [4.15](#4.15)) gives rise to certain ambiguities in the grammar for expressions. For example, the statement ```TypeScript f(g(7)); @@ -2736,7 +2991,7 @@ f(g < A, B > +(7)); are both interpreted as calls to 'f' with two arguments. -## 4.13 Type Assertions +## 4.16 Type Assertions TypeScript extends the JavaScript expression grammar with the ability to assert a type for an expression: @@ -2746,7 +3001,7 @@ TypeScript extends the JavaScript expression grammar with the ability to assert 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*. +In a type assertion expression of the form < *T* > *e*, *e* is contextually typed (section [4.23](#4.23)) 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 @@ -2775,15 +3030,19 @@ if (shape instanceof Circle) { } ``` -## 4.14 Unary Operators +## 4.17 JSX Expressions + +*TODO: Document [JSX expressions](https://github.com/Microsoft/TypeScript/issues/3203)*. + +## 4.18 Unary Operators The subsections that follow specify the compile-time processing rules of the unary operators. In general, if the operand of a unary operator does not meet the stated requirements, a compile-time error occurs and the result of the operation defaults to type Any in further processing. -### 4.14.1 The ++ and -- operators +### 4.18.1 The ++ and -- operators 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.18.2 The +, –, and ~ operators These operators permit their operand to be of any type and produce a result of the Number primitive type. @@ -2797,7 +3056,7 @@ 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'. -### 4.14.3 The ! operator +### 4.18.3 The ! operator The ! operator permits its operand to be of any type and produces a result of the Boolean primitive type. @@ -2811,17 +3070,17 @@ 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'. -### 4.14.4 The delete Operator +### 4.18.4 The delete Operator The 'delete' operator takes an operand of any type and produces a result of the Boolean primitive type. -### 4.14.5 The void Operator +### 4.18.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.7](#3.2.7)). -### 4.14.6 The typeof Operator +### 4.18.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.7.9](#3.7.9)) 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.8.10](#3.8.10)) to produce the type of an expression. ```TypeScript var x = 5; @@ -2831,11 +3090,11 @@ 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. -## 4.15 Binary Operators +## 4.19 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 other types (the Other column in the tables) are provided. -### 4.15.1 The *, /, %, –, <<, >>, >>>, &, ^, and | operators +### 4.19.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. @@ -2847,7 +3106,7 @@ These operators require their operands to be of type Any, the Number primitive t |String|||||| |Other|||||| -### 4.15.2 The + operator +### 4.19.2 The + operator The binary + operator requires both operands to be of the Number primitive type or an enum type, or at least one of the operands to be of type Any or the String primitive 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. If both operands are of the Number primitive type, the result is of the Number primitive type. If one or both operands are of the String primitive type, the result is of the String primitive type. Otherwise, the result is of type Any. @@ -2869,7 +3128,7 @@ 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'. -### 4.15.3 The <, >, <=, >=, ==, !=, ===, and !== operators +### 4.19.3 The <, >, <=, >=, ==, !=, ===, and !== operators These operators require one or both of the operand types to be assignable to the other. The result is always of the Boolean primitive type. @@ -2881,17 +3140,17 @@ These operators require one or both of the operand types to be assignable to the |String|Boolean|||Boolean|| |Other|Boolean||||Boolean| -### 4.15.4 The instanceof operator +### 4.19.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. 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 +### 4.19.5 The in operator The `in` operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type, and the right operand to be of type Any, an object type, or a type parameter type. The result is always of the Boolean primitive type. -### 4.15.6 The && operator +### 4.19.6 The && operator The && operator permits the operands to be of any type and produces a result of the same type as the second operand. @@ -2903,11 +3162,11 @@ The && operator permits the operands to be of any type and produces a result of |String|Any|Boolean|Number|String|Other| |Other|Any|Boolean|Number|String|Other| -### 4.15.7 The || operator +### 4.19.7 The || operator 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. 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 contextually typed (section [4.23](#4.23)), 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. The type of the result is the union type of the two operand types. @@ -2919,7 +3178,7 @@ The type of the result is the union type of the two operand types. |String|Any|S | B|S | N|String|S | O| |Other|Any|B | O|N | O|S | O|Other| -## 4.16 The Conditional Operator +## 4.20 The Conditional Operator In a conditional expression of the form @@ -2929,11 +3188,11 @@ 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. Otherwise, *expr1* and *expr2* are not contextually typed. +If the conditional expression is contextually typed (section [4.23](#4.23)), *expr1* and *expr2* are contextually typed by the same type. Otherwise, *expr1* and *expr2* are not contextually typed. The type of the result is the union type of the types of *expr1* and *expr2*. -## 4.17 Assignment Operators +## 4.21 Assignment Operators An assignment of the form @@ -2941,7 +3200,7 @@ An assignment of the form v = expr ``` -requires *v* to be classified as a reference (section [4.1](#4.1)) or as an assignment pattern (section [4.17.1](#4.17.1)). The *expr* expression is contextually typed (section [4.19](#4.19)) by the type of *v*, and the type of *expr* must be assignable to (section [3.10.4](#3.10.4)) the type of *v*, or otherwise a compile-time error occurs. The result is a value with the type of *expr*. +requires *v* to be classified as a reference (section [4.1](#4.1)) or as an assignment pattern (section [4.21.1](#4.21.1)). The *expr* expression is contextually typed (section [4.23](#4.23)) by the type of *v*, and the type of *expr* must be assignable to (section [3.11.4](#3.11.4)) the type of *v*, or otherwise a compile-time error occurs. The result is a value with the type of *expr*. A compound assignment of the form @@ -2957,42 +3216,9 @@ where ??= is one of the compound assignment operators is subject to the same requirements, and produces a value of the same type, as the corresponding non-compound operation. A compound assignment furthermore requires *v* to be classified as a reference (section [4.1](#4.1)) and the type of the non-compound operation to be assignable to the type of *v*. Note that *v* is not permitted to be an assignment pattern in a compound assignment. -### 4.17.1 Destructuring Assignment +### 4.21.1 Destructuring Assignment -A ***destructuring assignment*** is an assignment operation in which the left hand operand is a destructuring assignment pattern. - -  *AssignmentPattern:* -   *ObjectAssignmentPattern* -   *ArrayAssignmentPattern* - -  *ObjectBindingPattern:* -   `{` `}` -   `{` *AssignmentPropertyList* `,`*opt* `}` - -  *AssignmentPropertyList:* -   *AssignmentProperty* -   *AssignmentPropertyList* `,` *AssignmentProperty* - -  *AssignmentProperty:* -   *Identifier* *Initialiseropt* -   *PropertyName* `:` *LeftHandSideExpression* *Initialiseropt* -   *PropertyName* `:` *AssignmentPattern* *Initialiseropt* - -  *ArrayAssignmentPattern:* -   `[` *Elisionopt* *AssignmentRestElementopt* `]` -   `[` *AssignmentElementList* `]` -   `[` *AssignmentElementList* `,` *Elisionopt* *AssignmentRestElementopt* `]` - -  *AssignmentElementList:* -   *Elisionopt* *AssignmentElement* -   *AssignmentElementList* `,` *Elisionopt* *AssignmentElement* - -  *AssignmentElement:* -   *LeftHandSideExpression* *Initialiseropt* -   *AssignmentPattern* *Initialiseropt* - -  *AssignmentRestElement:* -   `...` *LeftHandSideExpression* +A ***destructuring assignment*** is an assignment operation in which the left hand operand is a destructuring assignment pattern as defined by the *AssignmentPattern* production in the ECMAScript 6 specification. In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. An expression of type *S* is considered assignable to an assignment target *V* if one of the following is true: @@ -3009,9 +3235,7 @@ In a destructuring assignment expression, the type of the expression on the righ In an assignment property or element that includes a default value, the type of the default value must be assignable to the target given in the assignment property or element. -When the output target is ECMAScript 6 or higher, destructuring variable assignments remain unchanged in the emitted JavaScript code. - -When the output target is ECMAScript 3 or 5, destructuring variable assignments are rewritten to series of simple assignments. For example, the destructuring assignment +When the output target is ECMAScript 6 or higher, destructuring variable assignments remain unchanged in the emitted JavaScript code. When the output target is ECMAScript 3 or 5, destructuring variable assignments are rewritten to series of simple assignments. For example, the destructuring assignment ```TypeScript var x = 1; @@ -3028,18 +3252,18 @@ _a = [y, x], x = _a[0], y = _a[1]; var _a; ``` -## 4.18 The Comma Operator +## 4.22 The Comma Operator The comma operator permits the operands to be of any type and produces a result that is of the same type as the second operand. -## 4.19 Contextually Typed Expressions +## 4.23 Contextually Typed Expressions Type checking of an expression is improved in several contexts by factoring in the type of the destination of the value computed by the expression. In such situations, the expression is said to be ***contextually typed*** by the type of the destination. An expression is contextually typed in the following circumstances: * In a variable, parameter, binding property, binding element, or member declaration, an initializer expression is contextually typed by * the type given in the declaration's type annotation, if any, or otherwise - * for a parameter, the contextual type for the declaration (section [4.9.3](#4.9.3)), if any, or otherwise - * the type implied by the binding pattern in the declaration (section [5.1.3](#5.1.3)), if any. + * for a parameter, the type provided by a contextual signature (section [4.10](#4.10)), if any, or otherwise + * the type implied by the binding pattern in the declaration (section [5.2.3](#5.2.3)), if any. * In the body of a function declaration, function expression, arrow function, method declaration, or get accessor declaration that has a return type annotation, return expressions are contextually typed by the type given in the return type annotation. * In the body of a function expression or arrow function that has no return type annotation, if the function expression or arrow function is contextually typed by a function type with exactly one call signature, and if that call signature is non-generic, return expressions are contextually typed by the return type of that call signature. * In the body of a constructor declaration, return expressions are contextually typed by the containing class type. @@ -3083,7 +3307,7 @@ 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'. -## 4.20 Type Guards +## 4.24 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. @@ -3100,12 +3324,12 @@ function foo(x: number | string) { 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 a 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 a 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 a 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 a 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 a 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 a type guard in the left operand *when false*, provided the right operand contains no assignments to the variable or parameter. +* In the true branch statement of an 'if' statement, the type of a variable or parameter is *narrowed* by a type guard in the 'if' condition *when true*, provided no part of the 'if' statement contains 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 a type guard in the 'if' condition *when false*, provided no part of the 'if' statement contains assignments to the variable or parameter. +* In the true expression of a conditional expression, the type of a variable or parameter is *narrowed* by a type guard in the condition *when true*, provided no part of the conditional expression contains assignments to the variable or parameter. +* In the false expression of a conditional expression, the type of a variable or parameter is *narrowed* by a type guard in the condition *when false*, provided no part of the conditional expression contains assignments to the variable or parameter. +* In the right operand of a && operation, the type of a variable or parameter is *narrowed* by a type guard in the left operand *when true*, provided neither operand contains assignments to the variable or parameter. +* In the right operand of a || operation, the type of a variable or parameter is *narrowed* by a type guard in the left operand *when false*, provided neither operand contains 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: @@ -3198,17 +3422,29 @@ function getName(obj: Object) { } ``` -the type of `obj` is narrowed to `NamedItem` in the first condtional expression, and the inferred type of the `getName` function is `string`. +the type of `obj` is narrowed to `NamedItem` in the first conditional expression, and the inferred type of the `getName` function is `string`.
#
5 Statements -This chapter describes the static type checking TypeScript provides for JavaScript statements. TypeScript itself does not introduce any new statement constructs. +This chapter describes the static type checking TypeScript provides for JavaScript statements. TypeScript itself does not introduce any new statement constructs, but it does extend the grammar for local declarations to include interface, type alias, and enum declarations. -## 5.1 Variable Statements +## 5.1 Blocks -Variable statements are extended to include optional type annotations and ECMAScript 6 destructuring declarations. +Blocks are extended to include local interface, type alias, and enum declarations (classes are already included by the ECMAScript 6 grammar). + +  *Declaration:* *( Modified )* +   … +   *InterfaceDeclaration* +   *TypeAliasDeclaration* +   *EnumDeclaration* + +Local class, interface, type alias, and enum declarations are block scoped, similar to let and const declarations. + +## 5.2 Variable Statements + +Variable statements are extended to include optional type annotations.   *VariableDeclaration:* *( Modified )*    *SimpleVariableDeclaration* @@ -3216,23 +3452,20 @@ Variable statements are extended to include optional type annotations and ECMASc A variable declaration is either a simple variable declaration or a destructuring variable declaration. -### 5.1.1 Simple Variable Declarations +### 5.2.1 Simple Variable Declarations A ***simple variable declaration*** introduces a single named variable and optionally assigns it an initial value.   *SimpleVariableDeclaration:* -   *Identifier* *TypeAnnotationopt* *Initialiseropt* - -  *TypeAnnotation:* -   `:` *Type* +   *BindingIdentifier* *TypeAnnotationopt* *Initializeropt* The type *T* of a variable introduced by a simple variable declaration is determined as follows: * If the declaration includes a type annotation, *T* is that type. -* Otherwise, if the declaration includes an initializer expression, *T* is the widened form (section [3.11](#3.11)) of the type of the initializer expression. +* Otherwise, if the declaration includes an initializer expression, *T* is the widened form (section [3.12](#3.12)) of the type of the initializer expression. * Otherwise, *T* is the Any type. -When a variable declaration specifies both a type annotation and an initializer expression, the type of the initializer expression is required to be assignable to (section [3.10.4](#3.10.4)) the type given in the type annotation. +When a variable declaration specifies both a type annotation and an initializer expression, the type of the initializer expression is required to be assignable to (section [3.11.4](#3.11.4)) the type given in the type annotation. 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. @@ -3270,47 +3503,16 @@ var d: { x: number; y: number; } = { x: 0, y: undefined }; var e = <{ x: number; y: number; }> { x: 0, y: undefined }; ``` -### 5.1.2 Destructuring Variable Declarations +### 5.2.2 Destructuring Variable Declarations A ***destructuring variable declaration*** introduces zero or more named variables and initializes them with values extracted from properties of an object or elements of an array.   *DestructuringVariableDeclaration:* -   *BindingPattern* *TypeAnnotationopt* *Initialiser* +   *BindingPattern* *TypeAnnotationopt* *Initializer* -  *BindingPattern:* -   *ObjectBindingPattern* -   *ArrayBindingPattern* +Each binding property or element that specifies an identifier introduces a variable by that name. The type of the variable is the widened form (section [3.12](#3.12)) of the type associated with the binding property or element, as defined in the following. -  *ObjectBindingPattern:* -   `{` `}` -   `{` *BindingPropertyList* `,`*opt* `}` - -  *BindingPropertyList:* -   *BindingProperty* -   *BindingPropertyList* `,` *BindingProperty* - -  *BindingProperty:* -   *Identifier* *Initialiseropt* -   *PropertyName* `:` *Identifier* *Initialiseropt* -   *PropertyName* `:` *BindingPattern* *Initialiseropt* - -  *ArrayBindingPattern:* -   `[` *Elisionopt* *BindingRestElementopt* `]` -   `[` *BindingElementList* `]` -   `[` *BindingElementList* `,` *Elisionopt* *BindingRestElementopt* `]` - -  *BindingElementList:* -   *Elisionopt* *BindingElement* -   *BindingElementList* `,` *Elisionopt* *BindingElement* - -  *BindingElement:* -   *Identifier* *Initialiseropt* -   *BindingPattern* *Initialiseropt* - -  *BindingRestElement:* -   `...` *Identifier* - -Each binding property or element that specifies an identifier introduces a variable by that name. The type of the variable is the widened form (section [3.11](#3.11)) of the type associated with the binding property or element, as defined in the following. +*TODO: Document destructuring an [iterator](https://github.com/Microsoft/TypeScript/pull/2498) into an array*. The type *T* associated with a destructuring variable declaration is determined as follows: @@ -3401,7 +3603,7 @@ var _a = getSomeObject(), z = _d === void 0 ? 10 : _d; ``` -### 5.1.3 Implied Type +### 5.2.3 Implied Type A variable, parameter, binding property, or binding element declaration that specifies a binding pattern has an ***implied type*** which is determined as follows: @@ -3431,15 +3633,31 @@ var [a, b, c] = [1, "hello", true]; the array literal initializer expression is contextually typed by the implied type of the binding pattern, specifically the tuple type '[any, any, any]'. Because the contextual type is a tuple type, the resulting type of the array literal is the tuple type '[number, string, boolean]', and the destructuring declaration thus gives the types number, string, and boolean to a, b, and c respectively. -## 5.2 If, Do, and While Statements +## 5.3 Let and Const Declarations + +Let and const declarations are exended to include optional type annotations. + +  *LexicalBinding:* *( Modified )* +   *SimpleLexicalBinding* +   *DestructuringLexicalBinding* + +  *SimpleLexicalBinding:* +   *BindingIdentifier* *TypeAnnotationopt* *Initializeropt* + +  *DestructuringLexicalBinding:* +   *BindingPattern* *TypeAnnotationopt* *Initializeropt* + +*TODO: Document scoping and types of [let and const declarations](https://github.com/Microsoft/TypeScript/pull/904)*. + +## 5.4 If, Do, and While Statements Expressions controlling 'if', 'do', and 'while' statements can be of any type (and not just type Boolean). -## 5.3 For Statements +## 5.5 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.2](#5.2)). -## 5.4 For-In Statements +## 5.6 For-In Statements In a 'for-in' statement of the form @@ -3457,21 +3675,25 @@ for (var v in expr) statement *v* must be a variable declaration without a type annotation that declares a variable of type Any, and *expr* must be an expression of type Any, an object type, or a type parameter type. -## 5.5 Continue Statements +## 5.7 For-Of Statements + +*TODO: Document [for-of statements](https://github.com/Microsoft/TypeScript/issues/7)*. + +## 5.8 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. -## 5.6 Break Statements +## 5.9 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. -## 5.7 Return Statements +## 5.10 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 namespace 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. -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.23](#4.23)) 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). @@ -3485,19 +3707,19 @@ 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'. -## 5.8 With Statements +## 5.11 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. -## 5.9 Switch Statements +## 5.12 Switch Statements -In a 'switch' statement, each 'case' expression must be of a type that is assignable to or from (section [3.10.4](#3.10.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.11.4](#3.11.4)) the type of the 'switch' expression. -## 5.10 Throw Statements +## 5.13 Throw Statements The expression specified in a 'throw' statement can be of any type. -## 5.11 Try Statements +## 5.14 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. @@ -3509,26 +3731,23 @@ TypeScript extends JavaScript functions to include type parameters, parameter an ## 6.1 Function Declarations -Function declarations consist of an optional set of function overloads followed by an actual function implementation. +Function declarations are extended to permit the function body to be omitted in overload declarations.   *FunctionDeclaration:* *( Modified )* -   *FunctionOverloadsopt* *FunctionImplementation* +   `function` *BindingIdentifieropt* *CallSignature* `{` *FunctionBody* `}` +   `function` *BindingIdentifieropt* *CallSignature* `;` -  *FunctionOverloads:* -   *FunctionOverload* -   *FunctionOverloads* *FunctionOverload* +A *FunctionDeclaration* introduces a named value of a function type in the containing declaration space. The *BindingIdentifier* is optional only when the function declaration occurs in an export default declaration (section [11.3.4.2](#11.3.4.2)). -  *FunctionOverload:* -   `function` *Identifier* *CallSignature* `;` +Function declarations that specify a body are called ***function implementations*** and function declarations without a body are called ***function overloads***. It is possible to specify multiple overloads for the same function (i.e. for the same name in the same declaration space), but a function can have at most one implementation. All declarations for the same function must specify the same set of modifiers (i.e. the same combination of `declare`, `export`, and `default`). -  *FunctionImplementation:* -   `function` *Identifier* *CallSignature* `{` *FunctionBody* `}` +When a function has overload declarations, the overloads determine the call signatures of the type given to the function object and the function implementation signature (if any) must be assignable to that type. Otherwise, the function implementation itself determines the call signature. -A function declaration introduces a function with the given name in the containing declaration space. Function overloads, if present, must specify the same name as the function implementation. If a function declaration includes overloads, the overloads determine the call signatures of the type given to the function object and the function implementation signature must be assignable to that type. Otherwise, the function implementation itself determines the call signature. Function overloads have no other effect on a function declaration. +When a function has both overloads and an implementation, the overloads must precede the implementation and all of the declarations must be consecutive with no intervening grammatical elements. ## 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.15](#4.15). Function overloads are purely a compile-time construct. They have no impact on the emitted JavaScript and thus no run-time cost. @@ -3568,8 +3787,8 @@ A function implementation without a return type annotation is said to be an ***i * 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.4](#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.10.3](#3.10.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. +* Otherwise, if *f* is a contextually typed function expression (section [4.10](#4.10)), the inferred return type is the union type (section [3.4](#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.11.3](#3.11.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 @@ -3590,11 +3809,11 @@ An explicitly typed function whose return type isn't the Void or the Any type mu 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.11](#3.11)) of the type of the initializer expression. +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.23](#4.23)) 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.12](#3.12)) of the type of the initializer expression. Initializer expressions are evaluated in the scope of the function body but are not permitted to reference local variables and are only permitted to access parameters that are declared to the left of the parameter they initialize, unless the parameter reference occurs in a nested function expression. -For each parameter with an initializer, a statement that substitutes the default value for an omitted argument is included in the generated JavaScript, as described in section [6.6](#6.6). The example +When the output target is ECMAScript 3 or 5, for each parameter with an initializer, a statement that substitutes the default value for an omitted argument is included in the generated JavaScript, as described in section [6.6](#6.6). The example ```TypeScript function strange(x: number, y = x * 2, z = x + y) { @@ -3625,13 +3844,14 @@ the local variable 'x' is in scope in the parameter initializer (thus hiding the ## 6.4 Destructuring Parameter Declarations -Parameter declarations can specify binding patterns (section [3.8.2.2](#3.8.2.2)) and are then called ***destructuring parameter declarations***. Similar to a destructuring variable declaration (section [5.1.2](#5.1.2)), a destructuring parameter declaration introduces zero or more named locals and initializes them with values extracted from properties or elements of the object or array passed as an argument for the parameter. +Parameter declarations can specify binding patterns (section [3.9.2.2](#3.9.2.2)) and are then called ***destructuring parameter declarations***. Similar to a destructuring variable declaration (section [5.2.2](#5.2.2)), a destructuring parameter declaration introduces zero or more named locals and initializes them with values extracted from properties or elements of the object or array passed as an argument for the parameter. The type of local introduced in a destructuring parameter declaration is determined in the same manner as a local introduced by a destructuring variable declaration, except the type *T* associated with a destructuring parameter declaration is determined as follows: * If the declaration includes a type annotation, *T* is that type. -* Otherwise, if the declaration includes an initializer expression, *T* is the widened form (section [3.11](#3.11)) of the type of the initializer expression. -* Otherwise, if the declaration specifies a binding pattern, *T* is the implied type of that binding pattern (section [5.1.3](#5.1.3)). +* If the declaration occurs in a function expression for which a contextual signature is available (section [4.10](#4.10)), *T* is the type obtained from the contextual signature. +* Otherwise, if the declaration includes an initializer expression, *T* is the widened form (section [3.12](#3.12)) of the type of the initializer expression. +* Otherwise, if the declaration specifies a binding pattern, *T* is the implied type of that binding pattern (section [5.2.3](#5.2.3)). * Otherwise, if the parameter is a rest parameter, *T* is `any[]`. * Otherwise, *T* is `any`. @@ -3683,7 +3903,7 @@ function drawText({ text, location: [x, y], bold }: DrawTextInfo) { ## 6.5 Generic Functions -A function implementation may include type parameters in its signature (section [3.8.2.1](#3.8.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.9.2.1](#3.9.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. @@ -3701,9 +3921,9 @@ 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.5.1](#3.5.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.6.1](#3.6.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 +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.15.2](#4.15.2)) from the types of the regular arguments in the call. In the example ```TypeScript class Person { @@ -3741,6 +3961,14 @@ where *Parameter* is the parameter name and *Default* is the default value expre *FunctionStatements* is the code generated for the statements specified in the function body. +## 6.7 Generator Functions + +*TODO: Document [generator functions](https://github.com/Microsoft/TypeScript/issues/2873)*. + +## 6.8 Type Guard Functions + +*TODO: Document [type guard functions](https://github.com/Microsoft/TypeScript/issues/1007)*. +
#
7 Interfaces @@ -3749,16 +3977,16 @@ Interfaces provide the ability to name and parameterize object types and to comp 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.10.2](#3.10.2)). +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.11.2](#3.11.2)). Class declarations may reference interfaces in their implements clause to validate that they provide an implementation of the interfaces. ## 7.1 Interface Declarations -An interface declaration declares a new named type (section [3.6](#3.6)) by introducing a type name in the containing module. +An interface declaration declares an ***interface type***.   *InterfaceDeclaration:* -   `interface` *Identifier* *TypeParametersopt* *InterfaceExtendsClauseopt* *ObjectType* +   `interface` *BindingIdentifier* *TypeParametersopt* *InterfaceExtendsClauseopt* *ObjectType*   *InterfaceExtendsClause:*    `extends` *ClassOrInterfaceTypeList* @@ -3770,9 +3998,9 @@ An interface declaration declares a new named type (section [3.6](#3.6)) by intr   *ClassOrInterfaceType:*    *TypeReference* -The *Identifier* of an interface declaration may not be one of the predefined type names (section [3.7.1](#3.7.1)). +An *InterfaceDeclaration* introduces a named type (section [3.7](#3.7)) in the containing declaration space. The *BindingIdentifier* of an interface declaration may not be one of the predefined type names (section [3.8.1](#3.8.1)). -An interface may optionally have type parameters (section [3.5.1](#3.5.1)) that serve as placeholders for actual types to be provided when the interface is referenced in type references. An interface with type parameters is called a ***generic interface***. The type parameters of a generic interface declaration are in scope in the entire declaration and may be referenced in the *InterfaceExtendsClause* and *ObjectType* body. +An interface may optionally have type parameters (section [3.6.1](#3.6.1)) that serve as placeholders for actual types to be provided when the interface is referenced in type references. An interface with type parameters is called a ***generic interface***. The type parameters of a generic interface declaration are in scope in the entire declaration and may be referenced in the *InterfaceExtendsClause* and *ObjectType* body. 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. @@ -3786,9 +4014,9 @@ The following constraints must be satisfied by an interface declaration or other * An interface declaration may not, directly or indirectly, specify a base type that originates in the same declaration. In other words an interface cannot, directly or indirectly, be a base type of itself, regardless of type arguments. * An interface cannot declare a property with the same name as an inherited private or protected property. -* Inherited properties with the same name must be identical (section [3.10.2](#3.10.2)). -* All properties of the interface must satisfy the constraints implied by the index signatures of the interface as specified in section [3.8.4](#3.8.4). -* The instance type (section [3.6.1](#3.6.1)) of the declared interface must be assignable (section [3.10.4](#3.10.4)) to each of the base type references. +* Inherited properties with the same name must be identical (section [3.11.2](#3.11.2)). +* All properties of the interface must satisfy the constraints implied by the index signatures of the interface as specified in section [3.9.4](#3.9.4). +* The instance type (section [3.7.1](#3.7.1)) of the declared interface must be assignable (section [3.11.4](#3.11.4)) to each of the base type references. An interface is permitted to inherit identical members from multiple base types and will in that case only contain one occurrence of each particular member. @@ -3891,7 +4119,7 @@ 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.10](#3.10)). +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.11](#3.11)). 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. @@ -3919,24 +4147,24 @@ function asMoverShaker(obj: any): MoverShaker { # 8 Classes -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. +TypeScript extends JavaScript classes to include type parameters, implements clauses, accessibility modifiers, member variable declarations, and parameter property declarations in constructors. -*NOTE: TypeScript currently doesn't support class expressions or nested class declarations from the ECMAScript 6 proposal*. +*TODO: Document [abstract classes](https://github.com/Microsoft/TypeScript/issues/3578)*. ## 8.1 Class Declarations -Class declarations introduce named types and provide implementations of those types. Classes support inheritance, allowing derived classes to extend and specialize base classes. +A class declaration declares a ***class type*** and a ***constructor function***. -  *ClassDeclaration:* -   `class` *Identifier* *TypeParametersopt* *ClassHeritage* `{` *ClassBody* `}` +  *ClassDeclaration:* *( Modified )* +   `class` *BindingIdentifieropt* *TypeParametersopt* *ClassHeritage* `{` *ClassBody* `}` -A *ClassDeclaration* declares a ***class type*** and a ***constructor function***, both with the name given by *Identifier*, in the containing module. The class type is created from the instance members declared in the class body and the instance members inherited from the base class. The constructor function is created from the constructor declaration, the static member declarations in the class body, and the static members inherited from the base class. The constructor function initializes and returns an instance of the class type. +A *ClassDeclaration* introduces a named type (the class type) and a named value (the constructor function) in the containing declaration space. The class type is formed from the instance members declared in the class body and the instance members inherited from the base class. The constructor function is given an anonymous type formed from the constructor declaration, the static member declarations in the class body, and the static members inherited from the base class. The constructor function initializes and returns an instance of the class type. -The *Identifier* of a class declaration may not be one of the predefined type names (section [3.7.1](#3.7.1)). +The *BindingIdentifier* of a class declaration may not be one of the predefined type names (section [3.8.1](#3.8.1)). The *BindingIdentifier* is optional only when the class declaration occurs in an export default declaration (section [11.3.4.2](#11.3.4.2)). -A class may optionally have type parameters (section [3.5.1](#3.5.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*. +A class may optionally have type parameters (section [3.6.1](#3.6.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 named value called 'Point' (the constructor function) in the containing declaration space. ```TypeScript class Point { @@ -3946,7 +4174,7 @@ class Point { } ``` -The 'Point' type is exactly equivalent to +The named type 'Point' is exactly equivalent to ```TypeScript interface Point { @@ -3956,7 +4184,7 @@ interface Point { } ``` -The 'Point' member is a constructor function whose type corresponds to the declaration +The named value 'Point' is a constructor function whose type corresponds to the declaration ```TypeScript var Point: { @@ -3975,9 +4203,11 @@ the identifier 'Point' in the type annotation refers to the class instance type, ### 8.1.1 Class Heritage Specification +*TODO: Update this section to reflect [expressions in class extends clauses](https://github.com/Microsoft/TypeScript/pull/3516)*. + The heritage specification of a class consists of optional `extends` and `implements` clauses. The `extends` clause specifies the base class of the class and the `implements` clause specifies a set of interfaces for which to validate the class provides an implementation. -  *ClassHeritage:* +  *ClassHeritage:* *( Modified )*    *ClassExtendsClauseopt* *ImplementsClauseopt*   *ClassExtendsClause:* @@ -3995,7 +4225,7 @@ The following constraints must be satisfied by the class heritage specification * If present, the type reference specified in the `extends` clause must denote a class type. Furthermore, the *TypeName* part of the type reference is required to be a reference to the class constructor function when evaluated as an expression. * A class declaration may not, directly or indirectly, specify a base class that originates in the same declaration. In other words a class cannot, directly or indirectly, be a base class of itself, regardless of type arguments. -* The instance type (section [3.6.1](#3.6.1)) of the declared class must be assignable (section [3.10.4](#3.10.4)) to the base type reference and each of the type references listed in the `implements` clause. +* The instance type (section [3.7.1](#3.7.1)) of the declared class must be assignable (section [3.11.4](#3.11.4)) to the base type reference and each of the type references listed in the `implements` clause. * The constructor function type created by the class declaration must be assignable to the base class constructor function type, ignoring construct signatures. The following example illustrates a situation in which the first rule above would be violated: @@ -4003,7 +4233,7 @@ The following example illustrates a situation in which the first rule above woul ```TypeScript class A { a: number; } -module Foo { +namespace Foo { var A = 1; class B extends A { b: string; } } @@ -4019,14 +4249,7 @@ Note that because TypeScript has a structural type system, a class doesn't need 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* - -  *ClassElements:* -   *ClassElement* -   *ClassElements* *ClassElement* - -  *ClassElement:* +  *ClassElement:* *( Modified )*    *ConstructorDeclaration*    *PropertyMemberDeclaration*    *IndexMemberDeclaration* @@ -4043,7 +4266,7 @@ The members of a class consist of the members introduced through member declarat Members are either ***instance members*** or ***static members***. -Instance members are members of the class type (section [8.2.4](#8.2.4)) and its associated instance type. Within constructors, instance member functions, and instance member accessors, the type of `this` is the instance type (section [3.6.1](#3.6.1)) of the class. +Instance members are members of the class type (section [8.2.4](#8.2.4)) and its associated instance type. Within constructors, instance member functions, and instance member accessors, the type of `this` is the instance type (section [3.7.1](#3.7.1)) of the class. Static members are declared using the `static` modifier and are members of the constructor function type (section [8.2.5](#8.2.5)). Within static member functions and static member accessors, the type of `this` is the constructor function type. @@ -4091,7 +4314,7 @@ In class 'A', the accesses to 'x' are permitted because 'x' is declared in 'A', 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.10.4](#3.10.4)) to the type of the overridden property member, or otherwise a compile-time error occurs. +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.11.4](#3.11.4)) to the type of the overridden property member, or otherwise a compile-time error occurs. Base class instance member functions can be overridden by derived class instance member functions, but not by other kinds of members. @@ -4099,11 +4322,11 @@ Base class instance member variables and accessors can be overridden by derived Base class static property members can be overridden by derived class static property members of any kind as long as the types are compatible, as described above. -An index member in a derived class is said to override an index member in a base class when the derived class index member is of the same index kind (string or numeric) as the base class index member. The type of an overriding index member must be assignable (section [3.10.4](#3.10.4)) to the type of the overridden index member, or otherwise a compile-time error occurs. +An index member in a derived class is said to override an index member in a base class when the derived class index member is of the same index kind (string or numeric) as the base class index member. The type of an overriding index member must be assignable (section [3.11.4](#3.11.4)) to the type of the overridden index member, or otherwise a compile-time error occurs. ### 8.2.4 Class Types -A class declaration declares a new named type (section [3.6](#3.6)) called a class type. Within the constructor and member functions of a class, the type of `this` is the instance type (section [3.6.1](#3.6.1)) of this class type. The class type has the following members: +A class declaration declares a new named type (section [3.7](#3.7)) called a class type. Within the constructor and member functions of a class, the type of `this` is the instance type (section [3.7.1](#3.7.1)) of this class type. The class type has the following members: * A property for each instance member variable declaration in the class body. * A property of a function type for each instance member function declaration in the class body. @@ -4112,7 +4335,7 @@ A class declaration declares a new named type (section [3.6](#3.6)) called a cla * An index signature for each instance index member declaration in the class body. * All base class instance type property or index members that are not overridden in the class. -All instance property members (including those that are private or protected) of a class must satisfy the constraints implied by the index members of the class as specified in section [3.8.4](#3.8.4). +All instance property members (including those that are private or protected) of a class must satisfy the constraints implied by the index members of the class as specified in section [3.9.4](#3.9.4). In the example @@ -4212,23 +4435,16 @@ Note that the construct signatures in the constructor function types have the sa A constructor declaration declares the constructor function of a class.   *ConstructorDeclaration:* -   *ConstructorOverloadsopt* *ConstructorImplementation* - -  *ConstructorOverloads:* -   *ConstructorOverload* -   *ConstructorOverloads* *ConstructorOverload* - -  *ConstructorOverload:* +   *AccessibilityModifieropt* `constructor` `(` *ParameterListopt* `)` `{` *FunctionBody* `}`    *AccessibilityModifieropt* `constructor` `(` *ParameterListopt* `)` `;` -  *ConstructorImplementation:* -   *AccessibilityModifieropt* `constructor` `(` *ParameterListopt* `)` `{` *FunctionBody* `}` +Constructor declarations that specify a body are called ***constructor implementations*** and constructor declarations without a body are called ***constructor overloads***. It is possible to specify multiple constructor overloads in a class, but a class can have at most one constructor implementation. All constructor declarations in a class must specify the same set of modifiers. Only public constructors are supported and private or protected constructors result in an error. -A class may contain at most one constructor declaration. If a class contains no constructor declaration, an automatic constructor is provided, as described in section [8.3.3](#8.3.3). +In a class with no constructor declaration, an automatic constructor is provided, as described in section [8.3.3](#8.3.3). -Overloads and the implementation of a constructor may include an accessibility modifier, but only public constructors are supported and private or protected constructors result in an error. +When a class has constructor overloads, the overloads determine the construct signatures of the type given to the constructor function object, and the constructor implementation signature (if any) must be assignable to that type. Otherwise, the constructor implementation itself determines the construct signature. This exactly parallels the way overloads are processed in a function declaration (section [6.2](#6.2)). -If a constructor declaration includes overloads, the overloads determine the construct signatures of the type given to the constructor function object, and the constructor implementation signature must be assignable to that type. Otherwise, the constructor implementation itself determines the construct signature. This exactly parallels the way overloads are processed in a function declaration (section [6.2](#6.2)). +When a class has both constructor overloads and a constructor implementation, the overloads must precede the implementation and all of the declarations must be consecutive with no intervening grammatical elements. The function body of a constructor is permitted to contain return statements. If return statements specify expressions, those expressions must be of types that are assignable to the instance type of the class. @@ -4236,7 +4452,7 @@ The type parameters of a generic class are in scope and accessible in a construc ### 8.3.1 Constructor Parameters -Similar to functions, only the constructor implementation (and not constructor overloads) can specify default value expressions for optional parameters. It is a compile-time error for such default value expressions to reference `this`. For each parameter with a default value, a statement that substitutes the default value for an omitted argument is included in the JavaScript generated for the constructor function. +Similar to functions, only the constructor implementation (and not constructor overloads) can specify default value expressions for optional parameters. It is a compile-time error for such default value expressions to reference `this`. When the output target is ECMAScript 3 or 5, for each parameter with a default value, a statement that substitutes the default value for an omitted argument is included in the JavaScript generated for the constructor function. A parameter of a *ConstructorImplementation* may be prefixed with a `public`, `private`, or `protected` modifier. This is called a ***parameter property declaration*** and is shorthand for declaring a property with the same name as the parameter and initializing it with the value of the parameter. For example, the declaration @@ -4264,7 +4480,7 @@ class Point { ### 8.3.2 Super Calls -Super calls (section [4.8.1](#4.8.1)) are used to call the constructor of the base class. A super call consists of the keyword `super` followed by an argument list enclosed in parentheses. For example: +Super calls (section [4.9.1](#4.9.1)) are used to call the constructor of the base class. A super call consists of the keyword `super` followed by an argument list enclosed in parentheses. For example: ```TypeScript class ColoredPoint extends Point { @@ -4358,13 +4574,13 @@ var Point: { A member variable declaration declares an instance member variable or a static member variable.   *MemberVariableDeclaration:* -   *AccessibilityModifieropt* `static`*opt* *PropertyName* *TypeAnnotationopt* *Initialiseropt* `;` +   *AccessibilityModifieropt* `static`*opt* *PropertyName* *TypeAnnotationopt* *Initializeropt* `;` -The type associated with a member variable declaration is determined in the same manner as an ordinary variable declaration (see section [5.1](#5.1)). +The type associated with a member variable declaration is determined in the same manner as an ordinary variable declaration (see section [5.2](#5.2)). An instance member variable declaration introduces a member in the class instance type and optionally initializes a property on instances of the class. Initializers in instance member variable declarations are executed once for every new instance of the class and are equivalent to assignments to properties of `this` in the constructor. In an initializer expression for an instance member variable, `this` is of the class instance type. -A static member variable declaration introduces a property in the constructor function type and optionally initializes a property on the constructor function object. Initializers in static member variable declarations are executed once when the containing program or module is loaded. +A static member variable declaration introduces a property in the constructor function type and optionally initializes a property on the constructor function object. Initializers in static member variable declarations are executed once when the containing script or module is loaded. Initializer expressions for instance member variables are evaluated in the scope of the class constructor body but are not permitted to reference parameters or local variables of the constructor. This effectively means that entities from outer scopes by the same name as a constructor parameter or local variable are inaccessible in initializer expressions for instance member variables. @@ -4402,27 +4618,18 @@ class Employee { A member function declaration declares an instance member function or a static member function.   *MemberFunctionDeclaration:* -   *MemberFunctionOverloadsopt* *MemberFunctionImplementation* - -  *MemberFunctionOverloads*: -   *MemberFunctionOverload* -   *MemberFunctionOverloads* *MemberFunctionOverload* - -  *MemberFunctionOverload*: +   *AccessibilityModifieropt* `static`*opt* *PropertyName* *CallSignature* `{` *FunctionBody* `}`    *AccessibilityModifieropt* `static`*opt* *PropertyName* *CallSignature* `;` -  *MemberFunctionImplementation:* -   *AccessibilityModifieropt* `static`*opt* *PropertyName* *CallSignature* `{` *FunctionBody* `}` - A member function declaration is processed in the same manner as an ordinary function declaration (section [6](#6)), except that in a member function `this` has a known type. -All overloads of a member function must have the same accessibility (public, private, or protected) and kind (instance or static). +All declarations for the same member function must specify the same accessibility (public, private, or protected) and kind (instance or static). An instance member function declaration declares a property in the class instance type and assigns a function object to a property on the prototype object of the class. In the body of an instance member function declaration, `this` is of the class instance type. A static member function declaration declares a property in the constructor function type and assigns a function object to a property on the constructor function object. In the body of a static member function declaration, the type of `this` is the constructor function type. -A member function can access overridden base class members using a super property access (section [4.8.2](#4.8.2)). For example +A member function can access overridden base class members using a super property access (section [4.9.2](#4.9.2)). For example ```TypeScript class Point { @@ -4490,16 +4697,24 @@ A static member accessor declaration declares a property in the constructor func 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.4.4 Dynamic Property Declarations + +If the *PropertyName* of a property member declaration is a computed property name that doesn't denote a well-known symbol ([2.2.3](#2.2.3)), the construct is considered a ***dynamic property declaration***. The following rules apply to dynamic property declarations: + +* A dynamic property declaration does not introduce a property in the class instance type or constructor function type. +* The property name expression of a dynamic property assignment must be of type Any or the String, Number, or Symbol primitive type. +* The name associated with a dynamic property declarations is considered to be a numeric property name if the property name expression is of type Any or the Number primitive type. + ## 8.5 Index Member Declarations -An index member declaration introduces an index signature (section [3.8.4](#3.8.4)) in the class instance type. +An index member declaration introduces an index signature (section [3.9.4](#3.9.4)) in the class instance type.   *IndexMemberDeclaration:*    *IndexSignature* `;` Index member declarations have no body and cannot specify an accessibility modifier. -A class declaration can have at most one string index member declaration and one numeric index member declaration. All instance property members of a class must satisfy the constraints implied by the index members of the class as specified in section [3.8.4](#3.8.4). +A class declaration can have at most one string index member declaration and one numeric index member declaration. All instance property members of a class must satisfy the constraints implied by the index members of the class as specified in section [3.9.4](#3.9.4). It is not possible to declare index members for the static side of a class. @@ -4507,7 +4722,7 @@ Note that it is seldom meaningful to include a string index signature in a class ## 8.6 Code Generation -This section describes the structure of the JavaScript code generated from TypeScript classes. +When the output target is ECMAScript 6 or higher, type parameters, implements clauses, accessibility modifiers, and member variable declarations are removed in the emitted code, but otherwise class declarations are emitted as written. When the output target is ECMAScript 3 or 5, more comprehensive rewrites are performed, as described in this section. ### 8.6.1 Classes Without Extends Clauses @@ -4696,14 +4911,14 @@ An enum type is a distinct subtype of the Number primitive type with an associat ## 9.1 Enum Declarations -An enum declaration declares an ***enum type*** and an ***enum object*** in the containing module. +An enum declaration declares an ***enum type*** and an ***enum object***.   *EnumDeclaration:* -   `const`*opt* `enum` *Identifier* `{` *EnumBodyopt* `}` +   `const`*opt* `enum` *BindingIdentifier* `{` *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'. +An *EnumDeclaration* introduces a named type (the enum type) and a named value (the enum object) in the containing declaration space. The enum type is a distinct subtype of the Number primitive type. The enum object is a value 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.7.1](#3.7.1)). +The *BindingIdentifier* of an enum declaration may not be one of the predefined type names (section [3.8.1](#3.8.1)). When an enum declaration includes a `const` modifier it is said to be a constant enum declaration. The members of a constant enum declaration must all have constant values that can be computed at compile time. Constant enum declarations are discussed in section [9.4](#9.4). @@ -4749,6 +4964,8 @@ The body of an enum declaration defines zero or more enum members which are the   *EnumValue:*    *AssignmentExpression* +The *PropertyName* of an enum member cannot be a computed property name ([2.2.3](#2.2.3)). + Enum members are either ***constant members*** or ***computed members***. Constant members have known constant values that are substituted in place of references to the members in the generated JavaScript code. Computed members have values that are computed at run-time and not known at compile-time. No substitution is performed for references to computed members. An enum member is classified as follows: @@ -4858,46 +5075,48 @@ var Color;
-#
10 Internal Modules +# 10 Namespaces -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. +Namespaces provide a mechanism for organizing code and declarations in hierarchies of named containers. Namespaces have named members that each denote a value, a type, or a namespace, or some combination thereof, and those members may be local or exported. The body of a namespace corresponds to a function that is executed once, thereby providing a mechanism for maintaining local state with assured isolation. Namespaces can be thought of as a formalization of the [immediately-invoked function expression](https://en.wikipedia.org/wiki/Immediately-invoked_function_expression) (IIFE) pattern. -## 10.1 Module Declarations +## 10.1 Namespace Declarations -An internal module declaration declares a namespace name and, in the case of an instantiated module, a member name in the containing module. +A namespace declaration introduces a name with a namespace meaning and, in the case of an instantiated namespace, a value meaning in the containing declaration space. -  *ModuleDeclaration:* -   `module` *IdentifierPath* `{` *ModuleBody* `}` +  *NamespaceDeclaration:* +   `namespace` *IdentifierPath* `{` *NamespaceBody* `}`   *IdentifierPath:* -   *Identifier* -   *IdentifierPath* `.` *Identifier* +   *BindingIdentifier* +   *IdentifierPath* `.` *BindingIdentifier* -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. +Namespaces are declared using the `namespace` keyword, but for backward compatibility of earlier versions of TypeScript a `module` keyword can also be used. -When a module identifier is referenced as a *ModuleName* (section [3.7.2](#3.7.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: +Namespaces are either ***instantiated*** or ***non-instantiated***. A non-instantiated namespace is a namespace containing only interface types, type aliases, and other non-instantiated namespace. An instantiated namespace is a namespace that doesn't meet this definition. In intuitive terms, an instantiated namespace is one for which a namespace instance is created, whereas a non-instantiated namespace is one for which no code is generated. + +When a namespace identifier is referenced as a *NamespaceName* (section [3.8.2](#3.8.2)) it denotes a container of namespace and type names, and when a namespace identifier is referenced as a *PrimaryExpression* (section [4.3](#4.3)) it denotes the singleton namespace instance. For example: ```TypeScript -module M { +namespace M { export interface P { x: number; y: number; } export var a = 1; } -var p: M.P; // M used as ModuleName +var p: M.P; // M used as NamespaceName var m = M; // M used as PrimaryExpression var x1 = M.a; // M used as PrimaryExpression 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 *NamespaceName* 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 namespace 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: +A namespace declaration that specifies an *IdentifierPath* with more than one identifier is equivalent to a series of nested single-identifier namespace declarations where all but the outermost are automatically exported. For example: ```TypeScript -module A.B.C { +namespace A.B.C { export var x = 1; } ``` @@ -4905,106 +5124,128 @@ module A.B.C { corresponds to ```TypeScript -module A { - export module B { - export module C { +namespace A { + export namespace B { + export namespace C { export var x = 1; } } } ``` -## 10.2 Module Body +The hierarchy formed by namespace and named type names partially mirrors that formed by namespace instances and members. The example -The body of an internal module corresponds to a function that is executed once to initialize the module instance. +```TypeScript +namespace A { + export namespace B { + export class C { } + } +} +``` -  *ModuleBody:* -   *ModuleElementsopt* +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 -  *ModuleElements:* -   *ModuleElement* -   *ModuleElements* *ModuleElement* +```TypeScript +var c: A.B.C = new A.B.C(); +``` -  *ModuleElement:* +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. + +## 10.2 Namespace Body + +The body of a namespace corresponds to a function that is executed once to initialize the namespace instance. + +  *NamespaceBody:* +   *NamespaceElementsopt* + +  *NamespaceElements:* +   *NamespaceElement* +   *NamespaceElements* *NamespaceElement* + +  *NamespaceElement:*    *Statement* -   `export`*opt* *VariableDeclaration* -   `export`*opt* *FunctionDeclaration* -   `export`*opt* *ClassDeclaration* -   `export`*opt* *InterfaceDeclaration* -   `export`*opt* *TypeAliasDeclaration* -   `export`*opt* *EnumDeclaration* -   `export`*opt* *ModuleDeclaration* -   `export`*opt* *ImportDeclaration* -   `export`*opt* *AmbientDeclaration* +   *LexicalDeclaration* +   *FunctionDeclaration* +   *GeneratorDeclaration* +   *ClassDeclaration* +   *InterfaceDeclaration* +   *TypeAliasDeclaration* +   *EnumDeclaration* +   *NamespaceDeclaration +   AmbientDeclaration +   ImportAliasDeclaration +   ExportNamespaceElement* -Each module body has a declaration space for local variables (including functions, modules, class constructor functions, and enum objects), a declaration space for local named types (classes, interfaces, and enums), and a declaration space for local namespaces (containers of named types). Every declaration (whether local or exported) in a module contributes to one or more of these declaration spaces. +  *ExportNamespaceElement:* +   `export` *VariableStatement* +   `export` *LexicalDeclaration* +   `export` *FunctionDeclaration* +   `export` *GeneratorDeclaration* +   `export` *ClassDeclaration* +   `export` *InterfaceDeclaration* +   `export` *TypeAliasDeclaration* +   `export` *EnumDeclaration* +   `export` *NamespaceDeclaration* +   `export` *AmbientDeclaration* +   `export` *ImportAliasDeclaration* -## 10.3 Import Declarations +## 10.3 Import Alias Declarations -Import declarations are used to create local aliases for entities in other modules. +Import alias declarations are used to create local aliases for entities in other namespaces. -  *ImportDeclaration:* -   `import` *Identifier* `=` *EntityName* `;` +  *ImportAliasDeclaration:* +   `import` *BindingIdentifier* `=` *EntityName* `;`   *EntityName:* -   *ModuleName* -   *ModuleName* `.` *Identifier* +   *NamespaceName* +   *NamespaceName* `.` *IdentifierReference* -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 a single identifier is resolved as a *NamespaceName* and is thus required to reference a namespace. The resulting local alias references the given namespace and is itself classified as a namespace. -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 *NamespaceName* followed by an identifier that names an exported entity in the given namespace. The resulting local alias has all the meanings of the referenced entity. (As many as three distinct meanings are possible for an entity name—value, type, and namespace.) In effect, it is as if the imported entity was declared locally with the local alias name. In the example ```TypeScript -module A { +namespace A { export interface X { s: string } export var X: X; } -module B { +namespace B { interface A { n: number } - import Y = A; // Alias only for module A - import Z = A.X; // Alias for both type and member A.X + import Y = A; // Alias for namespace A + import Z = A.X; // Alias for type and value A.X var v: Z = Z; } ``` -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 namespace '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 +If the *NamespaceName* portion of an *EntityName* references an instantiated namespace, the *NamespaceName* is required to reference the namespace instance when evaluated as an expression. In the example ```TypeScript -module A { +namespace A { export interface X { s: string } } -module B { +namespace B { var A = 1; import Y = 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'. +'Y' is a local alias for the non-instantiated namespace 'A'. If the declaration of 'A' is changed such that 'A' becomes an instantiated namespace, 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 namespace instance of namespace 'A'. When an import statement includes an export modifier, all meanings of the local alias are exported. ## 10.4 Export Declarations -An export declaration declares an externally accessible module member. An export declaration is simply a regular declaration prefixed with the keyword `export`. +An export declaration declares an externally accessible namespace member. An export declaration is simply a regular declaration prefixed with the keyword `export`. -Exported class, interface, and enum types can be accessed as a *TypeName* (section [3.7.2](#3.7.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. +The members of a namespace's export declaration space (section [2.3](#2.3)) constitute the namespace's ***export member set***. A namespace's ***instance type*** is an object type with a property for each member in the namespace's export member set that denotes a value. -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. -* A property of a constructor type for each exported class declaration. -* A property of an object type for each exported enum declaration. -* A property of an object type for each exported instantiated module declaration. -* A property for each exported import alias that references a variable, function, class, enum, or instantiated module. - -An exported member depends on a (possibly empty) set of named types (section [3.6](#3.6)). Those named types must be at least as accessible as the exported member, or otherwise an error occurs. +An exported member depends on a (possibly empty) set of named types (section [3.7](#3.7)). Those named types must be at least as accessible as the exported member, or otherwise an error occurs. The named types upon which a member depends are the named types occurring in the transitive closure of the ***directly depends on*** relationship defined as follows: @@ -5012,40 +5253,40 @@ The named types upon which a member depends are the named types occurring in the * A function directly depends on each *Type* specified in a parameter or return type annotation. * A class directly depends on each *Type* specified as a type parameter constraint, each *TypeReference* specified as a base class or implemented interface, and each *Type* specified in a constructor parameter type annotation, public member variable type annotation, public member function parameter or return type annotation, public member accessor parameter or return type annotation, or index signature type annotation. * An interface directly depends on each *Type* specified as a type parameter constraint, each *TypeReference* specified as a base interface, and the *ObjectType* specified as its body. -* A module directly depends on its exported members. +* A namespace directly depends on its exported members. * A *Type* or *ObjectType* directly depends on every *TypeReference* that occurs within the type at any level of nesting. * A *TypeReference* directly depends on the type it references and on each *Type* specified as a type argument. -A named type *T* having a root module *R* (section [2.3](#2.3)) is said to be ***at least as accessible as*** a member *M* if +A named type *T* having a root namespace *R* (section [2.3](#2.3)) is said to be ***at least as accessible as*** a member *M* if -* *R* is the global module or an external module, or -* *R* is an internal module in the parent module chain of *M*. +* *R* is the global namespace or a module, or +* *R* is a namespace in the parent namespace chain of *M*. In the example ```TypeScript interface A { x: string; } -module M { +namespace M { export interface B { x: A; } export interface C { x: B; } 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 I t is declared in a parent namespace of foo's namespace. ## 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. +Namespaces are "open-ended" and namespace declarations with the same qualified name relative to a common root (as defined in section [2.3](#2.3)) contribute to a single namespace. For example, the following two declarations of a namespace 'outer' might be located in separate source files. File a.ts: ```TypeScript -module outer { +namespace outer { var local = 1; // Non-exported local variable export var a = local; // outer.a - export module inner { + export namespace inner { export var x = 10; // outer.inner.x } } @@ -5054,16 +5295,16 @@ module outer { File b.ts: ```TypeScript -module outer { +namespace outer { var local = 2; // Non-exported local variable export var b = local; // outer.b - export module inner { + export namespace inner { export var y = 20; // outer.inner.y } } ``` -Assuming the two source files are part of the same program, the two declarations will have the global module as their common root and will therefore contribute to the same module instance, the instance type of which will be: +Assuming the two source files are part of the same program, the two declarations will have the global namespace as their common root and will therefore contribute to the same namespace instance, the instance type of which will be: ```TypeScript { @@ -5076,15 +5317,17 @@ Assuming the two source files are part of the same program, the two declarations } ``` -Declaration merging does not apply to local aliases created by import declarations. In other words, it is not possible have an import declaration and a module declaration for the same name within the same module body. +Declaration merging does not apply to local aliases created by import alias declarations. In other words, it is not possible have an import alias declaration and a namespace declaration for the same name within the same namespace body. -Declaration merging also extends to internal module declarations with the same qualified name relative to a common root as a function, class, or enum declaration: +*TODO: Clarify rules for [alias resolution](https://github.com/Microsoft/TypeScript/issues/3158)*. -* When merging a function and an internal module, the type of the function object is merged with the instance type of the module. In effect, the overloads or implementation of the function provide the call signatures and the exported members of the module provide the properties of the combined type. -* 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. +Declaration merging also extends to namespace declarations with the same qualified name relative to a common root as a function, class, or enum declaration: -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 function and a namespace, the type of the function object is merged with the instance type of the namespace. In effect, the overloads or implementation of the function provide the call signatures and the exported members of the namespace provide the properties of the combined type. +* When merging a class and a namespace, the type of the constructor function object is merged with the instance type of the namespace. 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 namespace provide the properties of the combined type. It is an error to have static class members and exported namespace members with the same name. +* When merging an enum and a namespace, the type of the enum object is merged with the instance type of the namespace. In effect, the members of the enum and the exported members of the namespace provide the properties of the combined type. It is an error to have enum members and exported namespace members with the same name. + +When merging a non-ambient function or class declaration and a non-ambient namespace declaration, the function or class declaration must be located prior to the namespace 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 @@ -5098,7 +5341,7 @@ function point(x: number, y: number): Point { return { x: x, y: y }; } -module point { +namespace point { export var origin = point(0, 0); export function equals(p1: Point, p2: Point) { return p1.x == p2.x && p1.y == p2.y; @@ -5110,20 +5353,20 @@ 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 namespace declaration for 'point' is located after the function declaration. ## 10.6 Code Generation -An internal module generates JavaScript code that is equivalent to the following: +A namespace generates JavaScript code that is equivalent to the following: ```TypeScript -var ; -(function() { - -})(||(={})); +var ; +(function() { + +})(||(={})); ``` -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 *NamespaceName* is the name of the namespace and *NamespaceStatements* is the code generated for the statements in the namespace body. The *NamespaceName* 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 namespace 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 namespace instance, but rather it extends the existing instance (which may have just been created in the function call). This ensures that namespaces can extend each other. An import statement generates code of the form @@ -5131,182 +5374,428 @@ An import statement generates code of the form var = ; ``` -This code is emitted only if the imported entity is referenced as a *PrimaryExpression* somewhere in the body of the importing module. If an imported entity is referenced only as a *TypeName* or *ModuleName*, nothing is emitted. This ensures that types declared in one internal module can be referenced through an import alias in another internal module with no run-time overhead. +This code is emitted only if the imported entity is referenced as a *PrimaryExpression* somewhere in the body of the importing namespace. If an imported entity is referenced only as a *TypeName* or *NamespaceName*, nothing is emitted. This ensures that types declared in one namespace can be referenced through an import alias in another namespace with no run-time overhead. -When a variable is exported, all references to the variable in the body of the module are replaced with +When a variable is exported, all references to the variable in the body of the namespace are replaced with ```TypeScript -. +. ``` -This effectively promotes the variable to be a property on the module instance and ensures that all references to the variable become references to the property. +This effectively promotes the variable to be a property on the namespace instance and ensures that all references to the variable become references to the property. -When a function, class, enum, or module is exported, the code generated for the entity is followed by an assignment statement of the form +When a function, class, enum, or namespace is exported, the code generated for the entity is followed by an assignment statement of the form ```TypeScript -. = ; +. = ; ``` -This copies a reference to the entity into a property on the module instance. +This copies a reference to the entity into a property on the namespace instance.
-#
11 Source Files and External Modules +# 11 Scripts and Modules -TypeScript implements external modules that are closely aligned with those proposed for ECMAScript 6 and supports code generation targeting CommonJS and AMD module systems. +TypeScript implements support for ECMAScript 6 modules and supports down-level code generation targeting CommonJS, AMD, and other 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*. +## 11.1 Programs and Source Files -## 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.   *SourceFile:*    *ImplementationSourceFile*    *DeclarationSourceFile*   *ImplementationSourceFile:* -   *ImplementationElementsopt* - -  *ImplementationElements:* -   *ImplementationElement* -   *ImplementationElements* *ImplementationElement* - -  *ImplementationElement:* -   *ModuleElement* -   *ExportAssignment* -   *AmbientExternalModuleDeclaration* -   `export`*opt* *ExternalImportDeclaration* +   *ImplementationScript* +   *ImplementationModule*   *DeclarationSourceFile:* -   *DeclarationElementsopt* +   *DeclarationScript* +   *DeclarationModule* -  *DeclarationElements:* -   *DeclarationElement* -   *DeclarationElements* *DeclarationElement* +Source files with extension '.ts' are ***implementation source files*** containing statements and declarations, and source files with extension '.d.ts' are ***declaration source files*** containing declarations only. -  *DeclarationElement:* -   *ExportAssignment* -   *AmbientExternalModuleDeclaration* -   `export`*opt* *InterfaceDeclaration* -   `export`*opt* *TypeAliasDeclaration* -   `export`*opt* *ImportDeclaration* -   `export`*opt* *AmbientDeclaration* -   `export`*opt* *ExternalImportDeclaration* +Declaration source files are a strict subset of implementation source files and are 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. 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 *TypeAliasDeclaration* (section [3.9](#3.9)), *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. - -Implementation and declaration source files that contain no import or export declarations form the single ***global module***. Entities declared in the global module are in scope everywhere in a program. Initialization order of the source files that make up the global module ultimately depends on the order in which the generated JavaScript files are loaded at run-time (which, for example, may be controlled by <script/> tags that reference the generated JavaScript files). - -Implementation and declaration source files that contain at least one external import declaration, export assignment, or top-level exported declaration are considered separate ***external modules***. Entities declared in an external module are in scope only in that module, but exported entities can be imported into other modules using import declarations. Initialization order of external modules is determined by the module loader being and is not specified by the TypeScript language. However, it is generally the case that non-circularly dependent modules are automatically loaded and initialized in the correct order. - -External modules can additionally be declared using *AmbientExternalModuleDeclarations* in the global module that directly specify the external module names as string literals. This is described further in section [12.2](#12.2). - ### 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 module 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 module import declaration that specifies a relative module name (section [11.3.1](#11.3.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. +* A module import declaration that specifies a top-level module name (section [11.3.1](#11.3.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. -## 11.2 External Modules +## 11.2 Scripts -External modules are separately loaded bodies of code referenced using external module names. External modules can be likened to functions that are loaded and executed once to initialize their associated module instance. Entities declared in an external module are private and inaccessible elsewhere unless they are exported. +Source files that contain no module import or export declarations are classified as ***scripts***. Scripts form the single ***global namespace*** and entities declared in scripts are in scope everywhere in a program. -External modules are written as separate source files that contain at least one external import declaration, export assignment, or top-level exported declaration. Specifically, if a source file contains at least one +  *ImplementationScript:* +   *ImplementationScriptElementsopt* -* *ExternalImportDeclaration*, -* *ExportAssignment*, -* top-level exported *VariableDeclaration*, -* top-level exported *FunctionDeclaration*, -* top-level exported *ClassDeclaration*, -* top-level exported *InterfaceDeclaration*, -* top-level exported *TypeAliasDeclaration*, -* top-level exported *EnumDeclaration*, -* top-level exported *ModuleDeclaration*, -* top-level exported *ImportDeclaration*, or -* top-level exported *AmbientDeclaration*, +  *ImplementationScriptElements:* +   *ImplementationScriptElement* +   *ImplementationScriptElements* *ImplementationScriptElement* -that source file is considered an external module; otherwise, the source file is considered part of the global module. +  *ImplementationScriptElement:* +   *ImplementationElement* +   *AmbientModuleDeclaration* -Below is an example of two external modules written in separate source files. +  *ImplementationElement:* +   *Statement* +   *LexicalDeclaration* +   *FunctionDeclaration* +   *GeneratorDeclaration* +   *ClassDeclaration* +   *InterfaceDeclaration* +   *TypeAliasDeclaration* +   *EnumDeclaration* +   *NamespaceDeclaration* +   *AmbientDeclaration* +   *ImportAliasDeclaration* -File main.ts: +  *DeclarationScript:* +   *DeclarationScriptElementsopt* + +  *DeclarationScriptElements:* +   *DeclarationScriptElement* +   *DeclarationScriptElements* *DeclarationScriptElement* + +  *DeclarationScriptElement:* +   *DeclarationElement* +   *AmbientModuleDeclaration* + +  *DeclarationElement:* +   *InterfaceDeclaration* +   *TypeAliasDeclaration* +   *NamespaceDeclaration* +   *AmbientDeclaration* +   *ImportAliasDeclaration* + +The initialization order of the scripts that make up the global namespace ultimately depends on the order in which the generated JavaScript files are loaded at run-time (which, for example, may be controlled by <script/> tags that reference the generated JavaScript files). + +## 11.3 Modules + +Source files that contain at least one module import or export declaration are considered separate ***modules***. Non-exported entities declared in a module are in scope only in that module, but exported entities can be imported into other modules using import declarations. + +  *ImplementationModule:* +   *ImplementationModuleElementsopt* + +  *ImplementationModuleElements:* +   *ImplementationModuleElement* +   *ImplementationModuleElements* *ImplementationModuleElement* + +  *ImplementationModuleElement:* +   *ImplementationElement* +   *ImportDeclaration* +   *ImportAliasDeclaration* +   *ImportRequireDeclaration* +   *ExportImplementationElement* +   *ExportDefaultImplementationElement* +   *ExportListDeclaration* +   *ExportAssignment* + +  *DeclarationModule:* +   *DeclarationModuleElementsopt* + +  *DeclarationModuleElements:* +   *DeclarationModuleElement* +   *DeclarationModuleElements* *DeclarationModuleElement* + +  *DeclarationModuleElement:* +   *DeclarationElement* +   *ImportDeclaration* +   *ImportAliasDeclaration* +   *ExportDeclarationElement* +   *ExportDefaultDeclarationElement* +   *ExportListDeclaration* +   *ExportAssignment* + +Initialization order of modules is determined by the module loader being used and is not specified by the TypeScript language. However, it is generally the case that non-circularly dependent modules are automatically loaded and initialized in the correct order. + +Modules can additionally be declared using *AmbientModuleDeclarations* in declaration scripts that directly specify the module names as string literals. This is described further in section [12.2](#12.2). + +Below is an example of two modules written in separate source files: ```TypeScript -import log = require("./log"); -log.message("hello"); -``` +// -------- main.ts -------- +import { message } from "./log"; +message("hello"); -File log.ts: - -```TypeScript +// -------- log.ts -------- export function message(s: string) { console.log(s); } ``` -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. -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. +TypeScript supports multiple patterns of JavaScript code generation for modules: -### 11.2.1 External Module Names +* CommonJS. This format is used by server frameworks such as node.js. +* AMD (Asynchronous Module Definition). This format is used by asynchronous module loaders such as RequireJS. +* UMD (Universal Module Definition). A variation of the AMD format that allows modules to also be loaded by CommonJS loaders. +* System. This format is used to represent ECMAScript 6 semantics with high fidelity in down-level environments. -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. +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 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. -* 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 "..". +### 11.3.1 Module Names + +Modules are identified and referenced using module names. The following definition is aligned with that provided in the [CommonJS Modules](http://www.commonjs.org/specs/modules/1.0/) 1.0 specification. + +* A module name is a string of terms delimited by forward slashes. +* Module names may not have file-name extensions like ".js". +* Module names may be relative or top-level. A 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 module references, TypeScript associates a file path with every module. The file path is simply the path of the module's source file without the file extension. For example, a module contained in the source file 'C:\src\lib\io.ts' has the file path 'C:/src/lib/io' and a 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: +A 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 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. +* If the import declaration specifies a relative 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 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 module name and the program contains an *AmbientModuleDeclaration* (section [12.2](#12.2)) with a string literal that specifies that exact name, then the import declaration references that ambient module. +* If the import declaration specifies a top-level module name and the program contains no *AmbientModuleDeclaration* (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. -### 11.2.2 External Import Declarations +### 11.3.2 Import Declarations -External import declarations are used to import external modules and create local aliases by which they may be referenced. +Import declarations are used to import entities from other modules and provide bindings for them in the current module. -  *ExternalImportDeclaration:* -   `import` *Identifier* `=` *ExternalModuleReference* `;` +An import declaration of the form -  *ExternalModuleReference:* -   `require` `(` *StringLiteral* `)` +```TypeScript +import * as m from "mod"; +``` -The string literal specified in an *ExternalModuleReference* is interpreted as an external module name (section [11.2.1](#11.2.1)). +imports the module with the given name and creates a local binding for the module itself. The local binding is classified as a value (representing the module instance) and a namespace (representing a container of types and namespaces). -An external import declaration introduces a local identifier that references a given external module. The local identifier becomes an alias for, and is classified exactly like, the entity or entities exported from the referenced external module. Specifically, if the referenced external module contains no export assignment the identifier is classified as a module, and if the referenced external module contains an export assignment the identifier is classified exactly like the entity or entities named in the export assignment. +An import declaration of the form -### 11.2.3 Export Declarations +```TypeScript +import { x, y, z } from "mod"; +``` -An external module that contains no export assignment (section [11.2.4](#11.2.4)) exports an entity classified as a module. Similarly to an internal module, export declarations (section [10.4](#10.4)) in the external module are used to declare the members of this entity. +imports a given module and creates local bindings for a specified list of exported members of the module. The specified names must each reference an entity in the export member set ([11.3.4.4](#11.3.4.4)) of the given module. The local bindings have the same names and classifications as the entities they represent unless `as` clauses are used to that specify different local names: -Unlike a non-instantiated internal module (section [10.1](#10.1)), an external module containing only interface types and non-instantiated internal modules still has a module instance associated with it, albeit one with no members. +```TypeScript +import { x as a, y as b } from "mod"; +``` -If an external module contains an export assignment it is an error for the external module to also contain export declarations. The two types of exports are mutually exclusive. +An import declaration of the form -### 11.2.4 Export Assignments +```TypeScript +import d from "mod"; +``` -An export assignment designates a module member as the entity to be exported in place of the external module itself. +is exactly equivalent to the import declaration + +```TypeScript +import { default as d } from "mod"; +``` + +An import declaration of the form + +```TypeScript +import "mod"; +``` + +imports the given module without creating any local bindings (this is useful only if the imported module has side effects). + +### 11.3.3 Import Require Declarations + +Import require declarations exist for backward compatibility with earlier versions of TypeScript. + +  *ImportRequireDeclaration:* +   `import` *BindingIdentifier* `=` `require` `(` *StringLiteral* `)` `;` + +An import require declaration introduces a local identifier that references a given module. The string literal specified in an import require declaration is interpreted as a module name (section [11.3.1](#11.3.1)). The local identifier introduced by the declaration becomes an alias for, and is classified exactly like, the entity exported from the referenced module. Specifically, if the referenced module contains no export assignment the identifier is classified as a value and a namespace, and if the referenced module contains an export assignment the identifier is classified exactly like the entity named in the export assignment. + +An import require declaration of the form + +```TypeScript +import m = require("mod"); +``` + +is equivalent to the ECMAScript 6 import declaration + +```TypeScript +import * as m from "mod"; +``` + +provided the referenced module contains no export assignment. + +### 11.3.4 Export Declarations + +An export declaration declares one or more exported module members. The exported members of a module can be imported in other modules using import declarations ([11.3.2](#11.3.2)). + +#### 11.3.4.1 Export Modifiers + +In the body of a module, a declaration can export the declared entity by including an `export` modifier. + +  *ExportImplementationElement:* +   `export` *VariableStatement* +   `export` *LexicalDeclaration* +   `export` *FunctionDeclaration* +   `export` *GeneratorDeclaration* +   `export` *ClassDeclaration* +   `export` *InterfaceDeclaration* +   `export` *TypeAliasDeclaration* +   `export` *EnumDeclaration* +   `export` *NamespaceDeclaration* +   `export` *AmbientDeclaration* +   `export` *ImportAliasDeclaration* + +  *ExportDeclarationElement:* +   `export` *InterfaceDeclaration* +   `export` *TypeAliasDeclaration* +   `export` *AmbientDeclaration* +   `export` *ImportAliasDeclaration* + +In addition to introducing a name in the local declaration space of the module, an exported declaration introduces the same name with the same classification in the module's export declaration space. For example, the declaration + +```TypeScript +export function point(x: number, y: number) { + return { x, y }; +} +``` + +introduces a local name `point` and an exported name `point` that both reference the function. + +#### 11.3.4.2 Export Default Declarations + +Export default declarations provide short-hand syntax for exporting an entity named `default`. + +  *ExportDefaultImplementationElement:* +   `export` `default` *FunctionDeclaration* +   `export` `default` *GeneratorDeclaration* +   `export` `default` *ClassDeclaration* +   `export` `default` *AssignmentExpression* `;` + +  *ExportDefaultDeclarationElement:* +   `export` `default` *AmbientFunctionDeclaration* +   `export` `default` *AmbientClassDeclaration* +   `export` `default` *IdentifierReference* `;` + +An *ExportDefaultImplementationElement* or *ExportDefaultDeclarationElement* for a function, generator, or class introduces a value named `default`, and in the case of a class, a type named `default`, in the containing module's export declaration space. The declaration may optionally specify a local name for the exported function, generator, or class. For example, the declaration + +```TypeScript +export default function point(x: number, y: number) { + return { x, y }; +} +``` + +introduces a local name `point` and an exported name `default` that both reference the function. The declaration is effectively equivalent to + +```TypeScript +function point(x: number, y: number) { + return { x, y }; +} + +export default point; +``` + +which again is equivalent to + +```TypeScript +function point(x: number, y: number) { + return { x, y }; +} + +export { point as default }; +``` + +An *ExportDefaultImplementationElement* or *ExportDefaultDeclarationElement* for an expression consisting of a single identifier must name an entity declared in the current module or the global namespace. The declaration introduces an entity named `default`, with the same classification as the referenced entity, in the containing module's export declaration space. For example, the declarations + +```TypeScript +interface Point { + x: number; + y: number; +} + +function Point(x: number, y: number): Point { + return { x, y }; +} + +export default Point; +``` + +introduce a local name `Point` and an exported name `default`, both with a value and a type meaning. + +An *ExportDefaultImplementationElement* for any expression but a single identifier introduces a value named `default` in the containing module's export declaration space. For example, the declaration + +```TypeScript +export default "hello"; +``` + +introduces an exported value named `default` of type string. + +#### 11.3.4.3 Export List Declarations + +An export list declaration exports one or more entities from the current module or a specified module. + +  *ExportListDeclaration:* +   `export` `*` *FromClause* `;` +   `export` *ExportClause* *FromClause* `;` +   `export` *ExportClause* `;` + +An *ExportListDeclaration* without a *FromClause* exports entities from the current module. In a declaration of the form + +```TypeScript +export { x }; +``` + +the name `x` must reference an entity declared in the current module or the global namespace, and the declaration introduces an entity with the same name and meaning in the containing module's export declaration space. + +An *ExportListDeclaration* with a *FromClause* re-exports entities from a specified module. In a declaration of the form + +```TypeScript +export { x } from "mod"; +``` + +the name `x` must reference an entity in the export member set of the specified module, and the declaration introduces an entity with the same name and meaning in the containing module's export declaration space. No local bindings are created for `x`. + +The *ExportClause* of an *ExportListDeclaration* can specify multiple entities and may optionally specify different names to be used for the exported entities. For example, the declaration + +```TypeScript +export { x, y as b, z as c }; +``` + +introduces entities named `x`, `b`, and `c` in the containing module's export declaration space with the same meaning as the local entities named `x`, `y`, and `z` respectively. + +An *ExportListDeclaration* that specifies `*` instead of an *ExportClause* is called an ***export star*** declaration. An export star declaration re-exports all members of a specified module. + +```TypeScript +export * from "mod"; +``` + +Explicitly exported members take precedence over members re-exported using export star declarations, as described in the following section. + +#### 11.3.4.4 Export Member Set + +The ***export member set*** of a particular module is determined by starting with an empty set of members *E* and an empty set of processed modules *P*, and then processing the module as described below to form the full set of exported members in *E*. Processing a module *M* consists of these steps: + +* Add *M* to *P*. +* Add to *E* each member in the export declaration space of *M* with a name that isn't already in *E*. +* For each export star declaration in *M*, in order of declaration, process the referenced module if it is not already in *P*. + +A module's ***instance type*** is an object type with a property for each member in the module's export member set that denotes a value. + +If a module contains an export assignment it is an error for the module to also contain export declarations. The two types of exports are mutually exclusive. + +### 11.3.5 Export Assignments + +Export assignments exist for backward compatibility with earlier versions of TypeScript. An export assignment designates a module member as the entity to be exported in place of the module itself.   *ExportAssignment:* -   `export` `=` *Identifier* `;` +   `export` `=` *IdentifierReference* `;` -When an external module containing an export assignment is imported, the local alias introduced by the external import declaration takes on all meanings of the identifier named in the export assignment. +A module containing an export assignment can be imported using an import require declaration ([11.3.3](#11.3.3)), and the local alias introduced by the import require declaration then takes on all meanings of the identifier named in the export assignment. -It is an error for an external module to contain more than one export assignment. +A module containing an export assignment can also be imported using a regular import declaration ([11.3.2](#11.3.2)) provided the entity referenced in the export assignment is declared as a namespace or as a variable with a type annotation. Assume the following example resides in the file 'point.ts': @@ -5319,7 +5808,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 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"); @@ -5330,11 +5819,11 @@ var p2 = Pt.origin; Note that there is no requirement that the import alias use the same name as the exported entity. -### 11.2.5 CommonJS Modules +### 11.3.6 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](http://www.commonjs.org/specs/modules/1.0/) 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 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.3](#11.3) above generates the following JavaScript code when compiled for the CommonJS Modules pattern: File main.js: @@ -5351,7 +5840,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. +A module 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 *NamespaceName* or *TypeQueryExpression*, nothing is emitted. An example: @@ -5392,9 +5881,9 @@ the emitted JavaScript would have no dependency on the 'geometry' module and wou var p = { x: 10, y: 20 }; ``` -### 11.2.6 AMD Modules +### 11.3.7 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](https://github.com/amdjs/amdjs-api/wiki/AMD) (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 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. @@ -5416,31 +5905,40 @@ 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 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 *NamespaceName*, 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 namespaces, 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 -Ambient declarations are written using the `declare` keyword and can declare variables, functions, classes, enums, internal modules, or external modules. +Ambient declarations are written using the `declare` keyword and can declare variables, functions, classes, enums, namespaces, or modules.   *AmbientDeclaration:*    `declare` *AmbientVariableDeclaration*    `declare` *AmbientFunctionDeclaration*    `declare` *AmbientClassDeclaration*    `declare` *AmbientEnumDeclaration* -   `declare` *AmbientModuleDeclaration* +   `declare` *AmbientNamespaceDeclaration* ### 12.1.1 Ambient Variable Declarations An ambient variable declaration introduces a variable in the containing declaration space.   *AmbientVariableDeclaration:* -   `var` *Identifier*  *TypeAnnotationopt* `;` +   `var` *AmbientBindingList* `;` +   `let` *AmbientBindingList* `;` +   `const` *AmbientBindingList* `;` + +  *AmbientBindingList:* +   *AmbientBinding* +   *AmbientBindingList* `,` *AmbientBinding* + +  *AmbientBinding:* +   *BindingIdentifier* *TypeAnnotationopt* An ambient variable declaration may optionally include a type annotation. If no type annotation is present, the variable is assumed to have type Any. @@ -5451,18 +5949,18 @@ An ambient variable declaration does not permit an initializer expression to be An ambient function declaration introduces a function in the containing declaration space.   *AmbientFunctionDeclaration:* -   `function` *Identifier* *CallSignature* `;` +   `function` *BindingIdentifier* *CallSignature* `;` -Ambient functions may be overloaded by specifying multiple ambient function declarations with the same name, but it is an error to declare multiple overloads that are considered identical (section [3.10.2](#3.10.2)) or differ only in their return types. +Ambient functions may be overloaded by specifying multiple ambient function declarations with the same name, but it is an error to declare multiple overloads that are considered identical (section [3.11.2](#3.11.2)) or differ only in their return types. Ambient function declarations cannot specify a function bodies and do not permit default parameter values. ### 12.1.3 Ambient Class Declarations -An ambient class declaration declares a class instance type and a constructor function in the containing module. +An ambient class declaration declares a class instance type and a constructor function in the containing declaration space.   *AmbientClassDeclaration:* -   `class` *Identifier* *TypeParametersopt* *ClassHeritage* `{` *AmbientClassBody* `}` +   `class` *BindingIdentifier* *TypeParametersopt* *ClassHeritage* `{` *AmbientClassBody* `}`   *AmbientClassBody:*    *AmbientClassBodyElementsopt* @@ -5497,55 +5995,44 @@ Ambient enum declarations differ from non-ambient enum declarations in two ways: Ambient enum declarations are otherwise processed in the same manner as non-ambient enum declarations. -### 12.1.5 Ambient Module Declarations +### 12.1.5 Ambient Namespace Declarations -An ambient module declaration declares an internal module. +An ambient namespace declaration declares a namespace. -  *AmbientModuleDeclaration:* -   `module` *IdentifierPath* `{` *AmbientModuleBody* `}` +  *AmbientNamespaceDeclaration:* +   `namespace` *IdentifierPath* `{` *AmbientNamespaceBody* `}` -  *AmbientModuleBody:* -   *AmbientModuleElementsopt* +  *AmbientNamespaceBody:* +   *AmbientNamespaceElementsopt* -  *AmbientModuleElements:* -   *AmbientModuleElement* -   *AmbientModuleElements* *AmbientModuleElement* +  *AmbientNamespaceElements:* +   *AmbientNamespaceElement* +   *AmbientNamespaceElements* *AmbientNamespaceElement* -  *AmbientModuleElement:* +  *AmbientNamespaceElement:*    `export`*opt* *AmbientVariableDeclaration* +   `export`*opt* *AmbientLexicalDeclaration*    `export`*opt* *AmbientFunctionDeclaration*    `export`*opt* *AmbientClassDeclaration*    `export`*opt* *InterfaceDeclaration*    `export`*opt* *AmbientEnumDeclaration* -   `export`*opt* *AmbientModuleDeclaration* -   `export`*opt* *ImportDeclaration* +   `export`*opt* *AmbientNamespaceDeclaration* +   `export`*opt* *ImportAliasDeclaration* -Except for *ImportDeclarations*, *AmbientModuleElements* always declare exported entities regardless of whether they include the optional `export` modifier. +Except for *ImportAliasDeclarations*, *AmbientNamespaceElements* always declare exported entities regardless of whether they include the optional `export` modifier. -## 12.2 Ambient External Module Declarations +## 12.2 Ambient Module Declarations -An *AmbientExternalModuleDeclaration* declares an external module. This type of declaration is permitted only at the top level in a source file that contributes to the global module (section [11.1](#11.1)). The *StringLiteral* must specify a top-level external module name. Relative external module names are not permitted. +An *AmbientModuleDeclaration* declares a module. This type of declaration is permitted only at the top level in a source file that contributes to the global namespace (section [11.1](#11.1)). The *StringLiteral* must specify a top-level module name. Relative module names are not permitted. -  *AmbientExternalModuleDeclaration:* -   `declare` `module` *StringLiteral* `{`  *AmbientExternalModuleBody* `}` +  *AmbientModuleDeclaration:* +   `declare` `module` *StringLiteral* `{`  *DeclarationModule* `}` -  *AmbientExternalModuleBody:* -   *AmbientExternalModuleElementsopt* +An *ImportRequireDeclaration* in an *AmbientModuleDeclaration* may reference other modules only through top-level module names. Relative module names are not permitted. -  *AmbientExternalModuleElements:* -   *AmbientExternalModuleElement* -   *AmbientExternalModuleElements* *AmbientExternalModuleElement* +If an ambient 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 module declaration contains no export assignment, entities declared in the module are exported regardless of whether their declarations include the optional `export` modifier. -  *AmbientExternalModuleElement:* -   *AmbientModuleElement* -   *ExportAssignment* -   `export`*opt* *ExternalImportDeclaration* - -An *ExternalImportDeclaration* in an *AmbientExternalModuleDeclaration* may reference other external modules only through top-level external module names. Relative external module names are not permitted. - -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 modules are "open-ended" and ambient module declarations with the same string literal name contribute to a single module. For example, the following two declarations of a module 'io' might be located in separate source files. ```TypeScript declare module "io" { @@ -5570,7 +6057,7 @@ declare module "io" { # A Grammar -This appendix contains a summary of the grammar found in the main document. As described in section [2.1](#2.1), the TypeScript grammar is a superset of the grammar defined in the ECMAScript Language Specification (specifically, the ECMA-262 Standard, 5th Edition) and this appendix lists only productions that are new or modified from the ECMAScript grammar. +This appendix contains a summary of the grammar found in the main document. As described in section [2.1](#2.1), the TypeScript grammar is a superset of the grammar defined in the [ECMAScript Language Specification](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf) (specifically, the ECMA-262 Standard, 6th Edition) and this appendix lists only productions that are new or modified from the ECMAScript grammar. ## A.1 Types @@ -5582,7 +6069,7 @@ This appendix contains a summary of the grammar found in the main document. As d    *TypeParameterList* `,` *TypeParameter*   *TypeParameter:* -   *Identifier* *Constraintopt* +   *BindingIdentifier* *Constraintopt*   *Constraint:*    `extends` *Type* @@ -5598,13 +6085,17 @@ This appendix contains a summary of the grammar found in the main document. As d    *Type*   *Type:* -   *PrimaryOrUnionType* +   *UnionOrIntersectionOrPrimaryType*    *FunctionType*    *ConstructorType* -  *PrimaryOrUnionType:* -   *PrimaryType* -   *UnionType* +  *UnionOrIntersectionOrPrimaryType:* +   *UnionType* +   *IntersectionOrPrimaryType* + +  *IntersectionOrPrimaryType:* +   *IntersectionType* +   *PrimaryType*   *PrimaryType:*    *ParenthesizedType* @@ -5623,28 +6114,31 @@ This appendix contains a summary of the grammar found in the main document. As d    `number`    `boolean`    `string` +   `symbol`    `void`   *TypeReference:*    *TypeName* *[no LineTerminator here]* *TypeArgumentsopt*   *TypeName:* -   *Identifier* -   *ModuleName* `.` *Identifier* +   *IdentifierReference* +   *NamespaceName* `.` *IdentifierReference* -  *ModuleName:* -   *Identifier* -   *ModuleName* `.` *Identifier* +  *NamespaceName:* +   *IdentifierReference* +   *NamespaceName* `.` *IdentifierReference*   *ObjectType:*    `{` *TypeBodyopt* `}`   *TypeBody:* -   *TypeMemberList* `;`*opt* +   *TypeMemberList* `;`*opt* +   *TypeMemberList* `,`*opt*   *TypeMemberList:*    *TypeMember* -   *TypeMemberList* `;` *TypeMember* +   *TypeMemberList* `;` *TypeMember* +   *TypeMemberList* `,` *TypeMember*   *TypeMember:*    *PropertySignature* @@ -5667,7 +6161,10 @@ This appendix contains a summary of the grammar found in the main document. As d    *Type*   *UnionType:* -   *PrimaryOrUnionType* `|` *PrimaryType* +   *UnionOrIntersectionOrPrimaryType* `|` *IntersectionOrPrimaryType* + +  *IntersectionType:* +   *IntersectionOrPrimaryType* `&` *PrimaryType*   *FunctionType:*    *TypeParametersopt* `(` *ParameterListopt* `)` `=>` *Type* @@ -5679,7 +6176,7 @@ This appendix contains a summary of the grammar found in the main document. As d    `typeof` *TypeQueryExpression*   *TypeQueryExpression:* -   *Identifier* +   *IdentifierReference*    *TypeQueryExpression* `.` *IdentifierName*   *PropertySignature:* @@ -5690,6 +6187,9 @@ This appendix contains a summary of the grammar found in the main document. As d    *StringLiteral*    *NumericLiteral* +  *TypeAnnotation:* +   `:` *Type* +   *CallSignature:*    *TypeParametersopt* `(` *ParameterListopt* `)` *TypeAnnotationopt* @@ -5707,42 +6207,48 @@ This appendix contains a summary of the grammar found in the main document. As d    *RequiredParameterList* `,` *RequiredParameter*   *RequiredParameter:* -   *AccessibilityModifieropt* *Identifier* *TypeAnnotationopt* -   *Identifier* `:` *StringLiteral* +   *AccessibilityModifieropt* *BindingIdentifierOrPattern* *TypeAnnotationopt* +   *BindingIdentifier* `:` *StringLiteral*   *AccessibilityModifier:*    `public`    `private`    `protected` +  *BindingIdentifierOrPattern:* +   *BindingIdentifier* +   *BindingPattern* +   *OptionalParameterList:*    *OptionalParameter*    *OptionalParameterList* `,` *OptionalParameter*   *OptionalParameter:* -   *AccessibilityModifieropt* *Identifier* `?` *TypeAnnotationopt* -   *AccessibilityModifieropt* *Identifier* *TypeAnnotationopt* *Initialiser* -   *Identifier* `?` `:` *StringLiteral* +   *AccessibilityModifieropt* *BindingIdentifierOrPattern* `?` *TypeAnnotationopt* +   *AccessibilityModifieropt* *BindingIdentifierOrPattern* *TypeAnnotationopt* *Initializer* +   *BindingIdentifier* `?` `:` *StringLiteral*   *RestParameter:* -   `...` *Identifier* *TypeAnnotationopt* +   `...` *BindingIdentifier* *TypeAnnotationopt*   *ConstructSignature:*    `new` *TypeParametersopt* `(` *ParameterListopt* `)` *TypeAnnotationopt*   *IndexSignature:* -   `[` *Identifier* `:` `string` `]` *TypeAnnotation* -   `[` *Identifier* `:` `number` `]` *TypeAnnotation* +   `[` *BindingIdentifier* `:` `string` `]` *TypeAnnotation* +   `[` *BindingIdentifier* `:` `number` `]` *TypeAnnotation*   *MethodSignature:*    *PropertyName* `?`*opt* *CallSignature*   *TypeAliasDeclaration:* -   `type` *Identifier* `=` *Type* `;` +   `type` *BindingIdentifier* *TypeParametersopt* `=` *Type* `;` ## A.2 Expressions -  *PropertyAssignment:* *( Modified )* +  *PropertyDefinition:* *( Modified )* +   *IdentifierReference* +   *CoverInitializedName*    *PropertyName* `:` *AssignmentExpression*    *PropertyName* *CallSignature* `{` *FunctionBody* `}`    *GetAccessor* @@ -5752,36 +6258,13 @@ This appendix contains a summary of the grammar found in the main document. As d    `get` *PropertyName* `(` `)` *TypeAnnotationopt* `{` *FunctionBody* `}`   *SetAccessor:* -   `set` *PropertyName* `(` *Identifier* *TypeAnnotationopt* `)` `{` *FunctionBody* `}` - -  *ElementList:* *( Modified )* -   *Elisionopt* *AssignmentExpression* -   *Elisionopt* *SpreadElement* -   *ElementList* `,` *Elisionopt* *AssignmentExpression* -   *ElementList* `,` *Elisionopt* *SpreadElement* - -  *SpreadElement:* -   `...` *AssignmentExpression* - -  *CallExpression:* *( Modified )* -   … -   `super` `(` *ArgumentListopt* `)` -   `super` `.` *IdentifierName* +   `set` *PropertyName* `(` *BindingIdentifierOrPattern* *TypeAnnotationopt* `)` `{` *FunctionBody* `}`   *FunctionExpression:* *( Modified )* -   `function` *Identifieropt* *CallSignature* `{` *FunctionBody* `}` +   `function` *BindingIdentifieropt* *CallSignature* `{` *FunctionBody* `}` -  *AssignmentExpression:* *( Modified )* -   … -   *ArrowFunctionExpression* - -  *ArrowFunctionExpression:* -   *ArrowFormalParameters* `=>` *Block* -   *ArrowFormalParameters* `=>` *AssignmentExpression* - -  *ArrowFormalParameters:* -   *CallSignature* -   *Identifier* +  *ArrowFormalParameters:* *( Modified )* +   *CallSignature*   *Arguments:* *( Modified )*    *TypeArgumentsopt* `(` *ArgumentListopt* `)` @@ -5792,71 +6275,42 @@ This appendix contains a summary of the grammar found in the main document. As d ## A.3 Statements +  *Declaration:* *( Modified )* +   … +   *InterfaceDeclaration* +   *TypeAliasDeclaration* +   *EnumDeclaration* +   *VariableDeclaration:* *( Modified )*    *SimpleVariableDeclaration*    *DestructuringVariableDeclaration*   *SimpleVariableDeclaration:* -   *Identifier* *TypeAnnotationopt* *Initialiseropt* - -  *TypeAnnotation:* -   `:` *Type* +   *BindingIdentifier* *TypeAnnotationopt* *Initializeropt*   *DestructuringVariableDeclaration:* -   *BindingPattern* *TypeAnnotationopt* *Initialiser* +   *BindingPattern* *TypeAnnotationopt* *Initializer* -  *BindingPattern:* -   *ObjectBindingPattern* -   *ArrayBindingPattern* +  *LexicalBinding:* *( Modified )* +   *SimpleLexicalBinding* +   *DestructuringLexicalBinding* -  *ObjectBindingPattern:* -   `{` `}` -   `{` *BindingPropertyList* `,`*opt* `}` +  *SimpleLexicalBinding:* +   *BindingIdentifier* *TypeAnnotationopt* *Initializeropt* -  *BindingPropertyList:* -   *BindingProperty* -   *BindingPropertyList* `,` *BindingProperty* - -  *BindingProperty:* -   *Identifier* *Initialiseropt* -   *PropertyName* `:` *Identifier* *Initialiseropt* -   *PropertyName* `:` *BindingPattern* *Initialiseropt* - -  *ArrayBindingPattern:* -   `[` *Elisionopt* *BindingRestElementopt* `]` -   `[` *BindingElementList* `]` -   `[` *BindingElementList* `,` *Elisionopt* *BindingRestElementopt* `]` - -  *BindingElementList:* -   *Elisionopt* *BindingElement* -   *BindingElementList* `,` *Elisionopt* *BindingElement* - -  *BindingElement:* -   *Identifier* *Initialiseropt* -   *BindingPattern* *Initialiseropt* - -  *BindingRestElement:* -   `...` *Identifier* +  *DestructuringLexicalBinding:* +   *BindingPattern* *TypeAnnotationopt* *Initializeropt* ## A.4 Functions   *FunctionDeclaration:* *( Modified )* -   *FunctionOverloadsopt* *FunctionImplementation* - -  *FunctionOverloads:* -   *FunctionOverload* -   *FunctionOverloads* *FunctionOverload* - -  *FunctionOverload:* -   `function` *Identifier* *CallSignature* `;` - -  *FunctionImplementation:* -   `function` *Identifier* *CallSignature* `{` *FunctionBody* `}` +   `function` *BindingIdentifieropt* *CallSignature* `{` *FunctionBody* `}` +   `function` *BindingIdentifieropt* *CallSignature* `;` ## A.5 Interfaces   *InterfaceDeclaration:* -   `interface` *Identifier* *TypeParametersopt* *InterfaceExtendsClauseopt* *ObjectType* +   `interface` *BindingIdentifier* *TypeParametersopt* *InterfaceExtendsClauseopt* *ObjectType*   *InterfaceExtendsClause:*    `extends` *ClassOrInterfaceTypeList* @@ -5870,10 +6324,10 @@ This appendix contains a summary of the grammar found in the main document. As d ## A.6 Classes -  *ClassDeclaration:* -   `class` *Identifier* *TypeParametersopt* *ClassHeritage* `{` *ClassBody* `}` +  *ClassDeclaration:* *( Modified )* +   `class` *BindingIdentifieropt* *TypeParametersopt* *ClassHeritage* `{` *ClassBody* `}` -  *ClassHeritage:* +  *ClassHeritage:* *( Modified )*    *ClassExtendsClauseopt* *ImplementsClauseopt*   *ClassExtendsClause:* @@ -5885,52 +6339,27 @@ This appendix contains a summary of the grammar found in the main document. As d   *ImplementsClause:*    `implements` *ClassOrInterfaceTypeList* -  *ClassBody:* -   *ClassElementsopt* - -  *ClassElements:* -   *ClassElement* -   *ClassElements* *ClassElement* - -  *ClassElement:* +  *ClassElement:* *( Modified )*    *ConstructorDeclaration*    *PropertyMemberDeclaration*    *IndexMemberDeclaration*   *ConstructorDeclaration:* -   *ConstructorOverloadsopt* *ConstructorImplementation* - -  *ConstructorOverloads:* -   *ConstructorOverload* -   *ConstructorOverloads* *ConstructorOverload* - -  *ConstructorOverload:* +   *AccessibilityModifieropt* `constructor` `(` *ParameterListopt* `)` `{` *FunctionBody* `}`    *AccessibilityModifieropt* `constructor` `(` *ParameterListopt* `)` `;` -  *ConstructorImplementation:* -   *AccessibilityModifieropt* `constructor` `(` *ParameterListopt* `)` `{` *FunctionBody* `}` -   *PropertyMemberDeclaration:*    *MemberVariableDeclaration*    *MemberFunctionDeclaration*    *MemberAccessorDeclaration*   *MemberVariableDeclaration:* -   *AccessibilityModifieropt* `static`*opt* *PropertyName* *TypeAnnotationopt* *Initialiseropt* `;` +   *AccessibilityModifieropt* `static`*opt* *PropertyName* *TypeAnnotationopt* *Initializeropt* `;`   *MemberFunctionDeclaration:* -   *MemberFunctionOverloadsopt* *MemberFunctionImplementation* - -  *MemberFunctionOverloads*: -   *MemberFunctionOverload* -   *MemberFunctionOverloads* *MemberFunctionOverload* - -  *MemberFunctionOverload*: +   *AccessibilityModifieropt* `static`*opt* *PropertyName* *CallSignature* `{` *FunctionBody* `}`    *AccessibilityModifieropt* `static`*opt* *PropertyName* *CallSignature* `;` -  *MemberFunctionImplementation:* -   *AccessibilityModifieropt* `static`*opt* *PropertyName* *CallSignature* `{` *FunctionBody* `}` -   *MemberAccessorDeclaration:*    *AccessibilityModifieropt* `static`*opt* *GetAccessor*    *AccessibilityModifieropt* `static`*opt* *SetAccessor* @@ -5941,7 +6370,7 @@ This appendix contains a summary of the grammar found in the main document. As d ## A.7 Enums   *EnumDeclaration:* -   `const`*opt* `enum` *Identifier* `{` *EnumBodyopt* `}` +   `const`*opt* `enum` *BindingIdentifier* `{` *EnumBodyopt* `}`   *EnumBody:*    *EnumMemberList* `,`*opt* @@ -5957,84 +6386,185 @@ This appendix contains a summary of the grammar found in the main document. As d   *EnumValue:*    *AssignmentExpression* -## A.8 Internal Modules +## A.8 Namespaces -  *ModuleDeclaration:* -   `module` *IdentifierPath* `{` *ModuleBody* `}` +  *NamespaceDeclaration:* +   `namespace` *IdentifierPath* `{` *NamespaceBody* `}`   *IdentifierPath:* -   *Identifier* -   *IdentifierPath* `.` *Identifier* +   *BindingIdentifier* +   *IdentifierPath* `.` *BindingIdentifier* -  *ModuleBody:* -   *ModuleElementsopt* +  *NamespaceBody:* +   *NamespaceElementsopt* -  *ModuleElements:* -   *ModuleElement* -   *ModuleElements* *ModuleElement* +  *NamespaceElements:* +   *NamespaceElement* +   *NamespaceElements* *NamespaceElement* -  *ModuleElement:* +  *NamespaceElement:*    *Statement* -   `export`*opt* *VariableDeclaration* -   `export`*opt* *FunctionDeclaration* -   `export`*opt* *ClassDeclaration* -   `export`*opt* *InterfaceDeclaration* -   `export`*opt* *TypeAliasDeclaration* -   `export`*opt* *EnumDeclaration* -   `export`*opt* *ModuleDeclaration* -   `export`*opt* *ImportDeclaration* -   `export`*opt* *AmbientDeclaration* +   *LexicalDeclaration* +   *FunctionDeclaration* +   *GeneratorDeclaration* +   *ClassDeclaration* +   *InterfaceDeclaration* +   *TypeAliasDeclaration* +   *EnumDeclaration* +   *NamespaceDeclaration +   AmbientDeclaration +   ImportAliasDeclaration +   ExportNamespaceElement* -  *ImportDeclaration:* -   `import` *Identifier* `=` *EntityName* `;` +  *ExportNamespaceElement:* +   `export` *VariableStatement* +   `export` *LexicalDeclaration* +   `export` *FunctionDeclaration* +   `export` *GeneratorDeclaration* +   `export` *ClassDeclaration* +   `export` *InterfaceDeclaration* +   `export` *TypeAliasDeclaration* +   `export` *EnumDeclaration* +   `export` *NamespaceDeclaration* +   `export` *AmbientDeclaration* +   `export` *ImportAliasDeclaration* + +  *ImportAliasDeclaration:* +   `import` *BindingIdentifier* `=` *EntityName* `;`   *EntityName:* -   *ModuleName* -   *ModuleName* `.` *Identifier* +   *NamespaceName* +   *NamespaceName* `.` *IdentifierReference* -## A.9 Source Files and External Modules +## A.9 Scripts and Modules   *SourceFile:*    *ImplementationSourceFile*    *DeclarationSourceFile*   *ImplementationSourceFile:* -   *ImplementationElementsopt* - -  *ImplementationElements:* -   *ImplementationElement* -   *ImplementationElements* *ImplementationElement* - -  *ImplementationElement:* -   *ModuleElement* -   *ExportAssignment* -   *AmbientExternalModuleDeclaration* -   `export`*opt* *ExternalImportDeclaration* +   *ImplementationScript* +   *ImplementationModule*   *DeclarationSourceFile:* -   *DeclarationElementsopt* +   *DeclarationScript* +   *DeclarationModule* -  *DeclarationElements:* +  *ImplementationScript:* +   *ImplementationScriptElementsopt* + +  *ImplementationScriptElements:* +   *ImplementationScriptElement* +   *ImplementationScriptElements* *ImplementationScriptElement* + +  *ImplementationScriptElement:* +   *ImplementationElement* +   *AmbientModuleDeclaration* + +  *ImplementationElement:* +   *Statement* +   *LexicalDeclaration* +   *FunctionDeclaration* +   *GeneratorDeclaration* +   *ClassDeclaration* +   *InterfaceDeclaration* +   *TypeAliasDeclaration* +   *EnumDeclaration* +   *NamespaceDeclaration* +   *AmbientDeclaration* +   *ImportAliasDeclaration* + +  *DeclarationScript:* +   *DeclarationScriptElementsopt* + +  *DeclarationScriptElements:* +   *DeclarationScriptElement* +   *DeclarationScriptElements* *DeclarationScriptElement* + +  *DeclarationScriptElement:*    *DeclarationElement* -   *DeclarationElements* *DeclarationElement* +   *AmbientModuleDeclaration*   *DeclarationElement:* -   *ExportAssignment* -   *AmbientExternalModuleDeclaration* -   `export`*opt* *InterfaceDeclaration* -   `export`*opt* *TypeAliasDeclaration* -   `export`*opt* *ImportDeclaration* -   `export`*opt* *AmbientDeclaration* -   `export`*opt* *ExternalImportDeclaration* +   *InterfaceDeclaration* +   *TypeAliasDeclaration* +   *NamespaceDeclaration* +   *AmbientDeclaration* +   *ImportAliasDeclaration* -  *ExternalImportDeclaration:* -   `import` *Identifier* `=` *ExternalModuleReference* `;` +  *ImplementationModule:* +   *ImplementationModuleElementsopt* -  *ExternalModuleReference:* -   `require` `(` *StringLiteral* `)` +  *ImplementationModuleElements:* +   *ImplementationModuleElement* +   *ImplementationModuleElements* *ImplementationModuleElement* + +  *ImplementationModuleElement:* +   *ImplementationElement* +   *ImportDeclaration* +   *ImportAliasDeclaration* +   *ImportRequireDeclaration* +   *ExportImplementationElement* +   *ExportDefaultImplementationElement* +   *ExportListDeclaration* +   *ExportAssignment* + +  *DeclarationModule:* +   *DeclarationModuleElementsopt* + +  *DeclarationModuleElements:* +   *DeclarationModuleElement* +   *DeclarationModuleElements* *DeclarationModuleElement* + +  *DeclarationModuleElement:* +   *DeclarationElement* +   *ImportDeclaration* +   *ImportAliasDeclaration* +   *ExportDeclarationElement* +   *ExportDefaultDeclarationElement* +   *ExportListDeclaration* +   *ExportAssignment* + +  *ImportRequireDeclaration:* +   `import` *BindingIdentifier* `=` `require` `(` *StringLiteral* `)` `;` + +  *ExportImplementationElement:* +   `export` *VariableStatement* +   `export` *LexicalDeclaration* +   `export` *FunctionDeclaration* +   `export` *GeneratorDeclaration* +   `export` *ClassDeclaration* +   `export` *InterfaceDeclaration* +   `export` *TypeAliasDeclaration* +   `export` *EnumDeclaration* +   `export` *NamespaceDeclaration* +   `export` *AmbientDeclaration* +   `export` *ImportAliasDeclaration* + +  *ExportDeclarationElement:* +   `export` *InterfaceDeclaration* +   `export` *TypeAliasDeclaration* +   `export` *AmbientDeclaration* +   `export` *ImportAliasDeclaration* + +  *ExportDefaultImplementationElement:* +   `export` `default` *FunctionDeclaration* +   `export` `default` *GeneratorDeclaration* +   `export` `default` *ClassDeclaration* +   `export` `default` *AssignmentExpression* `;` + +  *ExportDefaultDeclarationElement:* +   `export` `default` *AmbientFunctionDeclaration* +   `export` `default` *AmbientClassDeclaration* +   `export` `default` *IdentifierReference* `;` + +  *ExportListDeclaration:* +   `export` `*` *FromClause* `;` +   `export` *ExportClause* *FromClause* `;` +   `export` *ExportClause* `;`   *ExportAssignment:* -   `export` `=` *Identifier* `;` +   `export` `=` *IdentifierReference* `;` ## A.10 Ambients @@ -6043,16 +6573,25 @@ This appendix contains a summary of the grammar found in the main document. As d    `declare` *AmbientFunctionDeclaration*    `declare` *AmbientClassDeclaration*    `declare` *AmbientEnumDeclaration* -   `declare` *AmbientModuleDeclaration* +   `declare` *AmbientNamespaceDeclaration*   *AmbientVariableDeclaration:* -   `var` *Identifier*  *TypeAnnotationopt* `;` +   `var` *AmbientBindingList* `;` +   `let` *AmbientBindingList* `;` +   `const` *AmbientBindingList* `;` + +  *AmbientBindingList:* +   *AmbientBinding* +   *AmbientBindingList* `,` *AmbientBinding* + +  *AmbientBinding:* +   *BindingIdentifier* *TypeAnnotationopt*   *AmbientFunctionDeclaration:* -   `function` *Identifier* *CallSignature* `;` +   `function` *BindingIdentifier* *CallSignature* `;`   *AmbientClassDeclaration:* -   `class` *Identifier* *TypeParametersopt* *ClassHeritage* `{` *AmbientClassBody* `}` +   `class` *BindingIdentifier* *TypeParametersopt* *ClassHeritage* `{` *AmbientClassBody* `}`   *AmbientClassBody:*    *AmbientClassBodyElementsopt* @@ -6076,37 +6615,26 @@ This appendix contains a summary of the grammar found in the main document. As d   *AmbientEnumDeclaration:*    *EnumDeclaration* -  *AmbientModuleDeclaration:* -   `module` *IdentifierPath* `{` *AmbientModuleBody* `}` +  *AmbientNamespaceDeclaration:* +   `namespace` *IdentifierPath* `{` *AmbientNamespaceBody* `}` -  *AmbientModuleBody:* -   *AmbientModuleElementsopt* +  *AmbientNamespaceBody:* +   *AmbientNamespaceElementsopt* -  *AmbientModuleElements:* -   *AmbientModuleElement* -   *AmbientModuleElements* *AmbientModuleElement* +  *AmbientNamespaceElements:* +   *AmbientNamespaceElement* +   *AmbientNamespaceElements* *AmbientNamespaceElement* -  *AmbientModuleElement:* +  *AmbientNamespaceElement:*    `export`*opt* *AmbientVariableDeclaration* +   `export`*opt* *AmbientLexicalDeclaration*    `export`*opt* *AmbientFunctionDeclaration*    `export`*opt* *AmbientClassDeclaration*    `export`*opt* *InterfaceDeclaration*    `export`*opt* *AmbientEnumDeclaration* -   `export`*opt* *AmbientModuleDeclaration* -   `export`*opt* *ImportDeclaration* +   `export`*opt* *AmbientNamespaceDeclaration* +   `export`*opt* *ImportAliasDeclaration* -  *AmbientExternalModuleDeclaration:* -   `declare` `module` *StringLiteral* `{`  *AmbientExternalModuleBody* `}` - -  *AmbientExternalModuleBody:* -   *AmbientExternalModuleElementsopt* - -  *AmbientExternalModuleElements:* -   *AmbientExternalModuleElement* -   *AmbientExternalModuleElements* *AmbientExternalModuleElement* - -  *AmbientExternalModuleElement:* -   *AmbientModuleElement* -   *ExportAssignment* -   `export`*opt* *ExternalImportDeclaration* +  *AmbientModuleDeclaration:* +   `declare` `module` *StringLiteral* `{`  *DeclarationModule* `}` diff --git a/bin/lib.core.d.ts b/lib/lib.core.d.ts similarity index 100% rename from bin/lib.core.d.ts rename to lib/lib.core.d.ts diff --git a/bin/lib.core.es6.d.ts b/lib/lib.core.es6.d.ts similarity index 100% rename from bin/lib.core.es6.d.ts rename to lib/lib.core.es6.d.ts diff --git a/bin/lib.d.ts b/lib/lib.d.ts similarity index 100% rename from bin/lib.d.ts rename to lib/lib.d.ts diff --git a/bin/lib.dom.d.ts b/lib/lib.dom.d.ts similarity index 100% rename from bin/lib.dom.d.ts rename to lib/lib.dom.d.ts diff --git a/bin/lib.es6.d.ts b/lib/lib.es6.d.ts similarity index 100% rename from bin/lib.es6.d.ts rename to lib/lib.es6.d.ts diff --git a/bin/lib.scriptHost.d.ts b/lib/lib.scriptHost.d.ts similarity index 100% rename from bin/lib.scriptHost.d.ts rename to lib/lib.scriptHost.d.ts diff --git a/bin/lib.webworker.d.ts b/lib/lib.webworker.d.ts similarity index 100% rename from bin/lib.webworker.d.ts rename to lib/lib.webworker.d.ts diff --git a/bin/tsc.js b/lib/tsc.js similarity index 100% rename from bin/tsc.js rename to lib/tsc.js diff --git a/bin/tsserver.js b/lib/tsserver.js similarity index 100% rename from bin/tsserver.js rename to lib/tsserver.js diff --git a/bin/typescript.d.ts b/lib/typescript.d.ts similarity index 100% rename from bin/typescript.d.ts rename to lib/typescript.d.ts diff --git a/bin/typescript.js b/lib/typescript.js similarity index 100% rename from bin/typescript.js rename to lib/typescript.js diff --git a/bin/typescriptServices.d.ts b/lib/typescriptServices.d.ts similarity index 100% rename from bin/typescriptServices.d.ts rename to lib/typescriptServices.d.ts diff --git a/bin/typescriptServices.js b/lib/typescriptServices.js similarity index 100% rename from bin/typescriptServices.js rename to lib/typescriptServices.js diff --git a/package.json b/package.json index 70ada6fef15..2079c41fdd4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "http://typescriptlang.org/", - "version": "1.5.3", + "version": "1.6.0", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ @@ -19,8 +19,7 @@ "type": "git", "url": "https://github.com/Microsoft/TypeScript.git" }, - "preferGlobal": true, - "main": "./bin/typescript.js", + "main": "./lib/typescript.js", "bin": { "tsc": "./bin/tsc", "tsserver": "./bin/tsserver" @@ -38,6 +37,11 @@ "tslint": "latest" }, "scripts": { - "test": "jake runtests" + "pretest": "jake tests", + "test": "jake runtests", + "build": "npm run build:compiler && npm run build:tests", + "build:compiler": "jake local", + "build:tests": "jake tests", + "clean": "jake clean" } } diff --git a/scripts/configureNightly.ts b/scripts/configureNightly.ts new file mode 100644 index 00000000000..640f330b376 --- /dev/null +++ b/scripts/configureNightly.ts @@ -0,0 +1,73 @@ +/// + +/** + * A minimal description for a parsed package.json object. + */ +interface PackageJson { + name: string; + version: string; + keywords: string[]; +} + +function main(): void { + const sys = ts.sys; + if (sys.args.length < 2) { + sys.write("Usage:" + sys.newLine) + sys.write("\tnode configureNightly.js " + sys.newLine); + return; + } + + // Acquire the version from the package.json file and modify it appropriately. + const packageJsonFilePath = ts.normalizePath(sys.args[0]); + const packageJsonContents = sys.readFile(packageJsonFilePath); + const packageJsonValue: PackageJson = JSON.parse(packageJsonContents); + + const nightlyVersion = getNightlyVersionString(packageJsonValue.version); + + // Modify the package.json structure + packageJsonValue.version = nightlyVersion; + + // Acquire and modify the source file that exposes the version string. + const tsFilePath = ts.normalizePath(sys.args[1]); + const tsFileContents = sys.readFile(tsFilePath); + const versionAssignmentRegExp = /export\s+const\s+version\s+=\s+".*";/; + const modifiedTsFileContents = tsFileContents.replace(versionAssignmentRegExp, `export const version = "${nightlyVersion}";`); + + // Ensure we are actually changing something - the user probably wants to know that the update failed. + if (tsFileContents === modifiedTsFileContents) { + let err = `\n '${tsFilePath}' was not updated while configuring for a nightly publish.\n `; + + if (tsFileContents.match(versionAssignmentRegExp)) { + err += `Ensure that you have not already run this script; otherwise, erase your changes using 'git checkout -- "${tsFilePath}"'.`; + } + else { + err += `The file seems to no longer have a string matching '${versionAssignmentRegExp}'.`; + } + + throw err + "\n"; + } + + // Finally write the changes to disk. + sys.writeFile(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4)) + sys.writeFile(tsFilePath, modifiedTsFileContents); +} + +function getNightlyVersionString(versionString: string): string { + // If the version string already contains "-nightly", + // then get the base string and update based on that. + const dashNightlyPos = versionString.indexOf("-dev"); + if (dashNightlyPos >= 0) { + versionString = versionString.slice(0, dashNightlyPos); + } + + // We're going to append a representation of the current time at the end of the current version. + // String.prototype.toISOString() returns a 24-character string formatted as 'YYYY-MM-DDTHH:mm:ss.sssZ', + // but we'd prefer to just remove separators and limit ourselves to YYYYMMDD. + // UTC time will always be implicit here. + const now = new Date(); + const timeStr = now.toISOString().replace(/:|T|\.|-/g, "").slice(0, 8); + + return `${versionString}-dev.${timeStr}`; +} + +main(); \ No newline at end of file diff --git a/scripts/word2md.js b/scripts/word2md.js index 0645acbb143..e80275d5b2d 100644 --- a/scripts/word2md.js +++ b/scripts/word2md.js @@ -1,8 +1,16 @@ +// word2md - Word to Markdown conversion tool +// +// word2md converts a Microsoft Word document to Markdown formatted text. The tool uses the +// Word Automation APIs to start an instance of Word and access the contents of the document +// being converted. The tool must be run using the cscript.exe script host and requires Word +// to be installed on the target machine. The name of the document to convert must be specified +// as a command line argument and the resulting Markdown is written to standard output. The +// tool recognizes the specific Word styles used in the TypeScript Language Specification. var sys = (function () { var fileStream = new ActiveXObject("ADODB.Stream"); - fileStream.Type = 2; + fileStream.Type = 2 /*text*/; var binaryStream = new ActiveXObject("ADODB.Stream"); - binaryStream.Type = 1; + binaryStream.Type = 1 /*binary*/; var args = []; for (var i = 0; i < WScript.Arguments.length; i++) { args[i] = WScript.Arguments.Item(i); @@ -17,11 +25,13 @@ var sys = (function () { 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); + binaryStream.SaveToFile(fileName, 2 /*overwrite*/); } finally { binaryStream.Close(); @@ -59,6 +69,17 @@ function convertDocumentToMarkdown(doc) { setProperties(replace, replaceOptions); find.execute(findText, false, false, false, false, false, true, 0, true, replaceText, 2); } + function fixHyperlinks() { + var count = doc.hyperlinks.count; + for (var i = 0; i < count; i++) { + var hyperlink = doc.hyperlinks.item(i + 1); + var address = hyperlink.address; + if (address && address.length > 0) { + var textToDisplay = hyperlink.textToDisplay; + hyperlink.textToDisplay = "[" + textToDisplay + "](" + address + ")"; + } + } + } function write(s) { result += s; } @@ -184,14 +205,15 @@ function convertDocumentToMarkdown(doc) { findReplace("<", { style: "Code Fragment" }, "<", {}); findReplace("<", { style: "Terminal" }, "<", {}); findReplace("", { font: { subscript: true } }, "^&", { font: { subscript: false } }); - findReplace("", { style: "Code Fragment" }, "`^&`", { style: -66 }); - findReplace("", { style: "Production" }, "*^&*", { style: -66 }); - findReplace("", { style: "Terminal" }, "`^&`", { style: -66 }); + findReplace("", { style: "Code Fragment" }, "`^&`", { style: -66 /* default font */ }); + findReplace("", { style: "Production" }, "*^&*", { style: -66 /* default font */ }); + findReplace("", { style: "Terminal" }, "`^&`", { style: -66 /* default font */ }); findReplace("", { font: { bold: true, italic: true } }, "***^&***", { font: { bold: false, italic: false } }); findReplace("", { font: { italic: true } }, "*^&*", { font: { italic: false } }); doc.fields.toggleShowCodes(); findReplace("^19 REF", {}, "[^&](#^&)", {}); doc.fields.toggleShowCodes(); + fixHyperlinks(); writeDocument(); result = result.replace(/\x85/g, "\u2026"); result = result.replace(/\x96/g, "\u2013"); @@ -210,3 +232,4 @@ function main(args) { app.quit(); } main(sys.args); +//# sourceMappingURL=file:///c:/ts/scripts/word2md.js.map \ No newline at end of file diff --git a/scripts/word2md.ts b/scripts/word2md.ts index 65b39d6e4f6..ec9ed634b3c 100644 --- a/scripts/word2md.ts +++ b/scripts/word2md.ts @@ -100,9 +100,19 @@ module Word { toggleShowCodes(): void; } + export interface Hyperlink { + address: string; + textToDisplay: string; + range: Range; + } + + export interface Hyperlinks extends Collection { + } + export interface Document { fields: Fields; paragraphs: Paragraphs; + hyperlinks: Hyperlinks; builtInDocumentProperties: Collection; close(saveChanges: boolean): void; range(): Range; @@ -195,6 +205,18 @@ function convertDocumentToMarkdown(doc: Word.Document): string { find.execute(findText, false, false, false, false, false, true, 0, true, replaceText, 2); } + function fixHyperlinks() { + var count = doc.hyperlinks.count; + for (var i = 0; i < count; i++) { + var hyperlink = doc.hyperlinks.item(i + 1); + var address = hyperlink.address; + if (address && address.length > 0) { + var textToDisplay = hyperlink.textToDisplay; + hyperlink.textToDisplay = "[" + textToDisplay + "](" + address + ")"; + } + } + } + function write(s: string) { result += s; } @@ -347,6 +369,8 @@ function convertDocumentToMarkdown(doc: Word.Document): string { findReplace("^19 REF", {}, "[^&](#^&)", {}); doc.fields.toggleShowCodes(); + fixHyperlinks(); + writeDocument(); result = result.replace(/\x85/g, "\u2026"); diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index e839d6d6c9a..50ba634b58d 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -139,7 +139,7 @@ namespace ts { function getDeclarationName(node: Declaration): string { if (node.name) { if (node.kind === SyntaxKind.ModuleDeclaration && node.name.kind === SyntaxKind.StringLiteral) { - return '"' + (node.name).text + '"'; + return `"${(node.name).text}"`; } if (node.name.kind === SyntaxKind.ComputedPropertyName) { let nameExpression = (node.name).expression; @@ -518,15 +518,21 @@ namespace ts { } else { declareSymbolAndAddToSymbolTable(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes); - - let currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly; - if (node.symbol.constEnumOnlyModule === undefined) { - // non-merged case - use the current state - node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly; + if (node.symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.RegularEnum)) { + // if module was already merged with some function, class or non-const enum + // treat is a non-const-enum-only + node.symbol.constEnumOnlyModule = false; } else { - // merged case: module is const enum only if all its pieces are non-instantiated or const enum - node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly; + let currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly; + if (node.symbol.constEnumOnlyModule === undefined) { + // non-merged case - use the current state + node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly; + } + else { + // merged case: module is const enum only if all its pieces are non-instantiated or const enum + node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly; + } } } } @@ -824,7 +830,7 @@ namespace ts { // Note: the node text must be exactly "use strict" or 'use strict'. It is not ok for the // string to contain unicode escapes (as per ES5). - return nodeText === '"use strict"' || nodeText === "'use strict'"; + return nodeText === "\"use strict\"" || nodeText === "'use strict'"; } function bindWorker(node: Node) { @@ -924,7 +930,7 @@ namespace ts { function bindSourceFileIfExternalModule() { setExportContextFlag(file); if (isExternalModule(file)) { - bindAnonymousDeclaration(file, SymbolFlags.ValueModule, '"' + removeFileExtension(file.fileName) + '"'); + bindAnonymousDeclaration(file, SymbolFlags.ValueModule, `"${removeFileExtension(file.fileName)}"`); } } @@ -1056,4 +1062,4 @@ namespace ts { : declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes); } } -} +} diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2fb68eb7ab8..2f923782a5a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -59,17 +59,21 @@ namespace ts { isArgumentsSymbol: symbol => symbol === argumentsSymbol, getDiagnostics, getGlobalDiagnostics, - getTypeOfSymbolAtLocation, + + // The language service will always care about the narrowed type of a symbol, because that is + // the type the language says the symbol should have. + getTypeOfSymbolAtLocation: getNarrowedTypeOfSymbol, getDeclaredTypeOfSymbol, getPropertiesOfType, getPropertyOfType, getSignaturesOfType, getIndexTypeOfType, + getBaseTypes, getReturnTypeOfSignature, getSymbolsInScope, getSymbolAtLocation, getShorthandAssignmentValueSymbol, - getTypeAtLocation, + getTypeAtLocation: getTypeOfNode, typeToString, getSymbolDisplayBuilder, symbolToString, @@ -87,7 +91,8 @@ namespace ts { getExportsOfModule: getExportsOfModuleAsArray, getJsxElementAttributesType, - getJsxIntrinsicTagNames + getJsxIntrinsicTagNames, + isOptionalParameter }; let unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown"); @@ -109,6 +114,10 @@ namespace ts { emptyGenericType.instantiations = {}; let anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + // The anyFunctionType contains the anyFunctionType by definition. The flag is further propagated + // in getPropagatingFlagsOfTypes, and it is checked in inferFromTypes. + anyFunctionType.flags |= TypeFlags.ContainsAnyFunctionType; + let noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); let anySignature = createSignature(undefined, undefined, emptyArray, anyType, undefined, 0, false, false); @@ -159,8 +168,9 @@ namespace ts { let emitAwaiter = false; let emitGenerator = false; - let resolutionTargets: Object[] = []; + let resolutionTargets: TypeSystemEntity[] = []; let resolutionResults: boolean[] = []; + let resolutionPropertyNames: TypeSystemPropertyName[] = []; let mergedSymbols: Symbol[] = []; let symbolLinks: SymbolLinks[] = []; @@ -201,6 +211,18 @@ namespace ts { let assignableRelation: Map = {}; let identityRelation: Map = {}; + // This is for caching the result of getSymbolDisplayBuilder. Do not access directly. + let _displayBuilder: SymbolDisplayBuilder; + + type TypeSystemEntity = Symbol | Type | Signature; + + const enum TypeSystemPropertyName { + Type, + ResolvedBaseConstructorType, + DeclaredType, + ResolvedReturnType + } + initializeTypeChecker(); return checker; @@ -573,7 +595,19 @@ namespace ts { declarationNameToString(propertyName), typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg)); return undefined; } - if (result.flags & SymbolFlags.BlockScopedVariable) { + + // Only check for block-scoped variable if we are looking for the + // name with variable meaning + // For example, + // declare module foo { + // interface bar {} + // } + // let foo/*1*/: foo/*2*/.bar; + // The foo at /*1*/ and /*2*/ will share same symbol with two meaning + // block - scope variable and namespace module. However, only when we + // try to resolve name in /*1*/ which is used in variable position, + // we want to check for block- scoped + if (meaning & SymbolFlags.BlockScopedVariable && result.flags & SymbolFlags.BlockScopedVariable) { checkResolvedBlockScopedVariable(result, errorLocation); } } @@ -934,7 +968,7 @@ namespace ts { if (!moduleName) return; let isRelative = isExternalModuleNameRelative(moduleName); if (!isRelative) { - let symbol = getSymbol(globals, '"' + moduleName + '"', SymbolFlags.ValueModule); + let symbol = getSymbol(globals, "\"" + moduleName + "\"", SymbolFlags.ValueModule); if (symbol) { return symbol; } @@ -1459,8 +1493,6 @@ namespace ts { return undefined; } - // This is for caching the result of getSymbolDisplayBuilder. Do not access directly. - let _displayBuilder: SymbolDisplayBuilder; function getSymbolDisplayBuilder(): SymbolDisplayBuilder { function getNameOfSymbol(symbol: Symbol): string { @@ -1980,18 +2012,15 @@ namespace ts { } 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 + buildSymbolDisplay, + buildTypeDisplay, + buildTypeParameterDisplay, + buildParameterDisplay, + buildDisplayForParametersAndDelimiters, + buildDisplayForTypeParametersAndDelimiters, + buildTypeParameterDisplayFromSymbol, + buildSignatureDisplay, + buildReturnTypeDisplay }); } @@ -2177,35 +2206,69 @@ namespace ts { } } - // Push an entry on the type resolution stack. If an entry with the given target is not already on the stack, - // a new entry with that target and an associated result value of true is pushed on the stack, and the value - // true is returned. Otherwise, a circularity has occurred and the result values of the existing entry and - // all entries pushed after it are changed to false, and the value false is returned. The target object provides - // a unique identity for a particular type resolution result: Symbol instances are used to track resolution of - // SymbolLinks.type, SymbolLinks instances are used to track resolution of SymbolLinks.declaredType, and - // Signature instances are used to track resolution of Signature.resolvedReturnType. - function pushTypeResolution(target: Object): boolean { - let i = 0; - let count = resolutionTargets.length; - while (i < count && resolutionTargets[i] !== target) { - i++; - } - if (i < count) { - do { - resolutionResults[i++] = false; + /** + * Push an entry on the type resolution stack. If an entry with the given target and the given property name + * is already on the stack, and no entries in between already have a type, then a circularity has occurred. + * In this case, the result values of the existing entry and all entries pushed after it are changed to false, + * and the value false is returned. Otherwise, the new entry is just pushed onto the stack, and true is returned. + * In order to see if the same query has already been done before, the target object and the propertyName both + * must match the one passed in. + * + * @param target The symbol, type, or signature whose type is being queried + * @param propertyName The property name that should be used to query the target for its type + */ + function pushTypeResolution(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): boolean { + let resolutionCycleStartIndex = findResolutionCycleStartIndex(target, propertyName); + if (resolutionCycleStartIndex >= 0) { + // A cycle was found + let { length } = resolutionTargets; + for (let i = resolutionCycleStartIndex; i < length; i++) { + resolutionResults[i] = false; } - while (i < count); return false; } resolutionTargets.push(target); resolutionResults.push(true); + resolutionPropertyNames.push(propertyName); return true; } + function findResolutionCycleStartIndex(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): number { + for (let i = resolutionTargets.length - 1; i >= 0; i--) { + if (hasType(resolutionTargets[i], resolutionPropertyNames[i])) { + return -1; + } + if (resolutionTargets[i] === target && resolutionPropertyNames[i] === propertyName) { + return i; + } + } + + return -1; + } + + function hasType(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): Type { + if (propertyName === TypeSystemPropertyName.Type) { + return getSymbolLinks(target).type; + } + if (propertyName === TypeSystemPropertyName.DeclaredType) { + return getSymbolLinks(target).declaredType; + } + if (propertyName === TypeSystemPropertyName.ResolvedBaseConstructorType) { + Debug.assert(!!((target).flags & TypeFlags.Class)); + return (target).resolvedBaseConstructorType; + } + if (propertyName === TypeSystemPropertyName.ResolvedReturnType) { + return (target).resolvedReturnType; + } + + Debug.fail("Unhandled TypeSystemPropertyName " + propertyName); + } + // Pop an entry from the type resolution stack and return its associated result value. The result value will // be true if no circularities were detected, or false if a circularity was found. function popTypeResolution(): boolean { resolutionTargets.pop(); + resolutionPropertyNames.pop(); return resolutionResults.pop(); } @@ -2274,10 +2337,6 @@ namespace ts { // fact an iterable or array (depending on target language). let elementType = checkIteratedTypeOrElementType(parentType, pattern, /*allowStringInput*/ false); if (!declaration.dotDotDotToken) { - if (isTypeAny(elementType)) { - return elementType; - } - // Use specific property type when parent is a tuple or numeric index type when parent is an array let propName = "" + indexOf(pattern.elements, declaration); type = isTupleLikeType(parentType) @@ -2307,6 +2366,7 @@ namespace ts { if (declaration.parent.parent.kind === SyntaxKind.ForInStatement) { return anyType; } + if (declaration.parent.parent.kind === SyntaxKind.ForOfStatement) { // checkRightHandSideOfForOf will return undefined if the for-of expression type was // missing properties/signatures required to get its iteratedType (like @@ -2314,13 +2374,16 @@ namespace ts { // or it may have led to an error inside getElementTypeOfIterable. return checkRightHandSideOfForOf((declaration.parent.parent).expression) || anyType; } + if (isBindingPattern(declaration.parent)) { return getTypeForBindingElement(declaration); } + // Use type from type annotation if one is present if (declaration.type) { return getTypeFromTypeNode(declaration.type); } + if (declaration.kind === SyntaxKind.Parameter) { let func = declaration.parent; // For a parameter of a set accessor, use the type of the get accessor if one is present @@ -2336,14 +2399,22 @@ namespace ts { return type; } } + // Use the type of the initializer expression if one is present if (declaration.initializer) { return checkExpressionCached(declaration.initializer); } + // If it is a short-hand property assignment, use the type of the identifier if (declaration.kind === SyntaxKind.ShorthandPropertyAssignment) { return checkIdentifier(declaration.name); } + + // If the declaration specifies a binding pattern, use the type implied by the binding pattern + if (isBindingPattern(declaration.name)) { + return getTypeFromBindingPattern(declaration.name); + } + // No type specified and nothing can be inferred return undefined; } @@ -2429,13 +2500,10 @@ namespace ts { // tools see the actual type. return declaration.kind !== SyntaxKind.PropertyAssignment ? getWidenedType(type) : type; } - // If no type was specified and nothing could be inferred, and if the declaration specifies a binding pattern, use - // the type implied by the binding pattern - if (isBindingPattern(declaration.name)) { - return getTypeFromBindingPattern(declaration.name); - } + // Rest parameters default to type any[], other parameters default to type any type = declaration.dotDotDotToken ? anyArrayType : anyType; + // Report implicit any errors unless this is a private property within an ambient declaration if (reportErrors && compilerOptions.noImplicitAny) { let root = getRootDeclaration(declaration); @@ -2463,7 +2531,7 @@ namespace ts { return links.type = checkExpression((declaration).expression); } // Handle variable, parameter or property - if (!pushTypeResolution(symbol)) { + if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) { return unknownType; } let type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true); @@ -2504,7 +2572,7 @@ namespace ts { function getTypeOfAccessors(symbol: Symbol): Type { let links = getSymbolLinks(symbol); if (!links.type) { - if (!pushTypeResolution(symbol)) { + if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) { return unknownType; } let getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor); @@ -2720,7 +2788,7 @@ namespace ts { if (!baseTypeNode) { return type.resolvedBaseConstructorType = undefinedType; } - if (!pushTypeResolution(type)) { + if (!pushTypeResolution(type, TypeSystemPropertyName.ResolvedBaseConstructorType)) { return unknownType; } let baseConstructorType = checkExpression(baseTypeNode.expression); @@ -2847,7 +2915,7 @@ namespace ts { if (!links.declaredType) { // Note that we use the links object as the target here because the symbol object is used as the unique // identity for resolution of the 'type' property in SymbolLinks. - if (!pushTypeResolution(links)) { + if (!pushTypeResolution(symbol, TypeSystemPropertyName.DeclaredType)) { return unknownType; } let declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration); @@ -3063,44 +3131,57 @@ namespace ts { 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 (let i = 0; i < s.length; i++) { - if (!compareSignatures(s[i], t[i], /*compareReturnTypes*/ false, compareTypes)) { - return false; + function findMatchingSignature(signature: Signature, signatureList: Signature[]): Signature { + for (let s of signatureList) { + // Only signatures with no type parameters may differ in return types + if (compareSignatures(signature, s, /*compareReturnTypes*/ !!signature.typeParameters, compareTypes)) { + return s; } } - 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[] { - let signatureLists = map(types, t => getSignaturesOfType(t, kind)); - let signatures = signatureLists[0]; - for (let signature of signatures) { - if (signature.typeParameters) { - return emptyArray; - } - } + function findMatchingSignatures(signature: Signature, signatureLists: Signature[][]): Signature[] { + let result: Signature[] = undefined; for (let i = 1; i < signatureLists.length; i++) { - if (!signatureListsIdentical(signatures, signatureLists[i])) { - return emptyArray; + let match = findMatchingSignature(signature, signatureLists[i]); + if (!match) { + return undefined; + } + if (!result) { + result = [signature]; + } + if (match !== signature) { + result.push(match); } - } - let result = map(signatures, cloneSignature); - for (var i = 0; i < result.length; i++) { - let s = result[i]; - // Clear resolved return type we possibly got from cloneSignature - s.resolvedReturnType = undefined; - s.unionSignatures = map(signatureLists, signatures => signatures[i]); } return result; } + // The signatures of a union type are those signatures that are present and identical in each of the + // constituent types, except that non-generic signatures may differ in return types. When signatures + // differ in return types, the resulting return type is the union of the constituent return types. + function getUnionSignatures(types: Type[], kind: SignatureKind): Signature[] { + let signatureLists = map(types, t => getSignaturesOfType(t, kind)); + let result: Signature[] = undefined; + for (let source of signatureLists[0]) { + let unionSignatures = findMatchingSignatures(source, signatureLists); + if (unionSignatures) { + let signature: Signature = undefined; + if (unionSignatures.length === 1 || source.typeParameters) { + signature = source; + } + else { + signature = cloneSignature(source); + // Clear resolved return type we possibly got from cloneSignature + signature.resolvedReturnType = undefined; + signature.unionSignatures = unionSignatures; + } + (result || (result = [])).push(signature); + } + } + return result || emptyArray; + } + function getUnionIndexType(types: Type[], kind: IndexKind): Type { let indexTypes: Type[] = []; for (let type of types) { @@ -3258,9 +3339,6 @@ namespace ts { * 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.Union) { - type = getReducedTypeOfUnionType(type); - } if (type.flags & TypeFlags.TypeParameter) { do { type = getConstraintOfTypeParameter(type); @@ -3365,6 +3443,29 @@ namespace ts { return undefined; } + // Check if a property with the given name is known anywhere in the given type. In an object + // type, a property is considered known if the object type is empty, if it has any index + // signatures, or if the property is actually declared in the type. In a union or intersection + // type, a property is considered known if it is known in any constituent type. + function isKnownProperty(type: Type, name: string): boolean { + if (type.flags & TypeFlags.ObjectType && type !== globalObjectType) { + const resolved = resolveStructuredTypeMembers(type); + return !!(resolved.properties.length === 0 || + resolved.stringIndexType || + resolved.numberIndexType || + getPropertyOfType(type, name)); + } + if (type.flags & TypeFlags.UnionOrIntersection) { + for (let t of (type).types) { + if (isKnownProperty(t, name)) { + return true; + } + } + return false; + } + return true; + } + function getSignaturesOfStructuredType(type: Type, kind: SignatureKind): Signature[] { if (type.flags & TypeFlags.StructuredType) { let resolved = resolveStructuredTypeMembers(type); @@ -3434,7 +3535,19 @@ namespace ts { } function isOptionalParameter(node: ParameterDeclaration) { - return hasQuestionToken(node) || !!node.initializer; + if (hasQuestionToken(node)) { + return true; + } + + if (node.initializer) { + let signatureDeclaration = node.parent; + let signature = getSignatureFromDeclaration(signatureDeclaration); + let parameterIndex = signatureDeclaration.parameters.indexOf(node); + Debug.assert(parameterIndex >= 0); + return parameterIndex >= signature.minArgumentCount; + } + + return false; } function getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature { @@ -3452,11 +3565,16 @@ namespace ts { if (param.type && param.type.kind === SyntaxKind.StringLiteral) { hasStringLiterals = true; } - if (minArgumentCount < 0) { - if (param.initializer || param.questionToken || param.dotDotDotToken) { + + if (param.initializer || param.questionToken || param.dotDotDotToken) { + if (minArgumentCount < 0) { minArgumentCount = i; } } + else { + // If we see any required parameters, it means the prior ones were not in fact optional. + minArgumentCount = -1; + } } if (minArgumentCount < 0) { @@ -3534,7 +3652,7 @@ namespace ts { function getReturnTypeOfSignature(signature: Signature): Type { if (!signature.resolvedReturnType) { - if (!pushTypeResolution(signature)) { + if (!pushTypeResolution(signature, TypeSystemPropertyName.ResolvedReturnType)) { return unknownType; } let type: Type; @@ -3674,22 +3792,23 @@ namespace ts { } } - // This function is used to propagate widening flags when creating new object types references and union types. - // It is only necessary to do so if a constituent type might be the undefined type, the null type, or the type - // of an object literal (since those types have widening related information we need to track). - function getWideningFlagsOfTypes(types: Type[]): TypeFlags { + // This function is used to propagate certain flags when creating new object type references and union types. + // It is only necessary to do so if a constituent type might be the undefined type, the null type, the type + // of an object literal or the anyFunctionType. This is because there are operations in the type checker + // that care about the presence of such types at arbitrary depth in a containing type. + function getPropagatingFlagsOfTypes(types: Type[]): TypeFlags { let result: TypeFlags = 0; for (let type of types) { result |= type.flags; } - return result & TypeFlags.RequiresWidening; + return result & TypeFlags.PropagatingFlags; } function createTypeReference(target: GenericType, typeArguments: Type[]): TypeReference { let id = getTypeListId(typeArguments); let type = target.instantiations[id]; if (!type) { - let flags = TypeFlags.Reference | getWideningFlagsOfTypes(typeArguments); + let flags = TypeFlags.Reference | getPropagatingFlagsOfTypes(typeArguments); type = target.instantiations[id] = createObjectType(flags, target.symbol); type.target = target; type.typeArguments = typeArguments; @@ -3943,7 +4062,7 @@ namespace ts { let id = getTypeListId(elementTypes); let type = tupleTypes[id]; if (!type) { - type = tupleTypes[id] = createObjectType(TypeFlags.Tuple | getWideningFlagsOfTypes(elementTypes)); + type = tupleTypes[id] = createObjectType(TypeFlags.Tuple | getPropagatingFlagsOfTypes(elementTypes)); type.elementTypes = elementTypes; } return type; @@ -3974,26 +4093,79 @@ namespace ts { } } - function isSubtypeOfAny(candidate: Type, types: Type[]): boolean { + function isObjectLiteralTypeDuplicateOf(source: ObjectType, target: ObjectType): boolean { + let sourceProperties = getPropertiesOfObjectType(source); + let targetProperties = getPropertiesOfObjectType(target); + if (sourceProperties.length !== targetProperties.length) { + return false; + } + for (let sourceProp of sourceProperties) { + let targetProp = getPropertyOfObjectType(target, sourceProp.name); + if (!targetProp || + getDeclarationFlagsFromSymbol(targetProp) & (NodeFlags.Private | NodeFlags.Protected) || + !isTypeDuplicateOf(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp))) { + return false; + } + } + return true; + } + + function isTupleTypeDuplicateOf(source: TupleType, target: TupleType): boolean { + let sourceTypes = source.elementTypes; + let targetTypes = target.elementTypes; + if (sourceTypes.length !== targetTypes.length) { + return false; + } + for (var i = 0; i < sourceTypes.length; i++) { + if (!isTypeDuplicateOf(sourceTypes[i], targetTypes[i])) { + return false; + } + } + return true; + } + + // Returns true if the source type is a duplicate of the target type. A source type is a duplicate of + // a target type if the the two are identical, with the exception that the source type may have null or + // undefined in places where the target type doesn't. This is by design an asymmetric relationship. + function isTypeDuplicateOf(source: Type, target: Type): boolean { + if (source === target) { + return true; + } + if (source.flags & TypeFlags.Undefined || source.flags & TypeFlags.Null && !(target.flags & TypeFlags.Undefined)) { + return true; + } + if (source.flags & TypeFlags.ObjectLiteral && target.flags & TypeFlags.ObjectType) { + return isObjectLiteralTypeDuplicateOf(source, target); + } + if (isArrayType(source) && isArrayType(target)) { + return isTypeDuplicateOf((source).typeArguments[0], (target).typeArguments[0]); + } + if (isTupleType(source) && isTupleType(target)) { + return isTupleTypeDuplicateOf(source, target); + } + return isTypeIdenticalTo(source, target); + } + + function isTypeDuplicateOfSomeType(candidate: Type, types: Type[]): boolean { for (let type of types) { - if (candidate !== type && isTypeSubtypeOf(candidate, type)) { + if (candidate !== type && isTypeDuplicateOf(candidate, type)) { return true; } } return false; } - function removeSubtypes(types: Type[]) { + function removeDuplicateTypes(types: Type[]) { let i = types.length; while (i > 0) { i--; - if (isSubtypeOfAny(types[i], types)) { + if (isTypeDuplicateOfSomeType(types[i], types)) { types.splice(i, 1); } } } - function containsTypeAny(types: Type[]) { + function containsTypeAny(types: Type[]): boolean { for (let type of types) { if (isTypeAny(type)) { return true; @@ -4012,30 +4184,26 @@ namespace ts { } } - function compareTypeIds(type1: Type, type2: Type): number { - return type1.id - type2.id; - } - - // The noSubtypeReduction flag is there because it isn't possible to always do subtype reduction. The flag - // is true when creating a union type from a type node and when instantiating a union type. In both of those - // cases subtype reduction has to be deferred to properly support recursive union types. For example, a - // type alias of the form "type Item = string | (() => Item)" cannot be reduced during its declaration. - function getUnionType(types: Type[], noSubtypeReduction?: boolean): Type { + // We always deduplicate the constituent type set based on object identity, but we'll also deduplicate + // based on the structure of the types unless the noDeduplication flag is true, which is the case when + // creating a union type from a type node and when instantiating a union type. In both of those cases, + // structural deduplication has to be deferred to properly support recursive union types. For example, + // a type of the form "type Item = string | (() => Item)" cannot be deduplicated during its declaration. + function getUnionType(types: Type[], noDeduplication?: boolean): Type { if (types.length === 0) { return emptyObjectType; } let typeSet: Type[] = []; addTypesToSet(typeSet, types, TypeFlags.Union); - typeSet.sort(compareTypeIds); - if (noSubtypeReduction) { - if (containsTypeAny(typeSet)) { - return anyType; - } + if (containsTypeAny(typeSet)) { + return anyType; + } + if (noDeduplication) { removeAllButLast(typeSet, undefinedType); removeAllButLast(typeSet, nullType); } else { - removeSubtypes(typeSet); + removeDuplicateTypes(typeSet); } if (typeSet.length === 1) { return typeSet[0]; @@ -4043,40 +4211,21 @@ namespace ts { let id = getTypeListId(typeSet); let type = unionTypes[id]; if (!type) { - type = unionTypes[id] = createObjectType(TypeFlags.Union | getWideningFlagsOfTypes(typeSet)); + type = unionTypes[id] = createObjectType(TypeFlags.Union | getPropagatingFlagsOfTypes(typeSet)); type.types = typeSet; - type.reducedType = noSubtypeReduction ? undefined : type; } return type; } - // Subtype reduction is basically an optimization we do to avoid excessively large union types, which take longer - // to process and look strange in quick info and error messages. Semantically there is no difference between the - // reduced type and the type itself. So, when we detect a circularity we simply say that the reduced type is the - // type itself. - function getReducedTypeOfUnionType(type: UnionType): Type { - if (!type.reducedType) { - type.reducedType = circularType; - let reducedType = getUnionType(type.types, /*noSubtypeReduction*/ false); - if (type.reducedType === circularType) { - type.reducedType = reducedType; - } - } - else if (type.reducedType === circularType) { - type.reducedType = type; - } - return type.reducedType; - } - function getTypeFromUnionTypeNode(node: UnionTypeNode): Type { let links = getNodeLinks(node); if (!links.resolvedType) { - links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode), /*noSubtypeReduction*/ true); + links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode), /*noDeduplication*/ true); } return links.resolvedType; } - // We do not perform supertype reduction on intersection types. Intersection types are created only by the & + // We do not perform structural deduplication on intersection types. Intersection types are created only by the & // type operator and we can't reduce those because we want to support recursive intersection types. For example, // a type alias of the form "type List = T & { next: List }" cannot be reduced during its declaration. // Also, unlike union types, the order of the constituent types is preserved in order that overload resolution @@ -4096,7 +4245,7 @@ namespace ts { let id = getTypeListId(typeSet); let type = intersectionTypes[id]; if (!type) { - type = intersectionTypes[id] = createObjectType(TypeFlags.Intersection | getWideningFlagsOfTypes(typeSet)); + type = intersectionTypes[id] = createObjectType(TypeFlags.Intersection | getPropagatingFlagsOfTypes(typeSet)); type.types = typeSet; } return type; @@ -4179,7 +4328,7 @@ namespace ts { // Callers should first ensure this by calling isTypeNode case SyntaxKind.Identifier: case SyntaxKind.QualifiedName: - let symbol = getSymbolInfo(node); + let symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); default: return unknownType; @@ -4244,7 +4393,7 @@ namespace ts { } function createInferenceMapper(context: InferenceContext): TypeMapper { - return t => { + let mapper: TypeMapper = t => { for (let i = 0; i < context.typeParameters.length; i++) { if (t === context.typeParameters[i]) { context.inferences[i].isFixed = true; @@ -4253,6 +4402,9 @@ namespace ts { } return t; }; + + mapper.context = context; + return mapper; } function identityMapper(type: Type): Type { @@ -4354,7 +4506,7 @@ namespace ts { return createTupleType(instantiateList((type).elementTypes, mapper, instantiateType)); } if (type.flags & TypeFlags.Union) { - return getUnionType(instantiateList((type).types, mapper, instantiateType), /*noSubtypeReduction*/ true); + return getUnionType(instantiateList((type).types, mapper, instantiateType), /*noDeduplication*/ true); } if (type.flags & TypeFlags.Intersection) { return getIntersectionType(instantiateList((type).types, mapper, instantiateType)); @@ -4499,6 +4651,16 @@ namespace ts { errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); } + function reportRelationError(message: DiagnosticMessage, source: Type, target: Type) { + let sourceType = typeToString(source); + let targetType = typeToString(target); + if (sourceType === targetType) { + sourceType = typeToString(source, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType); + targetType = typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType); + } + reportError(message || Diagnostics.Type_0_is_not_assignable_to_type_1, sourceType, targetType); + } + // Compare two types and return // Ternary.True if they are related with no assumptions, // Ternary.Maybe if they are related with assumptions of other relationships, or @@ -4507,106 +4669,141 @@ namespace ts { let result: Ternary; // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return Ternary.True; - if (relation !== identityRelation) { - if (isTypeAny(target)) return Ternary.True; - if (source === undefinedType) return Ternary.True; - if (source === nullType && target !== undefinedType) return Ternary.True; - if (source.flags & TypeFlags.Enum && target === numberType) return Ternary.True; - if (source.flags & TypeFlags.StringLiteral && target === stringType) return Ternary.True; - if (relation === assignableRelation) { - if (isTypeAny(source)) return Ternary.True; - if (source === numberType && target.flags & TypeFlags.Enum) return Ternary.True; - } + if (relation === identityRelation) { + return isIdenticalTo(source, target); } + + if (isTypeAny(target)) return Ternary.True; + if (source === undefinedType) return Ternary.True; + if (source === nullType && target !== undefinedType) return Ternary.True; + if (source.flags & TypeFlags.Enum && target === numberType) return Ternary.True; + if (source.flags & TypeFlags.StringLiteral && target === stringType) return Ternary.True; + if (relation === assignableRelation) { + if (isTypeAny(source)) return Ternary.True; + if (source === numberType && target.flags & TypeFlags.Enum) return Ternary.True; + } + + if (source.flags & TypeFlags.FreshObjectLiteral) { + if (hasExcessProperties(source, target, reportErrors)) { + if (reportErrors) { + reportRelationError(headMessage, source, target); + } + return Ternary.False; + } + // Above we check for excess properties with respect to the entire target type. When union + // and intersection types are further deconstructed on the target side, we don't want to + // make the check again (as it might fail for a partial target type). Therefore we obtain + // the regular source type and proceed with that. + source = getRegularTypeOfObjectLiteral(source); + } + let saveErrorInfo = errorInfo; - if (source.flags & TypeFlags.Reference && target.flags & TypeFlags.Reference && (source).target === (target).target) { - // We have type references to same target type, see if relationship holds for all type arguments - if (result = typesRelatedTo((source).typeArguments, (target).typeArguments, reportErrors)) { + + // Note that the "each" checks must precede the "some" checks to produce the correct results + if (source.flags & TypeFlags.Union) { + if (result = eachTypeRelatedToType(source, target, reportErrors)) { return result; } } - else if (source.flags & TypeFlags.TypeParameter && target.flags & TypeFlags.TypeParameter) { - if (result = typeParameterRelatedTo(source, target, reportErrors)) { + else if (target.flags & TypeFlags.Intersection) { + if (result = typeRelatedToEachType(source, target, reportErrors)) { return result; } } - else if (relation !== identityRelation) { - // Note that the "each" checks must precede the "some" checks to produce the correct results - if (source.flags & TypeFlags.Union) { - if (result = eachTypeRelatedToType(source, target, reportErrors)) { - return result; - } - } - else if (target.flags & TypeFlags.Intersection) { - if (result = typeRelatedToEachType(source, target, reportErrors)) { - return result; - } - } - else { - // It is necessary to try "each" checks on both sides because there may be nested "some" checks - // on either side that need to be prioritized. For example, A | B = (A | B) & (C | D) or - // A & B = (A & B) | (C & D). - if (source.flags & TypeFlags.Intersection) { - // If target is a union type the following check will report errors so we suppress them here - if (result = someTypeRelatedToType(source, target, reportErrors && !(target.flags & TypeFlags.Union))) { - return result; - } - } - if (target.flags & TypeFlags.Union) { - if (result = typeRelatedToSomeType(source, target, reportErrors)) { - return result; - } - } - } - } else { - if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union || - source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Intersection) { - if (result = eachTypeRelatedToSomeType(source, target)) { - if (result &= eachTypeRelatedToSomeType(target, source)) { - return result; - } + // It is necessary to try "some" checks on both sides because there may be nested "each" checks + // on either side that need to be prioritized. For example, A | B = (A | B) & (C | D) or + // A & B = (A & B) | (C & D). + if (source.flags & TypeFlags.Intersection) { + // If target is a union type the following check will report errors so we suppress them here + if (result = someTypeRelatedToType(source, target, reportErrors && !(target.flags & TypeFlags.Union))) { + return result; + } + } + if (target.flags & TypeFlags.Union) { + if (result = typeRelatedToSomeType(source, target, reportErrors)) { + return result; } } } - // Even if relationship doesn't hold for unions, type parameters, or generic type references, - // it may hold in a structural comparison. - // Report structural errors only if we haven't reported any errors yet - let reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo; - // Identity relation does not use apparent type - let sourceOrApparentType = relation === identityRelation ? source : getApparentType(source); - // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates - // to X. Failing both of those we want to check if the aggregation of A and B's members structurally - // relates to X. Thus, we include intersection types on the source side here. - if (sourceOrApparentType.flags & (TypeFlags.ObjectType | TypeFlags.Intersection) && target.flags & TypeFlags.ObjectType) { - if (result = objectTypeRelatedTo(sourceOrApparentType, target, reportStructuralErrors)) { + if (source.flags & TypeFlags.TypeParameter) { + let constraint = getConstraintOfTypeParameter(source); + if (!constraint || constraint.flags & TypeFlags.Any) { + constraint = emptyObjectType; + } + // Report constraint errors only if the constraint is not the empty object type + let reportConstraintErrors = reportErrors && constraint !== emptyObjectType; + if (result = isRelatedTo(constraint, target, reportConstraintErrors)) { errorInfo = saveErrorInfo; return result; } } - else if (source.flags & TypeFlags.TypeParameter && sourceOrApparentType.flags & TypeFlags.UnionOrIntersection) { - // We clear the errors first because the following check often gives a better error than - // the union or intersection comparison above if it is applicable. - errorInfo = saveErrorInfo; - if (result = isRelatedTo(sourceOrApparentType, target, reportErrors)) { - return result; + else { + if (source.flags & TypeFlags.Reference && target.flags & TypeFlags.Reference && (source).target === (target).target) { + // We have type references to same target type, see if relationship holds for all type arguments + if (result = typesRelatedTo((source).typeArguments, (target).typeArguments, reportErrors)) { + return result; + } + } + // Even if relationship doesn't hold for unions, intersections, or generic type references, + // it may hold in a structural comparison. + let apparentType = getApparentType(source); + // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates + // to X. Failing both of those we want to check if the aggregation of A and B's members structurally + // relates to X. Thus, we include intersection types on the source side here. + if (apparentType.flags & (TypeFlags.ObjectType | TypeFlags.Intersection) && target.flags & TypeFlags.ObjectType) { + // Report structural errors only if we haven't reported any errors yet + let reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo; + if (result = objectTypeRelatedTo(apparentType, target, reportStructuralErrors)) { + errorInfo = saveErrorInfo; + return result; + } } } if (reportErrors) { - headMessage = headMessage || Diagnostics.Type_0_is_not_assignable_to_type_1; - let sourceType = typeToString(source); - let targetType = typeToString(target); - if (sourceType === targetType) { - sourceType = typeToString(source, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType); - targetType = typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType); - } - reportError(headMessage, sourceType, targetType); + reportRelationError(headMessage, source, target); } return Ternary.False; } + function isIdenticalTo(source: Type, target: Type): Ternary { + let result: Ternary; + if (source.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType) { + if (source.flags & TypeFlags.Reference && target.flags & TypeFlags.Reference && (source).target === (target).target) { + // We have type references to same target type, see if all type arguments are identical + if (result = typesRelatedTo((source).typeArguments, (target).typeArguments, /*reportErrors*/ false)) { + return result; + } + } + return objectTypeRelatedTo(source, target, /*reportErrors*/ false); + } + if (source.flags & TypeFlags.TypeParameter && target.flags & TypeFlags.TypeParameter) { + return typeParameterIdenticalTo(source, target); + } + if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union || + source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Intersection) { + if (result = eachTypeRelatedToSomeType(source, target)) { + if (result &= eachTypeRelatedToSomeType(target, source)) { + return result; + } + } + } + return Ternary.False; + } + + function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean { + for (let prop of getPropertiesOfObjectType(source)) { + if (!isKnownProperty(target, prop.name)) { + if (reportErrors) { + reportError(Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target)); + } + return true; + } + } + } + function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType): Ternary { let result = Ternary.True; let sourceTypes = source.types; @@ -4680,29 +4877,18 @@ namespace ts { return result; } - function typeParameterRelatedTo(source: TypeParameter, target: TypeParameter, reportErrors: boolean): Ternary { - if (relation === identityRelation) { - if (source.symbol.name !== target.symbol.name) { - return Ternary.False; - } - // covers case when both type parameters does not have constraint (both equal to noConstraintType) - if (source.constraint === target.constraint) { - return Ternary.True; - } - if (source.constraint === noConstraintType || target.constraint === noConstraintType) { - return Ternary.False; - } - return isRelatedTo(source.constraint, target.constraint, reportErrors); - } - else { - while (true) { - let constraint = getConstraintOfTypeParameter(source); - if (constraint === target) return Ternary.True; - if (!(constraint && constraint.flags & TypeFlags.TypeParameter)) break; - source = constraint; - } + function typeParameterIdenticalTo(source: TypeParameter, target: TypeParameter): Ternary { + if (source.symbol.name !== target.symbol.name) { return Ternary.False; } + // covers case when both type parameters does not have constraint (both equal to noConstraintType) + if (source.constraint === target.constraint) { + return Ternary.True; + } + if (source.constraint === noConstraintType || target.constraint === noConstraintType) { + return Ternary.False; + } + return isIdenticalTo(source.constraint, target.constraint); } // Determine if two object types are related by structure. First, check if the result is already available in the global cache. @@ -5070,7 +5256,7 @@ namespace ts { return indexTypesIdenticalTo(IndexKind.String, source, target); } let targetType = getIndexTypeOfType(target, IndexKind.String); - if (targetType) { + if (targetType && !(targetType.flags & TypeFlags.Any)) { let sourceType = getIndexTypeOfType(source, IndexKind.String); if (!sourceType) { if (reportErrors) { @@ -5095,7 +5281,7 @@ namespace ts { return indexTypesIdenticalTo(IndexKind.Number, source, target); } let targetType = getIndexTypeOfType(target, IndexKind.Number); - if (targetType) { + if (targetType && !(targetType.flags & TypeFlags.Any)) { let sourceStringType = getIndexTypeOfType(source, IndexKind.String); let sourceNumberType = getIndexTypeOfType(source, IndexKind.Number); if (!(sourceStringType || sourceNumberType)) { @@ -5303,6 +5489,24 @@ namespace ts { return !!(type.flags & TypeFlags.Tuple); } + function getRegularTypeOfObjectLiteral(type: Type): Type { + if (type.flags & TypeFlags.FreshObjectLiteral) { + let regularType = (type).regularType; + if (!regularType) { + regularType = createType((type).flags & ~TypeFlags.FreshObjectLiteral); + regularType.symbol = (type).symbol; + regularType.members = (type).members; + regularType.properties = (type).properties; + regularType.callSignatures = (type).callSignatures; + regularType.constructSignatures = (type).constructSignatures; + regularType.stringIndexType = (type).stringIndexType; + regularType.numberIndexType = (type).numberIndexType; + } + return regularType; + } + return type; + } + function getWidenedTypeOfObjectLiteral(type: Type): Type { let properties = getPropertiesOfObjectType(type); let members: SymbolTable = {}; @@ -5463,7 +5667,9 @@ namespace ts { function createInferenceContext(typeParameters: TypeParameter[], inferUnionTypes: boolean): InferenceContext { let inferences: TypeInferences[] = []; for (let unused of typeParameters) { - inferences.push({ primary: undefined, secondary: undefined, isFixed: false }); + inferences.push({ + primary: undefined, secondary: undefined, isFixed: false + }); } return { typeParameters, @@ -5490,11 +5696,17 @@ namespace ts { } function inferFromTypes(source: Type, target: Type) { - if (source === anyFunctionType) { - return; - } if (target.flags & TypeFlags.TypeParameter) { - // If target is a type parameter, make an inference + // If target is a type parameter, make an inference, unless the source type contains + // the anyFunctionType (the wildcard type that's used to avoid contextually typing functions). + // Because the anyFunctionType is internal, it should not be exposed to the user by adding + // it as an inference candidate. Hopefully, a better candidate will come along that does + // not contain anyFunctionType when we come back to this argument for its second round + // of inference. + if (source.flags & TypeFlags.ContainsAnyFunctionType) { + return; + } + let typeParameters = context.typeParameters; for (let i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { @@ -5525,6 +5737,14 @@ namespace ts { inferFromTypes(sourceTypes[i], targetTypes[i]); } } + else if (source.flags & TypeFlags.Tuple && target.flags & TypeFlags.Tuple && (source).elementTypes.length === (target).elementTypes.length) { + // If source and target are tuples of the same size, infer from element types + let sourceTypes = (source).elementTypes; + let targetTypes = (target).elementTypes; + for (let i = 0; i < sourceTypes.length; i++) { + inferFromTypes(sourceTypes[i], targetTypes[i]); + } + } else if (target.flags & TypeFlags.UnionOrIntersection) { let targetTypes = (target).types; let typeParameterCount = 0; @@ -5831,47 +6051,6 @@ namespace ts { } } - function resolveLocation(node: Node) { - // Resolve location from top down towards node if it is a context sensitive expression - // That helps in making sure not assigning types as any when resolved out of order - let containerNodes: Node[] = []; - for (let parent = node.parent; parent; parent = parent.parent) { - if ((isExpression(parent) || isObjectLiteralMethod(node)) && - isContextSensitive(parent)) { - containerNodes.unshift(parent); - } - } - - ts.forEach(containerNodes, node => { getTypeOfNode(node); }); - } - - function getSymbolAtLocation(node: Node): Symbol { - resolveLocation(node); - return getSymbolInfo(node); - } - - function getTypeAtLocation(node: Node): Type { - resolveLocation(node); - return getTypeOfNode(node); - } - - function getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type { - resolveLocation(node); - // Get the narrowed type of symbol at given location instead of just getting - // the type of the symbol. - // eg. - // function foo(a: string | number) { - // if (typeof a === "string") { - // a/**/ - // } - // } - // getTypeOfSymbol for a would return type of parameter symbol string | number - // Unless we provide location /**/, checker wouldn't know how to narrow the type - // By using getNarrowedTypeOfSymbol would return string since it would be able to narrow - // it by typeguard in the if true condition - return getNarrowedTypeOfSymbol(symbol, node); - } - // Get the narrowed type of a given symbol at a given location function getNarrowedTypeOfSymbol(symbol: Symbol, node: Node) { let type = getTypeOfSymbol(symbol); @@ -6041,14 +6220,20 @@ namespace ts { } function getNarrowedType(originalType: Type, narrowedTypeCandidate: Type) { - // Narrow to the target type if it's a subtype of the current type - if (isTypeSubtypeOf(narrowedTypeCandidate, originalType)) { + // If the current type is a union type, remove all constituents that aren't assignable to target. If that produces + // 0 candidates, fall back to the assignability check + if (originalType.flags & TypeFlags.Union) { + let assignableConstituents = filter((originalType).types, t => isTypeAssignableTo(t, narrowedTypeCandidate)); + if (assignableConstituents.length) { + return getUnionType(assignableConstituents); + } + } + + if (isTypeAssignableTo(narrowedTypeCandidate, originalType)) { + // Narrow to the target type if it's assignable to the current type return narrowedTypeCandidate; } - // If the current type is a union type, remove all constituents that aren't subtypes of the target. - if (originalType.flags & TypeFlags.Union) { - return getUnionType(filter((originalType).types, t => isTypeSubtypeOf(t, narrowedTypeCandidate))); - } + return originalType; } @@ -6270,22 +6455,79 @@ namespace ts { let classType = classDeclaration && getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration)); let baseClassType = classType && getBaseTypes(classType)[0]; + let container = getSuperContainer(node, /*includeFunctions*/ true); + let needToCaptureLexicalThis = false; + + if (!isCallExpression) { + // adjust the container reference in case if super is used inside arrow functions with arbitrary deep nesting + while (container && container.kind === SyntaxKind.ArrowFunction) { + container = getSuperContainer(container, /*includeFunctions*/ true); + needToCaptureLexicalThis = languageVersion < ScriptTarget.ES6; + } + } + + let canUseSuperExpression = isLegalUsageOfSuperExpression(container); + let nodeCheckFlag: NodeCheckFlags = 0; + + // always set NodeCheckFlags for 'super' expression node + if (canUseSuperExpression) { + if ((container.flags & NodeFlags.Static) || isCallExpression) { + nodeCheckFlag = NodeCheckFlags.SuperStatic; + } + else { + nodeCheckFlag = NodeCheckFlags.SuperInstance; + } + + getNodeLinks(node).flags |= nodeCheckFlag; + + if (needToCaptureLexicalThis) { + // call expressions are allowed only in constructors so they should always capture correct 'this' + // super property access expressions can also appear in arrow functions - + // in this case they should also use correct lexical this + captureLexicalThis(node.parent, container); + } + } + if (!baseClassType) { if (!classDeclaration || !getClassExtendsHeritageClauseElement(classDeclaration)) { error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class); } + return unknownType; + } + + if (!canUseSuperExpression) { + if (container && container.kind === SyntaxKind.ComputedPropertyName) { + error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name); + } + else if (isCallExpression) { + error(node, Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors); + } + else { + error(node, Diagnostics.super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class); + } + return unknownType; } + + if (container.kind === SyntaxKind.Constructor && isInConstructorArgumentInitializer(node, container)) { + // issue custom error message for super property access in constructor arguments (to be aligned with old compiler) + error(node, Diagnostics.super_cannot_be_referenced_in_constructor_arguments); + return unknownType; + } + + return nodeCheckFlag === NodeCheckFlags.SuperStatic + ? getBaseConstructorTypeOfClass(classType) + : baseClassType; + + function isLegalUsageOfSuperExpression(container: Node): boolean { + if (!container) { + return false; + } - let container = getSuperContainer(node, /*includeFunctions*/ true); - - if (container) { - let canUseSuperExpression = false; - let needToCaptureLexicalThis: boolean; if (isCallExpression) { // TS 1.0 SPEC (April 2014): 4.8.1 // Super calls are only permitted in constructors of derived classes - canUseSuperExpression = container.kind === SyntaxKind.Constructor; + return container.kind === SyntaxKind.Constructor; } else { // TS 1.0 SPEC (April 2014) @@ -6293,75 +6535,28 @@ namespace ts { // - In a constructor, instance member function, instance member accessor, or instance member variable initializer where this references a derived class instance // - In a static member function or static member accessor - // super property access might appear in arrow functions with arbitrary deep nesting - needToCaptureLexicalThis = false; - while (container && container.kind === SyntaxKind.ArrowFunction) { - container = getSuperContainer(container, /*includeFunctions*/ true); - needToCaptureLexicalThis = languageVersion < ScriptTarget.ES6; - } - // topmost container must be something that is directly nested in the class declaration if (container && isClassLike(container.parent)) { if (container.flags & NodeFlags.Static) { - canUseSuperExpression = - container.kind === SyntaxKind.MethodDeclaration || - container.kind === SyntaxKind.MethodSignature || - container.kind === SyntaxKind.GetAccessor || - container.kind === SyntaxKind.SetAccessor; + return container.kind === SyntaxKind.MethodDeclaration || + container.kind === SyntaxKind.MethodSignature || + container.kind === SyntaxKind.GetAccessor || + container.kind === SyntaxKind.SetAccessor; } else { - canUseSuperExpression = - container.kind === SyntaxKind.MethodDeclaration || - container.kind === SyntaxKind.MethodSignature || - container.kind === SyntaxKind.GetAccessor || - container.kind === SyntaxKind.SetAccessor || - container.kind === SyntaxKind.PropertyDeclaration || - container.kind === SyntaxKind.PropertySignature || - container.kind === SyntaxKind.Constructor; + return container.kind === SyntaxKind.MethodDeclaration || + container.kind === SyntaxKind.MethodSignature || + container.kind === SyntaxKind.GetAccessor || + container.kind === SyntaxKind.SetAccessor || + container.kind === SyntaxKind.PropertyDeclaration || + container.kind === SyntaxKind.PropertySignature || + container.kind === SyntaxKind.Constructor; } } } - - if (canUseSuperExpression) { - let returnType: Type; - - if ((container.flags & NodeFlags.Static) || isCallExpression) { - getNodeLinks(node).flags |= NodeCheckFlags.SuperStatic; - returnType = getBaseConstructorTypeOfClass(classType); - } - else { - getNodeLinks(node).flags |= NodeCheckFlags.SuperInstance; - returnType = baseClassType; - } - - if (container.kind === SyntaxKind.Constructor && isInConstructorArgumentInitializer(node, container)) { - // issue custom error message for super property access in constructor arguments (to be aligned with old compiler) - error(node, Diagnostics.super_cannot_be_referenced_in_constructor_arguments); - returnType = unknownType; - } - - if (!isCallExpression && needToCaptureLexicalThis) { - // call expressions are allowed only in constructors so they should always capture correct 'this' - // super property access expressions can also appear in arrow functions - - // in this case they should also use correct lexical this - captureLexicalThis(node.parent, container); - } - - return returnType; - } - } - - if (container && container.kind === SyntaxKind.ComputedPropertyName) { - error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name); - } - else if (isCallExpression) { - error(node, Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors); - } - else { - error(node, Diagnostics.super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class); - } - - return unknownType; + + return false; + } } // Return contextual type of parameter or undefined if no contextual type is available @@ -6764,10 +6959,23 @@ namespace ts { return result; } - // Presence of a contextual type mapper indicates inferential typing, except the identityMapper object is - // used as a special marker for other purposes. + /** + * Detect if the mapper implies an inference context. Specifically, there are 4 possible values + * for a mapper. Let's go through each one of them: + * + * 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, + * which could cause us to assign a parameter a type + * 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in + * inferential typing (context is undefined for the identityMapper) + * 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign + * types to parameters and fix type parameters (context is defined) + * 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be + * passed as the contextual mapper when checking an expression (context is undefined for these) + * + * isInferentialContext is detecting if we are in case 3 + */ function isInferentialContext(mapper: TypeMapper) { - return mapper && mapper !== identityMapper; + return mapper && mapper.context; } // A node is an assignment target if it is on the left hand side of an '=' token, if it is parented by a property @@ -6955,7 +7163,7 @@ namespace ts { let stringIndexType = getIndexType(IndexKind.String); let numberIndexType = getIndexType(IndexKind.Number); let result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); - result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | (typeFlags & TypeFlags.ContainsUndefinedOrNull); + result.flags |= TypeFlags.ObjectLiteral | TypeFlags.FreshObjectLiteral | TypeFlags.ContainsObjectLiteral | (typeFlags & TypeFlags.PropagatingFlags); return result; function getIndexType(kind: IndexKind) { @@ -7001,13 +7209,17 @@ namespace ts { } function checkJsxElement(node: JsxElement) { + // Check attributes + checkJsxOpeningLikeElement(node.openingElement); + // Check that the closing tag matches if (!tagNamesAreEquivalent(node.openingElement.tagName, node.closingElement.tagName)) { error(node.closingElement, Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, getTextOfNode(node.openingElement.tagName)); } - - // Check attributes - checkJsxOpeningLikeElement(node.openingElement); + else { + // Perform resolution on the closing tag so that rename/go to definition/etc work + getJsxElementTagSymbol(node.closingElement); + } // Check children for (let child of node.children) { @@ -7118,7 +7330,7 @@ namespace ts { /// If this is a class-based tag (otherwise returns undefined), returns the symbol of the class /// type or factory function. /// Otherwise, returns unknownSymbol. - function getJsxElementTagSymbol(node: JsxOpeningLikeElement): Symbol { + function getJsxElementTagSymbol(node: JsxOpeningLikeElement|JsxClosingElement): Symbol { let flags: JsxFlags = JsxFlags.UnknownElement; let links = getNodeLinks(node); if (!links.resolvedSymbol) { @@ -7130,7 +7342,7 @@ namespace ts { } return links.resolvedSymbol; - function lookupIntrinsicTag(node: JsxOpeningLikeElement): Symbol { + function lookupIntrinsicTag(node: JsxOpeningLikeElement|JsxClosingElement): Symbol { let intrinsicElementsType = getJsxIntrinsicElementsType(); if (intrinsicElementsType !== unknownType) { // Property case @@ -7148,7 +7360,7 @@ namespace ts { } // Wasn't found - error(node, Diagnostics.Property_0_does_not_exist_on_type_1, (node.tagName).text, 'JSX.' + JsxNames.IntrinsicElements); + error(node, Diagnostics.Property_0_does_not_exist_on_type_1, (node.tagName).text, "JSX." + JsxNames.IntrinsicElements); return unknownSymbol; } else { @@ -7158,19 +7370,10 @@ namespace ts { } } - function lookupClassTag(node: JsxOpeningLikeElement): Symbol { - let valueSymbol: Symbol; + function lookupClassTag(node: JsxOpeningLikeElement|JsxClosingElement): Symbol { + let valueSymbol: Symbol = resolveJsxTagName(node); // Look up the value in the current scope - if (node.tagName.kind === SyntaxKind.Identifier) { - let tag = node.tagName; - let sym = getResolvedSymbol(tag); - valueSymbol = sym.exportSymbol || sym; - } - else { - valueSymbol = checkQualifiedName(node.tagName).symbol; - } - if (valueSymbol && valueSymbol !== unknownSymbol) { links.jsxFlags |= JsxFlags.ClassElement; getSymbolLinks(valueSymbol).referenced = true; @@ -7178,6 +7381,17 @@ namespace ts { return valueSymbol || unknownSymbol; } + + function resolveJsxTagName(node: JsxOpeningLikeElement|JsxClosingElement): Symbol { + if (node.tagName.kind === SyntaxKind.Identifier) { + let tag = node.tagName; + let sym = getResolvedSymbol(tag); + return sym.exportSymbol || sym; + } + else { + return checkQualifiedName(node.tagName).symbol; + } + } } /** @@ -7186,10 +7400,9 @@ namespace ts { * For example, in the element , the element instance type is `MyClass` (not `typeof MyClass`). */ function getJsxElementInstanceType(node: JsxOpeningLikeElement) { - if (!(getNodeLinks(node).jsxFlags & JsxFlags.ClassElement)) { - // There is no such thing as an instance type for a non-class element - return undefined; - } + // There is no such thing as an instance type for a non-class element. This + // line shouldn't be hit. + Debug.assert(!!(getNodeLinks(node).jsxFlags & JsxFlags.ClassElement), "Should not call getJsxElementInstanceType on non-class Element"); let classSymbol = getJsxElementTagSymbol(node); if (classSymbol === unknownSymbol) { @@ -7212,16 +7425,11 @@ namespace ts { if (signatures.length === 0) { // We found no signatures at all, which is an error error(node.tagName, Diagnostics.JSX_element_type_0_does_not_have_any_construct_or_call_signatures, getTextOfNode(node.tagName)); - return undefined; + return unknownType; } } - // Check that the constructor/factory returns an object type - let returnType = getUnionType(signatures.map(s => getReturnTypeOfSignature(s))); - if (!isTypeAny(returnType) && !(returnType.flags & TypeFlags.ObjectType)) { - error(node.tagName, Diagnostics.The_return_type_of_a_JSX_element_constructor_must_return_an_object_type); - return undefined; - } + let returnType = getUnionType(signatures.map(getReturnTypeOfSignature)); // Issue an error if this return type isn't assignable to JSX.ElementClass let elemClassType = getJsxGlobalElementClassType(); @@ -7282,7 +7490,7 @@ namespace ts { let elemInstanceType = getJsxElementInstanceType(node); if (isTypeAny(elemInstanceType)) { - return links.resolvedJsxType = anyType; + return links.resolvedJsxType = elemInstanceType; } let propsName = getJsxElementPropertiesName(); @@ -7374,7 +7582,7 @@ namespace ts { // be marked as 'used' so we don't incorrectly elide its import. And if there // is no 'React' symbol in scope, we should issue an error. if (compilerOptions.jsx === JsxEmit.React) { - let reactSym = resolveName(node.tagName, 'React', SymbolFlags.Value, Diagnostics.Cannot_find_name_0, 'React'); + let reactSym = resolveName(node.tagName, "React", SymbolFlags.Value, Diagnostics.Cannot_find_name_0, "React"); if (reactSym) { getSymbolLinks(reactSym).referenced = true; } @@ -8487,6 +8695,9 @@ namespace ts { if (!produceDiagnostics) { for (let candidate of candidates) { if (hasCorrectArity(node, args, candidate)) { + if (candidate.typeParameters && typeArguments) { + candidate = getSignatureInstantiation(candidate, map(typeArguments, getTypeFromTypeNode)); + } return candidate; } } @@ -8835,7 +9046,7 @@ namespace ts { } function checkAssertion(node: AssertionExpression) { - let exprType = checkExpression(node.expression); + let exprType = getRegularTypeOfObjectLiteral(checkExpression(node.expression)); let targetType = getTypeFromTypeNode(node.type); if (produceDiagnostics && targetType !== unknownType) { let widenedType = getWidenedType(exprType); @@ -8856,13 +9067,52 @@ namespace ts { let len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0); for (let i = 0; i < len; i++) { let parameter = signature.parameters[i]; - let links = getSymbolLinks(parameter); - links.type = instantiateType(getTypeAtPosition(context, i), mapper); + let contextualParameterType = getTypeAtPosition(context, i); + assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper); } if (signature.hasRestParameter && context.hasRestParameter && signature.parameters.length >= context.parameters.length) { let parameter = lastOrUndefined(signature.parameters); - let links = getSymbolLinks(parameter); - links.type = instantiateType(getTypeOfSymbol(lastOrUndefined(context.parameters)), mapper); + let contextualParameterType = getTypeOfSymbol(lastOrUndefined(context.parameters)); + assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper); + } + } + + function assignTypeToParameterAndFixTypeParameters(parameter: Symbol, contextualType: Type, mapper: TypeMapper) { + let links = getSymbolLinks(parameter); + if (!links.type) { + links.type = instantiateType(contextualType, mapper); + } + else if (isInferentialContext(mapper)) { + // Even if the parameter already has a type, it might be because it was given a type while + // processing the function as an argument to a prior signature during overload resolution. + // If this was the case, it may have caused some type parameters to be fixed. So here, + // we need to ensure that type parameters at the same positions get fixed again. This is + // done by calling instantiateType to attach the mapper to the contextualType, and then + // calling inferTypes to force a walk of contextualType so that all the correct fixing + // happens. The choice to pass in links.type may seem kind of arbitrary, but it serves + // to make sure that all the correct positions in contextualType are reached by the walk. + // Here is an example: + // + // interface Base { + // baseProp; + // } + // interface Derived extends Base { + // toBase(): Base; + // } + // + // var derived: Derived; + // + // declare function foo(x: T, func: (p: T) => T): T; + // declare function foo(x: T, func: (p: T) => T): T; + // + // var result = foo(derived, d => d.toBase()); + // + // We are typing d while checking the second overload. But we've already given d + // a type (Derived) from the first overload. However, we still want to fix the + // T in the second overload so that we do not infer Base as a candidate for T + // (inferring Base would make type argument inference inconsistent between the two + // overloads). + inferTypes(mapper.context, links.type, instantiateType(contextualType, mapper)); } } @@ -9082,27 +9332,36 @@ namespace ts { let links = getNodeLinks(node); let type = getTypeOfSymbol(node.symbol); - // Check if function expression is contextually typed and assign parameter types if so - if (!(links.flags & NodeCheckFlags.ContextChecked)) { + let contextSensitive = isContextSensitive(node); + let mightFixTypeParameters = contextSensitive && isInferentialContext(contextualMapper); + + // Check if function expression is contextually typed and assign parameter types if so. + // See the comment in assignTypeToParameterAndFixTypeParameters to understand why we need to + // check mightFixTypeParameters. + if (mightFixTypeParameters || !(links.flags & NodeCheckFlags.ContextChecked)) { let contextualSignature = getContextualSignature(node); // If a type check is started at a function expression that is an argument of a function call, obtaining the // contextual type may recursively get back to here during overload resolution of the call. If so, we will have // already assigned contextual types. - if (!(links.flags & NodeCheckFlags.ContextChecked)) { + let contextChecked = !!(links.flags & NodeCheckFlags.ContextChecked); + if (mightFixTypeParameters || !contextChecked) { links.flags |= NodeCheckFlags.ContextChecked; if (contextualSignature) { let signature = getSignaturesOfType(type, SignatureKind.Call)[0]; - if (isContextSensitive(node)) { + if (contextSensitive) { assignContextualParameterTypes(signature, contextualSignature, contextualMapper || identityMapper); } - if (!node.type && !signature.resolvedReturnType) { + if (mightFixTypeParameters || !node.type && !signature.resolvedReturnType) { let returnType = getReturnTypeFromBody(node, contextualMapper); if (!signature.resolvedReturnType) { signature.resolvedReturnType = returnType; } } } - checkSignatureDeclaration(node); + + if (!contextChecked) { + checkSignatureDeclaration(node); + } } } @@ -9612,7 +9871,7 @@ namespace ts { return getUnionType([leftType, rightType]); case SyntaxKind.EqualsToken: checkAssignmentOperator(rightType); - return rightType; + return getRegularTypeOfObjectLiteral(rightType); case SyntaxKind.CommaToken: return rightType; } @@ -9792,7 +10051,7 @@ namespace ts { } function instantiateTypeWithSingleGenericCallSignature(node: Expression | MethodDeclaration, type: Type, contextualMapper?: TypeMapper) { - if (contextualMapper && contextualMapper !== identityMapper) { + if (isInferentialContext(contextualMapper)) { let signature = getSingleCallSignature(type); if (signature && signature.typeParameters) { let contextualType = getContextualType(node); @@ -10037,7 +10296,7 @@ namespace ts { } else { checkTypeAssignableTo(typePredicate.type, - getTypeAtLocation(node.parameters[typePredicate.parameterIndex]), + getTypeOfNode(node.parameters[typePredicate.parameterIndex]), typePredicateNode.type); } } @@ -10217,17 +10476,21 @@ namespace ts { return n.kind === SyntaxKind.CallExpression && (n).expression.kind === SyntaxKind.SuperKeyword; } + function containsSuperCallAsComputedPropertyName(n: Declaration): boolean { + return n.name && containsSuperCall(n.name); + } + function containsSuperCall(n: Node): boolean { if (isSuperCallExpression(n)) { return true; } - switch (n.kind) { - case SyntaxKind.FunctionExpression: - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.ArrowFunction: - case SyntaxKind.ObjectLiteralExpression: return false; - default: return forEachChild(n, containsSuperCall); + else if (isFunctionLike(n)) { + return false; } + else if (isClassLike(n)) { + return forEach((n).members, containsSuperCallAsComputedPropertyName); + } + return forEachChild(n, containsSuperCall); } function markThisReferencesAsErrors(n: Node): void { @@ -10248,10 +10511,19 @@ namespace ts { // TS 1.0 spec (April 2014): 8.3.2 // Constructors of classes with no extends clause may not contain super calls, whereas // constructors of derived classes must contain at least one super call somewhere in their function body. - if (getClassExtendsHeritageClauseElement(node.parent)) { + let containingClassDecl = node.parent; + if (getClassExtendsHeritageClauseElement(containingClassDecl)) { + let containingClassSymbol = getSymbolOfNode(containingClassDecl); + let containingClassInstanceType = getDeclaredTypeOfSymbol(containingClassSymbol); + let baseConstructorType = getBaseConstructorTypeOfClass(containingClassInstanceType); if (containsSuperCall(node.body)) { - // The first statement in the body of a constructor must be a super call if both of the following are true: + if (baseConstructorType === nullType) { + error(node, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null); + } + + // The first statement in the body of a constructor (excluding prologue directives) must be a super call + // if both of the following are true: // - The containing class is a derived class. // - The constructor declares parameter properties // or the containing class declares instance member variables with initializers. @@ -10259,18 +10531,30 @@ namespace ts { forEach((node.parent).members, isInstancePropertyWithInitializer) || forEach(node.parameters, p => p.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)); + // Skip past any prologue directives to find the first statement + // to ensure that it was a super call. if (superCallShouldBeFirst) { let statements = (node.body).statements; - if (!statements.length || statements[0].kind !== SyntaxKind.ExpressionStatement || !isSuperCallExpression((statements[0]).expression)) { - error(node, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); + let superCallStatement: ExpressionStatement; + for (let statement of statements) { + if (statement.kind === SyntaxKind.ExpressionStatement && isSuperCallExpression((statement).expression)) { + superCallStatement = statement; + break; + } + if (!isPrologueDirective(statement)) { + break; + } } + if (!superCallStatement) { + error(node, Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties); + } else { // In such a required super call, it is a compile-time error for argument expressions to reference this. - markThisReferencesAsErrors((statements[0]).expression); + markThisReferencesAsErrors(superCallStatement.expression); } } } - else { + else if (baseConstructorType !== nullType) { error(node, Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call); } } @@ -10661,9 +10945,6 @@ namespace ts { return; } - // Exports should be checked only if enclosing module contains both exported and non exported declarations. - // In case if all declarations are non-exported check is unnecessary. - // if localSymbol is defined on node then node itself is exported - check is required let symbol = node.localSymbol; if (!symbol) { @@ -10683,27 +10964,45 @@ namespace ts { // we use SymbolFlags.ExportValue, SymbolFlags.ExportType and SymbolFlags.ExportNamespace // to denote disjoint declarationSpaces (without making new enum type). - let exportedDeclarationSpaces: SymbolFlags = 0; - let nonExportedDeclarationSpaces: SymbolFlags = 0; - forEach(symbol.declarations, d => { + let exportedDeclarationSpaces = SymbolFlags.None; + let nonExportedDeclarationSpaces = SymbolFlags.None; + let defaultExportedDeclarationSpaces = SymbolFlags.None; + for (let d of symbol.declarations) { let declarationSpaces = getDeclarationSpaces(d); - if (getEffectiveDeclarationFlags(d, NodeFlags.Export)) { - exportedDeclarationSpaces |= declarationSpaces; + let effectiveDeclarationFlags = getEffectiveDeclarationFlags(d, NodeFlags.Export | NodeFlags.Default); + + if (effectiveDeclarationFlags & NodeFlags.Export) { + if (effectiveDeclarationFlags & NodeFlags.Default) { + defaultExportedDeclarationSpaces |= declarationSpaces; + } + else { + exportedDeclarationSpaces |= declarationSpaces; + } } else { nonExportedDeclarationSpaces |= declarationSpaces; } - }); + } - let commonDeclarationSpace = exportedDeclarationSpaces & nonExportedDeclarationSpaces; + // Spaces for anyting not declared a 'default export'. + let nonDefaultExportedDeclarationSpaces = exportedDeclarationSpaces | nonExportedDeclarationSpaces; + + let commonDeclarationSpacesForExportsAndLocals = exportedDeclarationSpaces & nonExportedDeclarationSpaces; + let commonDeclarationSpacesForDefaultAndNonDefault = defaultExportedDeclarationSpaces & nonDefaultExportedDeclarationSpaces; - if (commonDeclarationSpace) { + if (commonDeclarationSpacesForExportsAndLocals || commonDeclarationSpacesForDefaultAndNonDefault) { // declaration spaces for exported and non-exported declarations intersect - forEach(symbol.declarations, d => { - if (getDeclarationSpaces(d) & commonDeclarationSpace) { + for (let d of symbol.declarations) { + let declarationSpaces = getDeclarationSpaces(d); + + // Only error on the declarations that conributed to the intersecting spaces. + if (declarationSpaces & commonDeclarationSpacesForDefaultAndNonDefault) { + error(d.name, Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead, declarationNameToString(d.name)); + } + else if (declarationSpaces & commonDeclarationSpacesForExportsAndLocals) { error(d.name, Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, declarationNameToString(d.name)); } - }); + } } function getDeclarationSpaces(d: Declaration): SymbolFlags { @@ -12548,28 +12847,7 @@ namespace ts { } let initializer = member.initializer; if (initializer) { - autoValue = getConstantValueForEnumMemberInitializer(initializer); - if (autoValue === undefined) { - if (enumIsConst) { - error(initializer, Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression); - } - else if (!ambient) { - // Only here do we need to check that the initializer is assignable to the enum type. - // If it is a constant value (not undefined), it is syntactically constrained to be a number. - // Also, we do not need to check this for ambients because there is already - // a syntax error if it is not a constant. - checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, /*headMessage*/ undefined); - } - } - else if (enumIsConst) { - if (isNaN(autoValue)) { - error(initializer, Diagnostics.const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN); - } - else if (!isFinite(autoValue)) { - error(initializer, Diagnostics.const_enum_member_initializer_was_evaluated_to_a_non_finite_value); - } - } - + autoValue = computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient); } else if (ambient && !enumIsConst) { autoValue = undefined; @@ -12583,8 +12861,36 @@ namespace ts { nodeLinks.flags |= NodeCheckFlags.EnumValuesComputed; } - function getConstantValueForEnumMemberInitializer(initializer: Expression): number { - return evalConstant(initializer); + function computeConstantValueForEnumMemberInitializer(initializer: Expression, enumType: Type, enumIsConst: boolean, ambient: boolean): number { + // Controls if error should be reported after evaluation of constant value is completed + // Can be false if another more precise error was already reported during evaluation. + let reportError = true; + let value = evalConstant(initializer); + + if (reportError) { + if (value === undefined) { + if (enumIsConst) { + error(initializer, Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression); + } + else if (!ambient) { + // Only here do we need to check that the initializer is assignable to the enum type. + // If it is a constant value (not undefined), it is syntactically constrained to be a number. + // Also, we do not need to check this for ambients because there is already + // a syntax error if it is not a constant. + checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, /*headMessage*/ undefined); + } + } + else if (enumIsConst) { + if (isNaN(value)) { + error(initializer, Diagnostics.const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN); + } + else if (!isFinite(value)) { + error(initializer, Diagnostics.const_enum_member_initializer_was_evaluated_to_a_non_finite_value); + } + } + } + + return value; function evalConstant(e: Node): number { switch (e.kind) { @@ -12693,6 +12999,8 @@ namespace ts { // illegal case: forward reference if (!isDefinedBefore(propertyDecl, member)) { + reportError = false; + error(e, Diagnostics.A_member_initializer_in_a_const_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_const_enums); return undefined; } @@ -13610,7 +13918,9 @@ namespace ts { meaning |= SymbolFlags.Alias; return resolveEntityName(entityName, meaning); } - else if ((entityName.parent.kind === SyntaxKind.JsxOpeningElement) || (entityName.parent.kind === SyntaxKind.JsxSelfClosingElement)) { + else if ((entityName.parent.kind === SyntaxKind.JsxOpeningElement) || + (entityName.parent.kind === SyntaxKind.JsxSelfClosingElement) || + (entityName.parent.kind === SyntaxKind.JsxClosingElement)) { return getJsxElementTagSymbol(entityName.parent); } else if (isExpression(entityName)) { @@ -13659,7 +13969,7 @@ namespace ts { return undefined; } - function getSymbolInfo(node: Node) { + function getSymbolAtLocation(node: Node) { if (isInsideWithStatementBody(node)) { // We cannot answer semantic questions within a with block, do not proceed any further return undefined; @@ -13670,10 +13980,22 @@ namespace ts { return getSymbolOfNode(node.parent); } - if (node.kind === SyntaxKind.Identifier && isInRightSideOfImportOrExportAssignment(node)) { - return node.parent.kind === SyntaxKind.ExportAssignment - ? getSymbolOfEntityNameOrPropertyAccessExpression(node) - : getSymbolOfPartOfRightHandSideOfImportEquals(node); + if (node.kind === SyntaxKind.Identifier) { + if (isInRightSideOfImportOrExportAssignment(node)) { + return node.parent.kind === SyntaxKind.ExportAssignment + ? getSymbolOfEntityNameOrPropertyAccessExpression(node) + : getSymbolOfPartOfRightHandSideOfImportEquals(node); + } + else if (node.parent.kind === SyntaxKind.BindingElement && + node.parent.parent.kind === SyntaxKind.ObjectBindingPattern && + node === (node.parent).propertyName) { + let typeOfPattern = getTypeOfNode(node.parent.parent); + let propertyDeclaration = typeOfPattern && getPropertyOfType(typeOfPattern, (node).text); + + if (propertyDeclaration) { + return propertyDeclaration; + } + } } switch (node.kind) { @@ -13750,24 +14072,24 @@ namespace ts { } if (isTypeDeclaration(node)) { - // In this case, we call getSymbolOfNode instead of getSymbolInfo because it is a declaration + // In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration let symbol = getSymbolOfNode(node); return getDeclaredTypeOfSymbol(symbol); } if (isTypeDeclarationName(node)) { - let symbol = getSymbolInfo(node); + let symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); } if (isDeclaration(node)) { - // In this case, we call getSymbolOfNode instead of getSymbolInfo because it is a declaration + // In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration let symbol = getSymbolOfNode(node); return getTypeOfSymbol(symbol); } if (isDeclarationName(node)) { - let symbol = getSymbolInfo(node); + let symbol = getSymbolAtLocation(node); return symbol && getTypeOfSymbol(symbol); } @@ -13776,7 +14098,7 @@ namespace ts { } if (isInRightSideOfImportOrExportAssignment(node)) { - let symbol = getSymbolInfo(node); + let symbol = getSymbolAtLocation(node); let declaredType = symbol && getDeclaredTypeOfSymbol(symbol); return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol); } @@ -13945,7 +14267,11 @@ namespace ts { return true; } // const enums and modules that contain only const enums are not considered values from the emit perespective - return target !== unknownSymbol && target && target.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(target); + // unless 'preserveConstEnums' option is set to true + return target !== unknownSymbol && + target && + target.flags & SymbolFlags.Value && + (compilerOptions.preserveConstEnums || !isConstEnumOrConstEnumOnlyModule(target)); } function isConstEnumOrConstEnumOnlyModule(s: Symbol): boolean { @@ -14160,6 +14486,7 @@ namespace ts { getBlockScopedVariableId, getReferencedValueDeclaration, getTypeReferenceSerializationKind, + isOptionalParameter }; } @@ -14555,17 +14882,15 @@ namespace ts { return grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_have_an_initializer); } } - else if (parameter.questionToken || parameter.initializer) { + else if (parameter.questionToken) { seenOptionalParameter = true; - if (parameter.questionToken && parameter.initializer) { + if (parameter.initializer) { return grammarErrorOnNode(parameter.name, Diagnostics.Parameter_cannot_have_question_mark_and_initializer); } } - else { - if (seenOptionalParameter) { - return grammarErrorOnNode(parameter.name, Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter); - } + else if (seenOptionalParameter && !parameter.initializer) { + return grammarErrorOnNode(parameter.name, Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter); } } } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index ba7d8ca9ce3..9a984b9a2f1 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -335,7 +335,7 @@ namespace ts { * @param fileName The path to the config file */ export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } { - let text = ''; + let text = ""; try { text = sys.readFile(fileName); } @@ -422,10 +422,13 @@ namespace ts { if (json["files"] instanceof Array) { fileNames = map(json["files"], s => combinePaths(basePath, s)); } + else { + errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "files", "Array")); + } } else { let exclude = json["exclude"] instanceof Array ? map(json["exclude"], normalizeSlashes) : undefined; - let sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude)); + let sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude)); for (let i = 0; i < sysFiles.length; i++) { let name = sysFiles[i]; if (fileExtensionIs(name, ".d.ts")) { diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ec171d4aee2..3305d4b1497 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -219,10 +219,10 @@ namespace ts { export function reduceLeft(array: T[], f: (a: U, x: T) => U, initial: U): U; export function reduceLeft(array: T[], f: (a: U, x: T) => U, initial?: U): U { if (array) { - var count = array.length; + const count = array.length; if (count > 0) { - var pos = 0; - var result = arguments.length <= 2 ? array[pos++] : initial; + let pos = 0; + let result = arguments.length <= 2 ? array[pos++] : initial; while (pos < count) { result = f(result, array[pos++]); } @@ -236,9 +236,9 @@ namespace ts { export function reduceRight(array: T[], f: (a: U, x: T) => U, initial: U): U; export function reduceRight(array: T[], f: (a: U, x: T) => U, initial?: U): U { if (array) { - var pos = array.length - 1; + let pos = array.length - 1; if (pos >= 0) { - var result = arguments.length <= 2 ? array[pos--] : initial; + let result = arguments.length <= 2 ? array[pos--] : initial; while (pos >= 0) { result = f(result, array[pos--]); } @@ -523,7 +523,7 @@ namespace ts { if (path.lastIndexOf("file:///", 0) === 0) { return "file:///".length; } - let idx = path.indexOf('://'); + let idx = path.indexOf("://"); if (idx !== -1) { return idx + "://".length; } @@ -805,4 +805,4 @@ namespace ts { Debug.assert(false, message); } } -} +} diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 6c0803f8761..63d71b0339e 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1371,7 +1371,7 @@ namespace ts { else { writeTextOfNode(currentSourceFile, node.name); } - if (node.initializer || hasQuestionToken(node)) { + if (resolver.isOptionalParameter(node)) { write("?"); } decreaseIndent(); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index a0a95d47c8c..5ccc0a0db9b 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -254,6 +254,7 @@ namespace ts { Only_a_void_function_can_be_called_with_the_new_keyword: { code: 2350, category: DiagnosticCategory.Error, key: "Only a void function can be called with the 'new' keyword." }, Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature: { code: 2351, category: DiagnosticCategory.Error, key: "Cannot use 'new' with an expression whose type lacks a call or construct signature." }, Neither_type_0_nor_type_1_is_assignable_to_the_other: { code: 2352, category: DiagnosticCategory.Error, key: "Neither type '{0}' nor type '{1}' is assignable to the other." }, + Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1: { code: 2353, category: DiagnosticCategory.Error, key: "Object literal may only specify known properties, and '{0}' does not exist in type '{1}'." }, No_best_common_type_exists_among_return_expressions: { code: 2354, category: DiagnosticCategory.Error, key: "No best common type exists among return expressions." }, A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value_or_consist_of_a_single_throw_statement: { code: 2355, category: DiagnosticCategory.Error, key: "A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement." }, An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type: { code: 2356, category: DiagnosticCategory.Error, key: "An arithmetic operand must be of type 'any', 'number' or an enum type." }, @@ -293,7 +294,7 @@ namespace ts { Multiple_constructor_implementations_are_not_allowed: { code: 2392, category: DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." }, Duplicate_function_implementation: { code: 2393, category: DiagnosticCategory.Error, key: "Duplicate function implementation." }, Overload_signature_is_not_compatible_with_function_implementation: { code: 2394, category: DiagnosticCategory.Error, key: "Overload signature is not compatible with function implementation." }, - Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2395, category: DiagnosticCategory.Error, key: "Individual declarations in merged declaration {0} must be all exported or all local." }, + Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local: { code: 2395, category: DiagnosticCategory.Error, key: "Individual declarations in merged declaration '{0}' must be all exported or all local." }, Duplicate_identifier_arguments_Compiler_uses_arguments_to_initialize_rest_parameters: { code: 2396, category: DiagnosticCategory.Error, key: "Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters." }, Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference: { code: 2399, category: DiagnosticCategory.Error, key: "Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference." }, Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference: { code: 2400, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference." }, @@ -424,6 +425,8 @@ namespace ts { JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property: { code: 2607, category: DiagnosticCategory.Error, key: "JSX element class does not support attributes because it does not have a '{0}' property" }, The_global_type_JSX_0_may_not_have_more_than_one_property: { code: 2608, category: DiagnosticCategory.Error, key: "The global type 'JSX.{0}' may not have more than one property" }, Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" }, + A_member_initializer_in_a_const_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_const_enums: { code: 2651, category: DiagnosticCategory.Error, key: "A member initializer in a 'const' enum declaration cannot reference members declared after it, including members defined in other 'const' enums." }, + Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead: { code: 2652, category: DiagnosticCategory.Error, key: "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -508,7 +511,6 @@ namespace ts { Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." }, Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." }, Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." }, - Option_sourceMap_cannot_be_specified_with_option_isolatedModules: { code: 5043, category: DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'isolatedModules'." }, Option_declaration_cannot_be_specified_with_option_isolatedModules: { code: 5044, category: DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'isolatedModules'." }, Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules: { code: 5045, category: DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'isolatedModules'." }, Option_out_cannot_be_specified_with_option_isolatedModules: { code: 5046, category: DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'isolatedModules'." }, @@ -613,5 +615,6 @@ namespace ts { Expected_corresponding_JSX_closing_tag_for_0: { code: 17002, category: DiagnosticCategory.Error, key: "Expected corresponding JSX closing tag for '{0}'." }, JSX_attribute_expected: { code: 17003, category: DiagnosticCategory.Error, key: "JSX attribute expected." }, Cannot_use_JSX_unless_the_jsx_flag_is_provided: { code: 17004, category: DiagnosticCategory.Error, key: "Cannot use JSX unless the '--jsx' flag is provided." }, + A_constructor_cannot_contain_a_super_call_when_its_class_extends_null: { code: 17005, category: DiagnosticCategory.Error, key: "A constructor cannot contain a 'super' call when its class extends 'null'" }, }; } \ No newline at end of file diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index acf4e74ae9f..e138e2ddac4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1,4 +1,4 @@ -{ + { "Unterminated string literal.": { "category": "Error", "code": 1002 @@ -1005,6 +1005,10 @@ "category": "Error", "code": 2352 }, + "Object literal may only specify known properties, and '{0}' does not exist in type '{1}'.": { + "category": "Error", + "code": 2353 + }, "No best common type exists among return expressions.": { "category": "Error", "code": 2354 @@ -1161,7 +1165,7 @@ "category": "Error", "code": 2394 }, - "Individual declarations in merged declaration {0} must be all exported or all local.": { + "Individual declarations in merged declaration '{0}' must be all exported or all local.": { "category": "Error", "code": 2395 }, @@ -1685,6 +1689,14 @@ "category": "Error", "code": 2650 }, + "A member initializer in a 'const' enum declaration cannot reference members declared after it, including members defined in other 'const' enums.": { + "category": "Error", + "code": 2651 + }, + "Merged declaration '{0}' cannot include a default export declaration. Consider adding a separate 'export default {0}' declaration instead.": { + "category": "Error", + "code": 2652 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 @@ -2021,10 +2033,6 @@ "category": "Error", "code": 5042 }, - "Option 'sourceMap' cannot be specified with option 'isolatedModules'.": { - "category": "Error", - "code": 5043 - }, "Option 'declaration' cannot be specified with option 'isolatedModules'.": { "category": "Error", "code": 5044 @@ -2445,5 +2453,9 @@ "Cannot use JSX unless the '--jsx' flag is provided.": { "category": "Error", "code": 17004 + }, + "A constructor cannot contain a 'super' call when its class extends 'null'": { + "category": "Error", + "code": 17005 } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 98de37c752c..68ebd6772a9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -380,7 +380,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function base64VLQFormatEncode(inValue: number) { function base64FormatEncode(inValue: number) { if (inValue < 64) { - return 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.charAt(inValue); + return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(inValue); } throw TypeError(inValue + ": not a 64 based value"); } @@ -895,7 +895,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // Any template literal or string literal with an extended escape // (e.g. "\u{0067}") will need to be downleveled as a escaped string literal. if (languageVersion < ScriptTarget.ES6 && (isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { - return getQuotedEscapedLiteralText('"', node.text, '"'); + return getQuotedEscapedLiteralText("\"", node.text, "\""); } // If we don't need to downlevel and we can reach the original source text using @@ -908,15 +908,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // or an escaped quoted form of the original text if it's string-like. switch (node.kind) { case SyntaxKind.StringLiteral: - return getQuotedEscapedLiteralText('"', node.text, '"'); + return getQuotedEscapedLiteralText("\"", node.text, "\""); case SyntaxKind.NoSubstitutionTemplateLiteral: - return getQuotedEscapedLiteralText('`', node.text, '`'); + return getQuotedEscapedLiteralText("`", node.text, "`"); case SyntaxKind.TemplateHead: - return getQuotedEscapedLiteralText('`', node.text, '${'); + return getQuotedEscapedLiteralText("`", node.text, "${"); case SyntaxKind.TemplateMiddle: - return getQuotedEscapedLiteralText('}', node.text, '${'); + return getQuotedEscapedLiteralText("}", node.text, "${"); case SyntaxKind.TemplateTail: - return getQuotedEscapedLiteralText('}', node.text, '`'); + return getQuotedEscapedLiteralText("}", node.text, "`"); case SyntaxKind.NumericLiteral: return node.text; } @@ -947,7 +947,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi text = text.replace(/\r\n?/g, "\n"); text = escapeString(text); - write('"' + text + '"'); + write(`"${text}"`); } function emitDownlevelTaggedTemplateArray(node: TaggedTemplateExpression, literalEmitter: (literal: LiteralExpression) => void) { @@ -1134,9 +1134,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi /// 'Div' for upper-cased or dotted names function emitTagName(name: Identifier|QualifiedName) { if (name.kind === SyntaxKind.Identifier && isIntrinsicJsxName((name).text)) { - write('"'); + write("\""); emit(name); - write('"'); + write("\""); } else { emit(name); @@ -1148,9 +1148,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi /// about keywords, just non-identifier characters function emitAttributeName(name: Identifier) { if (/[A-Za-z_]+[\w*]/.test(name.text)) { - write('"'); + write("\""); emit(name); - write('"'); + write("\""); } else { emit(name); @@ -1248,10 +1248,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // Don't emit empty strings if (children[i].kind === SyntaxKind.JsxText) { let text = getTextToEmit(children[i]); - if(text !== undefined) { - write(', "'); + if (text !== undefined) { + write(", \""); write(text); - write('"'); + write("\""); } } else { @@ -1425,6 +1425,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi case SyntaxKind.IfStatement: case SyntaxKind.JsxSelfClosingElement: case SyntaxKind.JsxOpeningElement: + case SyntaxKind.JsxSpreadAttribute: + case SyntaxKind.JsxExpression: case SyntaxKind.NewExpression: case SyntaxKind.ParenthesizedExpression: case SyntaxKind.PostfixUnaryExpression: @@ -1489,7 +1491,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (declaration.kind === SyntaxKind.ImportClause) { // Identifier references default import write(getGeneratedNameForNode(declaration.parent)); - write(languageVersion === ScriptTarget.ES3 ? '["default"]' : ".default"); + write(languageVersion === ScriptTarget.ES3 ? "[\"default\"]" : ".default"); return; } else if (declaration.kind === SyntaxKind.ImportSpecifier) { @@ -2004,12 +2006,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function tryEmitConstantValue(node: PropertyAccessExpression | ElementAccessExpression): boolean { - if (compilerOptions.isolatedModules) { - // do not inline enum values in separate compilation mode - return false; - } - - let constantValue = resolver.getConstantValue(node); + let constantValue = tryGetConstEnumValue(node); if (constantValue !== undefined) { write(constantValue.toString()); if (!compilerOptions.removeComments) { @@ -2020,6 +2017,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } return false; } + + function tryGetConstEnumValue(node: Node): number { + if (compilerOptions.isolatedModules) { + return undefined; + } + + return node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.ElementAccessExpression + ? resolver.getConstantValue(node) + : undefined + } // Returns 'true' if the code was actually indented, false otherwise. // If the code is not indented, an optional valueToWriteWhenNotIndenting will be @@ -2052,10 +2059,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); // 1 .toString is a valid property access, emit a space after the literal + // Also emit a space if expression is a integer const enum value - it will appear in generated code as numeric literal let shouldEmitSpace: boolean; - if (!indentedBeforeDot && node.expression.kind === SyntaxKind.NumericLiteral) { - let text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression); - shouldEmitSpace = text.indexOf(tokenToString(SyntaxKind.DotToken)) < 0; + if (!indentedBeforeDot) { + if (node.expression.kind === SyntaxKind.NumericLiteral) { + // check if numeric literal was originally written with a dot + let text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression); + shouldEmitSpace = text.indexOf(tokenToString(SyntaxKind.DotToken)) < 0; + } + else { + // check if constant enum value is integer + let constantValue = tryGetConstEnumValue(node.expression); + // isFinite handles cases when constantValue is undefined + shouldEmitSpace = isFinite(constantValue) && Math.floor(constantValue) === constantValue; + } } if (shouldEmitSpace) { @@ -3012,6 +3029,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return result; } + function emitEs6ExportDefaultCompat(node: Node) { + if (node.parent.kind === SyntaxKind.SourceFile) { + Debug.assert(!!(node.flags & NodeFlags.Default) || node.kind === SyntaxKind.ExportAssignment); + // only allow export default at a source file level + if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.module === ModuleKind.AMD || compilerOptions.module === ModuleKind.UMD) { + if (!currentSourceFile.symbol.exports["___esModule"]) { + if (languageVersion === ScriptTarget.ES5) { + // default value of configurable, enumerable, writable are `false`. + write("Object.defineProperty(exports, \"__esModule\", { value: true });"); + writeLine(); + } + else if (languageVersion === ScriptTarget.ES3) { + write("exports.__esModule = true;"); + writeLine(); + } + } + } + } + } + function emitExportMemberAssignment(node: FunctionLikeDeclaration | ClassDeclaration) { if (node.flags & NodeFlags.Export) { writeLine(); @@ -3034,9 +3071,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } else { if (node.flags & NodeFlags.Default) { + emitEs6ExportDefaultCompat(node); if (languageVersion === ScriptTarget.ES3) { write("exports[\"default\"]"); - } else { + } + else { write("exports.default"); } } @@ -3249,7 +3288,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitAssignmentExpression(root: BinaryExpression) { let target = root.left; let value = root.right; - if (isAssignmentExpressionStatement) { + + if (isEmptyObjectLiteralOrArrayLiteral(target)) { + emit(value); + } + else if (isAssignmentExpressionStatement) { emitDestructuringAssignment(target, value); } else { @@ -4227,11 +4270,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emitDetachedComments(ctor.body.statements); } emitCaptureThisForNodeIfNecessary(node); + let superCall: ExpressionStatement; if (ctor) { emitDefaultValueAssignments(ctor); emitRestParameter(ctor); if (baseTypeElement) { - var superCall = findInitialSuperCall(ctor); + superCall = findInitialSuperCall(ctor); if (superCall) { writeLine(); emit(superCall); @@ -4839,6 +4883,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitSerializedTypeNode(node: TypeNode) { + if (!node) { + return; + } + switch (node.kind) { case SyntaxKind.VoidKeyword: write("void 0"); @@ -4912,7 +4960,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let temp = createAndRecordTempVariable(TempFlags.Auto); write("(typeof ("); emitNodeWithoutSourceMap(temp); - write(" = ") + write(" = "); emitEntityNameAsExpression(typeName, /*useFallback*/ true); write(") === 'function' && "); emitNodeWithoutSourceMap(temp); @@ -4971,7 +5019,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // // For the rules on serializing the type of each parameter declaration, see `serializeTypeOfDeclaration`. if (node) { - var valueDeclaration: FunctionLikeDeclaration; + let valueDeclaration: FunctionLikeDeclaration; if (node.kind === SyntaxKind.ClassDeclaration) { valueDeclaration = getFirstConstructorWithBody(node); } @@ -4980,8 +5028,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } if (valueDeclaration) { - var parameters = valueDeclaration.parameters; - var parameterCount = parameters.length; + const parameters = valueDeclaration.parameters; + const parameterCount = parameters.length; if (parameterCount > 0) { for (var i = 0; i < parameterCount; i++) { if (i > 0) { @@ -4989,7 +5037,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } if (parameters[i].dotDotDotToken) { - var parameterType = parameters[i].type; + let parameterType = parameters[i].type; if (parameterType.kind === SyntaxKind.ArrayType) { parameterType = (parameterType).elementType; } @@ -5013,7 +5061,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi /** Serializes the return type of function. Used by the __metadata decorator for a method. */ function emitSerializedReturnTypeOfNode(node: Node): string | string[] { - if (node && isFunctionLike(node)) { + if (node && isFunctionLike(node) && (node).type) { emitSerializedTypeNode((node).type); return; } @@ -5412,17 +5460,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi (!isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { emitLeadingComments(node); emitStart(node); - if (isES6ExportedDeclaration(node)) { - write("export "); - write("var "); + + // variable declaration for import-equals declaration can be hoisted in system modules + // in this case 'var' should be omitted and emit should contain only initialization + let variableDeclarationIsHoisted = shouldHoistVariable(node, /*checkIfSourceFileLevelDecl*/ true); + + // is it top level export import v = a.b.c in system module? + // if yes - it needs to be rewritten as exporter('v', v = a.b.c) + let isExported = isSourceFileLevelDeclarationInSystemJsModule(node, /*isExported*/ true); + + if (!variableDeclarationIsHoisted) { + Debug.assert(!isExported); + + if (isES6ExportedDeclaration(node)) { + write("export "); + write("var "); + } + else if (!(node.flags & NodeFlags.Export)) { + write("var "); + } } - else if (!(node.flags & NodeFlags.Export)) { - write("var "); + + + if (isExported) { + write(`${exportFunctionForFile}("`); + emitNodeWithoutSourceMap(node.name); + write(`", `); } + emitModuleMemberName(node); write(" = "); emit(node.moduleReference); - write(";"); + + if (isExported) { + write(")"); + } + + write(";"); emitEnd(node); emitExportImportAssignments(node); emitTrailingComments(node); @@ -5543,6 +5617,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(")"); } else { + emitEs6ExportDefaultCompat(node); emitContainingModuleName(node); if (languageVersion === ScriptTarget.ES3) { write("[\"default\"] = "); @@ -5761,6 +5836,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(`function ${exportStarFunction}(m) {`); increaseIndent(); writeLine(); + write(`var exports = {};`); + writeLine(); write(`for(var n in m) {`); increaseIndent(); writeLine(); @@ -5768,10 +5845,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (localNames) { write(`&& !${localNames}.hasOwnProperty(n)`); } - write(`) ${exportFunctionForFile}(n, m[n]);`); + write(`) exports[n] = m[n];`); decreaseIndent(); writeLine(); write("}"); + writeLine(); + write(`${exportFunctionForFile}(exports);`); decreaseIndent(); writeLine(); write("}"); @@ -5943,6 +6022,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } return; } + + if (isInternalModuleImportEqualsDeclaration(node)) { + if (!hoistedVars) { + hoistedVars = []; + } + + hoistedVars.push(node.name); + return; + } if (isBindingPattern(node)) { forEach((node).elements, visit); @@ -6104,16 +6192,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if ((importNode).exportClause) { // export {a, b as c} from 'foo' // emit as: - // exports('a', _foo["a"]) - // exports('c', _foo["b"]) + // var reexports = {} + // reexports['a'] = _foo["a"]; + // reexports['c'] = _foo["b"]; + // exports_(reexports); + let reexportsVariableName = makeUniqueName("reexports"); + writeLine(); + write(`var ${reexportsVariableName} = {};`); + writeLine(); for (let e of (importNode).exportClause.elements) { - writeLine(); - write(`${exportFunctionForFile}("`); + write(`${reexportsVariableName}["`); emitNodeWithoutSourceMap(e.name); - write(`", ${parameterName}["`); + write(`"] = ${parameterName}["`); emitNodeWithoutSourceMap(e.propertyName || e.name); - write(`"]);`); + write(`"];`); + writeLine(); } + write(`${exportFunctionForFile}(${reexportsVariableName});`); } else { writeLine(); @@ -6140,14 +6235,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi writeLine(); for (let i = startIndex; i < node.statements.length; ++i) { let statement = node.statements[i]; - // - imports/exports are not emitted for system modules + // - external module related imports/exports are not emitted for system modules // - function declarations are not emitted because they were already hoisted switch (statement.kind) { case SyntaxKind.ExportDeclaration: case SyntaxKind.ImportDeclaration: - case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.FunctionDeclaration: continue; + case SyntaxKind.ImportEqualsDeclaration: + if (!isInternalModuleImportEqualsDeclaration(statement)) { + continue; + } } writeLine(); emit(statement); @@ -6186,6 +6284,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(`], function(${exportFunctionForFile}) {`); writeLine(); increaseIndent(); + emitEmitHelpers(node); emitCaptureThisForNodeIfNecessary(node); emitSystemModuleBody(node, startIndex); decreaseIndent(); @@ -6257,6 +6356,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitAMDModule(node: SourceFile, startIndex: number) { + emitEmitHelpers(node); collectExternalModuleInfo(node); writeLine(); @@ -6278,6 +6378,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitCommonJSModule(node: SourceFile, startIndex: number) { + emitEmitHelpers(node); collectExternalModuleInfo(node); emitExportStarHelper(); emitCaptureThisForNodeIfNecessary(node); @@ -6287,6 +6388,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitUMDModule(node: SourceFile, startIndex: number) { + emitEmitHelpers(node); collectExternalModuleInfo(node); // Module is detected first to support Browserify users that load into a browser with an AMD loader @@ -6316,6 +6418,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi exportSpecifiers = undefined; exportEquals = undefined; hasExportStars = false; + emitEmitHelpers(node); emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); @@ -6361,7 +6464,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (isLineBreak(c)) { if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) { let part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1); - result = (result ? result + '" + \' \' + "' : '') + part; + result = (result ? result + "\" + ' ' + \"" : "") + part; } firstNonWhitespace = -1; } @@ -6374,7 +6477,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } if (firstNonWhitespace !== -1) { let part = text.substr(firstNonWhitespace); - result = (result ? result + '" + \' \' + "' : '') + part; + result = (result ? result + "\" + ' ' + \"" : "") + part; } return result; @@ -6399,14 +6502,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitJsxText(node: JsxText) { switch (compilerOptions.jsx) { case JsxEmit.React: - write('"'); + write("\""); write(trimReactWhitespace(node)); - write('"'); + write("\""); break; case JsxEmit.Preserve: default: // Emit JSX-preserve as default when no --jsx flag is specified - write(getTextOfNode(node, true)); + writer.writeLiteral(getTextOfNode(node, true)); break; } } @@ -6416,9 +6519,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi switch (compilerOptions.jsx) { case JsxEmit.Preserve: default: - write('{'); + write("{"); emit(node.expression); - write('}'); + write("}"); break; case JsxEmit.React: emit(node.expression); @@ -6454,14 +6557,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } - function emitSourceFileNode(node: SourceFile) { - // Start new file on new line - writeLine(); - emitDetachedComments(node); - - // emit prologue directives prior to __extends - let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); - + function emitEmitHelpers(node: SourceFile): void { // Only emit helpers if the user did not say otherwise. if (!compilerOptions.noEmitHelpers) { // Only Emit __extends function when target ES5. @@ -6489,6 +6585,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi awaiterEmitted = true; } } + } + + function emitSourceFileNode(node: SourceFile) { + // Start new file on new line + writeLine(); + emitShebang(); + emitDetachedComments(node); + + // emit prologue directives prior to __extends + let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); if (isExternalModule(node) || compilerOptions.isolatedModules) { if (languageVersion >= ScriptTarget.ES6) { @@ -6512,6 +6618,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi exportSpecifiers = undefined; exportEquals = undefined; hasExportStars = false; + emitEmitHelpers(node); emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); @@ -6773,6 +6880,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return leadingComments; } + /** + * Removes all but the pinned or triple slash comments. + * @param ranges The array to be filtered + * @param onlyPinnedOrTripleSlashComments whether the filtering should be performed. + */ function filterComments(ranges: CommentRange[], onlyPinnedOrTripleSlashComments: boolean): CommentRange[] { // If we're removing comments, then we want to strip out all but the pinned or // triple slash comments. @@ -6900,6 +7012,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } } + + function emitShebang() { + let shebang = getShebang(currentSourceFile.text); + if (shebang) { + write(shebang); + } + } function isPinnedOrTripleSlashComment(comment: CommentRange) { if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 127d1b58ee4..10ebe86368d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3148,7 +3148,7 @@ namespace ts { } function parseAwaitExpression() { - var node = createNode(SyntaxKind.AwaitExpression); + const node = createNode(SyntaxKind.AwaitExpression); nextToken(); node.expression = parseUnaryExpressionOrHigher(); return finishNode(node); @@ -3340,7 +3340,7 @@ namespace ts { case SyntaxKind.LessThanToken: return parseJsxElementOrSelfClosingElement(); } - Debug.fail('Unknown JSX child kind ' + token); + Debug.fail("Unknown JSX child kind " + token); } function parseJsxChildren(openingTagName: EntityName): NodeArray { @@ -5140,7 +5140,7 @@ namespace ts { // the 'from' keyword can be parsed as a named export when the export clause is unterminated (i.e. `export { from "moduleName";`) // If we don't have a 'from' keyword, see if we have a string literal such that ASI won't take effect. if (token === SyntaxKind.FromKeyword || (token === SyntaxKind.StringLiteral && !scanner.hasPrecedingLineBreak())) { - parseExpected(SyntaxKind.FromKeyword) + parseExpected(SyntaxKind.FromKeyword); node.moduleSpecifier = parseModuleSpecifier(); } } @@ -6011,7 +6011,7 @@ namespace ts { return; function visitNode(node: IncrementalNode) { - let text = ''; + let text = ""; if (aggressiveChecks && shouldCheckNode(node)) { text = oldText.substring(node.pos, node.end); } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 5ce4846b43b..4b1f10eb649 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -8,7 +8,7 @@ namespace ts { /* @internal */ export let ioWriteTime = 0; /** The version of the TypeScript compiler release */ - export const version = "1.5.3"; + export const version = "1.6.0"; export function findConfigFile(searchPath: string): string { let fileName = "tsconfig.json"; @@ -341,7 +341,7 @@ namespace ts { }); } - function getDeclarationDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] { + function getDeclarationDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] { return runWithCancellationToken(() => { if (!isDeclarationFile(sourceFile)) { let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile, cancellationToken); @@ -350,7 +350,7 @@ namespace ts { return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); } }); - } + } function getOptionsDiagnostics(): Diagnostic[] { let allDiagnostics: Diagnostic[] = []; @@ -602,10 +602,6 @@ namespace ts { function verifyCompilerOptions() { if (options.isolatedModules) { - if (options.sourceMap) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceMap_cannot_be_specified_with_option_isolatedModules)); - } - if (options.declaration) { diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_declaration_cannot_be_specified_with_option_isolatedModules)); } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index d52f96c912b..7db8f243192 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -401,6 +401,9 @@ namespace ts { case CharacterCodes.greaterThan: // Starts of conflict marker trivia return true; + case CharacterCodes.hash: + // Only if its the beginning can we have #! trivia + return pos === 0; default: return ch > CharacterCodes.maxAsciiCharacter; } @@ -461,6 +464,13 @@ namespace ts { } break; + case CharacterCodes.hash: + if (isShebangTrivia(text, pos)) { + pos = scanShebangTrivia(text, pos); + continue; + } + break; + default: if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch) || isLineBreak(ch))) { pos++; @@ -528,6 +538,20 @@ namespace ts { return pos; } + const shebangTriviaRegex = /^#!.*/; + + function isShebangTrivia(text: string, pos: number) { + // Shebangs check must only be done at the start of the file + Debug.assert(pos === 0); + return shebangTriviaRegex.test(text); + } + + function scanShebangTrivia(text: string, pos: number) { + let shebang = shebangTriviaRegex.exec(text)[0]; + pos = pos + shebang.length; + return pos; + } + // Extract comments from the given source text starting at the given position. If trailing is // false, whitespace is skipped until the first line break and comments between that location // and the next token are returned.If trailing is true, comments occurring between the given @@ -617,6 +641,13 @@ namespace ts { export function getTrailingCommentRanges(text: string, pos: number): CommentRange[] { return getCommentRanges(text, pos, /*trailing*/ true); } + + /** Optionally, get the shebang */ + export function getShebang(text: string): string { + return shebangTriviaRegex.test(text) + ? shebangTriviaRegex.exec(text)[0] + : undefined; + } export function isIdentifierStart(ch: number, languageVersion: ScriptTarget): boolean { return ch >= CharacterCodes.A && ch <= CharacterCodes.Z || ch >= CharacterCodes.a && ch <= CharacterCodes.z || @@ -629,9 +660,9 @@ namespace ts { ch >= CharacterCodes._0 && ch <= CharacterCodes._9 || ch === CharacterCodes.$ || ch === CharacterCodes._ || ch > CharacterCodes.maxAsciiCharacter && isUnicodeIdentifierPart(ch, languageVersion); } - + /* @internal */ - // Creates a scanner over a (possibly unspecified) range of a piece of text. + // Creates a scanner over a (possibly unspecified) range of a piece of text. export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, languageVariant = LanguageVariant.Standard, @@ -1087,6 +1118,18 @@ namespace ts { return token = SyntaxKind.EndOfFileToken; } let ch = text.charCodeAt(pos); + + // Special handling for shebang + if (ch === CharacterCodes.hash && pos === 0 && isShebangTrivia(text, pos)) { + pos = scanShebangTrivia(text, pos); + if (skipTrivia) { + continue; + } + else { + return token = SyntaxKind.ShebangTrivia; + } + } + switch (ch) { case CharacterCodes.lineFeed: case CharacterCodes.carriageReturn: diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 228b9516de1..1730e45ee9e 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -30,8 +30,8 @@ namespace ts { declare var global: any; declare var __filename: string; declare var Buffer: { - new (str: string, encoding ?: string): any; - } + new (str: string, encoding?: string): any; + }; declare class Enumerator { public atEnd(): boolean; @@ -188,13 +188,13 @@ namespace ts { }; } function getNodeSystem(): System { - var _fs = require("fs"); - var _path = require("path"); - var _os = require('os'); + const _fs = require("fs"); + const _path = require("path"); + const _os = require("os"); - var platform: string = _os.platform(); + const platform: string = _os.platform(); // win32\win64 are case insensitive platforms, MacOS (darwin) by default is also case insensitive - var useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin"; + const useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin"; function readFile(fileName: string, encoding?: string): string { if (!_fs.existsSync(fileName)) { @@ -228,7 +228,7 @@ namespace ts { function writeFile(fileName: string, data: string, writeByteOrderMark?: boolean): void { // If a BOM is required, emit one if (writeByteOrderMark) { - data = '\uFEFF' + data; + data = "\uFEFF" + data; } _fs.writeFileSync(fileName, data, "utf8"); @@ -271,10 +271,10 @@ namespace ts { newLine: _os.EOL, useCaseSensitiveFileNames: useCaseSensitiveFileNames, write(s: string): void { - var buffer = new Buffer(s, 'utf8'); - var offset: number = 0; - var toWrite: number = buffer.length; - var written = 0; + const buffer = new Buffer(s, "utf8"); + let offset: number = 0; + let toWrite: number = buffer.length; + let written = 0; // 1 is a standard descriptor for stdout while ((written = _fs.writeSync(1, buffer, offset, toWrite)) < toWrite) { offset += written; @@ -297,7 +297,7 @@ namespace ts { } callback(fileName); - }; + } }, resolvePath: function (path: string): string { return _path.resolve(path); diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index a657cc8c314..22bd6d79b0e 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -3,7 +3,7 @@ namespace ts { export interface SourceFile { - fileWatcher: FileWatcher; + fileWatcher?: FileWatcher; } /** @@ -14,7 +14,7 @@ namespace ts { let matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase()); if (!matchResult) { - errors.push(createCompilerDiagnostic(Diagnostics.Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1, 'en', 'ja-jp')); + errors.push(createCompilerDiagnostic(Diagnostics.Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1, "en", "ja-jp")); return false; } @@ -49,7 +49,7 @@ namespace ts { } // TODO: Add codePage support for readFile? - let fileContents = ''; + let fileContents = ""; try { fileContents = sys.readFile(filePath); } @@ -245,7 +245,7 @@ namespace ts { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes)); } - function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError ?: (message: string) => void) { + function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void) { // Return existing SourceFile object if one is available if (cachedProgram) { let sourceFile = cachedProgram.getSourceFile(fileName); @@ -355,22 +355,23 @@ namespace ts { return { program, exitStatus }; function compileProgram(): ExitStatus { - // First get any syntactic errors. - let diagnostics = program.getSyntacticDiagnostics(); - reportDiagnostics(diagnostics); + let diagnostics: Diagnostic[]; + + // First get and report any syntactic errors. + diagnostics = program.getSyntacticDiagnostics(); // If we didn't have any syntactic errors, then also try getting the global and // semantic errors. if (diagnostics.length === 0) { - let diagnostics = program.getGlobalDiagnostics(); - reportDiagnostics(diagnostics); + diagnostics = program.getGlobalDiagnostics(); if (diagnostics.length === 0) { - let diagnostics = program.getSemanticDiagnostics(); - reportDiagnostics(diagnostics); + diagnostics = program.getSemanticDiagnostics(); } } + reportDiagnostics(diagnostics); + // If the user doesn't want us to emit, then we're done at this point. if (compilerOptions.noEmit) { return diagnostics.length diff --git a/src/compiler/types.ts b/src/compiler/types.ts index bba3d81da52..8cd10b44a27 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -17,6 +17,7 @@ namespace ts { } // token > SyntaxKind.Identifer => token is a keyword + // Also, If you add a new SyntaxKind be sure to keep the `Markers` section at the bottom in sync export const enum SyntaxKind { Unknown, EndOfFileToken, @@ -24,6 +25,8 @@ namespace ts { MultiLineCommentTrivia, NewLineTrivia, WhitespaceTrivia, + // We detect and preserve #! on the first line + ShebangTrivia, // We detect and provide better error recovery when we encounter a git merge marker. This // allows us to edit files with git-conflict markers in them in a much more pleasant manner. ConflictMarkerTrivia, @@ -1404,6 +1407,7 @@ namespace ts { getPropertyOfType(type: Type, propertyName: string): Symbol; getSignaturesOfType(type: Type, kind: SignatureKind): Signature[]; getIndexTypeOfType(type: Type, kind: IndexKind): Type; + getBaseTypes(type: InterfaceType): ObjectType[]; getReturnTypeOfSignature(signature: Signature): Type; getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]; @@ -1430,6 +1434,7 @@ namespace ts { getJsxElementAttributesType(elementNode: JsxOpeningLikeElement): Type; getJsxIntrinsicTagNames(): Symbol[]; + isOptionalParameter(node: ParameterDeclaration): boolean; // Should not be called directly. Should only be accessed through the Program instance. /* @internal */ getDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; @@ -1574,6 +1579,7 @@ namespace ts { getBlockScopedVariableId(node: Identifier): number; getReferencedValueDeclaration(reference: Identifier): Declaration; getTypeReferenceSerializationKind(typeName: EntityName): TypeReferenceSerializationKind; + isOptionalParameter(node: ParameterDeclaration): boolean; } export const enum SymbolFlags { @@ -1762,10 +1768,14 @@ namespace ts { FromSignature = 0x00040000, // Created for signature assignment check ObjectLiteral = 0x00080000, // Originates in an object literal /* @internal */ - ContainsUndefinedOrNull = 0x00100000, // Type is or contains Undefined or Null type + FreshObjectLiteral = 0x00100000, // Fresh object literal type /* @internal */ - ContainsObjectLiteral = 0x00200000, // Type is or contains object literal type - ESSymbol = 0x00400000, // Type of symbol primitive introduced in ES6 + ContainsUndefinedOrNull = 0x00200000, // Type is or contains Undefined or Null type + /* @internal */ + ContainsObjectLiteral = 0x00400000, // Type is or contains object literal type + /* @internal */ + ContainsAnyFunctionType = 0x00800000, // Type is or contains object literal type + ESSymbol = 0x01000000, // Type of symbol primitive introduced in ES6 /* @internal */ Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null, @@ -1774,10 +1784,12 @@ namespace ts { StringLike = String | StringLiteral, NumberLike = Number | Enum, ObjectType = Class | Interface | Reference | Tuple | Anonymous, - UnionOrIntersection = Union | Intersection, + UnionOrIntersection = Union | Intersection, StructuredType = ObjectType | Union | Intersection, /* @internal */ - RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral + RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral, + /* @internal */ + PropagatingFlags = ContainsUndefinedOrNull | ContainsObjectLiteral | ContainsAnyFunctionType } // Properties common to all types @@ -1806,7 +1818,9 @@ namespace ts { typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic) outerTypeParameters: TypeParameter[]; // Outer type parameters (undefined if none) localTypeParameters: TypeParameter[]; // Local type parameters (undefined if none) + /* @internal */ resolvedBaseConstructorType?: Type; // Resolved base constructor type of class + /* @internal */ resolvedBaseTypes: ObjectType[]; // Resolved base types } @@ -1858,6 +1872,14 @@ namespace ts { numberIndexType?: Type; // Numeric index type } + /* @internal */ + // Object literals are initially marked fresh. Freshness disappears following an assignment, + // before a type assertion, or when when an object literal's type is widened. The regular + // version of a fresh type is identical except for the TypeFlags.FreshObjectLiteral flag. + export interface FreshObjectLiteralType extends ResolvedType { + regularType: ResolvedType; // Regular version of fresh type + } + // Just a place to cache element types of iterables and iterators /* @internal */ export interface IterableOrIteratorType extends ObjectType, UnionType { @@ -1912,6 +1934,9 @@ namespace ts { /* @internal */ export interface TypeMapper { (t: TypeParameter): Type; + context?: InferenceContext; // The inference context this mapper was created from. + // Only inference mappers have this set (in createInferenceMapper). + // The identity mapper and regular instantiation mappers do not need it. } /* @internal */ @@ -2208,6 +2233,7 @@ namespace ts { export interface CompilerHost { getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile; + getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; writeFile: WriteFileCallback; getCurrentDirectory(): string; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 79c16716be5..26484bfe97a 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -568,7 +568,7 @@ namespace ts { } } - export function isVariableLike(node: Node): boolean { + export function isVariableLike(node: Node): node is VariableLikeDeclaration { if (node) { switch (node.kind) { case SyntaxKind.BindingElement: @@ -965,7 +965,7 @@ namespace ts { return ((node).moduleReference).expression; } - export function isInternalModuleImportEqualsDeclaration(node: Node) { + export function isInternalModuleImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration { return node.kind === SyntaxKind.ImportEqualsDeclaration && (node).moduleReference.kind !== SyntaxKind.ExternalModuleReference; } @@ -988,15 +988,13 @@ namespace ts { if (node) { switch (node.kind) { case SyntaxKind.Parameter: - return (node).questionToken !== undefined; case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - return (node).questionToken !== undefined; case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.PropertyAssignment: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: - return (node).questionToken !== undefined; + return (node).questionToken !== undefined; } } @@ -1884,7 +1882,7 @@ namespace ts { function writeTrimmedCurrentLine(pos: number, nextLineStart: number) { let end = Math.min(comment.end, nextLineStart - 1); - let currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, ''); + let currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, ""); if (currentLineText) { // trimmed forward and ending spaces text writer.write(currentLineText); @@ -1997,6 +1995,17 @@ namespace ts { (node.parent.kind === SyntaxKind.PropertyAccessExpression && (node.parent).name === node); } + export function isEmptyObjectLiteralOrArrayLiteral(expression: Node): boolean { + let kind = expression.kind; + if (kind === SyntaxKind.ObjectLiteralExpression) { + return (expression).properties.length === 0; + } + if (kind === SyntaxKind.ArrayLiteralExpression) { + return (expression).elements.length === 0; + } + return false; + } + export function getLocalSymbolForExportDefault(symbol: Symbol) { return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & NodeFlags.Default) ? symbol.valueDeclaration.localSymbol : undefined; } diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index b1d43302372..87e22e08cfa 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -1,6 +1,6 @@ -/// -/// -/// +/// +/// +/// const enum CompilerTestType { Conformance, @@ -9,7 +9,7 @@ const enum CompilerTestType { } class CompilerBaselineRunner extends RunnerBase { - private basePath = 'tests/cases'; + private basePath = "tests/cases"; private testSuiteName: string; private errors: boolean; private emit: boolean; @@ -25,21 +25,21 @@ class CompilerBaselineRunner extends RunnerBase { this.decl = true; this.output = true; if (testType === CompilerTestType.Conformance) { - this.testSuiteName = 'conformance'; + this.testSuiteName = "conformance"; } else if (testType === CompilerTestType.Regressions) { - this.testSuiteName = 'compiler'; + this.testSuiteName = "compiler"; } else if (testType === CompilerTestType.Test262) { - this.testSuiteName = 'test262'; + this.testSuiteName = "test262"; } else { - this.testSuiteName = 'compiler'; // default to this for historical reasons + this.testSuiteName = "compiler"; // default to this for historical reasons } - this.basePath += '/' + this.testSuiteName; + this.basePath += "/" + this.testSuiteName; } public checkTestCodeOutput(fileName: string) { - describe('compiler tests for ' + fileName, () => { + describe("compiler tests for " + fileName, () => { // Mocha holds onto the closure environment of the describe callback even after the test is done. // Everything declared here should be cleared out in the "after" callback. let justName: string; @@ -64,14 +64,14 @@ class CompilerBaselineRunner extends RunnerBase { let createNewInstance = false; before(() => { - justName = fileName.replace(/^.*[\\\/]/, ''); // strips the fileName from the path. + justName = fileName.replace(/^.*[\\\/]/, ""); // strips the fileName from the path. content = Harness.IO.readFile(fileName); testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, fileName); units = testCaseContent.testUnitData; tcSettings = testCaseContent.settings; createNewInstance = false; lastUnit = units[units.length - 1]; - rootDir = lastUnit.originalFilePath.indexOf('conformance') === -1 ? 'tests/cases/compiler/' : lastUnit.originalFilePath.substring(0, lastUnit.originalFilePath.lastIndexOf('/')) + '/'; + rootDir = lastUnit.originalFilePath.indexOf("conformance") === -1 ? "tests/cases/compiler/" : lastUnit.originalFilePath.substring(0, lastUnit.originalFilePath.lastIndexOf("/")) + "/"; harnessCompiler = Harness.Compiler.getCompiler(); // We need to assemble the list of input files for the compiler and other related files on the 'filesystem' (ie in a multi-file test) // If the last file in a test uses require or a triple slash reference we'll assume all other files will be brought in via references, @@ -106,7 +106,7 @@ class CompilerBaselineRunner extends RunnerBase { eventually to remove this limitation. */ for (let i = 0; i < tcSettings.length; ++i) { // noImplicitAny is passed to getCompiler, but target is just passed in the settings blob to setCompilerSettings - if (!createNewInstance && (tcSettings[i].flag == "noimplicitany" || tcSettings[i].flag === 'target')) { + if (!createNewInstance && (tcSettings[i].flag == "noimplicitany" || tcSettings[i].flag === "target")) { harnessCompiler = Harness.Compiler.getCompiler(); harnessCompiler.setCompilerSettings(tcSettings); createNewInstance = true; @@ -148,9 +148,9 @@ class CompilerBaselineRunner extends RunnerBase { } // check errors - it('Correct errors for ' + fileName, () => { + it("Correct errors for " + fileName, () => { if (this.errors) { - Harness.Baseline.runBaseline('Correct errors for ' + fileName, justName.replace(/\.tsx?$/, '.errors.txt'), (): string => { + Harness.Baseline.runBaseline("Correct errors for " + fileName, justName.replace(/\.tsx?$/, ".errors.txt"), (): string => { if (result.errors.length === 0) return null; return getErrorBaseline(toBeCompiled, otherFiles, result); }); @@ -158,12 +158,12 @@ class CompilerBaselineRunner extends RunnerBase { }); // Source maps? - it('Correct sourcemap content for ' + fileName, () => { + it("Correct sourcemap content for " + fileName, () => { if (options.sourceMap || options.inlineSourceMap) { - Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.tsx?$/, '.sourcemap.txt'), () => { + Harness.Baseline.runBaseline("Correct sourcemap content for " + fileName, justName.replace(/\.tsx?$/, ".sourcemap.txt"), () => { let record = result.getSourceMapRecord(); if (options.noEmitOnError && result.errors.length !== 0 && record === undefined) { - // Because of the noEmitOnError option no files are created. We need to return null because baselining isn't required. + // Because of the noEmitOnError option no files are created. We need to return null because baselining isn"t required. return null; } return record; @@ -171,35 +171,35 @@ class CompilerBaselineRunner extends RunnerBase { } }); - it('Correct JS output for ' + fileName, () => { - if (!ts.fileExtensionIs(lastUnit.name, '.d.ts') && this.emit) { + it("Correct JS output for " + fileName, () => { + if (!ts.fileExtensionIs(lastUnit.name, ".d.ts") && this.emit) { if (result.files.length === 0 && result.errors.length === 0) { - throw new Error('Expected at least one js file to be emitted or at least one error to be created.'); + throw new Error("Expected at least one js file to be emitted or at least one error to be created."); } // check js output - Harness.Baseline.runBaseline('Correct JS output for ' + fileName, justName.replace(/\.tsx?/, '.js'), () => { - let tsCode = ''; + Harness.Baseline.runBaseline("Correct JS output for " + fileName, justName.replace(/\.tsx?/, ".js"), () => { + let tsCode = ""; let tsSources = otherFiles.concat(toBeCompiled); if (tsSources.length > 1) { - tsCode += '//// [' + fileName + '] ////\r\n\r\n'; + tsCode += "//// [" + fileName + "] ////\r\n\r\n"; } for (let i = 0; i < tsSources.length; i++) { - tsCode += '//// [' + Harness.Path.getFileName(tsSources[i].unitName) + ']\r\n'; - tsCode += tsSources[i].content + (i < (tsSources.length - 1) ? '\r\n' : ''); + tsCode += "//// [" + Harness.Path.getFileName(tsSources[i].unitName) + "]\r\n"; + tsCode += tsSources[i].content + (i < (tsSources.length - 1) ? "\r\n" : ""); } - let jsCode = ''; + let jsCode = ""; for (let i = 0; i < result.files.length; i++) { - jsCode += '//// [' + Harness.Path.getFileName(result.files[i].fileName) + ']\r\n'; + jsCode += "//// [" + Harness.Path.getFileName(result.files[i].fileName) + "]\r\n"; jsCode += getByteOrderMarkText(result.files[i]); jsCode += result.files[i].code; } if (result.declFilesCode.length > 0) { - jsCode += '\r\n\r\n'; + jsCode += "\r\n\r\n"; for (let i = 0; i < result.declFilesCode.length; i++) { - jsCode += '//// [' + Harness.Path.getFileName(result.declFilesCode[i].fileName) + ']\r\n'; + jsCode += "//// [" + Harness.Path.getFileName(result.declFilesCode[i].fileName) + "]\r\n"; jsCode += getByteOrderMarkText(result.declFilesCode[i]); jsCode += result.declFilesCode[i].code; } @@ -210,13 +210,13 @@ class CompilerBaselineRunner extends RunnerBase { }, options); if (declFileCompilationResult && declFileCompilationResult.declResult.errors.length) { - jsCode += '\r\n\r\n//// [DtsFileErrors]\r\n'; - jsCode += '\r\n\r\n'; + jsCode += "\r\n\r\n//// [DtsFileErrors]\r\n"; + jsCode += "\r\n\r\n"; jsCode += getErrorBaseline(declFileCompilationResult.declInputFiles, declFileCompilationResult.declOtherFiles, declFileCompilationResult.declResult); } if (jsCode.length > 0) { - return tsCode + '\r\n\r\n' + jsCode; + return tsCode + "\r\n\r\n" + jsCode; } else { return null; } @@ -224,28 +224,28 @@ class CompilerBaselineRunner extends RunnerBase { } }); - it('Correct Sourcemap output for ' + fileName, () => { + it("Correct Sourcemap output for " + fileName, () => { if (options.inlineSourceMap) { if (result.sourceMaps.length > 0) { - throw new Error('No sourcemap files should be generated if inlineSourceMaps was set.'); + throw new Error("No sourcemap files should be generated if inlineSourceMaps was set."); } return null; } else if (options.sourceMap) { if (result.sourceMaps.length !== result.files.length) { - throw new Error('Number of sourcemap files should be same as js files.'); + throw new Error("Number of sourcemap files should be same as js files."); } - Harness.Baseline.runBaseline('Correct Sourcemap output for ' + fileName, justName.replace(/\.tsx?/, '.js.map'), () => { + Harness.Baseline.runBaseline("Correct Sourcemap output for " + fileName, justName.replace(/\.tsx?/, ".js.map"), () => { if (options.noEmitOnError && result.errors.length !== 0 && result.sourceMaps.length === 0) { // We need to return null here or the runBaseLine will actually create a empty file. // Baselining isn't required here because there is no output. return null; } - let sourceMapCode = ''; + let sourceMapCode = ""; for (let i = 0; i < result.sourceMaps.length; i++) { - sourceMapCode += '//// [' + Harness.Path.getFileName(result.sourceMaps[i].fileName) + ']\r\n'; + sourceMapCode += "//// [" + Harness.Path.getFileName(result.sourceMaps[i].fileName) + "]\r\n"; sourceMapCode += getByteOrderMarkText(result.sourceMaps[i]); sourceMapCode += result.sourceMaps[i].code; } @@ -255,7 +255,7 @@ class CompilerBaselineRunner extends RunnerBase { } }); - it('Correct type/symbol baselines for ' + fileName, () => { + it("Correct type/symbol baselines for " + fileName, () => { if (fileName.indexOf("APISample") >= 0) { return; } @@ -317,15 +317,15 @@ class CompilerBaselineRunner extends RunnerBase { let fullBaseLine = generateBaseLine(fullResults, isSymbolBaseLine); let pullBaseLine = generateBaseLine(pullResults, isSymbolBaseLine); - let fullExtension = isSymbolBaseLine ? '.symbols' : '.types'; - let pullExtension = isSymbolBaseLine ? '.symbols.pull' : '.types.pull'; + let fullExtension = isSymbolBaseLine ? ".symbols" : ".types"; + let pullExtension = isSymbolBaseLine ? ".symbols.pull" : ".types.pull"; if (fullBaseLine !== pullBaseLine) { - Harness.Baseline.runBaseline('Correct full information for ' + fileName, justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine); - Harness.Baseline.runBaseline('Correct pull information for ' + fileName, justName.replace(/\.tsx?/, pullExtension), () => pullBaseLine); + Harness.Baseline.runBaseline("Correct full information for " + fileName, justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine); + Harness.Baseline.runBaseline("Correct pull information for " + fileName, justName.replace(/\.tsx?/, pullExtension), () => pullBaseLine); } else { - Harness.Baseline.runBaseline('Correct information for ' + fileName, justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine); + Harness.Baseline.runBaseline("Correct information for " + fileName, justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine); } } @@ -334,7 +334,7 @@ class CompilerBaselineRunner extends RunnerBase { let typeMap: { [fileName: string]: { [lineNum: number]: string[]; } } = {}; allFiles.forEach(file => { - let codeLines = file.content.split('\n'); + let codeLines = file.content.split("\n"); typeWriterResults[file.unitName].forEach(result => { if (isSymbolBaseline && !result.symbol) { return; @@ -354,30 +354,30 @@ class CompilerBaselineRunner extends RunnerBase { typeMap[file.unitName][result.line] = typeInfo; }); - typeLines.push('=== ' + file.unitName + ' ===\r\n'); + typeLines.push("=== " + file.unitName + " ===\r\n"); for (let i = 0; i < codeLines.length; i++) { let currentCodeLine = codeLines[i]; - typeLines.push(currentCodeLine + '\r\n'); + typeLines.push(currentCodeLine + "\r\n"); if (typeMap[file.unitName]) { let typeInfo = typeMap[file.unitName][i]; if (typeInfo) { typeInfo.forEach(ty => { - typeLines.push('>' + ty + '\r\n'); + typeLines.push(">" + ty + "\r\n"); }); - if (i + 1 < codeLines.length && (codeLines[i + 1].match(/^\s*[{|}]\s*$/) || codeLines[i + 1].trim() === '')) { + if (i + 1 < codeLines.length && (codeLines[i + 1].match(/^\s*[{|}]\s*$/) || codeLines[i + 1].trim() === "")) { } else { - typeLines.push('\r\n'); + typeLines.push("\r\n"); } } } else { - typeLines.push('No type information for this code.'); + typeLines.push("No type information for this code."); } } }); - return typeLines.join(''); + return typeLines.join(""); } } }); @@ -385,7 +385,7 @@ class CompilerBaselineRunner extends RunnerBase { } public initializeTests() { - describe(this.testSuiteName + ' tests', () => { + describe(this.testSuiteName + " tests", () => { describe("Setup compiler for compiler baselines", () => { let harnessCompiler = Harness.Compiler.getCompiler(); this.parseOptions(); @@ -416,23 +416,23 @@ class CompilerBaselineRunner extends RunnerBase { this.decl = false; this.output = false; - let opts = this.options.split(','); + let opts = this.options.split(","); for (let i = 0; i < opts.length; i++) { switch (opts[i]) { - case 'error': + case "error": this.errors = true; break; - case 'emit': + case "emit": this.emit = true; break; - case 'decl': + case "decl": this.decl = true; break; - case 'output': + case "output": this.output = true; break; default: - throw new Error('unsupported flag'); + throw new Error("unsupported flag"); } } } diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 06a680a2224..2ebf086cb74 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -13,11 +13,11 @@ // limitations under the License. // -/// -/// -/// -/// -/// +/// +/// +/// +/// +/// module FourSlash { ts.disableIncrementalParsing = false; @@ -26,9 +26,8 @@ module FourSlash { export interface FourSlashFile { // The contents of the file (with markers, etc stripped out) content: string; - fileName: string; - + version: number; // File-specific options (name/value pairs) fileOptions: { [index: string]: string; }; } @@ -101,12 +100,12 @@ module FourSlash { } let entityMap: ts.Map = { - '&': '&', - '"': '"', - "'": ''', - '/': '/', - '<': '<', - '>': '>' + "&": "&", + "\"": """, + "'": "'", + "/": "/", + "<": "<", + ">": ">" }; export function escapeXmlAttributeValue(s: string) { @@ -117,18 +116,18 @@ module FourSlash { // To add additional option, add property into the testOptMetadataNames, refer the property in either globalMetadataNames or fileMetadataNames // Add cases into convertGlobalOptionsToCompilationsSettings function for the compiler to acknowledge such option from meta data let metadataOptionNames = { - baselineFile: 'BaselineFile', - declaration: 'declaration', - emitThisFile: 'emitThisFile', // This flag is used for testing getEmitOutput feature. It allows test-cases to indicate what file to be output in multiple files project - fileName: 'Filename', - mapRoot: 'mapRoot', - module: 'module', - out: 'out', - outDir: 'outDir', - sourceMap: 'sourceMap', - sourceRoot: 'sourceRoot', - allowNonTsExtensions: 'allowNonTsExtensions', - resolveReference: 'ResolveReference', // This flag is used to specify entry file for resolve file references. The flag is only allow once per test file + baselineFile: "BaselineFile", + declaration: "declaration", + emitThisFile: "emitThisFile", // This flag is used for testing getEmitOutput feature. It allows test-cases to indicate what file to be output in multiple files project + fileName: "Filename", + mapRoot: "mapRoot", + module: "module", + out: "out", + outDir: "outDir", + sourceMap: "sourceMap", + sourceRoot: "sourceRoot", + allowNonTsExtensions: "allowNonTsExtensions", + resolveReference: "ResolveReference", // This flag is used to specify entry file for resolve file references. The flag is only allow once per test file }; // List of allowed metadata names @@ -327,7 +326,7 @@ module FourSlash { // Add triple reference files into language-service host ts.forEach(referencedFiles, referenceFile => { // Fourslash insert tests/cases/fourslash into inputFile.unitName so we will properly append the same base directory to refFile path - let referenceFilePath = this.basePath + '/' + referenceFile.fileName; + let referenceFilePath = this.basePath + "/" + referenceFile.fileName; this.addMatchedInputFile(referenceFilePath); }); @@ -335,7 +334,7 @@ module FourSlash { ts.forEach(importedFiles, importedFile => { // Fourslash insert tests/cases/fourslash into inputFile.unitName and import statement doesn't require ".ts" // so convert them before making appropriate comparison - let importedFilePath = this.basePath + '/' + importedFile.fileName + ".ts"; + let importedFilePath = this.basePath + "/" + importedFile.fileName + ".ts"; this.addMatchedInputFile(importedFilePath); }); @@ -370,9 +369,9 @@ module FourSlash { }; this.testData.files.forEach(file => { - let fileName = file.fileName.replace(Harness.IO.directoryName(file.fileName), '').substr(1); + let fileName = file.fileName.replace(Harness.IO.directoryName(file.fileName), "").substr(1); let fileNameWithoutExtension = fileName.substr(0, fileName.lastIndexOf(".")); - this.scenarioActions.push(''); + this.scenarioActions.push(""); }); // Open the first file by default @@ -385,7 +384,7 @@ module FourSlash { } // Entry points from fourslash.ts - public goToMarker(name = '') { + public goToMarker(name = "") { let marker = this.getMarkerByName(name); if (this.activeFile.fileName !== marker.fileName) { this.openFile(marker.fileName); @@ -393,7 +392,7 @@ module FourSlash { let content = this.getFileContent(marker.fileName); if (marker.position === -1 || marker.position > content.length) { - throw new Error('Marker "' + name + '" has been invalidated by unrecoverable edits to the file.'); + throw new Error(`Marker "${name}" has been invalidated by unrecoverable edits to the file.`); } this.lastKnownMarker = name; this.goToPosition(marker.position); @@ -411,9 +410,9 @@ module FourSlash { this.currentCaretPosition += count; this.currentCaretPosition = Math.min(this.currentCaretPosition, this.getFileContent(this.activeFile.fileName).length); if (count > 0) { - this.scenarioActions.push(''); + this.scenarioActions.push(``); } else { - this.scenarioActions.push(''); + this.scenarioActions.push(``); } } @@ -424,8 +423,8 @@ module FourSlash { let fileToOpen: FourSlashFile = this.findFile(indexOrName); fileToOpen.fileName = ts.normalizeSlashes(fileToOpen.fileName); this.activeFile = fileToOpen; - let fileName = fileToOpen.fileName.replace(Harness.IO.directoryName(fileToOpen.fileName), '').substr(1); - this.scenarioActions.push(''); + let fileName = fileToOpen.fileName.replace(Harness.IO.directoryName(fileToOpen.fileName), "").substr(1); + this.scenarioActions.push(``); // Let the host know that this file is now open this.languageServiceAdapterHost.openFile(fileToOpen.fileName); @@ -440,7 +439,7 @@ module FourSlash { let exists = this.anyErrorInRange(predicate, startMarker, endMarker); - this.taoInvalidReason = 'verifyErrorExistsBetweenMarkers NYI'; + this.taoInvalidReason = "verifyErrorExistsBetweenMarkers NYI"; if (exists !== negative) { this.printErrorLog(negative, this.getAllDiagnostics()); @@ -493,7 +492,7 @@ module FourSlash { }; } - this.taoInvalidReason = 'verifyErrorExistsAfterMarker NYI'; + this.taoInvalidReason = "verifyErrorExistsAfterMarker NYI"; let exists = this.anyErrorInRange(predicate, marker); let diagnostics = this.getAllDiagnostics(); @@ -542,7 +541,7 @@ module FourSlash { let errors = this.getDiagnostics(this.activeFile.fileName); let actual = errors.length; - this.scenarioActions.push(''); + this.scenarioActions.push(``); if (actual !== expected) { this.printErrorLog(false, errors); @@ -558,11 +557,11 @@ module FourSlash { throw new Error("Expected exactly one output from emit of " + this.activeFile.fileName); } - this.taoInvalidReason = 'verifyEval impossible'; + this.taoInvalidReason = "verifyEval impossible"; - let evaluation = new Function(emit.outputFiles[0].text + ';\r\nreturn (' + expr + ');')(); + let evaluation = new Function(`${emit.outputFiles[0].text};\r\nreturn (${expr});`)(); if (evaluation !== value) { - this.raiseError('Expected evaluation of expression "' + expr + '" to equal "' + value + '", but got "' + evaluation + '"'); + this.raiseError(`Expected evaluation of expression "${expr}" to equal "${value}", but got "${evaluation}"`); } } @@ -571,19 +570,19 @@ module FourSlash { if (emit.outputFiles.length !== 1) { throw new Error("Expected exactly one output from emit of " + this.activeFile.fileName); } - this.taoInvalidReason = 'verifyGetEmitOutputForCurrentFile impossible'; + this.taoInvalidReason = "verifyGetEmitOutputForCurrentFile impossible"; let actual = emit.outputFiles[0].text; if (actual !== expected) { - this.raiseError("Expected emit output to be '" + expected + "', but got '" + actual + "'"); + this.raiseError(`Expected emit output to be "${expected}", but got "${actual}"`); } } public verifyMemberListContains(symbol: string, text?: string, documentation?: string, kind?: string) { - this.scenarioActions.push(''); - this.scenarioActions.push(''); + this.scenarioActions.push(""); + this.scenarioActions.push(``); if (text || documentation || kind) { - this.taoInvalidReason = 'verifyMemberListContains only supports the "symbol" parameter'; + this.taoInvalidReason = "verifyMemberListContains only supports the \"symbol\" parameter"; } let members = this.getMemberListAtCaret(); @@ -601,11 +600,11 @@ module FourSlash { this.verifyMemberListIsEmpty(false); return; } else { - this.scenarioActions.push(''); + this.scenarioActions.push(""); } } else { - this.scenarioActions.push(''); - this.scenarioActions.push(''); + this.scenarioActions.push(""); + this.scenarioActions.push(``); } let members = this.getMemberListAtCaret(); @@ -623,31 +622,31 @@ module FourSlash { } public verifyMemberListDoesNotContain(symbol: string) { - this.scenarioActions.push(''); - this.scenarioActions.push(''); + this.scenarioActions.push(""); + this.scenarioActions.push(``); let members = this.getMemberListAtCaret(); if (members && members.entries.filter(e => e.name === symbol).length !== 0) { - this.raiseError('Member list did contain ' + symbol); + this.raiseError(`Member list did contain ${symbol}`); } } public verifyCompletionListItemsCountIsGreaterThan(count: number) { - this.taoInvalidReason = 'verifyCompletionListItemsCountIsGreaterThan NYI'; + this.taoInvalidReason = "verifyCompletionListItemsCountIsGreaterThan NYI"; let completions = this.getCompletionListAtCaret(); let itemsCount = completions.entries.length; if (itemsCount <= count) { - this.raiseError('Expected completion list items count to be greater than ' + count + ', but is actually ' + itemsCount); + this.raiseError(`Expected completion list items count to be greater than ${count}, but is actually ${itemsCount}`); } } public verifyMemberListIsEmpty(negative: boolean) { if (negative) { - this.scenarioActions.push(''); + this.scenarioActions.push(""); } else { - this.scenarioActions.push(''); + this.scenarioActions.push(""); } let members = this.getMemberListAtCaret(); @@ -667,24 +666,24 @@ module FourSlash { } public verifyCompletionListIsEmpty(negative: boolean) { - this.scenarioActions.push(''); + this.scenarioActions.push(""); let completions = this.getCompletionListAtCaret(); if ((!completions || completions.entries.length === 0) && negative) { - this.raiseError("Completion list is empty at Caret"); - } else if ((completions && completions.entries.length !== 0) && !negative) { - + this.raiseError("Completion list is empty at caret at position " + this.activeFile.fileName + " " + this.currentCaretPosition); + } + else if (completions && completions.entries.length !== 0 && !negative) { let errorMsg = "\n" + "Completion List contains: [" + completions.entries[0].name; for (let i = 1; i < completions.entries.length; i++) { errorMsg += ", " + completions.entries[i].name; } errorMsg += "]\n"; - Harness.IO.log(errorMsg); - this.raiseError("Completion list is not empty at Caret"); + this.raiseError("Completion list is not empty at caret at position " + this.activeFile.fileName + " " + this.currentCaretPosition + errorMsg); } } + public verifyCompletionListAllowsNewIdentifier(negative: boolean) { let completions = this.getCompletionListAtCaret(); @@ -731,12 +730,12 @@ module FourSlash { return documentation === expectedDocumentation ? true : false; } // Because expectedText and expectedDocumentation are undefined, we assume that - // users don't care to compare them so we will treat that entry as if the entry has matching text and documentation + // users don"t care to compare them so we will treat that entry as if the entry has matching text and documentation // and keep it in the list of filtered entry. return true; } - this.scenarioActions.push(''); - this.scenarioActions.push(''); + this.scenarioActions.push(""); + this.scenarioActions.push(``); let completions = this.getCompletionListAtCaret(); if (completions) { @@ -764,7 +763,7 @@ module FourSlash { } public verifyCompletionEntryDetails(entryName: string, expectedText: string, expectedDocumentation?: string, kind?: string) { - this.taoInvalidReason = 'verifyCompletionEntryDetails NYI'; + this.taoInvalidReason = "verifyCompletionEntryDetails NYI"; let details = this.getCompletionEntryDetails(entryName); @@ -780,30 +779,30 @@ module FourSlash { } public verifyReferencesAtPositionListContains(fileName: string, start: number, end: number, isWriteAccess?: boolean) { - this.taoInvalidReason = 'verifyReferencesAtPositionListContains NYI'; + this.taoInvalidReason = "verifyReferencesAtPositionListContains NYI"; let references = this.getReferencesAtCaret(); if (!references || references.length === 0) { - this.raiseError('verifyReferencesAtPositionListContains failed - found 0 references, expected at least one.'); + this.raiseError("verifyReferencesAtPositionListContains failed - found 0 references, expected at least one."); } for (let i = 0; i < references.length; i++) { let reference = references[i]; if (reference && reference.fileName === fileName && reference.textSpan.start === start && ts.textSpanEnd(reference.textSpan) === end) { if (typeof isWriteAccess !== "undefined" && reference.isWriteAccess !== isWriteAccess) { - this.raiseError('verifyReferencesAtPositionListContains failed - item isWriteAccess value does not match, actual: ' + reference.isWriteAccess + ', expected: ' + isWriteAccess + '.'); + this.raiseError(`verifyReferencesAtPositionListContains failed - item isWriteAccess value does not match, actual: ${reference.isWriteAccess}, expected: ${isWriteAccess}.`); } return; } } let missingItem = { fileName: fileName, start: start, end: end, isWriteAccess: isWriteAccess }; - this.raiseError('verifyReferencesAtPositionListContains failed - could not find the item: ' + JSON.stringify(missingItem) + ' in the returned list: (' + JSON.stringify(references) + ')'); + this.raiseError(`verifyReferencesAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(references)})`); } public verifyReferencesCountIs(count: number, localFilesOnly: boolean = true) { - this.taoInvalidReason = 'verifyReferences NYI'; + this.taoInvalidReason = "verifyReferences NYI"; let references = this.getReferencesAtCaret(); let referencesCount = 0; @@ -866,8 +865,8 @@ module FourSlash { public verifyQuickInfoString(negative: boolean, expectedText?: string, expectedDocumentation?: string) { [expectedText, expectedDocumentation].forEach(str => { if (str) { - this.scenarioActions.push(''); - this.scenarioActions.push(''); + this.scenarioActions.push(""); + this.scenarioActions.push(``); } }); @@ -897,8 +896,8 @@ module FourSlash { public verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: { start: number; length: number; }, displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[]) { - this.scenarioActions.push(''); - this.scenarioActions.push(''); + this.scenarioActions.push(""); + this.scenarioActions.push(``); function getDisplayPartsJson(displayParts: ts.SymbolDisplayPart[]) { let result = ""; @@ -965,23 +964,23 @@ module FourSlash { } public verifyQuickInfoExists(negative: boolean) { - this.taoInvalidReason = 'verifyQuickInfoExists NYI'; + this.taoInvalidReason = "verifyQuickInfoExists NYI"; let actualQuickInfo = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, this.currentCaretPosition); if (negative) { if (actualQuickInfo) { - this.raiseError('verifyQuickInfoExists failed. Expected quick info NOT to exist'); + this.raiseError("verifyQuickInfoExists failed. Expected quick info NOT to exist"); } } else { if (!actualQuickInfo) { - this.raiseError('verifyQuickInfoExists failed. Expected quick info to exist'); + this.raiseError("verifyQuickInfoExists failed. Expected quick info to exist"); } } } public verifyCurrentSignatureHelpIs(expected: string) { - this.taoInvalidReason = 'verifyCurrentSignatureHelpIs NYI'; + this.taoInvalidReason = "verifyCurrentSignatureHelpIs NYI"; let help = this.getActiveSignatureHelpItem(); assert.equal( @@ -991,7 +990,7 @@ module FourSlash { } public verifyCurrentParameterIsletiable(isVariable: boolean) { - this.taoInvalidReason = 'verifyCurrentParameterIsletiable NYI'; + this.taoInvalidReason = "verifyCurrentParameterIsletiable NYI"; let signature = this.getActiveSignatureHelpItem(); assert.isNotNull(signature); @@ -999,7 +998,7 @@ module FourSlash { } public verifyCurrentParameterHelpName(name: string) { - this.taoInvalidReason = 'verifyCurrentParameterHelpName NYI'; + this.taoInvalidReason = "verifyCurrentParameterHelpName NYI"; let activeParameter = this.getActiveParameter(); let activeParameterName = activeParameter.name; @@ -1007,7 +1006,7 @@ module FourSlash { } public verifyCurrentParameterSpanIs(parameter: string) { - this.taoInvalidReason = 'verifyCurrentParameterSpanIs NYI'; + this.taoInvalidReason = "verifyCurrentParameterSpanIs NYI"; let activeSignature = this.getActiveSignatureHelpItem(); let activeParameter = this.getActiveParameter(); @@ -1015,7 +1014,7 @@ module FourSlash { } public verifyCurrentParameterHelpDocComment(docComment: string) { - this.taoInvalidReason = 'verifyCurrentParameterHelpDocComment NYI'; + this.taoInvalidReason = "verifyCurrentParameterHelpDocComment NYI"; let activeParameter = this.getActiveParameter(); let activeParameterDocComment = activeParameter.documentation; @@ -1023,27 +1022,27 @@ module FourSlash { } public verifyCurrentSignatureHelpParameterCount(expectedCount: number) { - this.taoInvalidReason = 'verifyCurrentSignatureHelpParameterCount NYI'; + this.taoInvalidReason = "verifyCurrentSignatureHelpParameterCount NYI"; assert.equal(this.getActiveSignatureHelpItem().parameters.length, expectedCount); } public verifyCurrentSignatureHelpTypeParameterCount(expectedCount: number) { - this.taoInvalidReason = 'verifyCurrentSignatureHelpTypeParameterCount NYI'; + this.taoInvalidReason = "verifyCurrentSignatureHelpTypeParameterCount NYI"; // assert.equal(this.getActiveSignatureHelpItem().typeParameters.length, expectedCount); } public verifyCurrentSignatureHelpDocComment(docComment: string) { - this.taoInvalidReason = 'verifyCurrentSignatureHelpDocComment NYI'; + this.taoInvalidReason = "verifyCurrentSignatureHelpDocComment NYI"; let actualDocComment = this.getActiveSignatureHelpItem().documentation; assert.equal(ts.displayPartsToString(actualDocComment), docComment, assertionMessage("current signature help doc comment")); } public verifySignatureHelpCount(expected: number) { - this.scenarioActions.push(''); - this.scenarioActions.push(''); + this.scenarioActions.push(""); + this.scenarioActions.push(``); let help = this.languageService.getSignatureHelpItems(this.activeFile.fileName, this.currentCaretPosition); let actual = help && help.items ? help.items.length : 0; @@ -1051,14 +1050,14 @@ module FourSlash { } public verifySignatureHelpArgumentCount(expected: number) { - this.taoInvalidReason = 'verifySignatureHelpArgumentCount NYI'; + this.taoInvalidReason = "verifySignatureHelpArgumentCount NYI"; let signatureHelpItems = this.languageService.getSignatureHelpItems(this.activeFile.fileName, this.currentCaretPosition); let actual = signatureHelpItems.argumentCount; assert.equal(actual, expected); } public verifySignatureHelpPresent(shouldBePresent = true) { - this.taoInvalidReason = 'verifySignatureHelpPresent NYI'; + this.taoInvalidReason = "verifySignatureHelpPresent NYI"; let actual = this.languageService.getSignatureHelpItems(this.activeFile.fileName, this.currentCaretPosition); if (shouldBePresent) { @@ -1067,7 +1066,7 @@ module FourSlash { } } else { if (actual) { - this.raiseError("Expected no signature help, but got '" + JSON.stringify(actual) + "'"); + this.raiseError(`Expected no signature help, but got "${JSON.stringify(actual)}"`); } } } @@ -1201,12 +1200,12 @@ module FourSlash { } public getBreakpointStatementLocation(pos: number) { - this.taoInvalidReason = 'getBreakpointStatementLocation NYI'; + this.taoInvalidReason = "getBreakpointStatementLocation NYI"; return this.languageService.getBreakpointStatementAtPosition(this.activeFile.fileName, pos); } public baselineCurrentFileBreakpointLocations() { - this.taoInvalidReason = 'baselineCurrentFileBreakpointLocations impossible'; + this.taoInvalidReason = "baselineCurrentFileBreakpointLocations impossible"; Harness.Baseline.runBaseline( "Breakpoint Locations for " + this.activeFile.fileName, @@ -1218,7 +1217,7 @@ module FourSlash { } public baselineGetEmitOutput() { - this.taoInvalidReason = 'baselineGetEmitOutput impossible'; + this.taoInvalidReason = "baselineGetEmitOutput impossible"; // Find file to be emitted let emitFiles: FourSlashFile[] = []; // List of FourSlashFile that has emitThisFile flag on @@ -1289,7 +1288,7 @@ module FourSlash { let syntacticErrors = this.languageService.getSyntacticDiagnostics(this.activeFile.fileName); let semanticErrors = this.languageService.getSemanticDiagnostics(this.activeFile.fileName); let errorList = syntacticErrors.concat(semanticErrors); - Harness.IO.log('Error list (' + errorList.length + ' errors)'); + Harness.IO.log(`Error list (${errorList.length} errors)`); if (errorList.length) { errorList.forEach(err => { @@ -1305,10 +1304,10 @@ module FourSlash { for (let i = 0; i < this.testData.files.length; i++) { let file = this.testData.files[i]; let active = (this.activeFile === file); - Harness.IO.log('=== Script (' + file.fileName + ') ' + (active ? '(active, cursor at |)' : '') + ' ==='); + Harness.IO.log(`=== Script (${file.fileName}) ${(active ? "(active, cursor at |)" : "")} ===`); let content = this.getFileContent(file.fileName); if (active) { - content = content.substr(0, this.currentCaretPosition) + (makeCaretVisible ? '|' : "") + content.substr(this.currentCaretPosition); + content = content.substr(0, this.currentCaretPosition) + (makeCaretVisible ? "|" : "") + content.substr(this.currentCaretPosition); } if (makeWhitespaceVisible) { content = TestState.makeWhitespaceVisible(content); @@ -1344,7 +1343,7 @@ module FourSlash { } public deleteChar(count = 1) { - this.scenarioActions.push(''); + this.scenarioActions.push(``); let offset = this.currentCaretPosition; let ch = ""; @@ -1378,7 +1377,7 @@ module FourSlash { } public replace(start: number, length: number, text: string) { - this.taoInvalidReason = 'replace NYI'; + this.taoInvalidReason = "replace NYI"; this.languageServiceAdapterHost.editScript(this.activeFile.fileName, start, start + length, text); this.updateMarkersForEdit(this.activeFile.fileName, start, start + length, text); @@ -1386,7 +1385,7 @@ module FourSlash { } public deleteCharBehindMarker(count = 1) { - this.scenarioActions.push(''); + this.scenarioActions.push(``); let offset = this.currentCaretPosition; let ch = ""; @@ -1420,10 +1419,10 @@ module FourSlash { // Enters lines of text at the current caret position public type(text: string) { - if (text === '') { - this.taoInvalidReason = 'Test used empty-insert workaround.'; + if (text === "") { + this.taoInvalidReason = "Test used empty-insert workaround."; } else { - this.scenarioActions.push(''); + this.scenarioActions.push(``); } return this.typeHighFidelity(text); @@ -1434,7 +1433,7 @@ module FourSlash { // as much as possible private typeHighFidelity(text: string) { let offset = this.currentCaretPosition; - let prevChar = ' '; + let prevChar = " "; let checkCadence = (text.length >> 2) + 1; for (let i = 0; i < text.length; i++) { @@ -1446,10 +1445,10 @@ module FourSlash { this.updateMarkersForEdit(this.activeFile.fileName, offset, offset, ch); offset++; - if (ch === '(' || ch === ',') { + if (ch === "(" || ch === ",") { /* Signature help*/ this.languageService.getSignatureHelpItems(this.activeFile.fileName, offset); - } else if (prevChar === ' ' && /A-Za-z_/.test(ch)) { + } else if (prevChar === " " && /A-Za-z_/.test(ch)) { /* Completions */ this.languageService.getCompletionsAtPosition(this.activeFile.fileName, offset); } @@ -1479,7 +1478,7 @@ module FourSlash { // Enters text as if the user had pasted it public paste(text: string) { - this.scenarioActions.push(''); + this.scenarioActions.push(``); let start = this.currentCaretPosition; let offset = this.currentCaretPosition; @@ -1532,7 +1531,7 @@ module FourSlash { // that happens, move it back one character if (this.currentCaretPosition > 0) { let ch = this.getFileContent(this.activeFile.fileName).substring(this.currentCaretPosition - 1, this.currentCaretPosition); - if (ch === '\r') { + if (ch === "\r") { this.currentCaretPosition--; } }; @@ -1557,8 +1556,8 @@ module FourSlash { if (isFormattingEdit) { let newContent = this.getFileContent(fileName); - if (newContent.replace(/\s/g, '') !== oldContent.replace(/\s/g, '')) { - this.raiseError('Formatting operation destroyed non-whitespace content'); + if (newContent.replace(/\s/g, "") !== oldContent.replace(/\s/g, "")) { + this.raiseError("Formatting operation destroyed non-whitespace content"); } } return runningOffset; @@ -1575,7 +1574,7 @@ module FourSlash { } public formatDocument() { - this.scenarioActions.push(''); + this.scenarioActions.push(""); let edits = this.languageService.getFormattingEditsForDocument(this.activeFile.fileName, this.formatCodeOptions); this.currentCaretPosition += this.applyEdits(this.activeFile.fileName, edits, true); @@ -1583,7 +1582,7 @@ module FourSlash { } public formatSelection(start: number, end: number) { - this.taoInvalidReason = 'formatSelection NYI'; + this.taoInvalidReason = "formatSelection NYI"; let edits = this.languageService.getFormattingEditsForRange(this.activeFile.fileName, start, end, this.formatCodeOptions); this.currentCaretPosition += this.applyEdits(this.activeFile.fileName, edits, true); @@ -1618,18 +1617,18 @@ module FourSlash { public goToDefinition(definitionIndex: number) { if (definitionIndex === 0) { - this.scenarioActions.push(''); + this.scenarioActions.push(""); } else { - this.taoInvalidReason = 'GoToDefinition not supported for non-zero definition indices'; + this.taoInvalidReason = "GoToDefinition not supported for non-zero definition indices"; } let definitions = this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition); if (!definitions || !definitions.length) { - this.raiseError('goToDefinition failed - expected to at least one definition location but got 0'); + this.raiseError("goToDefinition failed - expected to at least one definition location but got 0"); } if (definitionIndex >= definitions.length) { - this.raiseError('goToDefinition failed - definitionIndex value (' + definitionIndex + ') exceeds definition list size (' + definitions.length + ')'); + this.raiseError(`goToDefinition failed - definitionIndex value (${definitionIndex}) exceeds definition list size (${definitions.length})`); } let definition = definitions[definitionIndex]; @@ -1639,19 +1638,19 @@ module FourSlash { public goToTypeDefinition(definitionIndex: number) { if (definitionIndex === 0) { - this.scenarioActions.push(''); + this.scenarioActions.push(""); } else { - this.taoInvalidReason = 'GoToTypeDefinition not supported for non-zero definition indices'; + this.taoInvalidReason = "GoToTypeDefinition not supported for non-zero definition indices"; } let definitions = this.languageService.getTypeDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition); if (!definitions || !definitions.length) { - this.raiseError('goToTypeDefinition failed - expected to at least one definition location but got 0'); + this.raiseError("goToTypeDefinition failed - expected to at least one definition location but got 0"); } if (definitionIndex >= definitions.length) { - this.raiseError('goToTypeDefinition failed - definitionIndex value (' + definitionIndex + ') exceeds definition list size (' + definitions.length + ')'); + this.raiseError(`goToTypeDefinition failed - definitionIndex value (${definitionIndex}) exceeds definition list size (${definitions.length})`); } let definition = definitions[definitionIndex]; @@ -1660,17 +1659,17 @@ module FourSlash { } public verifyDefinitionLocationExists(negative: boolean) { - this.taoInvalidReason = 'verifyDefinitionLocationExists NYI'; + this.taoInvalidReason = "verifyDefinitionLocationExists NYI"; let definitions = this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition); let foundDefinitions = definitions && definitions.length; if (foundDefinitions && negative) { - this.raiseError('goToDefinition - expected to 0 definition locations but got ' + definitions.length); + this.raiseError(`goToDefinition - expected to 0 definition locations but got ${definitions.length}`); } else if (!foundDefinitions && !negative) { - this.raiseError('goToDefinition - expected to at least one definition location but got 0'); + this.raiseError("goToDefinition - expected to at least one definition location but got 0"); } } @@ -1693,7 +1692,7 @@ module FourSlash { } public verifyDefinitionsName(negative: boolean, expectedName: string, expectedContainerName: string) { - this.taoInvalidReason = 'verifyDefinititionsInfo NYI'; + this.taoInvalidReason = "verifyDefinititionsInfo NYI"; let definitions = this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition); let actualDefinitionName = definitions && definitions.length ? definitions[0].name : ""; @@ -1717,15 +1716,15 @@ module FourSlash { return this.testData.ranges.slice(0); } - public verifyCaretAtMarker(markerName = '') { - this.taoInvalidReason = 'verifyCaretAtMarker NYI'; + public verifyCaretAtMarker(markerName = "") { + this.taoInvalidReason = "verifyCaretAtMarker NYI"; let pos = this.getMarkerByName(markerName); if (pos.fileName !== this.activeFile.fileName) { - throw new Error('verifyCaretAtMarker failed - expected to be in file "' + pos.fileName + '", but was in file "' + this.activeFile.fileName + '"'); + throw new Error(`verifyCaretAtMarker failed - expected to be in file "${pos.fileName}", but was in file "${this.activeFile.fileName}"`); } if (pos.position !== this.currentCaretPosition) { - throw new Error('verifyCaretAtMarker failed - expected to be at marker "/*' + markerName + '*/, but was at position ' + this.currentCaretPosition + '(' + this.getLineColStringAtPosition(this.currentCaretPosition) + ')'); + throw new Error(`verifyCaretAtMarker failed - expected to be at marker "/*${markerName}*/, but was at position ${this.currentCaretPosition}(${this.getLineColStringAtPosition(this.currentCaretPosition)})`); } } @@ -1734,84 +1733,84 @@ module FourSlash { } public verifyIndentationAtCurrentPosition(numberOfSpaces: number) { - this.taoInvalidReason = 'verifyIndentationAtCurrentPosition NYI'; + this.taoInvalidReason = "verifyIndentationAtCurrentPosition NYI"; let actual = this.getIndentation(this.activeFile.fileName, this.currentCaretPosition); let lineCol = this.getLineColStringAtPosition(this.currentCaretPosition); if (actual !== numberOfSpaces) { - this.raiseError('verifyIndentationAtCurrentPosition failed at ' + lineCol + ' - expected: ' + numberOfSpaces + ', actual: ' + actual); + this.raiseError(`verifyIndentationAtCurrentPosition failed at ${lineCol} - expected: ${numberOfSpaces}, actual: ${actual}`); } } public verifyIndentationAtPosition(fileName: string, position: number, numberOfSpaces: number) { - this.taoInvalidReason = 'verifyIndentationAtPosition NYI'; + this.taoInvalidReason = "verifyIndentationAtPosition NYI"; let actual = this.getIndentation(fileName, position); let lineCol = this.getLineColStringAtPosition(position); if (actual !== numberOfSpaces) { - this.raiseError('verifyIndentationAtPosition failed at ' + lineCol + ' - expected: ' + numberOfSpaces + ', actual: ' + actual); + this.raiseError(`verifyIndentationAtPosition failed at ${lineCol} - expected: ${numberOfSpaces}, actual: ${actual}`); } } public verifyCurrentLineContent(text: string) { - this.taoInvalidReason = 'verifyCurrentLineContent NYI'; + this.taoInvalidReason = "verifyCurrentLineContent NYI"; let actual = this.getCurrentLineContent(); if (actual !== text) { - throw new Error('verifyCurrentLineContent\n' + - '\tExpected: "' + text + '"\n' + - '\t Actual: "' + actual + '"'); + throw new Error("verifyCurrentLineContent\n" + + "\tExpected: \"" + text + "\"\n" + + "\t Actual: \"" + actual + "\""); } } public verifyCurrentFileContent(text: string) { - this.taoInvalidReason = 'verifyCurrentFileContent NYI'; + this.taoInvalidReason = "verifyCurrentFileContent NYI"; let actual = this.getFileContent(this.activeFile.fileName); let replaceNewlines = (str: string) => str.replace(/\r\n/g, "\n"); if (replaceNewlines(actual) !== replaceNewlines(text)) { - throw new Error('verifyCurrentFileContent\n' + - '\tExpected: "' + text + '"\n' + - '\t Actual: "' + actual + '"'); + throw new Error("verifyCurrentFileContent\n" + + "\tExpected: \"" + text + "\"\n" + + "\t Actual: \"" + actual + "\""); } } public verifyTextAtCaretIs(text: string) { - this.taoInvalidReason = 'verifyCurrentFileContent NYI'; + this.taoInvalidReason = "verifyCurrentFileContent NYI"; let actual = this.getFileContent(this.activeFile.fileName).substring(this.currentCaretPosition, this.currentCaretPosition + text.length); if (actual !== text) { - throw new Error('verifyTextAtCaretIs\n' + - '\tExpected: "' + text + '"\n' + - '\t Actual: "' + actual + '"'); + throw new Error("verifyTextAtCaretIs\n" + + "\tExpected: \"" + text + "\"\n" + + "\t Actual: \"" + actual + "\""); } } public verifyCurrentNameOrDottedNameSpanText(text: string) { - this.taoInvalidReason = 'verifyCurrentNameOrDottedNameSpanText NYI'; + this.taoInvalidReason = "verifyCurrentNameOrDottedNameSpanText NYI"; let span = this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, this.currentCaretPosition, this.currentCaretPosition); if (!span) { - this.raiseError('verifyCurrentNameOrDottedNameSpanText\n' + - '\tExpected: "' + text + '"\n' + - '\t Actual: undefined'); + this.raiseError("verifyCurrentNameOrDottedNameSpanText\n" + + "\tExpected: \"" + text + "\"\n" + + "\t Actual: undefined"); } let actual = this.getFileContent(this.activeFile.fileName).substring(span.start, ts.textSpanEnd(span)); if (actual !== text) { - this.raiseError('verifyCurrentNameOrDottedNameSpanText\n' + - '\tExpected: "' + text + '"\n' + - '\t Actual: "' + actual + '"'); + this.raiseError("verifyCurrentNameOrDottedNameSpanText\n" + + "\tExpected: \"" + text + "\"\n" + + "\t Actual: \"" + actual + "\""); } } private getNameOrDottedNameSpan(pos: number) { - this.taoInvalidReason = 'getNameOrDottedNameSpan NYI'; + this.taoInvalidReason = "getNameOrDottedNameSpan NYI"; return this.languageService.getNameOrDottedNameSpan(this.activeFile.fileName, pos, pos); } public baselineCurrentFileNameOrDottedNameSpans() { - this.taoInvalidReason = 'baselineCurrentFileNameOrDottedNameSpans impossible'; + this.taoInvalidReason = "baselineCurrentFileNameOrDottedNameSpans impossible"; Harness.Baseline.runBaseline( "Name OrDottedNameSpans for " + this.activeFile.fileName, @@ -1829,8 +1828,8 @@ module FourSlash { 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()); } @@ -1840,8 +1839,8 @@ module FourSlash { let expectedType: string = (ts.ClassificationTypeNames)[expectedClassification.classificationType]; if (expectedType !== actualClassification.classificationType) { - this.raiseError('verifyClassifications failed - expected classifications type to be ' + - expectedType + ', but was ' + + this.raiseError("verifyClassifications failed - expected classifications type to be " + + expectedType + ", but was " + actualClassification.classificationType + jsonMismatchString()); } @@ -1862,8 +1861,8 @@ module FourSlash { let actualText = this.activeFile.content.substr(actualSpan.start, actualSpan.length); if (expectedClassification.text !== actualText) { - this.raiseError('verifyClassifications failed - expected classified text to be ' + - expectedClassification.text + ', but was ' + + this.raiseError("verifyClassifications failed - expected classified text to be " + + expectedClassification.text + ", but was " + actualText + jsonMismatchString()); } @@ -1876,7 +1875,7 @@ module FourSlash { } } - private verifyProjectInfo(expected: string[]) { + public verifyProjectInfo(expected: string[]) { if (this.testType === FourSlashTestType.Server) { let actual = (this.languageService).getProjectInfo( this.activeFile.fileName, @@ -1906,19 +1905,19 @@ module FourSlash { } public verifyOutliningSpans(spans: TextSpan[]) { - this.taoInvalidReason = 'verifyOutliningSpans NYI'; + this.taoInvalidReason = "verifyOutliningSpans NYI"; let actual = this.languageService.getOutliningSpans(this.activeFile.fileName); if (actual.length !== spans.length) { - this.raiseError('verifyOutliningSpans failed - expected total spans to be ' + spans.length + ', but was ' + actual.length); + this.raiseError(`verifyOutliningSpans failed - expected total spans to be ${spans.length}, but was ${actual.length}`); } for (let i = 0; i < spans.length; i++) { let expectedSpan = spans[i]; let actualSpan = actual[i]; if (expectedSpan.start !== actualSpan.textSpan.start || expectedSpan.end !== ts.textSpanEnd(actualSpan.textSpan)) { - this.raiseError('verifyOutliningSpans failed - span ' + (i + 1) + ' expected: (' + expectedSpan.start + ',' + expectedSpan.end + '), actual: (' + actualSpan.textSpan.start + ',' + ts.textSpanEnd(actualSpan.textSpan) + ')'); + this.raiseError(`verifyOutliningSpans failed - span ${(i + 1)} expected: (${expectedSpan.start},${expectedSpan.end}), actual: (${actualSpan.textSpan.start},${ts.textSpanEnd(actualSpan.textSpan)})`); } } } @@ -1928,7 +1927,7 @@ module FourSlash { descriptors.map(d => { return { text: d, priority: 0 }; })); if (actual.length !== spans.length) { - this.raiseError('verifyTodoComments failed - expected total spans to be ' + spans.length + ', but was ' + actual.length); + this.raiseError(`verifyTodoComments failed - expected total spans to be ${spans.length}, but was ${actual.length}`); } for (let i = 0; i < spans.length; i++) { @@ -1937,18 +1936,18 @@ module FourSlash { let actualCommentSpan = ts.createTextSpan(actualComment.position, actualComment.message.length); if (expectedSpan.start !== actualCommentSpan.start || expectedSpan.end !== ts.textSpanEnd(actualCommentSpan)) { - this.raiseError('verifyOutliningSpans failed - span ' + (i + 1) + ' expected: (' + expectedSpan.start + ',' + expectedSpan.end + '), actual: (' + actualCommentSpan.start + ',' + ts.textSpanEnd(actualCommentSpan) + ')'); + this.raiseError(`verifyOutliningSpans failed - span ${(i + 1)} expected: (${expectedSpan.start},${expectedSpan.end}), actual: (${actualCommentSpan.start},${ts.textSpanEnd(actualCommentSpan)})`); } } } public verifyMatchingBracePosition(bracePosition: number, expectedMatchPosition: number) { - this.taoInvalidReason = 'verifyMatchingBracePosition NYI'; + this.taoInvalidReason = "verifyMatchingBracePosition NYI"; let actual = this.languageService.getBraceMatchingAtPosition(this.activeFile.fileName, bracePosition); if (actual.length !== 2) { - this.raiseError('verifyMatchingBracePosition failed - expected result to contain 2 spans, but it had ' + actual.length); + this.raiseError(`verifyMatchingBracePosition failed - expected result to contain 2 spans, but it had ${actual.length}`); } let actualMatchPosition = -1; @@ -1957,21 +1956,21 @@ module FourSlash { } else if (bracePosition === actual[1].start) { actualMatchPosition = actual[0].start; } else { - this.raiseError('verifyMatchingBracePosition failed - could not find the brace position: ' + bracePosition + ' in the returned list: (' + actual[0].start + ',' + ts.textSpanEnd(actual[0]) + ') and (' + actual[1].start + ',' + ts.textSpanEnd(actual[1]) + ')'); + this.raiseError(`verifyMatchingBracePosition failed - could not find the brace position: ${bracePosition} in the returned list: (${actual[0].start},${ts.textSpanEnd(actual[0])}) and (${actual[1].start},${ts.textSpanEnd(actual[1])})`); } if (actualMatchPosition !== expectedMatchPosition) { - this.raiseError('verifyMatchingBracePosition failed - expected: ' + actualMatchPosition + ', actual: ' + expectedMatchPosition); + this.raiseError(`verifyMatchingBracePosition failed - expected: ${actualMatchPosition}, actual: ${expectedMatchPosition}`); } } public verifyNoMatchingBracePosition(bracePosition: number) { - this.taoInvalidReason = 'verifyNoMatchingBracePosition NYI'; + this.taoInvalidReason = "verifyNoMatchingBracePosition NYI"; let actual = this.languageService.getBraceMatchingAtPosition(this.activeFile.fileName, bracePosition); if (actual.length !== 0) { - this.raiseError('verifyNoMatchingBracePosition failed - expected: 0 spans, actual: ' + actual.length); + this.raiseError("verifyNoMatchingBracePosition failed - expected: 0 spans, actual: " + actual.length); } } @@ -1980,7 +1979,7 @@ module FourSlash { Report an error if expected value and actual value do not match. */ public verifyNavigationItemsCount(expected: number, searchValue: string, matchKind?: string) { - this.taoInvalidReason = 'verifyNavigationItemsCount NYI'; + this.taoInvalidReason = "verifyNavigationItemsCount NYI"; let items = this.languageService.getNavigateToItems(searchValue); let actual = 0; @@ -1995,7 +1994,7 @@ module FourSlash { } if (expected !== actual) { - this.raiseError('verifyNavigationItemsCount failed - found: ' + actual + ' navigation items, expected: ' + expected + '.'); + this.raiseError(`verifyNavigationItemsCount failed - found: ${actual} navigation items, expected: ${expected}.`); } } @@ -2010,12 +2009,12 @@ module FourSlash { matchKind: string, fileName?: string, parentName?: string) { - this.taoInvalidReason = 'verifyNavigationItemsListContains NYI'; + this.taoInvalidReason = "verifyNavigationItemsListContains NYI"; let items = this.languageService.getNavigateToItems(searchValue); if (!items || items.length === 0) { - this.raiseError('verifyNavigationItemsListContains failed - found 0 navigation items, expected at least one.'); + this.raiseError("verifyNavigationItemsListContains failed - found 0 navigation items, expected at least one."); } for (let i = 0; i < items.length; i++) { @@ -2031,18 +2030,18 @@ module FourSlash { // if there was an explicit match kind specified, then it should be validated. if (matchKind !== undefined) { let missingItem = { name: name, kind: kind, searchValue: searchValue, matchKind: matchKind, fileName: fileName, parentName: parentName }; - this.raiseError('verifyNavigationItemsListContains failed - could not find the item: ' + JSON.stringify(missingItem) + ' in the returned list: (' + JSON.stringify(items) + ')'); + this.raiseError(`verifyNavigationItemsListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(items)})`); } } public verifyGetScriptLexicalStructureListCount(expected: number) { - this.taoInvalidReason = 'verifyNavigationItemsListContains impossible'; + this.taoInvalidReason = "verifyNavigationItemsListContains impossible"; let items = this.languageService.getNavigationBarItems(this.activeFile.fileName); let actual = this.getNavigationBarItemsCount(items); if (expected !== actual) { - this.raiseError('verifyGetScriptLexicalStructureListCount failed - found: ' + actual + ' navigation items, expected: ' + expected + '.'); + this.raiseError(`verifyGetScriptLexicalStructureListCount failed - found: ${actual} navigation items, expected: ${expected}.`); } } @@ -2058,16 +2057,13 @@ module FourSlash { return result; } - public verifGetScriptLexicalStructureListContains( - name: string, - kind: string, - markerPosition?: number) { - this.taoInvalidReason = 'verifGetScriptLexicalStructureListContains impossible'; + public verifyGetScriptLexicalStructureListContains(name: string, kind: string) { + this.taoInvalidReason = "verifyGetScriptLexicalStructureListContains impossible"; let items = this.languageService.getNavigationBarItems(this.activeFile.fileName); if (!items || items.length === 0) { - this.raiseError('verifyGetScriptLexicalStructureListContains failed - found 0 navigation items, expected at least one.'); + this.raiseError("verifyGetScriptLexicalStructureListContains failed - found 0 navigation items, expected at least one."); } if (this.navigationBarItemsContains(items, name, kind)) { @@ -2075,7 +2071,7 @@ module FourSlash { } let missingItem = { name: name, kind: kind }; - this.raiseError('verifyGetScriptLexicalStructureListContains failed - could not find the item: ' + JSON.stringify(missingItem) + ' in the returned list: (' + JSON.stringify(items, null, " ") + ')'); + this.raiseError(`verifyGetScriptLexicalStructureListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(items, null, " ")})`); } private navigationBarItemsContains(items: ts.NavigationBarItem[], name: string, kind: string) { @@ -2099,11 +2095,11 @@ module FourSlash { let items = this.languageService.getNavigateToItems(searchValue); let length = items && items.length; - Harness.IO.log('NavigationItems list (' + length + ' items)'); + Harness.IO.log(`NavigationItems list (${length} items)`); for (let i = 0; i < length; i++) { let item = items[i]; - Harness.IO.log('name: ' + item.name + ', kind: ' + item.kind + ', parentName: ' + item.containerName + ', fileName: ' + item.fileName); + Harness.IO.log(`name: ${item.name}, kind: ${item.kind}, parentName: ${item.containerName}, fileName: ${item.fileName}`); } } @@ -2111,11 +2107,11 @@ module FourSlash { let items = this.languageService.getNavigationBarItems(this.activeFile.fileName); let length = items && items.length; - Harness.IO.log('NavigationItems list (' + length + ' items)'); + Harness.IO.log(`NavigationItems list (${length} items)`); for (let i = 0; i < length; i++) { let item = items[i]; - Harness.IO.log('name: ' + item.text + ', kind: ' + item.kind); + Harness.IO.log(`name: ${item.text}, kind: ${item.kind}`); } } @@ -2124,35 +2120,80 @@ module FourSlash { } public verifyOccurrencesAtPositionListContains(fileName: string, start: number, end: number, isWriteAccess?: boolean) { - this.taoInvalidReason = 'verifyOccurrencesAtPositionListContains NYI'; + this.taoInvalidReason = "verifyOccurrencesAtPositionListContains NYI"; - let occurances = this.getOccurancesAtCurrentPosition(); + let occurrences = this.getOccurancesAtCurrentPosition(); - if (!occurances || occurances.length === 0) { + if (!occurrences || occurrences.length === 0) { this.raiseError('verifyOccurancesAtPositionListContains failed - found 0 references, expected at least one.'); } - for (let i = 0; i < occurances.length; i++) { - let occurance = occurances[i]; - if (occurance && occurance.fileName === fileName && occurance.textSpan.start === start && ts.textSpanEnd(occurance.textSpan) === end) { - if (typeof isWriteAccess !== "undefined" && occurance.isWriteAccess !== isWriteAccess) { - this.raiseError('verifyOccurancesAtPositionListContains failed - item isWriteAccess value doe not match, actual: ' + occurance.isWriteAccess + ', expected: ' + isWriteAccess + '.'); + for (let occurrence of occurrences) { + if (occurrence && occurrence.fileName === fileName && occurrence.textSpan.start === start && ts.textSpanEnd(occurrence.textSpan) === end) { + if (typeof isWriteAccess !== "undefined" && occurrence.isWriteAccess !== isWriteAccess) { + this.raiseError(`verifyOccurrencesAtPositionListContains failed - item isWriteAccess value does not match, actual: ${occurrence.isWriteAccess}, expected: ${isWriteAccess}.`); } return; } } let missingItem = { fileName: fileName, start: start, end: end, isWriteAccess: isWriteAccess }; - this.raiseError('verifyOccurancesAtPositionListContains failed - could not find the item: ' + JSON.stringify(missingItem) + ' in the returned list: (' + JSON.stringify(occurances) + ')'); + this.raiseError(`verifyOccurrencesAtPositionListContains failed - could not find the item: ${JSON.stringify(missingItem)} in the returned list: (${JSON.stringify(occurrences)})`); } public verifyOccurrencesAtPositionListCount(expectedCount: number) { - this.taoInvalidReason = 'verifyOccurrencesAtPositionListCount NYI'; + this.taoInvalidReason = "verifyOccurrencesAtPositionListCount NYI"; - let occurances = this.getOccurancesAtCurrentPosition(); - let actualCount = occurances ? occurances.length : 0; + let occurrences = this.getOccurancesAtCurrentPosition(); + let actualCount = occurrences ? occurrences.length : 0; if (expectedCount !== actualCount) { - this.raiseError('verifyOccurrencesAtPositionListCount failed - actual: ' + actualCount + ', expected:' + expectedCount); + this.raiseError(`verifyOccurrencesAtPositionListCount failed - actual: ${actualCount}, expected:${expectedCount}`); + } + } + + private getDocumentHighlightsAtCurrentPosition(fileNamesToSearch: string[]) { + let filesToSearch = fileNamesToSearch.map(name => ts.combinePaths(this.basePath, name)); + return this.languageService.getDocumentHighlights(this.activeFile.fileName, this.currentCaretPosition, filesToSearch); + } + + public verifyDocumentHighlightsAtPositionListContains(fileName: string, start: number, end: number, fileNamesToSearch: string[], kind?: string) { + this.taoInvalidReason = 'verifyDocumentHighlightsAtPositionListContains NYI'; + + let documentHighlights = this.getDocumentHighlightsAtCurrentPosition(fileNamesToSearch); + + if (!documentHighlights || documentHighlights.length === 0) { + this.raiseError('verifyDocumentHighlightsAtPositionListContains failed - found 0 highlights, expected at least one.'); + } + + for (let documentHighlight of documentHighlights) { + if (documentHighlight.fileName === fileName) { + let { highlightSpans } = documentHighlight; + + for (let highlight of highlightSpans) { + if (highlight && highlight.textSpan.start === start && ts.textSpanEnd(highlight.textSpan) === end) { + if (typeof kind !== "undefined" && highlight.kind !== kind) { + this.raiseError('verifyDocumentHighlightsAtPositionListContains failed - item "kind" value does not match, actual: ' + highlight.kind + ', expected: ' + kind + '.'); + } + return; + } + } + } + } + + let missingItem = { fileName: fileName, start: start, end: end, kind: kind }; + this.raiseError('verifyOccurancesAtPositionListContains failed - could not find the item: ' + JSON.stringify(missingItem) + ' in the returned list: (' + JSON.stringify(documentHighlights) + ')'); + } + + public verifyDocumentHighlightsAtPositionListCount(expectedCount: number, fileNamesToSearch: string[]) { + this.taoInvalidReason = 'verifyDocumentHighlightsAtPositionListCount NYI'; + + let documentHighlights = this.getDocumentHighlightsAtCurrentPosition(fileNamesToSearch); + let actualCount = documentHighlights + ? documentHighlights.reduce((currentCount, { highlightSpans }) => currentCount + highlightSpans.length, 0) + : 0; + + if (expectedCount !== actualCount) { + this.raiseError('verifyDocumentHighlightsAtPositionListCount failed - actual: ' + actualCount + ', expected:' + expectedCount); } } @@ -2186,11 +2227,11 @@ module FourSlash { } private assertItemInCompletionList(items: ts.CompletionEntry[], name: string, text?: string, documentation?: string, kind?: string) { - this.scenarioActions.push(''); - this.scenarioActions.push(''); + this.scenarioActions.push(""); + this.scenarioActions.push(``); if (text || documentation || kind) { - this.taoInvalidReason = 'assertItemInCompletionList only supports the "name" parameter'; + this.taoInvalidReason = "assertItemInCompletionList only supports the \"name\" parameter"; } for (let i = 0; i < items.length; i++) { @@ -2217,23 +2258,23 @@ module FourSlash { let itemsString = items.map((item) => JSON.stringify({ name: item.name, kind: item.kind })).join(",\n"); - this.raiseError('Expected "' + JSON.stringify({ name, text, documentation, kind }) + '" to be in list [' + itemsString + ']'); + this.raiseError(`Expected "${JSON.stringify({ name, text, documentation, kind })}" to be in list [${itemsString}]`); } private findFile(indexOrName: any) { let result: FourSlashFile = null; - if (typeof indexOrName === 'number') { + if (typeof indexOrName === "number") { let index = indexOrName; if (index >= this.testData.files.length) { - throw new Error('File index (' + index + ') in openFile was out of range. There are only ' + this.testData.files.length + ' files in this test.'); + throw new Error(`File index (${index}) in openFile was out of range. There are only ${this.testData.files.length} files in this test.`); } else { result = this.testData.files[index]; } - } else if (typeof indexOrName === 'string') { + } else if (typeof indexOrName === "string") { let name = indexOrName; // names are stored in the compiler with this relative path, this allows people to use goTo.file on just the fileName - name = name.indexOf('/') === -1 ? (this.basePath + '/' + name) : name; + name = name.indexOf("/") === -1 ? (this.basePath + "/" + name) : name; let availableNames: string[] = []; let foundIt = false; @@ -2250,10 +2291,10 @@ module FourSlash { } if (!foundIt) { - throw new Error('No test file named "' + name + '" exists. Available file names are:' + availableNames.join(', ')); + throw new Error(`No test file named "${name}" exists. Available file names are: ${availableNames.join(", ")}`); } } else { - throw new Error('Unknown argument type'); + throw new Error("Unknown argument type"); } return result; @@ -2261,29 +2302,29 @@ module FourSlash { private getLineColStringAtPosition(position: number) { let pos = this.languageServiceAdapterHost.positionToLineAndCharacter(this.activeFile.fileName, position); - return 'line ' + (pos.line + 1) + ', col ' + pos.character; + return `line ${(pos.line + 1)}, col ${pos.character}`; } - private getMarkerByName(markerName: string) { + public getMarkerByName(markerName: string) { let markerPos = this.testData.markerPositions[markerName]; if (markerPos === undefined) { let markerNames: string[] = []; for (let m in this.testData.markerPositions) markerNames.push(m); - throw new Error('Unknown marker "' + markerName + '" Available markers: ' + markerNames.map(m => '"' + m + '"').join(', ')); + throw new Error(`Unknown marker "${markerName}" Available markers: ${markerNames.map(m => "\"" + m + "\"").join(", ")}`); } else { return markerPos; } } private static makeWhitespaceVisible(text: string) { - return text.replace(/ /g, '\u00B7').replace(/\r/g, '\u00B6').replace(/\n/g, '\u2193\n').replace(/\t/g, '\u2192\ '); + return text.replace(/ /g, "\u00B7").replace(/\r/g, "\u00B6").replace(/\n/g, "\u2193\n").replace(/\t/g, "\u2192\ "); } public getTestXmlData(): TestXmlData { return { actions: this.scenarioActions, invalidReason: this.taoInvalidReason, - originalName: '' + originalName: "" }; } @@ -2327,7 +2368,7 @@ module FourSlash { currentTestState = new TestState(basePath, testType, testData); - let result = ''; + let result = ""; let host = Harness.Compiler.createCompilerHost( [ { unitName: Harness.Compiler.fourslashFileName, content: undefined }, @@ -2343,12 +2384,12 @@ module FourSlash { let diagnostics = ts.getPreEmitDiagnostics(program, sourceFile); if (diagnostics.length > 0) { - throw new Error('Error compiling ' + fileName + ': ' + - diagnostics.map(e => ts.flattenDiagnosticMessageText(e.messageText, ts.sys.newLine)).join('\r\n')); + throw new Error(`Error compiling ${fileName}: ` + + diagnostics.map(e => ts.flattenDiagnosticMessageText(e.messageText, ts.sys.newLine)).join("\r\n")); } program.emit(sourceFile); - result = result || ''; // Might have an empty fourslash file + result = result || ""; // Might have an empty fourslash file result = fourslashJsOutput + "\r\n" + result; @@ -2369,12 +2410,12 @@ module FourSlash { function chompLeadingSpace(content: string) { let lines = content.split("\n"); for (let i = 0; i < lines.length; i++) { - if ((lines[i].length !== 0) && (lines[i].charAt(0) !== ' ')) { + if ((lines[i].length !== 0) && (lines[i].charAt(0) !== " ")) { return content; } } - return lines.map(s => s.substr(1)).join('\n'); + return lines.map(s => s.substr(1)).join("\n"); } function parseTestData(basePath: string, contents: string, fileName: string): FourSlashData { @@ -2390,7 +2431,7 @@ module FourSlash { // Split up the input file by line // Note: IE JS engine incorrectly handles consecutive delimiters here when using RegExp split, so // we have to string-based splitting instead and try to figure out the delimiting chars - let lines = contents.split('\n'); + let lines = contents.split("\n"); let markerPositions: MarkerMap = {}; let markers: Marker[] = []; @@ -2405,23 +2446,23 @@ module FourSlash { let line = lines[i]; let lineLength = line.length; - if (lineLength > 0 && line.charAt(lineLength - 1) === '\r') { + if (lineLength > 0 && line.charAt(lineLength - 1) === "\r") { line = line.substr(0, lineLength - 1); } - if (line.substr(0, 4) === '////') { + if (line.substr(0, 4) === "////") { // Subfile content line // Append to the current subfile content, inserting a newline needed if (currentFileContent === null) { - currentFileContent = ''; + currentFileContent = ""; } else { // End-of-line - currentFileContent = currentFileContent + '\n'; + currentFileContent = currentFileContent + "\n"; } currentFileContent = currentFileContent + line.substr(4); - } else if (line.substr(0, 2) === '//') { + } else if (line.substr(0, 2) === "//") { // Comment line, check for global/file @options and record them let match = optionRegex.exec(line.substr(2)); if (match) { @@ -2429,7 +2470,7 @@ module FourSlash { let fileMetadataNamesIndex = fileMetadataNames.indexOf(match[1]); if (globalMetadataNamesIndex === -1) { if (fileMetadataNamesIndex === -1) { - throw new Error('Unrecognized metadata name "' + match[1] + '". Available global metadata names are: ' + globalMetadataNames.join(', ') + '; file metadata names are: ' + fileMetadataNames.join(', ')); + throw new Error(`Unrecognized metadata name "${match[1]}". Available global metadata names are: ${globalMetadataNames.join(", ")}; file metadata names are: ${fileMetadataNames.join(", ")}`); } else if (fileMetadataNamesIndex === fileMetadataNames.indexOf(metadataOptionNames.fileName)) { // Found an @FileName directive, if this is not the first then create a new subfile if (currentFileContent) { @@ -2445,7 +2486,7 @@ module FourSlash { currentFileName = fileName; } - currentFileName = basePath + '/' + match[2]; + currentFileName = basePath + "/" + match[2]; currentFileOptions[match[1]] = match[2]; } else { // Add other fileMetadata flag @@ -2460,7 +2501,7 @@ module FourSlash { } } // TODO: should be '==='? - } else if (line == '' || lineLength === 0) { + } else if (line == "" || lineLength === 0) { // Previously blank lines between fourslash content caused it to be considered as 2 files, // Remove this behavior since it just causes errors now } else { @@ -2480,6 +2521,17 @@ module FourSlash { } } + // @Filename is the only directive that can be used in a test that contains tsconfig.json file. + if (containTSConfigJson(files)) { + let directive = getNonFileNameOptionInFileList(files); + if (!directive) { + directive = getNonFileNameOptionInObject(globalOptions); + } + if (directive) { + throw Error("It is not allowed to use tsconfig.json along with directive '" + directive + "'"); + } + } + return { markerPositions, markers, @@ -2489,6 +2541,23 @@ module FourSlash { }; } + function containTSConfigJson(files: FourSlashFile[]): boolean { + return ts.forEach(files, f => f.fileOptions["Filename"] === "tsconfig.json"); + } + + function getNonFileNameOptionInFileList(files: FourSlashFile[]): string { + return ts.forEach(files, f => getNonFileNameOptionInObject(f.fileOptions)); + } + + function getNonFileNameOptionInObject(optionObject: { [s: string]: string }): string { + for (let option in optionObject) { + if (option !== metadataOptionNames.fileName) { + return option; + } + } + return undefined; + } + const enum State { none, inSlashStarMarker, @@ -2552,7 +2621,7 @@ module FourSlash { content = chompLeadingSpace(content); // Any slash-star comment with a character not in this string is not a marker. - let validMarkerChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$1234567890_'; + let validMarkerChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz$1234567890_"; /// The file content (minus metacharacters) so far let output: string = ""; @@ -2687,7 +2756,7 @@ module FourSlash { openMarker = null; state = State.none; } else if (validMarkerChars.indexOf(currentChar) < 0) { - if (currentChar === '*' && i < content.length - 1 && content.charAt(i + 1) === '/') { + if (currentChar === "*" && i < content.length - 1 && content.charAt(i + 1) === "/") { // The marker is about to be closed, ignore the 'invalid' char } else { // We've hit a non-valid marker character, so we were actually in a block comment @@ -2702,10 +2771,10 @@ module FourSlash { break; } - if (currentChar === '\n' && previousChar === '\r') { + if (currentChar === "\n" && previousChar === "\r") { // Ignore trailing \n after a \r continue; - } else if (currentChar === '\n' || currentChar === '\r') { + } else if (currentChar === "\n" || currentChar === "\r") { line++; column = 1; continue; @@ -2739,4 +2808,4 @@ module FourSlash { fileName: fileName }; } -} +} \ No newline at end of file diff --git a/src/harness/fourslashRunner.ts b/src/harness/fourslashRunner.ts index 05a11c4f52d..3914232dbe8 100644 --- a/src/harness/fourslashRunner.ts +++ b/src/harness/fourslashRunner.ts @@ -1,6 +1,6 @@ -/// -/// -/// +/// +/// +/// const enum FourSlashTestType { Native, @@ -16,16 +16,16 @@ class FourSlashRunner extends RunnerBase { super(); switch (testType) { case FourSlashTestType.Native: - this.basePath = 'tests/cases/fourslash'; - this.testSuiteName = 'fourslash'; + this.basePath = "tests/cases/fourslash"; + this.testSuiteName = "fourslash"; break; case FourSlashTestType.Shims: - this.basePath = 'tests/cases/fourslash/shims'; - this.testSuiteName = 'fourslash-shims'; + this.basePath = "tests/cases/fourslash/shims"; + this.testSuiteName = "fourslash-shims"; break; case FourSlashTestType.Server: - this.basePath = 'tests/cases/fourslash/server'; - this.testSuiteName = 'fourslash-server'; + this.basePath = "tests/cases/fourslash/server"; + this.testSuiteName = "fourslash-server"; break; } } @@ -35,25 +35,25 @@ class FourSlashRunner extends RunnerBase { this.tests = this.enumerateFiles(this.basePath, /\.ts/i, { recursive: false }); } - describe(this.testSuiteName + ' tests', () => { + describe(this.testSuiteName + " tests", () => { this.tests.forEach((fn: string) => { describe(fn, () => { fn = ts.normalizeSlashes(fn); - let justName = fn.replace(/^.*[\\\/]/, ''); + let justName = fn.replace(/^.*[\\\/]/, ""); // Convert to relative path - let testIndex = fn.indexOf('tests/'); + let testIndex = fn.indexOf("tests/"); if (testIndex >= 0) fn = fn.substr(testIndex); if (justName && !justName.match(/fourslash\.ts$/i) && !justName.match(/\.d\.ts$/i)) { - it(this.testSuiteName + ' test ' + justName + ' runs correctly', () => { + it(this.testSuiteName + " test " + justName + " runs correctly", () => { FourSlash.runFourSlashTest(this.basePath, this.testType, fn); }); } }); }); - describe('Generate Tao XML', () => { + describe("Generate Tao XML", () => { let invalidReasons: any = {}; FourSlash.xmlData.forEach(xml => { if (xml.invalidReason !== null) { @@ -69,37 +69,37 @@ class FourSlashRunner extends RunnerBase { invalidReport.sort((lhs, rhs) => lhs.count > rhs.count ? -1 : lhs.count === rhs.count ? 0 : 1); let lines: string[] = []; - lines.push(''); - lines.push(''); - lines.push(' '); - lines.push(' '); - lines.push(' '); - lines.push(' '); + lines.push("-->"); + lines.push(""); + lines.push(" "); + lines.push(" "); + lines.push(" "); + lines.push(" "); FourSlash.xmlData.forEach(xml => { if (xml.invalidReason !== null) { - lines.push(''); + lines.push(""); } else { - lines.push(' '); + lines.push(" "); xml.actions.forEach(action => { - lines.push(' ' + action); + lines.push(" " + action); }); - lines.push(' '); + lines.push(" "); } }); - lines.push(' '); - lines.push(' '); - lines.push(' '); - lines.push(' '); - lines.push(' '); - lines.push(' '); - lines.push(' '); - lines.push(' '); - lines.push(''); - Harness.IO.writeFile('built/local/fourslash.xml', lines.join('\r\n')); + lines.push(" "); + lines.push(" "); + lines.push(" "); + lines.push(" "); + lines.push(" "); + lines.push(" "); + lines.push(" "); + lines.push(" "); + lines.push(""); + Harness.IO.writeFile("built/local/fourslash.xml", lines.join("\r\n")); }); }); } @@ -108,6 +108,6 @@ class FourSlashRunner extends RunnerBase { class GeneratedFourslashRunner extends FourSlashRunner { constructor(testType: FourSlashTestType) { super(testType); - this.basePath += '/generated/'; + this.basePath += "/generated/"; } } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 17aa0dd325c..e37a8610089 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -14,23 +14,27 @@ // limitations under the License. // -/// -/// -/// -/// -/// -/// -/// -/// -/// +/// +/// +/// +/// +/// +/// +/// +/// +/// -var Buffer: BufferConstructor = require('buffer').Buffer; +// Block scoped definitions work poorly for global variables, temporarily enable var +/* tslint:disable:no-var-keyword */ +var Buffer: BufferConstructor = require("buffer").Buffer; // this will work in the browser via browserify -var _chai: typeof chai = require('chai'); +var _chai: typeof chai = require("chai"); var assert: typeof _chai.assert = _chai.assert; +var expect: typeof _chai.expect = _chai.expect; declare var __dirname: string; // Node-specific var global = Function("return this").call(null); +/* tslint:enable:no-var-keyword */ module Utils { // Setup some globals based on the current environment @@ -62,7 +66,7 @@ module Utils { eval(fileContents); break; case ExecutionEnvironment.Node: - let vm = require('vm'); + let vm = require("vm"); if (nodeContext) { vm.runInNewContext(fileContents, nodeContext, fileName); } else { @@ -70,7 +74,7 @@ module Utils { } break; default: - throw new Error('Unknown context'); + throw new Error("Unknown context"); } } @@ -79,9 +83,9 @@ module Utils { // Split up the input file by line // Note: IE JS engine incorrectly handles consecutive delimiters here when using RegExp split, so // we have to use string-based splitting instead and try to figure out the delimiting chars - let lines = content.split('\r\n'); + let lines = content.split("\r\n"); if (lines.length === 1) { - lines = content.split('\n'); + lines = content.split("\n"); if (lines.length === 1) { lines = content.split("\r"); @@ -92,7 +96,7 @@ module Utils { /** Reads a file under /tests */ export function readTestFile(path: string) { - if (path.indexOf('tests') < 0) { + if (path.indexOf("tests") < 0) { path = "tests/" + path; } @@ -387,7 +391,7 @@ module Utils { module Harness.Path { export function getFileName(fullPath: string) { - return fullPath.replace(/^.*[\\\/]/, ''); + return fullPath.replace(/^.*[\\\/]/, ""); } export function filePath(fullPath: string) { @@ -411,6 +415,7 @@ module Harness { log(text: string): void; getMemoryUsage?(): number; } + export var IO: IO; module IOImpl { declare class Enumerator { @@ -483,8 +488,8 @@ module Harness { declare let require: any; let fs: any, pathModule: any; if (require) { - fs = require('fs'); - pathModule = require('path'); + fs = require("fs"); + pathModule = require("path"); } else { fs = pathModule = {}; } @@ -492,7 +497,7 @@ module Harness { export let readFile: typeof IO.readFile = ts.sys.readFile; export let writeFile: typeof IO.writeFile = ts.sys.writeFile; export let fileExists: typeof IO.fileExists = fs.existsSync; - export let log: typeof IO.log = console.log; + export let log: typeof IO.log = s => console.log(s); export function createDirectory(path: string) { if (!directoryExists(path)) { @@ -558,8 +563,8 @@ module Harness { let serverRoot = "http://localhost:8888/"; // Unused? - let newLine = '\r\n'; - let currentDirectory = () => ''; + let newLine = "\r\n"; + let currentDirectory = () => ""; let supportsCodePage = () => false; module Http { @@ -605,9 +610,9 @@ module Harness { export function writeToServerSync(url: string, action: string, contents?: string): XHRResponse { let xhr = new XMLHttpRequest(); try { - let actionMsg = '?action=' + action; - xhr.open('POST', url + actionMsg, false); - xhr.setRequestHeader('Access-Control-Allow-Origin', '*'); + let actionMsg = "?action=" + action; + xhr.open("POST", url + actionMsg, false); + xhr.setRequestHeader("Access-Control-Allow-Origin", "*"); xhr.send(contents); } catch (e) { @@ -623,7 +628,7 @@ module Harness { } export function deleteFile(path: string) { - Http.writeToServerSync(serverRoot + path, 'DELETE', null); + Http.writeToServerSync(serverRoot + path, "DELETE", null); } export function directoryExists(path: string): boolean { @@ -636,15 +641,15 @@ module Harness { if (dirPath.match(/localhost:\d+$/) || dirPath.match(/localhost:\d+\/$/)) { dirPath = null; // path + fileName - } else if (dirPath.indexOf('.') === -1) { - dirPath = dirPath.substring(0, dirPath.lastIndexOf('/')); + } else if (dirPath.indexOf(".") === -1) { + dirPath = dirPath.substring(0, dirPath.lastIndexOf("/")); // path } else { // strip any trailing slash if (dirPath.match(/.*\/$/)) { dirPath = dirPath.substring(0, dirPath.length - 2); } - dirPath = dirPath.substring(0, dirPath.lastIndexOf('/')); + dirPath = dirPath.substring(0, dirPath.lastIndexOf("/")); } return dirPath; @@ -659,7 +664,7 @@ module Harness { export function _listFilesImpl(path: string, spec?: RegExp, options?: any) { let response = Http.getFileFromServerSync(serverRoot + path); if (response.status === 200) { - let results = response.responseText.split(','); + let results = response.responseText.split(","); if (spec) { return results.filter(file => spec.test(file)); } else { @@ -667,12 +672,12 @@ module Harness { } } else { - return ['']; + return [""]; } }; export let listFiles = Utils.memoize(_listFilesImpl); - export let log = console.log; + export let log = (s: string) => console.log(s); export function readFile(file: string) { let response = Http.getFileFromServerSync(serverRoot + file); @@ -684,12 +689,11 @@ module Harness { } export function writeFile(path: string, contents: string) { - Http.writeToServerSync(serverRoot + path, 'WRITE', contents); + Http.writeToServerSync(serverRoot + path, "WRITE", contents); } } } - export var IO: IO; switch (Utils.getExecutionEnvironment()) { case Utils.ExecutionEnvironment.CScript: IO = IOImpl.CScript; @@ -721,7 +725,7 @@ module Harness { tcServicesFileName = "built/local/typescriptServices.js"; break; default: - throw new Error('Unknown context'); + throw new Error("Unknown context"); } export let tcServicesFile = IO.readFile(tcServicesFileName); @@ -744,12 +748,12 @@ module Harness { public Write(str: string) { // out of memory usage concerns avoid using + or += if we're going to do any manipulation of this string later - this.currentLine = [(this.currentLine || ''), str].join(''); + this.currentLine = [(this.currentLine || ""), str].join(""); } public WriteLine(str: string) { // out of memory usage concerns avoid using + or += if we're going to do any manipulation of this string later - this.lines.push([(this.currentLine || ''), str].join('')); + this.lines.push([(this.currentLine || ""), str].join("")); this.currentLine = undefined; } @@ -798,7 +802,7 @@ module Harness { if (this.fileCollection.hasOwnProperty(p)) { let current = this.fileCollection[p]; if (current.lines.length > 0) { - if (p.indexOf('.d.ts') !== -1) { current.lines.unshift(['////[', Path.getFileName(p), ']'].join('')); } + if (p.indexOf(".d.ts") !== -1) { current.lines.unshift(["////[", Path.getFileName(p), "]"].join("")); } result.push({ fileName: p, file: this.fileCollection[p] }); } } @@ -827,12 +831,12 @@ module Harness { const carriageReturnLineFeed = "\r\n"; const lineFeed = "\n"; - export let defaultLibFileName = 'lib.d.ts'; - export let defaultLibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest); - export let defaultES6LibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + 'lib.core.es6.d.ts'), /*languageVersion*/ ts.ScriptTarget.Latest); + export let defaultLibFileName = "lib.d.ts"; + export let defaultLibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.core.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest); + export let defaultES6LibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.core.es6.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest); // Cache these between executions so we don't have to re-parse them for every test - export let fourslashFileName = 'fourslash.ts'; + export let fourslashFileName = "fourslash.ts"; export let fourslashSourceFile: ts.SourceFile; export function getCanonicalFileName(fileName: string): string { @@ -882,7 +886,7 @@ module Harness { return Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(canonicalAbsolutePath)) ? filemap[canonicalAbsolutePath] : undefined; } else if (fn === fourslashFileName) { - let tsFn = 'tests/cases/fourslash/' + fourslashFileName; + let tsFn = "tests/cases/fourslash/" + fourslashFileName; fourslashSourceFile = fourslashSourceFile || createSourceFileAndAssertInvariants(tsFn, Harness.IO.readFile(tsFn), scriptTarget); return fourslashSourceFile; } @@ -973,7 +977,7 @@ module Harness { settingsCallback(null); } - let newLine = '\r\n'; + let newLine = "\r\n"; options.skipDefaultLibCheck = true; // Files from built\local that are requested by test "@includeBuiltFiles" to be in the context. @@ -1010,19 +1014,19 @@ module Harness { // "fileName", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noimplicitany", "noresolve" case "module": case "modulegentarget": - if (typeof setting.value === 'string') { - if (setting.value.toLowerCase() === 'amd') { + if (typeof setting.value === "string") { + if (setting.value.toLowerCase() === "amd") { options.module = ts.ModuleKind.AMD; - } else if (setting.value.toLowerCase() === 'umd') { + } else if (setting.value.toLowerCase() === "umd") { options.module = ts.ModuleKind.UMD; - } else if (setting.value.toLowerCase() === 'commonjs') { + } else if (setting.value.toLowerCase() === "commonjs") { options.module = ts.ModuleKind.CommonJS; - } else if (setting.value.toLowerCase() === 'system') { + } else if (setting.value.toLowerCase() === "system") { options.module = ts.ModuleKind.System; - } else if (setting.value.toLowerCase() === 'unspecified') { + } else if (setting.value.toLowerCase() === "unspecified") { options.module = ts.ModuleKind.None; } else { - throw new Error('Unknown module type ' + setting.value); + throw new Error("Unknown module type " + setting.value); } } else { options.module = setting.value; @@ -1030,152 +1034,152 @@ module Harness { break; case "target": - case 'codegentarget': - if (typeof setting.value === 'string') { - if (setting.value.toLowerCase() === 'es3') { + case "codegentarget": + if (typeof setting.value === "string") { + if (setting.value.toLowerCase() === "es3") { options.target = ts.ScriptTarget.ES3; - } else if (setting.value.toLowerCase() === 'es5') { + } else if (setting.value.toLowerCase() === "es5") { options.target = ts.ScriptTarget.ES5; - } else if (setting.value.toLowerCase() === 'es6') { + } else if (setting.value.toLowerCase() === "es6") { options.target = ts.ScriptTarget.ES6; } else { - throw new Error('Unknown compile target ' + setting.value); + throw new Error("Unknown compile target " + setting.value); } } else { options.target = setting.value; } break; - case 'experimentaldecorators': - options.experimentalDecorators = setting.value === 'true'; + case "experimentaldecorators": + options.experimentalDecorators = setting.value === "true"; break; - case 'emitdecoratormetadata': - options.emitDecoratorMetadata = setting.value === 'true'; + case "emitdecoratormetadata": + options.emitDecoratorMetadata = setting.value === "true"; break; - case 'experimentalasyncfunctions': - options.experimentalAsyncFunctions = setting.value === 'true'; + case "experimentalasyncfunctions": + options.experimentalAsyncFunctions = setting.value === "true"; break; - case 'noemithelpers': - options.noEmitHelpers = setting.value === 'true'; + case "noemithelpers": + options.noEmitHelpers = setting.value === "true"; break; - case 'noemitonerror': - options.noEmitOnError = setting.value === 'true'; + case "noemitonerror": + options.noEmitOnError = setting.value === "true"; break; - case 'noresolve': - options.noResolve = setting.value === 'true'; + case "noresolve": + options.noResolve = setting.value === "true"; break; - case 'noimplicitany': - options.noImplicitAny = setting.value === 'true'; + case "noimplicitany": + options.noImplicitAny = setting.value === "true"; break; - case 'nolib': - options.noLib = setting.value === 'true'; + case "nolib": + options.noLib = setting.value === "true"; break; - case 'out': - case 'outfileoption': + case "out": + case "outfileoption": options.out = setting.value; break; - case 'outdiroption': - case 'outdir': + case "outdiroption": + case "outdir": options.outDir = setting.value; break; - case 'skipdefaultlibcheck': + case "skipdefaultlibcheck": options.skipDefaultLibCheck = setting.value === "true"; break; - case 'sourceroot': + case "sourceroot": options.sourceRoot = setting.value; break; - case 'maproot': + case "maproot": options.mapRoot = setting.value; break; - case 'sourcemap': - options.sourceMap = setting.value === 'true'; + case "sourcemap": + options.sourceMap = setting.value === "true"; break; - case 'declaration': - options.declaration = setting.value === 'true'; + case "declaration": + options.declaration = setting.value === "true"; break; - case 'newline': - if (setting.value.toLowerCase() === 'crlf') { + case "newline": + if (setting.value.toLowerCase() === "crlf") { options.newLine = ts.NewLineKind.CarriageReturnLineFeed; } - else if (setting.value.toLowerCase() === 'lf') { + else if (setting.value.toLowerCase() === "lf") { options.newLine = ts.NewLineKind.LineFeed; } else { - throw new Error('Unknown option for newLine: ' + setting.value); + throw new Error("Unknown option for newLine: " + setting.value); } break; - case 'comments': - options.removeComments = setting.value === 'false'; + case "comments": + options.removeComments = setting.value === "false"; break; - case 'stripinternal': - options.stripInternal = setting.value === 'true'; + case "stripinternal": + options.stripInternal = setting.value === "true"; - case 'usecasesensitivefilenames': - useCaseSensitiveFileNames = setting.value === 'true'; + case "usecasesensitivefilenames": + useCaseSensitiveFileNames = setting.value === "true"; break; - case 'filename': + case "filename": // Not supported yet break; - case 'emitbom': - options.emitBOM = setting.value === 'true'; + case "emitbom": + options.emitBOM = setting.value === "true"; break; - case 'errortruncation': - options.noErrorTruncation = setting.value === 'false'; + case "errortruncation": + options.noErrorTruncation = setting.value === "false"; break; - case 'preserveconstenums': - options.preserveConstEnums = setting.value === 'true'; + case "preserveconstenums": + options.preserveConstEnums = setting.value === "true"; break; - case 'isolatedmodules': - options.isolatedModules = setting.value === 'true'; + case "isolatedmodules": + options.isolatedModules = setting.value === "true"; break; - case 'suppressimplicitanyindexerrors': - options.suppressImplicitAnyIndexErrors = setting.value === 'true'; + case "suppressimplicitanyindexerrors": + options.suppressImplicitAnyIndexErrors = setting.value === "true"; break; - case 'includebuiltfile': + case "includebuiltfile": let builtFileName = libFolder + setting.value; includeBuiltFiles.push({ unitName: builtFileName, content: normalizeLineEndings(IO.readFile(builtFileName), newLine) }); break; - case 'inlinesourcemap': - options.inlineSourceMap = setting.value === 'true'; + case "inlinesourcemap": + options.inlineSourceMap = setting.value === "true"; break; - case 'inlinesources': - options.inlineSources = setting.value === 'true'; + case "inlinesources": + options.inlineSources = setting.value === "true"; break; - case 'jsx': - options.jsx = setting.value.toLowerCase() === 'react' ? ts.JsxEmit.React : - setting.value.toLowerCase() === 'preserve' ? ts.JsxEmit.Preserve : + case "jsx": + options.jsx = setting.value.toLowerCase() === "react" ? ts.JsxEmit.React : + setting.value.toLowerCase() === "preserve" ? ts.JsxEmit.Preserve : ts.JsxEmit.None; break; default: - throw new Error('Unsupported compiler setting ' + setting.flag); + throw new Error("Unsupported compiler setting " + setting.flag); } } } @@ -1188,7 +1192,7 @@ module Harness { // Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file currentDirectory?: string) { 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'); + throw new Error("There were no errors and declFiles generated did not match number of js files generated"); } let declInputFiles: { unitName: string; content: string }[] = []; @@ -1249,8 +1253,8 @@ module Harness { } function normalizeLineEndings(text: string, lineEnding: string): string { - let normalized = text.replace(/\r\n?/g, '\n'); - if (lineEnding !== '\n') { + let normalized = text.replace(/\r\n?/g, "\n"); + if (lineEnding !== "\n") { normalized = normalized.replace(/\n/g, lineEnding); } return normalized; @@ -1281,10 +1285,10 @@ module Harness { let message = ts.flattenDiagnosticMessageText(error.messageText, ts.sys.newLine); let errLines = RunnerBase.removeFullPaths(message) - .split('\n') - .map(s => s.length > 0 && s.charAt(s.length - 1) === '\r' ? s.substr(0, s.length - 1) : s) + .split("\n") + .map(s => s.length > 0 && s.charAt(s.length - 1) === "\r" ? s.substr(0, s.length - 1) : s) .filter(s => s.length > 0) - .map(s => '!!! ' + ts.DiagnosticCategory[error.category].toLowerCase() + " TS" + error.code + ": " + s); + .map(s => "!!! " + ts.DiagnosticCategory[error.category].toLowerCase() + " TS" + error.code + ": " + s); errLines.forEach(e => outputLines.push(e)); totalErrorsReported++; @@ -1304,7 +1308,7 @@ module Harness { // Header - outputLines.push('==== ' + inputFile.unitName + ' (' + fileErrors.length + ' errors) ===='); + outputLines.push("==== " + inputFile.unitName + " (" + fileErrors.length + " errors) ===="); // Make sure we emit something for every error let markedErrorCount = 0; @@ -1313,13 +1317,13 @@ module Harness { // we have to string-based splitting instead and try to figure out the delimiting chars let lineStarts = ts.computeLineStarts(inputFile.content); - let lines = inputFile.content.split('\n'); + let lines = inputFile.content.split("\n"); if (lines.length === 1) { lines = lines[0].split("\r"); } lines.forEach((line, lineIndex) => { - if (line.length > 0 && line.charAt(line.length - 1) === '\r') { + if (line.length > 0 && line.charAt(line.length - 1) === "\r") { line = line.substr(0, line.length - 1); } @@ -1332,7 +1336,7 @@ module Harness { nextLineStart = lineStarts[lineIndex + 1]; } // Emit this line from the original file - outputLines.push(' ' + line); + outputLines.push(" " + line); fileErrors.forEach(err => { // Does any error start or continue on to this line? Emit squiggles let end = ts.textSpanEnd(err); @@ -1344,7 +1348,7 @@ module Harness { // Calculate the start of the squiggle let squiggleStart = Math.max(0, relativeOffset); // TODO/REVIEW: this doesn't work quite right in the browser if a multi file test has files whose names are just the right length relative to one another - outputLines.push(' ' + line.substr(0, squiggleStart).replace(/[^\s]/g, ' ') + new Array(Math.min(length, line.length - squiggleStart) + 1).join('~')); + outputLines.push(" " + line.substr(0, squiggleStart).replace(/[^\s]/g, " ") + new Array(Math.min(length, line.length - squiggleStart) + 1).join("~")); // If the error ended here, or we're at the end of the file, emit its message if ((lineIndex === lines.length - 1) || nextLineStart > end) { @@ -1359,7 +1363,7 @@ module Harness { }); // Verify we didn't miss any errors in this file - assert.equal(markedErrorCount, fileErrors.length, 'count of errors in ' + inputFile.unitName); + assert.equal(markedErrorCount, fileErrors.length, "count of errors in " + inputFile.unitName); }); let numLibraryDiagnostics = ts.countWhere(diagnostics, diagnostic => { @@ -1372,10 +1376,10 @@ module Harness { }); // Verify we didn't miss any errors in total - assert.equal(totalErrorsReported + numLibraryDiagnostics + numTest262HarnessDiagnostics, diagnostics.length, 'total number of errors'); + assert.equal(totalErrorsReported + numLibraryDiagnostics + numTest262HarnessDiagnostics, diagnostics.length, "total number of errors"); return minimalDiagnosticsToString(diagnostics) + - ts.sys.newLine + ts.sys.newLine + outputLines.join('\r\n'); + ts.sys.newLine + ts.sys.newLine + outputLines.join("\r\n"); } export function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[]): string { @@ -1383,15 +1387,15 @@ module Harness { outputFiles.sort((a, b) => cleanName(a.fileName).localeCompare(cleanName(b.fileName))); // Emit them - let result = ''; + let result = ""; for (let outputFile of outputFiles) { // Some extra spacing if this isn't the first file if (result.length) { - result += '\r\n\r\n'; + result += "\r\n\r\n"; } // FileName header + content - result += '/*====== ' + outputFile.fileName + ' ======*/\r\n'; + result += "/*====== " + outputFile.fileName + " ======*/\r\n"; result += outputFile.code; } @@ -1399,7 +1403,7 @@ module Harness { return result; function cleanName(fn: string) { - let lastSlash = ts.normalizeSlashes(fn).lastIndexOf('/'); + let lastSlash = ts.normalizeSlashes(fn).lastIndexOf("/"); return fn.substr(lastSlash + 1).toLowerCase(); } } @@ -1417,7 +1421,7 @@ module Harness { // This does not need to exist strictly speaking, but many tests will need to be updated if it's removed export function compileString(code: string, unitName: string, callback: (result: CompilerResult) => void) { // NEWTODO: Re-implement 'compileString' - throw new Error('compileString NYI'); + throw new Error("compileString NYI"); } export interface GeneratedFile { @@ -1431,26 +1435,26 @@ module Harness { } export function isTS(fileName: string) { - return stringEndsWith(fileName, '.ts'); + return stringEndsWith(fileName, ".ts"); } export function isTSX(fileName: string) { - return stringEndsWith(fileName, '.tsx'); + return stringEndsWith(fileName, ".tsx"); } export function isDTS(fileName: string) { - return stringEndsWith(fileName, '.d.ts'); + return stringEndsWith(fileName, ".d.ts"); } export function isJS(fileName: string) { - return stringEndsWith(fileName, '.js'); + return stringEndsWith(fileName, ".js"); } export function isJSX(fileName: string) { - return stringEndsWith(fileName, '.jsx'); + return stringEndsWith(fileName, ".jsx"); } export function isJSMap(fileName: string) { - return stringEndsWith(fileName, '.js.map'); + return stringEndsWith(fileName, ".js.map") || stringEndsWith(fileName, ".jsx.map"); } /** Contains the code and errors of a compilation and some helper methods to check its status. */ @@ -1477,7 +1481,7 @@ module Harness { this.sourceMaps.push(emittedFile); } else { - throw new Error('Unrecognized file extension for file ' + emittedFile.fileName); + throw new Error("Unrecognized file extension for file " + emittedFile.fileName); } }); @@ -1586,10 +1590,10 @@ module Harness { // Subfile content line // Append to the current subfile content, inserting a newline needed if (currentFileContent === null) { - currentFileContent = ''; + currentFileContent = ""; } else { // End-of-line - currentFileContent = currentFileContent + '\n'; + currentFileContent = currentFileContent + "\n"; } currentFileContent = currentFileContent + line; } @@ -1600,7 +1604,7 @@ module Harness { // EOF, push whatever remains let newTestFile2 = { - content: currentFileContent || '', + content: currentFileContent || "", name: currentFileName, fileOptions: currentFileOptions, originalFilePath: fileName, @@ -1622,27 +1626,27 @@ module Harness { export function localPath(fileName: string, baselineFolder?: string, subfolder?: string) { if (baselineFolder === undefined) { - return baselinePath(fileName, 'local', 'tests/baselines', subfolder); + return baselinePath(fileName, "local", "tests/baselines", subfolder); } else { - return baselinePath(fileName, 'local', baselineFolder, subfolder); + return baselinePath(fileName, "local", baselineFolder, subfolder); } } function referencePath(fileName: string, baselineFolder?: string, subfolder?: string) { if (baselineFolder === undefined) { - return baselinePath(fileName, 'reference', 'tests/baselines', subfolder); + return baselinePath(fileName, "reference", "tests/baselines", subfolder); } else { - return baselinePath(fileName, 'reference', baselineFolder, subfolder); + return baselinePath(fileName, "reference", baselineFolder, subfolder); } } function baselinePath(fileName: string, type: string, baselineFolder: string, subfolder?: string) { if (subfolder !== undefined) { - return Harness.userSpecifiedRoot + baselineFolder + '/' + subfolder + '/' + type + '/' + fileName; + return Harness.userSpecifiedRoot + baselineFolder + "/" + subfolder + "/" + type + "/" + fileName; } else { - return Harness.userSpecifiedRoot + baselineFolder + '/' + type + '/' + fileName; + return Harness.userSpecifiedRoot + baselineFolder + "/" + type + "/" + fileName; } } @@ -1676,7 +1680,7 @@ module Harness { let actual = generateContent(); if (actual === undefined) { - throw new Error('The generated content was "undefined". Return "null" if no baselining is required."'); + throw new Error("The generated content was \"undefined\". Return \"null\" if no baselining is required.\""); } // Store the content in the 'local' folder so we @@ -1699,10 +1703,10 @@ module Harness { let refFileName = referencePath(relativeFileName, opts && opts.Baselinefolder, opts && opts.Subfolder); if (actual === null) { - actual = ''; + actual = ""; } - let expected = ''; + let expected = ""; if (IO.fileExists(refFileName)) { expected = IO.readFile(refFileName); } @@ -1711,10 +1715,10 @@ module Harness { } function writeComparison(expected: string, actual: string, relativeFileName: string, actualFileName: string, descriptionForDescribe: string) { - let encoded_actual = (new Buffer(actual)).toString('utf8'); + let encoded_actual = (new Buffer(actual)).toString("utf8"); if (expected != encoded_actual) { // Overwrite & issue error - let errMsg = 'The baseline file ' + relativeFileName + ' has changed'; + let errMsg = "The baseline file " + relativeFileName + " has changed"; throw new Error(errMsg); } } @@ -1743,7 +1747,7 @@ module Harness { } export function isLibraryFile(filePath: string): boolean { - return (Path.getFileName(filePath) === 'lib.d.ts') || (Path.getFileName(filePath) === 'lib.core.d.ts'); + return (Path.getFileName(filePath) === "lib.d.ts") || (Path.getFileName(filePath) === "lib.core.d.ts"); } export function isBuiltFile(filePath: string): boolean { diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 3c543e50566..0a35e3b4ed8 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -1,7 +1,7 @@ -/// -/// -/// -/// +/// +/// +/// +/// module Harness.LanguageService { export class ScriptInfo { @@ -242,7 +242,7 @@ module Harness.LanguageService { throw new Error("NYI"); } getClassificationsForLine(text: string, lexState: ts.EndOfLineState, classifyKeywordsInGenerics?: boolean): ts.ClassificationResult { - let result = this.shim.getClassificationsForLine(text, lexState, classifyKeywordsInGenerics).split('\n'); + let result = this.shim.getClassificationsForLine(text, lexState, classifyKeywordsInGenerics).split("\n"); let entries: ts.ClassificationInfo[] = []; let i = 0; let position = 0; diff --git a/src/harness/loggedIO.ts b/src/harness/loggedIO.ts index 0ce567e9563..db82a47d362 100644 --- a/src/harness/loggedIO.ts +++ b/src/harness/loggedIO.ts @@ -12,6 +12,7 @@ interface FindFileResult { } interface IOLog { + timestamp: string; arguments: string[]; executingPath: string; currentDirectory: string; @@ -72,7 +73,7 @@ interface PlaybackControl { module Playback { let recordLog: IOLog = undefined; let replayLog: IOLog = undefined; - let recordLogFileNameBase = ''; + let recordLogFileNameBase = ""; interface Memoized { (s: string): T; @@ -98,7 +99,7 @@ module Playback { return { timestamp: (new Date()).toString(), arguments: [], - currentDirectory: '', + currentDirectory: "", filesRead: [], filesWritten: [], filesDeleted: [], @@ -109,7 +110,7 @@ module Playback { dirExists: [], dirsCreated: [], pathsResolved: [], - executingPath: '' + executingPath: "" }; } @@ -169,7 +170,7 @@ module Playback { if (defaultValue !== undefined) { return defaultValue; } else { - throw new Error('No matching result in log array for: ' + JSON.stringify(expectedFields)); + throw new Error("No matching result in log array for: " + JSON.stringify(expectedFields)); } } return results[0].result; @@ -194,7 +195,7 @@ module Playback { } // If we got here, we didn't find a match if (defaultValue === undefined) { - throw new Error('No matching result in log array for path: ' + expectedPath); + throw new Error("No matching result in log array for path: " + expectedPath); } else { return defaultValue; } @@ -202,7 +203,7 @@ module Playback { let pathEquivCache: any = {}; function pathsAreEquivalent(left: string, right: string, wrapper: { resolvePath(s: string): string }) { - let key = left + '-~~-' + right; + let key = left + "-~~-" + right; function areSame(a: string, b: string) { return ts.normalizeSlashes(a).toLowerCase() === ts.normalizeSlashes(b).toLowerCase(); } @@ -232,14 +233,14 @@ module Playback { wrapper.endRecord = () => { if (recordLog !== undefined) { let i = 0; - let fn = () => recordLogFileNameBase + i + '.json'; + let fn = () => recordLogFileNameBase + i + ".json"; while (underlying.fileExists(fn())) i++; underlying.writeFile(fn(), JSON.stringify(recordLog)); recordLog = undefined; } }; - Object.defineProperty(wrapper, 'args', { + Object.defineProperty(wrapper, "args", { get() { if (replayLog !== undefined) { return replayLog.arguments; @@ -275,7 +276,7 @@ module Playback { wrapper.getCurrentDirectory = () => { if (replayLog !== undefined) { - return replayLog.currentDirectory || ''; + return replayLog.currentDirectory || ""; } else if (recordLog !== undefined) { return recordLog.currentDirectory = underlying.getCurrentDirectory(); } else { @@ -285,7 +286,7 @@ module Playback { wrapper.resolvePath = recordReplay(wrapper.resolvePath, underlying)( (path) => callAndRecord(underlying.resolvePath(path), recordLog.pathsResolved, { path: path }), - memoize((path) => findResultByFields(replayLog.pathsResolved, { path: path }, !ts.isRootedDiskPath(ts.normalizeSlashes(path)) && replayLog.currentDirectory ? replayLog.currentDirectory + '/' + path : ts.normalizeSlashes(path)))); + memoize((path) => findResultByFields(replayLog.pathsResolved, { path: path }, !ts.isRootedDiskPath(ts.normalizeSlashes(path)) && replayLog.currentDirectory ? replayLog.currentDirectory + "/" + path : ts.normalizeSlashes(path)))); wrapper.readFile = recordReplay(wrapper.readFile, underlying)( (path) => { @@ -298,7 +299,7 @@ module Playback { wrapper.writeFile = recordReplay(wrapper.writeFile, underlying)( (path, contents) => callAndRecord(underlying.writeFile(path, contents), recordLog.filesWritten, { path: path, contents: contents, bom: false }), - (path, contents) => noOpReplay('writeFile')); + (path, contents) => noOpReplay("writeFile")); wrapper.exit = (exitCode) => { if (recordLog !== undefined) { diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 5ea118aacbf..c91f789940b 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -74,7 +74,7 @@ class ProjectRunner extends RunnerBase { catch (e) { assert(false, "Testcase: " + testCaseFileName + " does not contain valid json format: " + e.message); } - let testCaseJustName = testCaseFileName.replace(/^.*[\\\/]/, '').replace(/\.json/, ""); + let testCaseJustName = testCaseFileName.replace(/^.*[\\\/]/, "").replace(/\.json/, ""); function moduleNameToString(moduleKind: ts.ModuleKind) { return moduleKind === ts.ModuleKind.AMD @@ -331,9 +331,9 @@ class ProjectRunner extends RunnerBase { return Harness.Compiler.getErrorBaseline(inputFiles, compilerResult.errors); } - let name = 'Compiling project for ' + testCase.scenario + ': testcase ' + testCaseFileName; + let name = "Compiling project for " + testCase.scenario + ": testcase " + testCaseFileName; - describe('Projects tests', () => { + describe("Projects tests", () => { describe(name, () => { function verifyCompilerResults(moduleKind: ts.ModuleKind) { let compilerResult: BatchCompileProjectTestCaseResult; @@ -367,27 +367,27 @@ class ProjectRunner extends RunnerBase { compilerResult = batchCompilerProjectTestCase(moduleKind); }); - it('Resolution information of (' + moduleNameToString(moduleKind) + '): ' + testCaseFileName, () => { - Harness.Baseline.runBaseline('Resolution information of (' + moduleNameToString(compilerResult.moduleKind) + '): ' + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + '.json', () => { + it("Resolution information of (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => { + Harness.Baseline.runBaseline("Resolution information of (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".json", () => { return JSON.stringify(getCompilerResolutionInfo(), undefined, " "); }); }); - it('Errors for (' + moduleNameToString(moduleKind) + '): ' + testCaseFileName, () => { + it("Errors for (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => { if (compilerResult.errors.length) { - Harness.Baseline.runBaseline('Errors for (' + moduleNameToString(compilerResult.moduleKind) + '): ' + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + '.errors.txt', () => { + Harness.Baseline.runBaseline("Errors for (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".errors.txt", () => { return getErrorsBaseline(compilerResult); }); } }); - it('Baseline of emitted result (' + moduleNameToString(moduleKind) + '): ' + testCaseFileName, () => { + it("Baseline of emitted result (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => { if (testCase.baselineCheck) { ts.forEach(compilerResult.outputFiles, outputFile => { - Harness.Baseline.runBaseline('Baseline of emitted result (' + moduleNameToString(compilerResult.moduleKind) + '): ' + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + outputFile.fileName, () => { + Harness.Baseline.runBaseline("Baseline of emitted result (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + outputFile.fileName, () => { try { return ts.sys.readFile(getProjectOutputFolder(outputFile.fileName, compilerResult.moduleKind)); } @@ -400,9 +400,9 @@ class ProjectRunner extends RunnerBase { }); - it('SourceMapRecord for (' + moduleNameToString(moduleKind) + '): ' + testCaseFileName, () => { + it("SourceMapRecord for (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => { if (compilerResult.sourceMapData) { - Harness.Baseline.runBaseline('SourceMapRecord for (' + moduleNameToString(compilerResult.moduleKind) + '): ' + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + '.sourcemap.txt', () => { + Harness.Baseline.runBaseline("SourceMapRecord for (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".sourcemap.txt", () => { return Harness.SourceMapRecoder.getSourceMapRecord(compilerResult.sourceMapData, compilerResult.program, ts.filter(compilerResult.outputFiles, outputFile => Harness.Compiler.isJS(outputFile.emittedFileName))); }); @@ -411,11 +411,11 @@ class ProjectRunner extends RunnerBase { // Verify that all the generated .d.ts files compile - it('Errors in generated Dts files for (' + moduleNameToString(moduleKind) + '): ' + testCaseFileName, () => { + it("Errors in generated Dts files for (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => { if (!compilerResult.errors.length && testCase.declaration) { let dTsCompileResult = compileCompileDTsFiles(compilerResult); if (dTsCompileResult.errors.length) { - Harness.Baseline.runBaseline('Errors in generated Dts files for (' + moduleNameToString(compilerResult.moduleKind) + '): ' + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + '.dts.errors.txt', () => { + Harness.Baseline.runBaseline("Errors in generated Dts files for (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".dts.errors.txt", () => { return getErrorsBaseline(dTsCompileResult); }); } diff --git a/src/harness/runner.ts b/src/harness/runner.ts index e4ed604e980..06aaf3d32b5 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -13,12 +13,12 @@ // limitations under the License. // -/// -/// -/// -/// -/// -/// +/// +/// +/// +/// +/// +/// let runners: RunnerBase[] = []; let iterations: number = 1; @@ -32,13 +32,13 @@ function runTests(runners: RunnerBase[]) { } // users can define tests to run in mytest.config that will override cmd line args, otherwise use cmd line args (test.config), otherwise no options -let mytestconfig = 'mytest.config'; -let testconfig = 'test.config'; +let mytestconfig = "mytest.config"; +let testconfig = "test.config"; let testConfigFile = Harness.IO.fileExists(mytestconfig) ? Harness.IO.readFile(mytestconfig) : - (Harness.IO.fileExists(testconfig) ? Harness.IO.readFile(testconfig) : ''); + (Harness.IO.fileExists(testconfig) ? Harness.IO.readFile(testconfig) : ""); -if (testConfigFile !== '') { +if (testConfigFile !== "") { let testConfig = JSON.parse(testConfigFile); if (testConfig.light) { Harness.lightMode = true; @@ -51,33 +51,33 @@ if (testConfigFile !== '') { } switch (option) { - case 'compiler': + case "compiler": runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance)); runners.push(new CompilerBaselineRunner(CompilerTestType.Regressions)); runners.push(new ProjectRunner()); break; - case 'conformance': + case "conformance": runners.push(new CompilerBaselineRunner(CompilerTestType.Conformance)); break; - case 'project': + case "project": runners.push(new ProjectRunner()); break; - case 'fourslash': + case "fourslash": runners.push(new FourSlashRunner(FourSlashTestType.Native)); break; - case 'fourslash-shims': + case "fourslash-shims": runners.push(new FourSlashRunner(FourSlashTestType.Shims)); break; - case 'fourslash-server': + case "fourslash-server": runners.push(new FourSlashRunner(FourSlashTestType.Server)); break; - case 'fourslash-generated': + case "fourslash-generated": runners.push(new GeneratedFourslashRunner(FourSlashTestType.Native)); break; - case 'rwc': + case "rwc": runners.push(new RWCRunner()); break; - case 'test262': + case "test262": runners.push(new Test262BaselineRunner()); break; } @@ -102,6 +102,6 @@ if (runners.length === 0) { // runners.push(new GeneratedFourslashRunner()); } -ts.sys.newLine = '\r\n'; +ts.sys.newLine = "\r\n"; runTests(runners); diff --git a/src/harness/runnerbase.ts b/src/harness/runnerbase.ts index 66438d938dd..afe757ea829 100644 --- a/src/harness/runnerbase.ts +++ b/src/harness/runnerbase.ts @@ -1,6 +1,6 @@ /// -class RunnerBase { +abstract class RunnerBase { constructor() { } // contains the tests to run @@ -18,9 +18,7 @@ class RunnerBase { /** 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 { - throw new Error('method not implemented'); - } + public abstract initializeTests(): void; /** Replaces instances of full paths with fileNames only */ static removeFullPaths(path: string) { @@ -35,7 +33,7 @@ class RunnerBase { // when running in the browser the 'full path' is the host name, shows up in error baselines let localHost = /http:\/localhost:\d+/g; - fixedPath = fixedPath.replace(localHost, ''); + fixedPath = fixedPath.replace(localHost, ""); return fixedPath; } } \ No newline at end of file diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index bbe80abc887..d8b52ec2e39 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -1,7 +1,7 @@ -/// -/// -/// -/// +/// +/// +/// +/// module RWC { function runWithIOLog(ioLog: IOLog, fn: () => void) { @@ -26,8 +26,8 @@ module RWC { let compilerResult: Harness.Compiler.CompilerResult; let compilerOptions: ts.CompilerOptions; let baselineOpts: Harness.Baseline.BaselineOptions = { - Subfolder: 'rwc', - Baselinefolder: 'internal/baselines' + Subfolder: "rwc", + Baselinefolder: "internal/baselines" }; let baseName = /(.*)\/(.*).json/.exec(ts.normalizeSlashes(jsonPath))[2]; let currentDirectory: string; @@ -49,7 +49,7 @@ module RWC { useCustomLibraryFile = undefined; }); - it('can compile', () => { + it("can compile", () => { let harnessCompiler = Harness.Compiler.getCompiler(); let opts: ts.ParsedCommandLine; @@ -74,10 +74,11 @@ module RWC { }); // Add files to compilation + let isInInputList = (resolvedPath: string) => (inputFile: { unitName: string; content: string; }) => inputFile.unitName === resolvedPath; for (let fileRead of ioLog.filesRead) { // Check if the file is already added into the set of input files. - var resolvedPath = ts.normalizeSlashes(ts.sys.resolvePath(fileRead.path)); - let inInputList = ts.forEach(inputFiles, inputFile => inputFile.unitName === resolvedPath); + const resolvedPath = ts.normalizeSlashes(ts.sys.resolvePath(fileRead.path)); + let inInputList = ts.forEach(inputFiles, isInInputList(resolvedPath)); if (!Harness.isLibraryFile(fileRead.path)) { if (inInputList) { @@ -123,21 +124,21 @@ module RWC { content = ts.sys.readFile(unitName); } catch (e) { - // Leave content undefined. + content = ts.sys.readFile(fileName); } return { unitName, content }; } }); - it('has the expected emitted code', () => { - Harness.Baseline.runBaseline('has the expected emitted code', baseName + '.output.js', () => { + it("has the expected emitted code", () => { + Harness.Baseline.runBaseline("has the expected emitted code", baseName + ".output.js", () => { return Harness.Compiler.collateOutputs(compilerResult.files); }, false, baselineOpts); }); - it('has the expected declaration file content', () => { - Harness.Baseline.runBaseline('has the expected declaration file content', baseName + '.d.ts', () => { + it("has the expected declaration file content", () => { + Harness.Baseline.runBaseline("has the expected declaration file content", baseName + ".d.ts", () => { if (!compilerResult.declFilesCode.length) { return null; } @@ -146,8 +147,8 @@ module RWC { }, false, baselineOpts); }); - it('has the expected source maps', () => { - Harness.Baseline.runBaseline('has the expected source maps', baseName + '.map', () => { + it("has the expected source maps", () => { + Harness.Baseline.runBaseline("has the expected source maps", baseName + ".map", () => { if (!compilerResult.sourceMaps.length) { return null; } @@ -156,16 +157,16 @@ module RWC { }, false, baselineOpts); }); - /*it('has correct source map record', () => { + /*it("has correct source map record", () => { if (compilerOptions.sourceMap) { - Harness.Baseline.runBaseline('has correct source map record', baseName + '.sourcemap.txt', () => { + 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', () => { + it("has the expected errors", () => { + Harness.Baseline.runBaseline("has the expected errors", baseName + ".errors.txt", () => { if (compilerResult.errors.length === 0) { return null; } @@ -176,9 +177,9 @@ module RWC { // Ideally, a generated declaration file will have no errors. But we allow generated // declaration file errors as part of the baseline. - it('has the expected errors in generated declaration files', () => { + it("has the expected errors in generated declaration files", () => { if (compilerOptions.declaration && !compilerResult.errors.length) { - Harness.Baseline.runBaseline('has the expected errors in generated declaration files', baseName + '.dts.errors.txt', () => { + Harness.Baseline.runBaseline("has the expected errors in generated declaration files", baseName + ".dts.errors.txt", () => { let declFileCompilationResult = Harness.Compiler.getCompiler().compileDeclarationFiles(inputFiles, otherFiles, compilerResult, /*settingscallback*/ undefined, compilerOptions, currentDirectory); if (declFileCompilationResult.declResult.errors.length === 0) { diff --git a/src/harness/sourceMapRecorder.ts b/src/harness/sourceMapRecorder.ts index 767dd37949f..55ca9ea9651 100644 --- a/src/harness/sourceMapRecorder.ts +++ b/src/harness/sourceMapRecorder.ts @@ -13,7 +13,7 @@ // limitations under the License. // -/// +/// module Harness.SourceMapRecoder { @@ -50,11 +50,11 @@ module Harness.SourceMapRecoder { return true; } - if (sourceMapMappings.charAt(decodingIndex) == ',') { + if (sourceMapMappings.charAt(decodingIndex) == ",") { return true; } - if (sourceMapMappings.charAt(decodingIndex) == ';') { + if (sourceMapMappings.charAt(decodingIndex) == ";") { return true; } @@ -117,7 +117,7 @@ module Harness.SourceMapRecoder { } while (decodingIndex < sourceMapMappings.length) { - if (sourceMapMappings.charAt(decodingIndex) == ';') { + if (sourceMapMappings.charAt(decodingIndex) == ";") { // New line decodeOfEncodedMapping.emittedLine++; decodeOfEncodedMapping.emittedColumn = 1; @@ -125,7 +125,7 @@ module Harness.SourceMapRecoder { continue; } - if (sourceMapMappings.charAt(decodingIndex) == ',') { + if (sourceMapMappings.charAt(decodingIndex) == ",") { // Next entry is on same line - no action needed decodingIndex++; continue; @@ -459,6 +459,6 @@ module Harness.SourceMapRecoder { SourceMapSpanWriter.close(); // If the last spans werent emitted, emit them } sourceMapRecoder.Close(); - return sourceMapRecoder.lines.join('\r\n'); + return sourceMapRecoder.lines.join("\r\n"); } } diff --git a/src/harness/test262Runner.ts b/src/harness/test262Runner.ts index e34e58844ac..d9bbd55e7a3 100644 --- a/src/harness/test262Runner.ts +++ b/src/harness/test262Runner.ts @@ -1,9 +1,9 @@ -/// -/// +/// +/// class Test262BaselineRunner extends RunnerBase { - private static basePath = 'internal/cases/test262'; - private static helpersFilePath = 'tests/cases/test262-harness/helpers.d.ts'; + private static basePath = "internal/cases/test262"; + private static helpersFilePath = "tests/cases/test262-harness/helpers.d.ts"; private static helperFile = { unitName: Test262BaselineRunner.helpersFilePath, content: Harness.IO.readFile(Test262BaselineRunner.helpersFilePath) @@ -15,8 +15,8 @@ class Test262BaselineRunner extends RunnerBase { module: ts.ModuleKind.CommonJS }; private static baselineOptions: Harness.Baseline.BaselineOptions = { - Subfolder: 'test262', - Baselinefolder: 'internal/baselines' + Subfolder: "test262", + Baselinefolder: "internal/baselines" }; private static getTestFilePath(filename: string): string { @@ -24,7 +24,7 @@ class Test262BaselineRunner extends RunnerBase { } private runTest(filePath: string) { - describe('test262 test for ' + filePath, () => { + describe("test262 test for " + filePath, () => { // Mocha holds onto the closure environment of the describe callback even after the test is done. // Everything declared here should be cleared out in the "after" callback. let testState: { @@ -36,7 +36,7 @@ class Test262BaselineRunner extends RunnerBase { before(() => { let content = Harness.IO.readFile(filePath); - let testFilename = ts.removeFileExtension(filePath).replace(/\//g, '_') + ".test"; + let testFilename = ts.removeFileExtension(filePath).replace(/\//g, "_") + ".test"; let testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, testFilename); let inputFiles = testCaseContent.testUnitData.map(unit => { @@ -61,15 +61,15 @@ class Test262BaselineRunner extends RunnerBase { testState = undefined; }); - it('has the expected emitted code', () => { - Harness.Baseline.runBaseline('has the expected emitted code', testState.filename + '.output.js', () => { + it("has the expected emitted code", () => { + Harness.Baseline.runBaseline("has the expected emitted code", testState.filename + ".output.js", () => { let files = testState.compilerResult.files.filter(f => f.fileName !== Test262BaselineRunner.helpersFilePath); return Harness.Compiler.collateOutputs(files); }, false, Test262BaselineRunner.baselineOptions); }); - it('has the expected errors', () => { - Harness.Baseline.runBaseline('has the expected errors', testState.filename + '.errors.txt', () => { + it("has the expected errors", () => { + Harness.Baseline.runBaseline("has the expected errors", testState.filename + ".errors.txt", () => { let errors = testState.compilerResult.errors; if (errors.length === 0) { return null; @@ -79,13 +79,13 @@ class Test262BaselineRunner extends RunnerBase { }, false, Test262BaselineRunner.baselineOptions); }); - it('satisfies inletiants', () => { + it("satisfies inletiants", () => { let sourceFile = testState.program.getSourceFile(Test262BaselineRunner.getTestFilePath(testState.filename)); Utils.assertInvariants(sourceFile, /*parent:*/ undefined); }); - it('has the expected AST', () => { - Harness.Baseline.runBaseline('has the expected AST', testState.filename + '.AST.txt', () => { + it("has the expected AST", () => { + Harness.Baseline.runBaseline("has the expected AST", testState.filename + ".AST.txt", () => { let sourceFile = testState.program.getSourceFile(Test262BaselineRunner.getTestFilePath(testState.filename)); return Utils.sourceFileToJSON(sourceFile); }, false, Test262BaselineRunner.baselineOptions); diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index f177c421f4f..442921ca5a4 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -971,14 +971,14 @@ interface JSON { * @param replacer A function that transforms the results. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: (key: string, value: any) => any, space: any): string; + stringify(value: any, replacer: (key: string, value: any) => any, space: string | number): string; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. * @param replacer Array that transforms the results. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. */ - stringify(value: any, replacer: any[], space: any): string; + stringify(value: any, replacer: any[], space: string | number): string; } /** * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. @@ -1181,4 +1181,4 @@ interface PromiseLike { */ then(onfulfilled?: (value: T) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): PromiseLike; then(onfulfilled?: (value: T) => TResult | PromiseLike, onrejected?: (reason: any) => void): PromiseLike; -} +} diff --git a/src/lib/es6.d.ts b/src/lib/es6.d.ts index f3c0a1418fe..97291f742bd 100644 --- a/src/lib/es6.d.ts +++ b/src/lib/es6.d.ts @@ -377,7 +377,7 @@ interface String { * @param searchString search string * @param position If position is undefined, 0 is assumed, so as to search all of the String. */ - contains(searchString: string, position?: number): boolean; + includes(searchString: string, position?: number): boolean; /** * Returns true if the sequence of elements of searchString converted to a String is the diff --git a/src/server/client.ts b/src/server/client.ts index e4a524dd210..cc89349b442 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -202,9 +202,7 @@ namespace ts.server { return { isMemberCompletion: false, isNewIdentifierLocation: false, - entries: response.body, - fileName: fileName, - position: position + entries: response.body }; } @@ -529,8 +527,33 @@ namespace ts.server { }); } - getDocumentHighlights(fileName: string, position: number): DocumentHighlights[] { - throw new Error("Not Implemented Yet."); + getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[] { + let { line, offset } = this.positionToOneBasedLineOffset(fileName, position); + let args: protocol.DocumentHighlightsRequestArgs = { file: fileName, line, offset, filesToSearch }; + + let request = this.processRequest(CommandNames.DocumentHighlights, args); + let response = this.processResponse(request); + + let self = this; + return response.body.map(convertToDocumentHighlights); + + function convertToDocumentHighlights(item: ts.server.protocol.DocumentHighlightsItem): ts.DocumentHighlights { + let { file, highlightSpans } = item; + + return { + fileName: file, + highlightSpans: highlightSpans.map(convertHighlightSpan) + }; + + function convertHighlightSpan(span: ts.server.protocol.HighlightSpan): ts.HighlightSpan { + let start = self.lineOffsetToPosition(file, span.start); + let end = self.lineOffsetToPosition(file, span.end); + return { + textSpan: ts.createTextSpanFromBounds(start, end), + kind: span.kind + }; + } + } } getOutliningSpans(fileName: string): OutliningSpan[] { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 91d400ff263..64ec600783a 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -803,9 +803,6 @@ namespace ts.server { } else { this.log("no config file"); } - if (configFileName) { - configFileName = getAbsolutePath(configFileName, searchPath); - } if (configFileName && (!this.configProjectIsActive(configFileName))) { var configResult = this.openConfigFile(configFileName, fileName); if (!configResult.success) { @@ -910,7 +907,8 @@ namespace ts.server { configFilename = ts.normalizePath(configFilename); // file references will be relative to dirPath (or absolute) var dirPath = ts.getDirectoryPath(configFilename); - var rawConfig: { config?: ProjectOptions; error?: Diagnostic; } = ts.readConfigFile(configFilename); + var contents = this.host.readFile(configFilename) + var rawConfig: { config?: ProjectOptions; error?: Diagnostic; } = ts.parseConfigFileText(configFilename, contents); if (rawConfig.error) { return rawConfig.error; } diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index 017a8c1d81a..837bce4f99d 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -156,6 +156,17 @@ declare namespace ts.server.protocol { arguments: FileLocationRequestArgs; } + /** + * Arguments in document highlight request; include: filesToSearch, file, + * line, offset. + */ + export interface DocumentHighlightsRequestArgs extends FileLocationRequestArgs { + /** + * List of files to search for document highlights. + */ + filesToSearch: string[]; + } + /** * Go to definition request; value of command field is * "definition". Return response giving the file locations that @@ -238,6 +249,35 @@ declare namespace ts.server.protocol { body?: OccurrencesResponseItem[]; } + /** + * Get document highlights request; value of command field is + * "documentHighlights". Return response giving spans that are relevant + * in the file at a given line and column. + */ + export interface DocumentHighlightsRequest extends FileLocationRequest { + arguments: DocumentHighlightsRequestArgs + } + + export interface HighlightSpan extends TextSpan { + kind: string + } + + export interface DocumentHighlightsItem { + /** + * File containing highlight spans. + */ + file: string, + + /** + * Spans to highlight in file. + */ + highlightSpans: HighlightSpan[]; + } + + export interface DocumentHighlightsResponse extends Response { + body?: DocumentHighlightsItem[]; + } + /** * Find references request; value of command field is * "references". Return response giving the file locations that diff --git a/src/server/session.ts b/src/server/session.ts index d2ac429aa3c..54e4423d382 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -89,6 +89,7 @@ namespace ts.server { export const NavBar = "navbar"; export const Navto = "navto"; export const Occurrences = "occurrences"; + export const DocumentHighlights = "documentHighlights"; export const Open = "open"; export const Quickinfo = "quickinfo"; export const References = "references"; @@ -109,13 +110,13 @@ namespace ts.server { } export class Session { - projectService: ProjectService; - pendingOperation = false; - fileHash: ts.Map = {}; - nextFileId = 1; - errorTimer: any; /*NodeJS.Timer | number*/ - immediateId: any; - changeSeq = 0; + protected projectService: ProjectService; + private pendingOperation = false; + private fileHash: ts.Map = {}; + private nextFileId = 1; + private errorTimer: any; /*NodeJS.Timer | number*/ + private immediateId: any; + private changeSeq = 0; constructor( private host: ServerHost, @@ -129,7 +130,7 @@ namespace ts.server { }); } - handleEvent(eventName: string, project: Project, fileName: string) { + private handleEvent(eventName: string, project: Project, fileName: string) { if (eventName == "context") { this.projectService.log("got context event, updating diagnostics for" + fileName, "Info"); this.updateErrorCheck([{ fileName, project }], this.changeSeq, @@ -137,7 +138,7 @@ namespace ts.server { } } - logError(err: Error, cmd: string) { + public logError(err: Error, cmd: string) { var typedErr = err; var msg = "Exception on executing command " + cmd; if (typedErr.message) { @@ -149,11 +150,11 @@ namespace ts.server { this.projectService.log(msg); } - sendLineToClient(line: string) { + private sendLineToClient(line: string) { this.host.write(line + this.host.newLine); } - send(msg: protocol.Message) { + public send(msg: protocol.Message) { var json = JSON.stringify(msg); if (this.logger.isVerbose()) { this.logger.info(msg.type + ": " + json); @@ -162,7 +163,7 @@ namespace ts.server { '\r\n\r\n' + json); } - event(info: any, eventName: string) { + public event(info: any, eventName: string) { var ev: protocol.Event = { seq: 0, type: "event", @@ -172,7 +173,7 @@ namespace ts.server { this.send(ev); } - response(info: any, cmdName: string, reqSeq = 0, errorMsg?: string) { + private response(info: any, cmdName: string, reqSeq = 0, errorMsg?: string) { var res: protocol.Response = { seq: 0, type: "response", @@ -189,11 +190,11 @@ namespace ts.server { this.send(res); } - output(body: any, commandName: string, requestSequence = 0, errorMessage?: string) { + public output(body: any, commandName: string, requestSequence = 0, errorMessage?: string) { this.response(body, commandName, requestSequence, errorMessage); } - semanticCheck(file: string, project: Project) { + private semanticCheck(file: string, project: Project) { try { var diags = project.compilerService.languageService.getSemanticDiagnostics(file); @@ -207,7 +208,7 @@ namespace ts.server { } } - syntacticCheck(file: string, project: Project) { + private syntacticCheck(file: string, project: Project) { try { var diags = project.compilerService.languageService.getSyntacticDiagnostics(file); if (diags) { @@ -220,12 +221,12 @@ namespace ts.server { } } - errorCheck(file: string, project: Project) { + private errorCheck(file: string, project: Project) { this.syntacticCheck(file, project); this.semanticCheck(file, project); } - updateProjectStructure(seq: number, matchSeq: (seq: number) => boolean, ms = 1500) { + private updateProjectStructure(seq: number, matchSeq: (seq: number) => boolean, ms = 1500) { setTimeout(() => { if (matchSeq(seq)) { this.projectService.updateProjectStructure(); @@ -233,7 +234,7 @@ namespace ts.server { }, ms); } - updateErrorCheck(checkList: PendingErrorCheck[], seq: number, + private updateErrorCheck(checkList: PendingErrorCheck[], seq: number, matchSeq: (seq: number) => boolean, ms = 1500, followMs = 200) { if (followMs > ms) { followMs = ms; @@ -269,7 +270,7 @@ namespace ts.server { } } - getDefinition(line: number, offset: number, fileName: string): protocol.FileSpan[] { + private getDefinition(line: number, offset: number, fileName: string): protocol.FileSpan[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -291,7 +292,7 @@ namespace ts.server { })); } - getTypeDefinition(line: number, offset: number, fileName: string): protocol.FileSpan[] { + private getTypeDefinition(line: number, offset: number, fileName: string): protocol.FileSpan[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -313,7 +314,7 @@ namespace ts.server { })); } - getOccurrences(line: number, offset: number, fileName: string): protocol.OccurrencesResponseItem[]{ + private getOccurrences(line: number, offset: number, fileName: string): protocol.OccurrencesResponseItem[] { fileName = ts.normalizePath(fileName); let project = this.projectService.getProjectForFile(fileName); @@ -343,7 +344,43 @@ namespace ts.server { }); } - getProjectInfo(fileName: string, needFileNameList: boolean): protocol.ProjectInfo { + private getDocumentHighlights(line: number, offset: number, fileName: string, filesToSearch: string[]): protocol.DocumentHighlightsItem[] { + fileName = ts.normalizePath(fileName); + let project = this.projectService.getProjectForFile(fileName); + + if (!project) { + throw Errors.NoProject; + } + + let { compilerService } = project; + let position = compilerService.host.lineOffsetToPosition(fileName, line, offset); + + let documentHighlights = compilerService.languageService.getDocumentHighlights(fileName, position, filesToSearch); + + if (!documentHighlights) { + return undefined; + } + + return documentHighlights.map(convertToDocumentHighlightsItem); + + function convertToDocumentHighlightsItem(documentHighlights: ts.DocumentHighlights): ts.server.protocol.DocumentHighlightsItem { + let { fileName, highlightSpans } = documentHighlights; + + return { + file: fileName, + highlightSpans: highlightSpans.map(convertHighlightSpan) + }; + + function convertHighlightSpan(highlightSpan: ts.HighlightSpan): ts.server.protocol.HighlightSpan { + let { textSpan, kind } = highlightSpan; + let start = compilerService.host.positionToLineOffset(fileName, textSpan.start); + let end = compilerService.host.positionToLineOffset(fileName, ts.textSpanEnd(textSpan)); + return { start, end, kind }; + } + } + } + + private getProjectInfo(fileName: string, needFileNameList: boolean): protocol.ProjectInfo { fileName = ts.normalizePath(fileName) let project = this.projectService.getProjectForFile(fileName) @@ -358,7 +395,7 @@ namespace ts.server { return projectInfo; } - getRenameLocations(line: number, offset: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody { + private getRenameLocations(line: number, offset: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -426,7 +463,7 @@ namespace ts.server { return { info: renameInfo, locs: bakedRenameLocs }; } - getReferences(line: number, offset: number, fileName: string): protocol.ReferencesResponseBody { + private getReferences(line: number, offset: number, fileName: string): protocol.ReferencesResponseBody { // TODO: get all projects for this file; report refs for all projects deleting duplicates // can avoid duplicates by eliminating same ref file from subsequent projects var file = ts.normalizePath(fileName); @@ -473,12 +510,12 @@ namespace ts.server { }; } - openClientFile(fileName: string) { + private openClientFile(fileName: string) { var file = ts.normalizePath(fileName); this.projectService.openClientFile(file); } - getQuickInfo(line: number, offset: number, fileName: string): protocol.QuickInfoResponseBody { + private getQuickInfo(line: number, offset: number, fileName: string): protocol.QuickInfoResponseBody { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -504,7 +541,7 @@ namespace ts.server { }; } - getFormattingEditsForRange(line: number, offset: number, endLine: number, endOffset: number, fileName: string): protocol.CodeEdit[] { + private getFormattingEditsForRange(line: number, offset: number, endLine: number, endOffset: number, fileName: string): protocol.CodeEdit[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -531,7 +568,7 @@ namespace ts.server { }); } - getFormattingEditsAfterKeystroke(line: number, offset: number, key: string, fileName: string): protocol.CodeEdit[] { + private getFormattingEditsAfterKeystroke(line: number, offset: number, key: string, fileName: string): protocol.CodeEdit[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); @@ -607,7 +644,7 @@ namespace ts.server { }); } - getCompletions(line: number, offset: number, prefix: string, fileName: string): protocol.CompletionEntry[] { + private getCompletions(line: number, offset: number, prefix: string, fileName: string): protocol.CompletionEntry[] { if (!prefix) { prefix = ""; } @@ -633,7 +670,7 @@ namespace ts.server { }, []).sort((a, b) => a.name.localeCompare(b.name)); } - getCompletionEntryDetails(line: number, offset: number, + private getCompletionEntryDetails(line: number, offset: number, entryNames: string[], fileName: string): protocol.CompletionEntryDetails[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); @@ -653,7 +690,7 @@ namespace ts.server { }, []); } - getSignatureHelpItems(line: number, offset: number, fileName: string): protocol.SignatureHelpItems { + private getSignatureHelpItems(line: number, offset: number, fileName: string): protocol.SignatureHelpItems { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -682,7 +719,7 @@ namespace ts.server { return result; } - getDiagnostics(delay: number, fileNames: string[]) { + private getDiagnostics(delay: number, fileNames: string[]) { var checkList = fileNames.reduce((accum: PendingErrorCheck[], fileName: string) => { fileName = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(fileName); @@ -697,7 +734,7 @@ namespace ts.server { } } - change(line: number, offset: number, endLine: number, endOffset: number, insertString: string, fileName: string) { + private change(line: number, offset: number, endLine: number, endOffset: number, insertString: string, fileName: string) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (project) { @@ -712,7 +749,7 @@ namespace ts.server { } } - reload(fileName: string, tempFileName: string, reqSeq = 0) { + private reload(fileName: string, tempFileName: string, reqSeq = 0) { var file = ts.normalizePath(fileName); var tmpfile = ts.normalizePath(tempFileName); var project = this.projectService.getProjectForFile(file); @@ -725,7 +762,7 @@ namespace ts.server { } } - saveToTmp(fileName: string, tempFileName: string) { + private saveToTmp(fileName: string, tempFileName: string) { var file = ts.normalizePath(fileName); var tmpfile = ts.normalizePath(tempFileName); @@ -735,12 +772,12 @@ namespace ts.server { } } - closeClientFile(fileName: string) { + private closeClientFile(fileName: string) { var file = ts.normalizePath(fileName); this.projectService.closeClientFile(file); } - decorateNavigationBarItem(project: Project, fileName: string, items: ts.NavigationBarItem[]): protocol.NavigationBarItem[] { + private decorateNavigationBarItem(project: Project, fileName: string, items: ts.NavigationBarItem[]): protocol.NavigationBarItem[] { if (!items) { return undefined; } @@ -759,7 +796,7 @@ namespace ts.server { })); } - getNavigationBarItems(fileName: string): protocol.NavigationBarItem[] { + private getNavigationBarItems(fileName: string): protocol.NavigationBarItem[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -775,7 +812,7 @@ namespace ts.server { return this.decorateNavigationBarItem(project, fileName, items); } - getNavigateToItems(searchValue: string, fileName: string, maxResultCount?: number): protocol.NavtoItem[] { + private getNavigateToItems(searchValue: string, fileName: string, maxResultCount?: number): protocol.NavtoItem[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -814,7 +851,7 @@ namespace ts.server { }); } - getBraceMatching(line: number, offset: number, fileName: string): protocol.TextSpan[] { + private getBraceMatching(line: number, offset: number, fileName: string): protocol.TextSpan[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); @@ -836,7 +873,7 @@ namespace ts.server { })); } - exit() { + public exit() { } private handlers : Map<(request: protocol.Request) => {response?: any, responseRequired?: boolean}> = { @@ -937,19 +974,23 @@ namespace ts.server { var { line, offset, file: fileName } = request.arguments; return {response: this.getOccurrences(line, offset, fileName), responseRequired: true}; }, + [CommandNames.DocumentHighlights]: (request: protocol.Request) => { + var { line, offset, file: fileName, filesToSearch } = request.arguments; + return {response: this.getDocumentHighlights(line, offset, fileName, filesToSearch), responseRequired: true}; + }, [CommandNames.ProjectInfo]: (request: protocol.Request) => { var { file, needFileNameList } = request.arguments; return {response: this.getProjectInfo(file, needFileNameList), responseRequired: true}; }, }; - addProtocolHandler(command: string, handler: (request: protocol.Request) => {response?: any, responseRequired: boolean}) { + public addProtocolHandler(command: string, handler: (request: protocol.Request) => {response?: any, responseRequired: boolean}) { if (this.handlers[command]) { throw new Error(`Protocol handler already exists for command "${command}"`); } this.handlers[command] = handler; } - executeCommand(request: protocol.Request) : {response?: any, responseRequired?: boolean} { + public executeCommand(request: protocol.Request) : {response?: any, responseRequired?: boolean} { var handler = this.handlers[request.command]; if (handler) { return handler(request); @@ -960,7 +1001,7 @@ namespace ts.server { } } - onMessage(message: string) { + public onMessage(message: string) { if (this.logger.isVerbose()) { this.logger.info("request: " + message); var start = this.hrtime(); diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index db748f7f494..3b291b6e39a 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -418,6 +418,7 @@ namespace ts.formatting { case SyntaxKind.DefaultClause: case SyntaxKind.CaseClause: case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.PropertyAccessExpression: case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: case SyntaxKind.VariableStatement: diff --git a/src/services/services.ts b/src/services/services.ts index df0e1fe0972..72b4b617b3a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -48,6 +48,7 @@ namespace ts { getConstructSignatures(): Signature[]; getStringIndexType(): Type; getNumberIndexType(): Type; + getBaseTypes(): ObjectType[] } export interface Signature { @@ -260,26 +261,25 @@ namespace ts { } public getFirstToken(sourceFile?: SourceFile): Node { - let children = this.getChildren(); - for (let child of children) { - if (child.kind < SyntaxKind.FirstNode) { - return child; - } - - return child.getFirstToken(sourceFile); + let children = this.getChildren(sourceFile); + if (!children.length) { + return undefined; } + + let child = children[0]; + + return child.kind < SyntaxKind.FirstNode ? child : child.getFirstToken(sourceFile); } public getLastToken(sourceFile?: SourceFile): Node { let children = this.getChildren(sourceFile); - for (let i = children.length - 1; i >= 0; i--) { - let child = children[i]; - if (child.kind < SyntaxKind.FirstNode) { - return child; - } - return child.getLastToken(sourceFile); + let child = lastOrUndefined(children); + if (!child) { + return undefined; } + + return child.kind < SyntaxKind.FirstNode ? child : child.getLastToken(sourceFile); } } @@ -682,6 +682,11 @@ namespace ts { getNumberIndexType(): Type { return this.checker.getIndexTypeOfType(this, IndexKind.Number); } + getBaseTypes(): ObjectType[] { + return this.flags & (TypeFlags.Class | TypeFlags.Interface) + ? this.checker.getBaseTypes(this) + : undefined; + } } class SignatureObject implements Signature { @@ -1105,6 +1110,7 @@ namespace ts { } export interface HighlightSpan { + fileName?: string; textSpan: TextSpan; kind: string; } @@ -1411,7 +1417,9 @@ namespace ts { * @param fileName The name of the file to be released * @param compilationSettings The compilation settings used to acquire the file */ - releaseDocument(fileName: string, compilationSettings: CompilerOptions): void + releaseDocument(fileName: string, compilationSettings: CompilerOptions): void; + + reportStats(): string; } // TODO: move these to enums @@ -1751,18 +1759,31 @@ namespace ts { sourceFile.version = version; sourceFile.scriptSnapshot = scriptSnapshot; } - + + export interface TranspileOptions { + compilerOptions?: CompilerOptions; + fileName?: string; + reportDiagnostics?: boolean; + moduleName?: string; + } + + export interface TranspileOutput { + outputText: string; + diagnostics?: Diagnostic[]; + sourceMapText?: string; + } + /* * This function will compile source text from 'input' argument using specified compiler options. * If not options are provided - it will use a set of default compiler options. - * Extra compiler options that will unconditionally be used bu this function are: + * Extra compiler options that will unconditionally be used by this function are: * - isolatedModules = true * - allowNonTsExtensions = true * - noLib = true * - noResolve = true - */ - export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string { - let options = compilerOptions ? clone(compilerOptions) : getDefaultCompilerOptions(); + */ + export function transpileModule(input: string, transpileOptions?: TranspileOptions): TranspileOutput { + let options = transpileOptions.compilerOptions ? clone(transpileOptions.compilerOptions) : getDefaultCompilerOptions(); options.isolatedModules = true; @@ -1778,23 +1799,30 @@ namespace ts { options.noResolve = true; // Parse - let inputFileName = fileName || "module.ts"; + let inputFileName = transpileOptions.fileName || "module.ts"; let sourceFile = createSourceFile(inputFileName, input, options.target); - if (moduleName) { - sourceFile.moduleName = moduleName; + if (transpileOptions.moduleName) { + sourceFile.moduleName = transpileOptions.moduleName; } let newLine = getNewLineCharacter(options); // Output let outputText: string; + let sourceMapText: string; // Create a compilerHost object to allow the compiler to read and write files let compilerHost: CompilerHost = { getSourceFile: (fileName, target) => fileName === inputFileName ? sourceFile : undefined, writeFile: (name, text, writeByteOrderMark) => { - Debug.assert(outputText === undefined, "Unexpected multiple outputs for the file: " + name); - outputText = text; + if (fileExtensionIs(name, ".map")) { + Debug.assert(sourceMapText === undefined, `Unexpected multiple source map outputs for the file '${name}'`); + sourceMapText = text; + } + else { + Debug.assert(outputText === undefined, "Unexpected multiple outputs for the file: " + name); + outputText = text; + } }, getDefaultLibFileName: () => "lib.d.ts", useCaseSensitiveFileNames: () => false, @@ -1804,16 +1832,29 @@ namespace ts { }; let program = createProgram([inputFileName], options, compilerHost); - - addRange(/*to*/ diagnostics, /*from*/ program.getSyntacticDiagnostics(sourceFile)); - addRange(/*to*/ diagnostics, /*from*/ program.getOptionsDiagnostics()); - + + let diagnostics: Diagnostic[]; + if (transpileOptions.reportDiagnostics) { + diagnostics = []; + addRange(/*to*/ diagnostics, /*from*/ program.getSyntacticDiagnostics(sourceFile)); + addRange(/*to*/ diagnostics, /*from*/ program.getOptionsDiagnostics()); + } // Emit program.emit(); Debug.assert(outputText !== undefined, "Output generation failed"); - return outputText; + return { outputText, diagnostics, sourceMapText }; + } + + /* + * This is a shortcut function for transpileModule - it accepts transpileOptions as parameters and returns only outputText part of the result. + */ + export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string { + let output = transpileModule(input, { compilerOptions, fileName, reportDiagnostics: !!diagnostics, moduleName }); + // addRange correctly handles cases when wither 'from' or 'to' argument is missing + addRange(diagnostics, output.diagnostics); + return output.outputText; } export function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile { @@ -3234,8 +3275,19 @@ namespace ts { // We are *only* completing on properties from the type being destructured. isNewIdentifierLocation = false; - typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer); - existingMembers = (objectLikeContainer).elements; + let rootDeclaration = getRootDeclaration(objectLikeContainer.parent); + if (isVariableLike(rootDeclaration)) { + // We don't want to complete using the type acquired by the shape + // of the binding pattern; we are only interested in types acquired + // through type declaration or inference. + if (rootDeclaration.initializer || rootDeclaration.type) { + typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer); + existingMembers = (objectLikeContainer).elements; + } + } + else { + Debug.fail("Root declaration is not variable-like.") + } } else { Debug.fail("Expected object literal or binding pattern, got " + objectLikeContainer.kind); @@ -3340,23 +3392,36 @@ namespace ts { case SyntaxKind.LessThanSlashToken: case SyntaxKind.SlashToken: case SyntaxKind.Identifier: - if(parent && (parent.kind === SyntaxKind.JsxSelfClosingElement || parent.kind === SyntaxKind.JsxOpeningElement)) { + case SyntaxKind.JsxAttribute: + case SyntaxKind.JsxSpreadAttribute: + if (parent && (parent.kind === SyntaxKind.JsxSelfClosingElement || parent.kind === SyntaxKind.JsxOpeningElement)) { return parent; } break; + // The context token is the closing } or " of an attribute, which means + // its parent is a JsxExpression, whose parent is a JsxAttribute, + // whose parent is a JsxOpeningLikeElement + case SyntaxKind.StringLiteral: + if (parent && ((parent.kind === SyntaxKind.JsxAttribute) || (parent.kind === SyntaxKind.JsxSpreadAttribute))) { + return parent.parent; + } + + break; + case SyntaxKind.CloseBraceToken: - // The context token is the closing } of an attribute, which means - // its parent is a JsxExpression, whose parent is a JsxAttribute, - // whose parent is a JsxOpeningLikeElement - if(parent && + if (parent && parent.kind === SyntaxKind.JsxExpression && parent.parent && - parent.parent.kind === SyntaxKind.JsxAttribute) { + (parent.parent.kind === SyntaxKind.JsxAttribute)) { return parent.parent.parent; } + if (parent && parent.kind === SyntaxKind.JsxSpreadAttribute) { + return parent.parent; + } + break; } } diff --git a/src/services/shims.ts b/src/services/shims.ts index e2055b3de77..ae853e1c72a 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -454,11 +454,11 @@ namespace ts { } } - export function realizeDiagnostics(diagnostics: Diagnostic[], newLine: string): { message: string; start: number; length: number; category: string; } []{ + export function realizeDiagnostics(diagnostics: Diagnostic[], newLine: string): { message: string; start: number; length: number; category: string; code: number; } []{ return diagnostics.map(d => realizeDiagnostic(d, newLine)); } - function realizeDiagnostic(diagnostic: Diagnostic, newLine: string): { message: string; start: number; length: number; category: string; } { + function realizeDiagnostic(diagnostic: Diagnostic, newLine: string): { message: string; start: number; length: number; category: string; code: number; } { return { message: flattenDiagnosticMessageText(diagnostic.messageText, newLine), start: diagnostic.start, diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index f44ebade2a7..df321647e5c 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -611,13 +611,11 @@ namespace ts.SignatureHelp { let displayParts = mapToDisplayParts(writer => typeChecker.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, invocation)); - let isOptional = hasQuestionToken(parameter.valueDeclaration); - return { name: parameter.name, documentation: parameter.getDocumentationComment(), displayParts, - isOptional + isOptional: typeChecker.isOptionalParameter(parameter.valueDeclaration) }; } diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 30951b90fca..9d44dfdc03e 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -75,28 +75,28 @@ function delint(sourceFile) { delintNode(sourceFile); function delintNode(node) { switch (node.kind) { - case 196 /* ForStatement */: - case 197 /* ForInStatement */: - case 195 /* WhileStatement */: - case 194 /* DoStatement */: - if (node.statement.kind !== 189 /* Block */) { + case 197 /* ForStatement */: + case 198 /* ForInStatement */: + case 196 /* WhileStatement */: + case 195 /* DoStatement */: + if (node.statement.kind !== 190 /* Block */) { report(node, "A looping statement's contents should be wrapped in a block body."); } break; - case 193 /* IfStatement */: + case 194 /* IfStatement */: var ifStatement = node; - if (ifStatement.thenStatement.kind !== 189 /* Block */) { + if (ifStatement.thenStatement.kind !== 190 /* Block */) { report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body."); } if (ifStatement.elseStatement && - ifStatement.elseStatement.kind !== 189 /* Block */ && - ifStatement.elseStatement.kind !== 193 /* IfStatement */) { + ifStatement.elseStatement.kind !== 190 /* Block */ && + ifStatement.elseStatement.kind !== 194 /* IfStatement */) { report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body."); } break; - case 178 /* BinaryExpression */: + case 179 /* BinaryExpression */: var op = node.operatorToken.kind; - if (op === 29 /* EqualsEqualsToken */ || op == 30 /* ExclamationEqualsToken */) { + if (op === 30 /* EqualsEqualsToken */ || op == 31 /* ExclamationEqualsToken */) { report(node, "Use '===' and '!=='."); } break; diff --git a/tests/baselines/reference/ES5For-of30.errors.txt b/tests/baselines/reference/ES5For-of30.errors.txt index e99b8284bf3..ee2d14a4f58 100644 --- a/tests/baselines/reference/ES5For-of30.errors.txt +++ b/tests/baselines/reference/ES5For-of30.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,6): error TS2461: Type 'string | number' is not an array type. +tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,6): error TS2461: Type 'number | string' is not an array type. tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,7): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,14): error TS2322: Type 'string' is not assignable to type 'number'. @@ -8,7 +8,7 @@ tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,14): error var tuple: [number, string] = [2, "3"]; for ([a = 1, b = ""] of tuple) { ~~~~~~~~~~~~~~~ -!!! error TS2461: Type 'string | number' is not an array type. +!!! error TS2461: Type 'number | string' is not an array type. ~ !!! error TS2322: Type 'number' is not assignable to type 'string'. ~ diff --git a/tests/baselines/reference/ES5For-ofTypeCheck11.errors.txt b/tests/baselines/reference/ES5For-ofTypeCheck11.errors.txt index 635bb09616a..57a28b6612c 100644 --- a/tests/baselines/reference/ES5For-ofTypeCheck11.errors.txt +++ b/tests/baselines/reference/ES5For-ofTypeCheck11.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck11.ts(3,6): error TS2322: Type 'string | number' is not assignable to type 'string'. +tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck11.ts(3,6): error TS2322: Type 'number | string' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. @@ -7,5 +7,5 @@ tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck11.ts(3,6) var v: string; for (v of union) { } ~ -!!! error TS2322: Type 'string | number' is not assignable to type 'string'. +!!! error TS2322: Type 'number | string' 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/ES5For-ofTypeCheck5.types b/tests/baselines/reference/ES5For-ofTypeCheck5.types index ed3d13f3918..f24aa54c7f3 100644 --- a/tests/baselines/reference/ES5For-ofTypeCheck5.types +++ b/tests/baselines/reference/ES5For-ofTypeCheck5.types @@ -3,6 +3,6 @@ var union: string | number[]; >union : string | number[] for (var v of union) { } ->v : string | number +>v : number | string >union : string | number[] diff --git a/tests/baselines/reference/ES5For-ofTypeCheck9.errors.txt b/tests/baselines/reference/ES5For-ofTypeCheck9.errors.txt index 156eb188803..3f382d72a08 100644 --- a/tests/baselines/reference/ES5For-ofTypeCheck9.errors.txt +++ b/tests/baselines/reference/ES5For-ofTypeCheck9.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck9.ts(2,15): error TS2461: Type 'number | symbol | string[]' is not an array type. +tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck9.ts(2,15): error TS2461: Type 'string[] | number | symbol' is not an array type. ==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck9.ts (1 errors) ==== var union: string | string[] | number | symbol; for (let v of union) { } ~~~~~ -!!! error TS2461: Type 'number | symbol | string[]' is not an array type. \ No newline at end of file +!!! error TS2461: Type 'string[] | number | symbol' is not an array type. \ No newline at end of file diff --git a/tests/baselines/reference/TypeGuardWithEnumUnion.types b/tests/baselines/reference/TypeGuardWithEnumUnion.types index 61cce562ba5..453ec220f02 100644 --- a/tests/baselines/reference/TypeGuardWithEnumUnion.types +++ b/tests/baselines/reference/TypeGuardWithEnumUnion.types @@ -6,14 +6,14 @@ enum Color { R, G, B } >B : Color function f1(x: Color | string) { ->f1 : (x: string | Color) => void ->x : string | Color +>f1 : (x: Color | string) => void +>x : Color | string >Color : Color if (typeof x === "number") { >typeof x === "number" : boolean >typeof x : string ->x : string | Color +>x : Color | string >"number" : string var y = x; @@ -35,14 +35,14 @@ function f1(x: Color | string) { } function f2(x: Color | string | string[]) { ->f2 : (x: string | Color | string[]) => void ->x : string | Color | string[] +>f2 : (x: Color | string | string[]) => void +>x : Color | string | string[] >Color : Color if (typeof x === "object") { >typeof x === "object" : boolean >typeof x : string ->x : string | Color | string[] +>x : Color | string | string[] >"object" : string var y = x; @@ -55,7 +55,7 @@ function f2(x: Color | string | string[]) { if (typeof x === "number") { >typeof x === "number" : boolean >typeof x : string ->x : string | Color | string[] +>x : Color | string | string[] >"number" : string var z = x; @@ -77,7 +77,7 @@ function f2(x: Color | string | string[]) { if (typeof x === "string") { >typeof x === "string" : boolean >typeof x : string ->x : string | Color | string[] +>x : Color | string | string[] >"string" : string var a = x; diff --git a/tests/baselines/reference/aliasUsageInOrExpression.types b/tests/baselines/reference/aliasUsageInOrExpression.types index e7ca8639762..f009e7084eb 100644 --- a/tests/baselines/reference/aliasUsageInOrExpression.types +++ b/tests/baselines/reference/aliasUsageInOrExpression.types @@ -34,7 +34,7 @@ var d2: IHasVisualizationModel = i || moduleA; var d2: IHasVisualizationModel = moduleA || i; >d2 : IHasVisualizationModel >IHasVisualizationModel : IHasVisualizationModel ->moduleA || i : IHasVisualizationModel +>moduleA || i : typeof moduleA >moduleA : typeof moduleA >i : IHasVisualizationModel diff --git a/tests/baselines/reference/aliasesInSystemModule1.errors.txt b/tests/baselines/reference/aliasesInSystemModule1.errors.txt new file mode 100644 index 00000000000..9b89332e458 --- /dev/null +++ b/tests/baselines/reference/aliasesInSystemModule1.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/aliasesInSystemModule1.ts(2,24): error TS2307: Cannot find module 'foo'. + + +==== tests/cases/compiler/aliasesInSystemModule1.ts (1 errors) ==== + + import alias = require('foo'); + ~~~~~ +!!! error TS2307: Cannot find module 'foo'. + import cls = alias.Class; + export import cls2 = alias.Class; + + let x = new alias.Class(); + let y = new cls(); + let z = new cls2(); + + module M { + export import cls = alias.Class; + let x = new alias.Class(); + let y = new cls(); + let z = new cls2(); + } + \ No newline at end of file diff --git a/tests/baselines/reference/aliasesInSystemModule1.js b/tests/baselines/reference/aliasesInSystemModule1.js new file mode 100644 index 00000000000..28ac1e9b4ad --- /dev/null +++ b/tests/baselines/reference/aliasesInSystemModule1.js @@ -0,0 +1,42 @@ +//// [aliasesInSystemModule1.ts] + +import alias = require('foo'); +import cls = alias.Class; +export import cls2 = alias.Class; + +let x = new alias.Class(); +let y = new cls(); +let z = new cls2(); + +module M { + export import cls = alias.Class; + let x = new alias.Class(); + let y = new cls(); + let z = new cls2(); +} + + +//// [aliasesInSystemModule1.js] +System.register(['foo'], function(exports_1) { + var alias; + var cls, cls2, x, y, z, M; + return { + setters:[ + function (_alias) { + alias = _alias; + }], + execute: function() { + cls = alias.Class; + exports_1("cls2", cls2 = alias.Class); + x = new alias.Class(); + y = new cls(); + z = new cls2(); + (function (M) { + M.cls = alias.Class; + var x = new alias.Class(); + var y = new M.cls(); + var z = new cls2(); + })(M || (M = {})); + } + } +}); diff --git a/tests/baselines/reference/aliasesInSystemModule2.errors.txt b/tests/baselines/reference/aliasesInSystemModule2.errors.txt new file mode 100644 index 00000000000..618e61c7f3c --- /dev/null +++ b/tests/baselines/reference/aliasesInSystemModule2.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/aliasesInSystemModule2.ts(2,21): error TS2307: Cannot find module 'foo'. + + +==== tests/cases/compiler/aliasesInSystemModule2.ts (1 errors) ==== + + import {alias} from "foo"; + ~~~~~ +!!! error TS2307: Cannot find module 'foo'. + import cls = alias.Class; + export import cls2 = alias.Class; + + let x = new alias.Class(); + let y = new cls(); + let z = new cls2(); + + module M { + export import cls = alias.Class; + let x = new alias.Class(); + let y = new cls(); + let z = new cls2(); + } \ No newline at end of file diff --git a/tests/baselines/reference/aliasesInSystemModule2.js b/tests/baselines/reference/aliasesInSystemModule2.js new file mode 100644 index 00000000000..0256d03a179 --- /dev/null +++ b/tests/baselines/reference/aliasesInSystemModule2.js @@ -0,0 +1,41 @@ +//// [aliasesInSystemModule2.ts] + +import {alias} from "foo"; +import cls = alias.Class; +export import cls2 = alias.Class; + +let x = new alias.Class(); +let y = new cls(); +let z = new cls2(); + +module M { + export import cls = alias.Class; + let x = new alias.Class(); + let y = new cls(); + let z = new cls2(); +} + +//// [aliasesInSystemModule2.js] +System.register(["foo"], function(exports_1) { + var foo_1; + var cls, cls2, x, y, z, M; + return { + setters:[ + function (_foo_1) { + foo_1 = _foo_1; + }], + execute: function() { + cls = foo_1.alias.Class; + exports_1("cls2", cls2 = foo_1.alias.Class); + x = new foo_1.alias.Class(); + y = new cls(); + z = new cls2(); + (function (M) { + M.cls = foo_1.alias.Class; + var x = new foo_1.alias.Class(); + var y = new M.cls(); + var z = new cls2(); + })(M || (M = {})); + } + } +}); diff --git a/tests/baselines/reference/apparentTypeSupertype.errors.txt b/tests/baselines/reference/apparentTypeSupertype.errors.txt index 7d653f34bf9..5fe5c92a5b3 100644 --- a/tests/baselines/reference/apparentTypeSupertype.errors.txt +++ b/tests/baselines/reference/apparentTypeSupertype.errors.txt @@ -1,6 +1,7 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts(9,7): error TS2415: Class 'Derived' incorrectly extends base class 'Base'. Types of property 'x' are incompatible. Type 'U' is not assignable to type 'string'. + Type 'String' is not assignable to type 'string'. ==== tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts (1 errors) ==== @@ -17,5 +18,6 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSuperty !!! error TS2415: Class 'Derived' incorrectly extends base class 'Base'. !!! error TS2415: Types of property 'x' are incompatible. !!! error TS2415: Type 'U' is not assignable to type 'string'. +!!! error TS2415: Type 'String' is not assignable to type 'string'. x: U; } \ No newline at end of file diff --git a/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt b/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt index 391fbf42384..d13e0a265f7 100644 --- a/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt +++ b/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt @@ -1,6 +1,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(13,12): error TS2493: Tuple type '[string, number]' with length '2' cannot be assigned to tuple with length '3'. tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(14,12): error TS2460: Type 'StrNum' has no property '2'. tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(15,5): error TS2461: Type '{ 0: string; 1: number; }' is not an array type. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(15,12): error TS2460: Type '{ 0: string; 1: number; }' has no property '2'. tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(16,5): error TS2322: Type '[string, number]' is not assignable to type '[number, number, number]'. Types of property '0' are incompatible. Type 'string' is not assignable to type 'number'. @@ -46,7 +47,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error Type 'string' is not assignable to type 'number'. -==== tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts (18 errors) ==== +==== tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts (19 errors) ==== interface StrNum extends Array { 0: string; 1: number; @@ -68,6 +69,8 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error var [g, h, i] = z; ~~~~~~~~~ !!! error TS2461: Type '{ 0: string; 1: number; }' is not an array type. + ~ +!!! error TS2460: Type '{ 0: string; 1: number; }' has no property '2'. var j1: [number, number, number] = x; ~~ !!! error TS2322: Type '[string, number]' is not assignable to type '[number, number, number]'. diff --git a/tests/baselines/reference/arrayBestCommonTypes.types b/tests/baselines/reference/arrayBestCommonTypes.types index 5650efc9ae7..9b05aff5ac6 100644 --- a/tests/baselines/reference/arrayBestCommonTypes.types +++ b/tests/baselines/reference/arrayBestCommonTypes.types @@ -294,8 +294,8 @@ module EmptyTypes { // 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; }[] +>a1 : ({ x: number; y: string; } | { x: string; y: string; } | { x: any; y: string; })[] +>[{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }] : ({ x: number; y: string; } | { x: string; y: string; } | { x: any; y: string; })[] >{ x: 0, y: 'a' } : { x: number; y: string; } >x : number >0 : number @@ -313,8 +313,8 @@ module EmptyTypes { >'a' : 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; }[] +>a2 : ({ x: any; y: string; } | { x: number; y: string; } | { x: string; y: string; })[] +>[{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }] : ({ x: any; y: string; } | { x: number; y: string; } | { x: string; y: string; })[] >{ x: anyObj, y: 'a' } : { x: any; y: string; } >x : any >anyObj : any @@ -332,8 +332,8 @@ module EmptyTypes { >'a' : 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; }[] +>a3 : ({ x: number; y: string; } | { x: any; y: string; } | { x: string; y: string; })[] +>[{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }] : ({ x: number; y: string; } | { x: any; y: string; } | { x: string; y: string; })[] >{ x: 0, y: 'a' } : { x: number; y: string; } >x : number >0 : number @@ -366,22 +366,22 @@ module EmptyTypes { >base2 : typeof base2 var b1 = [baseObj, base2Obj, ifaceObj]; ->b1 : iface[] ->[baseObj, base2Obj, ifaceObj] : iface[] +>b1 : base[] +>[baseObj, base2Obj, ifaceObj] : base[] >baseObj : base >base2Obj : base2 >ifaceObj : iface var b2 = [base2Obj, baseObj, ifaceObj]; ->b2 : iface[] ->[base2Obj, baseObj, ifaceObj] : iface[] +>b2 : base2[] +>[base2Obj, baseObj, ifaceObj] : base2[] >base2Obj : base2 >baseObj : base >ifaceObj : iface var b3 = [baseObj, ifaceObj, base2Obj]; ->b3 : iface[] ->[baseObj, ifaceObj, base2Obj] : iface[] +>b3 : base[] +>[baseObj, ifaceObj, base2Obj] : base[] >baseObj : base >ifaceObj : iface >base2Obj : base2 @@ -639,7 +639,7 @@ module NonEmptyTypes { >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: number; y: base; })[] >{ x: 7, y: new derived() } : { x: number; y: derived; } >x : number >7 : number @@ -658,7 +658,7 @@ module NonEmptyTypes { >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: boolean; y: base; })[] >{ x: true, y: new derived() } : { x: boolean; y: derived; } >x : boolean >true : boolean @@ -697,8 +697,8 @@ module NonEmptyTypes { // 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; }[] +>a1 : ({ x: number; y: string; } | { x: string; y: string; } | { x: any; y: string; })[] +>[{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }] : ({ x: number; y: string; } | { x: string; y: string; } | { x: any; y: string; })[] >{ x: 0, y: 'a' } : { x: number; y: string; } >x : number >0 : number @@ -716,8 +716,8 @@ module NonEmptyTypes { >'a' : 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; }[] +>a2 : ({ x: any; y: string; } | { x: number; y: string; } | { x: string; y: string; })[] +>[{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }] : ({ x: any; y: string; } | { x: number; y: string; } | { x: string; y: string; })[] >{ x: anyObj, y: 'a' } : { x: any; y: string; } >x : any >anyObj : any @@ -735,8 +735,8 @@ module NonEmptyTypes { >'a' : 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; }[] +>a3 : ({ x: number; y: string; } | { x: any; y: string; } | { x: string; y: string; })[] +>[{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }] : ({ x: number; y: string; } | { x: any; y: string; } | { x: string; y: string; })[] >{ x: 0, y: 'a' } : { x: number; y: string; } >x : number >0 : number @@ -769,29 +769,29 @@ module NonEmptyTypes { >base2 : typeof base2 var b1 = [baseObj, base2Obj, ifaceObj]; ->b1 : iface[] ->[baseObj, base2Obj, ifaceObj] : iface[] +>b1 : (base | base2 | iface)[] +>[baseObj, base2Obj, ifaceObj] : (base | base2 | iface)[] >baseObj : base >base2Obj : base2 >ifaceObj : iface var b2 = [base2Obj, baseObj, ifaceObj]; ->b2 : iface[] ->[base2Obj, baseObj, ifaceObj] : iface[] +>b2 : (base2 | base | iface)[] +>[base2Obj, baseObj, ifaceObj] : (base2 | base | iface)[] >base2Obj : base2 >baseObj : base >ifaceObj : iface var b3 = [baseObj, ifaceObj, base2Obj]; ->b3 : iface[] ->[baseObj, ifaceObj, base2Obj] : iface[] +>b3 : (base | iface | base2)[] +>[baseObj, ifaceObj, base2Obj] : (base | iface | base2)[] >baseObj : base >ifaceObj : iface >base2Obj : base2 var b4 = [ifaceObj, baseObj, base2Obj]; ->b4 : iface[] ->[ifaceObj, baseObj, base2Obj] : iface[] +>b4 : (iface | base | base2)[] +>[ifaceObj, baseObj, base2Obj] : (iface | base | base2)[] >ifaceObj : iface >baseObj : base >base2Obj : base2 diff --git a/tests/baselines/reference/arrayCast.errors.txt b/tests/baselines/reference/arrayCast.errors.txt index 10562cc57e4..82b4b856a97 100644 --- a/tests/baselines/reference/arrayCast.errors.txt +++ b/tests/baselines/reference/arrayCast.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/arrayCast.ts(3,1): error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other. Type '{ foo: string; }' is not assignable to type '{ id: number; }'. - Property 'id' is missing in type '{ foo: string; }'. + Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'. ==== tests/cases/compiler/arrayCast.ts (1 errors) ==== @@ -10,7 +10,7 @@ tests/cases/compiler/arrayCast.ts(3,1): error TS2352: Neither type '{ foo: strin ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other. !!! error TS2352: Type '{ foo: string; }' is not assignable to type '{ id: number; }'. -!!! error TS2352: Property 'id' is missing in type '{ foo: string; }'. +!!! error TS2352: Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'. // Should succeed, as the {} element causes the type of the array to be {}[] <{ id: number; }[]>[{ foo: "s" }, {}]; \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt index 3e9777aea7c..72ba1411320 100644 --- a/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt +++ b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(8,5): error TS2322: Type '[number, number, number, string]' is not assignable to type '[number, number, 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 '() => number | string' is not assignable to type '() => number'. + Type 'number | string' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(14,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. Property '0' is missing in type 'number[]'. @@ -19,8 +19,8 @@ tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionConte ~~~~ !!! error TS2322: Type '[number, number, number, string]' is not assignable to type '[number, number, 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 '() => number | string' is not assignable to type '() => number'. +!!! error TS2322: Type 'number | string' is not assignable to type 'number'. !!! error TS2322: Type 'string' is not assignable to type 'number'. // In a contextually typed array literal expression containing one or more spread elements, diff --git a/tests/baselines/reference/arrayLiteralTypeInference.errors.txt b/tests/baselines/reference/arrayLiteralTypeInference.errors.txt new file mode 100644 index 00000000000..105375f2e74 --- /dev/null +++ b/tests/baselines/reference/arrayLiteralTypeInference.errors.txt @@ -0,0 +1,72 @@ +tests/cases/compiler/arrayLiteralTypeInference.ts(13,5): error TS2322: Type '({ id: number; trueness: boolean; } | { id: number; name: string; })[]' is not assignable to type 'Action[]'. + Type '{ id: number; trueness: boolean; } | { id: number; name: string; }' is not assignable to type 'Action'. + Type '{ id: number; trueness: boolean; }' is not assignable to type 'Action'. + Object literal may only specify known properties, and 'trueness' does not exist in type 'Action'. +tests/cases/compiler/arrayLiteralTypeInference.ts(29,5): error TS2322: Type '({ id: number; trueness: boolean; } | { id: number; name: string; })[]' is not assignable to type '{ id: number; }[]'. + Type '{ id: number; trueness: boolean; } | { id: number; name: string; }' is not assignable to type '{ id: number; }'. + Type '{ id: number; trueness: boolean; }' is not assignable to type '{ id: number; }'. + Object literal may only specify known properties, and 'trueness' does not exist in type '{ id: number; }'. + + +==== tests/cases/compiler/arrayLiteralTypeInference.ts (2 errors) ==== + class Action { + id: number; + } + + class ActionA extends Action { + value: string; + } + + class ActionB extends Action { + trueNess: boolean; + } + + var x1: Action[] = [ + ~~ +!!! error TS2322: Type '({ id: number; trueness: boolean; } | { id: number; name: string; })[]' is not assignable to type 'Action[]'. +!!! error TS2322: Type '{ id: number; trueness: boolean; } | { id: number; name: string; }' is not assignable to type 'Action'. +!!! error TS2322: Type '{ id: number; trueness: boolean; }' is not assignable to type 'Action'. +!!! error TS2322: Object literal may only specify known properties, and 'trueness' does not exist in type 'Action'. + { id: 2, trueness: false }, + { id: 3, name: "three" } + ] + + var x2: Action[] = [ + new ActionA(), + new ActionB() + ] + + var x3: Action[] = [ + new Action(), + new ActionA(), + new ActionB() + ] + + var z1: { id: number }[] = + ~~ +!!! error TS2322: Type '({ id: number; trueness: boolean; } | { id: number; name: string; })[]' is not assignable to type '{ id: number; }[]'. +!!! error TS2322: Type '{ id: number; trueness: boolean; } | { id: number; name: string; }' is not assignable to type '{ id: number; }'. +!!! error TS2322: Type '{ id: number; trueness: boolean; }' is not assignable to type '{ id: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'trueness' does not exist in type '{ id: number; }'. + [ + { id: 2, trueness: false }, + { id: 3, name: "three" } + ] + + var z2: { id: number }[] = + [ + new ActionA(), + new ActionB() + ] + + var z3: { id: number }[] = + [ + new Action(), + new ActionA(), + new ActionB() + ] + + + + + \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiteralTypeInference.symbols b/tests/baselines/reference/arrayLiteralTypeInference.symbols deleted file mode 100644 index 005cb57f6c4..00000000000 --- a/tests/baselines/reference/arrayLiteralTypeInference.symbols +++ /dev/null @@ -1,113 +0,0 @@ -=== tests/cases/compiler/arrayLiteralTypeInference.ts === -class Action { ->Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0)) - - id: number; ->id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 0, 14)) -} - -class ActionA extends Action { ->ActionA : Symbol(ActionA, Decl(arrayLiteralTypeInference.ts, 2, 1)) ->Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0)) - - value: string; ->value : Symbol(value, Decl(arrayLiteralTypeInference.ts, 4, 30)) -} - -class ActionB extends Action { ->ActionB : Symbol(ActionB, Decl(arrayLiteralTypeInference.ts, 6, 1)) ->Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0)) - - trueNess: boolean; ->trueNess : Symbol(trueNess, Decl(arrayLiteralTypeInference.ts, 8, 30)) -} - -var x1: Action[] = [ ->x1 : Symbol(x1, Decl(arrayLiteralTypeInference.ts, 12, 3)) ->Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0)) - - { id: 2, trueness: false }, ->id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 13, 5)) ->trueness : Symbol(trueness, Decl(arrayLiteralTypeInference.ts, 13, 12)) - - { id: 3, name: "three" } ->id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 14, 5)) ->name : Symbol(name, Decl(arrayLiteralTypeInference.ts, 14, 12)) - -] - -var x2: Action[] = [ ->x2 : Symbol(x2, Decl(arrayLiteralTypeInference.ts, 17, 3)) ->Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0)) - - new ActionA(), ->ActionA : Symbol(ActionA, Decl(arrayLiteralTypeInference.ts, 2, 1)) - - new ActionB() ->ActionB : Symbol(ActionB, Decl(arrayLiteralTypeInference.ts, 6, 1)) - -] - -var x3: Action[] = [ ->x3 : Symbol(x3, Decl(arrayLiteralTypeInference.ts, 22, 3)) ->Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0)) - - new Action(), ->Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0)) - - new ActionA(), ->ActionA : Symbol(ActionA, Decl(arrayLiteralTypeInference.ts, 2, 1)) - - new ActionB() ->ActionB : Symbol(ActionB, Decl(arrayLiteralTypeInference.ts, 6, 1)) - -] - -var z1: { id: number }[] = ->z1 : Symbol(z1, Decl(arrayLiteralTypeInference.ts, 28, 3)) ->id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 28, 9)) - - [ - { id: 2, trueness: false }, ->id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 30, 9)) ->trueness : Symbol(trueness, Decl(arrayLiteralTypeInference.ts, 30, 16)) - - { id: 3, name: "three" } ->id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 31, 9)) ->name : Symbol(name, Decl(arrayLiteralTypeInference.ts, 31, 16)) - - ] - -var z2: { id: number }[] = ->z2 : Symbol(z2, Decl(arrayLiteralTypeInference.ts, 34, 3)) ->id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 34, 9)) - - [ - new ActionA(), ->ActionA : Symbol(ActionA, Decl(arrayLiteralTypeInference.ts, 2, 1)) - - new ActionB() ->ActionB : Symbol(ActionB, Decl(arrayLiteralTypeInference.ts, 6, 1)) - - ] - -var z3: { id: number }[] = ->z3 : Symbol(z3, Decl(arrayLiteralTypeInference.ts, 40, 3)) ->id : Symbol(id, Decl(arrayLiteralTypeInference.ts, 40, 9)) - - [ - new Action(), ->Action : Symbol(Action, Decl(arrayLiteralTypeInference.ts, 0, 0)) - - new ActionA(), ->ActionA : Symbol(ActionA, Decl(arrayLiteralTypeInference.ts, 2, 1)) - - new ActionB() ->ActionB : Symbol(ActionB, Decl(arrayLiteralTypeInference.ts, 6, 1)) - - ] - - - - - diff --git a/tests/baselines/reference/arrayLiteralTypeInference.types b/tests/baselines/reference/arrayLiteralTypeInference.types deleted file mode 100644 index 660592fceb8..00000000000 --- a/tests/baselines/reference/arrayLiteralTypeInference.types +++ /dev/null @@ -1,144 +0,0 @@ -=== tests/cases/compiler/arrayLiteralTypeInference.ts === -class Action { ->Action : Action - - id: number; ->id : number -} - -class ActionA extends Action { ->ActionA : ActionA ->Action : Action - - value: string; ->value : string -} - -class ActionB extends Action { ->ActionB : ActionB ->Action : Action - - trueNess: boolean; ->trueNess : boolean -} - -var x1: Action[] = [ ->x1 : Action[] ->Action : 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; } ->id : number ->2 : number ->trueness : boolean ->false : boolean - - { id: 3, name: "three" } ->{ id: 3, name: "three" } : { id: number; name: string; } ->id : number ->3 : number ->name : string ->"three" : string - -] - -var x2: Action[] = [ ->x2 : Action[] ->Action : Action ->[ new ActionA(), new ActionB()] : (ActionA | ActionB)[] - - new ActionA(), ->new ActionA() : ActionA ->ActionA : typeof ActionA - - new ActionB() ->new ActionB() : ActionB ->ActionB : typeof ActionB - -] - -var x3: Action[] = [ ->x3 : Action[] ->Action : Action ->[ new Action(), new ActionA(), new ActionB()] : Action[] - - new Action(), ->new Action() : Action ->Action : typeof Action - - new ActionA(), ->new ActionA() : ActionA ->ActionA : typeof ActionA - - new ActionB() ->new ActionB() : ActionB ->ActionB : typeof ActionB - -] - -var z1: { id: number }[] = ->z1 : { id: number; }[] ->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; } ->id : number ->2 : number ->trueness : boolean ->false : boolean - - { id: 3, name: "three" } ->{ id: 3, name: "three" } : { id: number; name: string; } ->id : number ->3 : number ->name : string ->"three" : string - - ] - -var z2: { id: number }[] = ->z2 : { id: number; }[] ->id : number - - [ ->[ new ActionA(), new ActionB() ] : (ActionA | ActionB)[] - - new ActionA(), ->new ActionA() : ActionA ->ActionA : typeof ActionA - - new ActionB() ->new ActionB() : ActionB ->ActionB : typeof ActionB - - ] - -var z3: { id: number }[] = ->z3 : { id: number; }[] ->id : number - - [ ->[ new Action(), new ActionA(), new ActionB() ] : Action[] - - new Action(), ->new Action() : Action ->Action : typeof Action - - new ActionA(), ->new ActionA() : ActionA ->ActionA : typeof ActionA - - new ActionB() ->new ActionB() : ActionB ->ActionB : typeof ActionB - - ] - - - - - diff --git a/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types b/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types index aad515b62ee..5b5a1be6b8a 100644 --- a/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types +++ b/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types @@ -23,8 +23,8 @@ var as = [a, b]; // { x: number; y?: number };[] >b : { x: number; z?: number; } var bs = [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; })[] +>bs : ({ x: number; z?: number; } | { x: number; y?: number; })[] +>[b, a] : ({ x: number; z?: number; } | { x: number; y?: number; })[] >b : { x: number; z?: number; } >a : { x: number; y?: number; } @@ -36,8 +36,8 @@ var cs = [a, b, c]; // { x: number; y?: 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: string) => number))[] +>[(x: Object) => 1, (x: string) => 2] : (((x: Object) => number) | ((x: string) => number))[] >(x: Object) => 1 : (x: Object) => number >x : Object >Object : Object @@ -47,8 +47,8 @@ var ds = [(x: Object) => 1, (x: string) => 2]; // { (x:Object) => number }[] >2 : number 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: Object) => number))[] +>[(x: string) => 2, (x: Object) => 1] : (((x: string) => number) | ((x: Object) => number))[] >(x: string) => 2 : (x: string) => number >x : string >2 : number diff --git a/tests/baselines/reference/arrayLiterals.errors.txt b/tests/baselines/reference/arrayLiterals.errors.txt new file mode 100644 index 00000000000..fd882804b8a --- /dev/null +++ b/tests/baselines/reference/arrayLiterals.errors.txt @@ -0,0 +1,50 @@ +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts(24,5): error TS2322: Type '({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]' is not assignable to type '{ [n: number]: { a: string; b: number; }; }'. + Index signatures are incompatible. + Type '{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }' is not assignable to type '{ a: string; b: number; }'. + Type '{ a: string; b: number; c: string; }' is not assignable to type '{ a: string; b: number; }'. + Object literal may only specify known properties, and 'c' does not exist in type '{ a: string; b: number; }'. + + +==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts (1 errors) ==== + // Empty array literal with no contextual type has type Undefined[] + + var arr1= [[], [1], ['']]; + + var arr2 = [[null], [1], ['']]; + + + // Array literal with elements of only EveryType E has type E[] + var stringArrArr = [[''], [""]]; + + var stringArr = ['', ""]; + + var numberArr = [0, 0.0, 0x00, 1e1]; + + var boolArr = [false, true, false, true]; + + class C { private p; } + var classArr = [new C(), new C()]; + + var classTypeArray = [C, C, C]; + 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 }]; + ~~~~~~~~ +!!! error TS2322: Type '({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]' is not assignable to type '{ [n: number]: { a: string; b: number; }; }'. +!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: Type '{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }' is not assignable to type '{ a: string; b: number; }'. +!!! error TS2322: Type '{ a: string; b: number; c: string; }' is not assignable to type '{ a: string; b: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'c' does not exist in type '{ a: string; b: number; }'. + var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; + + // Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] + class Base { private p; } + class Derived1 extends Base { private m }; + class Derived2 extends Base { private n }; + var context3: Base[] = [new Derived1(), new Derived2()]; + + // Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[] + var context4: Base[] = [new Derived1(), new Derived1()]; + + \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals.symbols b/tests/baselines/reference/arrayLiterals.symbols deleted file mode 100644 index b338e7ff6e6..00000000000 --- a/tests/baselines/reference/arrayLiterals.symbols +++ /dev/null @@ -1,94 +0,0 @@ -=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts === -// Empty array literal with no contextual type has type Undefined[] - -var arr1= [[], [1], ['']]; ->arr1 : Symbol(arr1, Decl(arrayLiterals.ts, 2, 3)) - -var arr2 = [[null], [1], ['']]; ->arr2 : Symbol(arr2, Decl(arrayLiterals.ts, 4, 3)) - - -// Array literal with elements of only EveryType E has type E[] -var stringArrArr = [[''], [""]]; ->stringArrArr : Symbol(stringArrArr, Decl(arrayLiterals.ts, 8, 3)) - -var stringArr = ['', ""]; ->stringArr : Symbol(stringArr, Decl(arrayLiterals.ts, 10, 3)) - -var numberArr = [0, 0.0, 0x00, 1e1]; ->numberArr : Symbol(numberArr, Decl(arrayLiterals.ts, 12, 3)) - -var boolArr = [false, true, false, true]; ->boolArr : Symbol(boolArr, Decl(arrayLiterals.ts, 14, 3)) - -class C { private p; } ->C : Symbol(C, Decl(arrayLiterals.ts, 14, 41)) ->p : Symbol(p, Decl(arrayLiterals.ts, 16, 9)) - -var classArr = [new C(), new C()]; ->classArr : Symbol(classArr, Decl(arrayLiterals.ts, 17, 3)) ->C : Symbol(C, Decl(arrayLiterals.ts, 14, 41)) ->C : Symbol(C, Decl(arrayLiterals.ts, 14, 41)) - -var classTypeArray = [C, C, C]; ->classTypeArray : Symbol(classTypeArray, Decl(arrayLiterals.ts, 19, 3), Decl(arrayLiterals.ts, 20, 3)) ->C : Symbol(C, Decl(arrayLiterals.ts, 14, 41)) ->C : Symbol(C, Decl(arrayLiterals.ts, 14, 41)) ->C : Symbol(C, Decl(arrayLiterals.ts, 14, 41)) - -var classTypeArray: Array; // Should OK, not be a parse error ->classTypeArray : Symbol(classTypeArray, Decl(arrayLiterals.ts, 19, 3), Decl(arrayLiterals.ts, 20, 3)) ->Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) ->C : Symbol(C, Decl(arrayLiterals.ts, 14, 41)) - -// 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 }]; ->context1 : Symbol(context1, Decl(arrayLiterals.ts, 23, 3)) ->n : Symbol(n, Decl(arrayLiterals.ts, 23, 17)) ->a : Symbol(a, Decl(arrayLiterals.ts, 23, 30)) ->b : Symbol(b, Decl(arrayLiterals.ts, 23, 41)) ->a : Symbol(a, Decl(arrayLiterals.ts, 23, 62)) ->b : Symbol(b, Decl(arrayLiterals.ts, 23, 69)) ->c : Symbol(c, Decl(arrayLiterals.ts, 23, 75)) ->a : Symbol(a, Decl(arrayLiterals.ts, 23, 86)) ->b : Symbol(b, Decl(arrayLiterals.ts, 23, 93)) ->c : Symbol(c, Decl(arrayLiterals.ts, 23, 99)) - -var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; ->context2 : Symbol(context2, Decl(arrayLiterals.ts, 24, 3)) ->a : Symbol(a, Decl(arrayLiterals.ts, 24, 17)) ->b : Symbol(b, Decl(arrayLiterals.ts, 24, 24)) ->c : Symbol(c, Decl(arrayLiterals.ts, 24, 30)) ->a : Symbol(a, Decl(arrayLiterals.ts, 24, 41)) ->b : Symbol(b, Decl(arrayLiterals.ts, 24, 48)) ->c : Symbol(c, Decl(arrayLiterals.ts, 24, 54)) - -// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] -class Base { private p; } ->Base : Symbol(Base, Decl(arrayLiterals.ts, 24, 63)) ->p : Symbol(p, Decl(arrayLiterals.ts, 27, 12)) - -class Derived1 extends Base { private m }; ->Derived1 : Symbol(Derived1, Decl(arrayLiterals.ts, 27, 25)) ->Base : Symbol(Base, Decl(arrayLiterals.ts, 24, 63)) ->m : Symbol(m, Decl(arrayLiterals.ts, 28, 29)) - -class Derived2 extends Base { private n }; ->Derived2 : Symbol(Derived2, Decl(arrayLiterals.ts, 28, 42)) ->Base : Symbol(Base, Decl(arrayLiterals.ts, 24, 63)) ->n : Symbol(n, Decl(arrayLiterals.ts, 29, 29)) - -var context3: Base[] = [new Derived1(), new Derived2()]; ->context3 : Symbol(context3, Decl(arrayLiterals.ts, 30, 3)) ->Base : Symbol(Base, Decl(arrayLiterals.ts, 24, 63)) ->Derived1 : Symbol(Derived1, Decl(arrayLiterals.ts, 27, 25)) ->Derived2 : Symbol(Derived2, Decl(arrayLiterals.ts, 28, 42)) - -// Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[] -var context4: Base[] = [new Derived1(), new Derived1()]; ->context4 : Symbol(context4, Decl(arrayLiterals.ts, 33, 3)) ->Base : Symbol(Base, Decl(arrayLiterals.ts, 24, 63)) ->Derived1 : Symbol(Derived1, Decl(arrayLiterals.ts, 27, 25)) ->Derived1 : Symbol(Derived1, Decl(arrayLiterals.ts, 27, 25)) - - diff --git a/tests/baselines/reference/arrayLiterals.types b/tests/baselines/reference/arrayLiterals.types deleted file mode 100644 index e103241dd0b..00000000000 --- a/tests/baselines/reference/arrayLiterals.types +++ /dev/null @@ -1,153 +0,0 @@ -=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts === -// Empty array literal with no contextual type has type Undefined[] - -var arr1= [[], [1], ['']]; ->arr1 : (number[] | string[])[] ->[[], [1], ['']] : (number[] | string[])[] ->[] : undefined[] ->[1] : number[] ->1 : number ->[''] : string[] ->'' : string - -var arr2 = [[null], [1], ['']]; ->arr2 : (number[] | string[])[] ->[[null], [1], ['']] : (number[] | string[])[] ->[null] : null[] ->null : null ->[1] : number[] ->1 : number ->[''] : string[] ->'' : string - - -// Array literal with elements of only EveryType E has type E[] -var stringArrArr = [[''], [""]]; ->stringArrArr : string[][] ->[[''], [""]] : string[][] ->[''] : string[] ->'' : string ->[""] : string[] ->"" : string - -var stringArr = ['', ""]; ->stringArr : string[] ->['', ""] : string[] ->'' : string ->"" : string - -var numberArr = [0, 0.0, 0x00, 1e1]; ->numberArr : number[] ->[0, 0.0, 0x00, 1e1] : number[] ->0 : number ->0.0 : number ->0x00 : number ->1e1 : number - -var boolArr = [false, true, false, true]; ->boolArr : boolean[] ->[false, true, false, true] : boolean[] ->false : boolean ->true : boolean ->false : boolean ->true : boolean - -class C { private p; } ->C : C ->p : any - -var classArr = [new C(), new C()]; ->classArr : C[] ->[new C(), new C()] : C[] ->new C() : C ->C : typeof C ->new C() : C ->C : typeof C - -var classTypeArray = [C, C, C]; ->classTypeArray : typeof C[] ->[C, C, C] : typeof C[] ->C : typeof C ->C : typeof C ->C : typeof C - -var classTypeArray: Array; // Should OK, not be a parse error ->classTypeArray : typeof C[] ->Array : T[] ->C : typeof C - -// 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 }]; ->context1 : { [n: number]: { a: string; b: number; }; } ->n : number ->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 ->'' : string ->b : number ->0 : number ->c : string ->'' : string ->{ a: "", b: 3, c: 0 } : { a: string; b: number; c: number; } ->a : string ->"" : string ->b : number ->3 : number ->c : number ->0 : number - -var 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 ->'' : string ->b : number ->0 : number ->c : string ->'' : string ->{ a: "", b: 3, c: 0 } : { a: string; b: number; c: number; } ->a : string ->"" : string ->b : number ->3 : number ->c : number ->0 : number - -// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] -class Base { private p; } ->Base : Base ->p : any - -class Derived1 extends Base { private m }; ->Derived1 : Derived1 ->Base : Base ->m : any - -class Derived2 extends Base { private n }; ->Derived2 : Derived2 ->Base : Base ->n : any - -var context3: Base[] = [new Derived1(), new Derived2()]; ->context3 : Base[] ->Base : Base ->[new Derived1(), new Derived2()] : (Derived1 | Derived2)[] ->new Derived1() : Derived1 ->Derived1 : typeof Derived1 ->new Derived2() : Derived2 ->Derived2 : typeof Derived2 - -// Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[] -var context4: Base[] = [new Derived1(), new Derived1()]; ->context4 : Base[] ->Base : Base ->[new Derived1(), new Derived1()] : Derived1[] ->new Derived1() : Derived1 ->Derived1 : typeof Derived1 ->new Derived1() : Derived1 ->Derived1 : typeof Derived1 - - diff --git a/tests/baselines/reference/arrayLiterals2ES5.types b/tests/baselines/reference/arrayLiterals2ES5.types index 6eae997f465..a9cf31611c2 100644 --- a/tests/baselines/reference/arrayLiterals2ES5.types +++ b/tests/baselines/reference/arrayLiterals2ES5.types @@ -24,8 +24,8 @@ var a1 = ["hello", "world"] >"world" : string var a2 = [, , , ...a0, "hello"]; ->a2 : (string | number)[] ->[, , , ...a0, "hello"] : (string | number)[] +>a2 : (number | string)[] +>[, , , ...a0, "hello"] : (number | string)[] > : undefined > : undefined > : undefined @@ -151,8 +151,8 @@ interface myArray2 extends Array { } >String : String var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[] ->d0 : (string | number | boolean)[] ->[1, true, ...temp,] : (string | number | boolean)[] +>d0 : (number | boolean | string)[] +>[1, true, ...temp,] : (number | boolean | string)[] >1 : number >true : boolean >...temp : string @@ -214,8 +214,8 @@ var d8: number[][] = [[...temp1]] >temp1 : number[] var d9 = [[...temp1], ...["hello"]]; ->d9 : (string | number[])[] ->[[...temp1], ...["hello"]] : (string | number[])[] +>d9 : (number[] | string)[] +>[[...temp1], ...["hello"]] : (number[] | string)[] >[...temp1] : number[] >...temp1 : number >temp1 : number[] diff --git a/tests/baselines/reference/arrayLiterals2ES6.types b/tests/baselines/reference/arrayLiterals2ES6.types index f05b0ca9282..b6bf4f1de1b 100644 --- a/tests/baselines/reference/arrayLiterals2ES6.types +++ b/tests/baselines/reference/arrayLiterals2ES6.types @@ -24,8 +24,8 @@ var a1 = ["hello", "world"] >"world" : string var a2 = [, , , ...a0, "hello"]; ->a2 : (string | number)[] ->[, , , ...a0, "hello"] : (string | number)[] +>a2 : (number | string)[] +>[, , , ...a0, "hello"] : (number | string)[] > : undefined > : undefined > : undefined @@ -140,8 +140,8 @@ interface myArray2 extends Array { } >String : String var d0 = [1, true, ...temp, ]; // has type (string|number|boolean)[] ->d0 : (string | number | boolean)[] ->[1, true, ...temp, ] : (string | number | boolean)[] +>d0 : (number | boolean | string)[] +>[1, true, ...temp, ] : (number | boolean | string)[] >1 : number >true : boolean >...temp : string @@ -176,10 +176,10 @@ var d4: myArray2 = [...temp, ...temp1]; >temp1 : number[] var d5 = [...a2]; ->d5 : (string | number)[] ->[...a2] : (string | number)[] ->...a2 : string | number ->a2 : (string | number)[] +>d5 : (number | string)[] +>[...a2] : (number | string)[] +>...a2 : number | string +>a2 : (number | string)[] var d6 = [...a3]; >d6 : number[] @@ -201,8 +201,8 @@ var d8: number[][] = [[...temp1]] >temp1 : number[] var d9 = [[...temp1], ...["hello"]]; ->d9 : (string | number[])[] ->[[...temp1], ...["hello"]] : (string | number[])[] +>d9 : (number[] | string)[] +>[[...temp1], ...["hello"]] : (number[] | string)[] >[...temp1] : number[] >...temp1 : number >temp1 : number[] diff --git a/tests/baselines/reference/arrayLiterals3.errors.txt b/tests/baselines/reference/arrayLiterals3.errors.txt index 36714162de0..637fb3e3bc4 100644 --- a/tests/baselines/reference/arrayLiterals3.errors.txt +++ b/tests/baselines/reference/arrayLiterals3.errors.txt @@ -5,18 +5,18 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(11,5): error Type 'string' is not assignable to type 'boolean'. tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(17,5): error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'. Types of property 'pop' are incompatible. - Type '() => string | number | boolean' is not assignable to type '() => number'. - Type 'string | number | boolean' is not assignable to type 'number'. + Type '() => number | string | boolean' is not assignable to type '() => number'. + Type 'number | string | boolean' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(32,5): error TS2322: Type '(number[] | string[])[]' is not assignable to type 'tup'. Property '0' is missing in type '(number[] | string[])[]'. tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(33,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. Property '0' is missing in type 'number[]'. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(number | string)[]' is not assignable to type 'myArray'. Types of property 'push' are incompatible. - Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. + Type '(...items: (number | string)[]) => number' is not assignable to type '(...items: Number[]) => number'. Types of parameters 'items' and 'items' are incompatible. - Type 'string | number' is not assignable to type 'Number'. + Type 'number | string' is not assignable to type 'Number'. Type 'string' is not assignable to type 'Number'. Property 'toFixed' is missing in type 'String'. @@ -49,8 +49,8 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error ~~~~~~~~ !!! error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'. !!! error TS2322: Types of property 'pop' are incompatible. -!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => number'. -!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'number'. +!!! error TS2322: Type '() => number | string | boolean' is not assignable to type '() => number'. +!!! error TS2322: Type 'number | string | boolean' is not assignable to type 'number'. !!! error TS2322: Type 'string' is not assignable to type 'number'. // The resulting type an array literal expression is determined as follows: @@ -76,11 +76,11 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error !!! error TS2322: Property '0' is missing in type 'number[]'. var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[] ~~ -!!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. +!!! error TS2322: Type '(number | string)[]' is not assignable to type 'myArray'. !!! error TS2322: Types of property 'push' are incompatible. -!!! error TS2322: Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. +!!! error TS2322: Type '(...items: (number | string)[]) => number' is not assignable to type '(...items: Number[]) => number'. !!! error TS2322: Types of parameters 'items' and 'items' are incompatible. -!!! error TS2322: Type 'string | number' is not assignable to type 'Number'. +!!! error TS2322: Type 'number | string' is not assignable to type 'Number'. !!! error TS2322: Type 'string' is not assignable to type 'Number'. !!! error TS2322: Property 'toFixed' is missing in type 'String'. \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types b/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types index 9cdbe0a0a61..b7224fe91c4 100644 --- a/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types +++ b/tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.types @@ -77,8 +77,8 @@ var myDerivedList: DerivedList; >DerivedList : DerivedList var as = [list, myDerivedList]; // List[] ->as : List[] ->[list, myDerivedList] : List[] +>as : (List | DerivedList)[] +>[list, myDerivedList] : (List | DerivedList)[] >list : List >myDerivedList : DerivedList diff --git a/tests/baselines/reference/arrayOfFunctionTypes3.errors.txt b/tests/baselines/reference/arrayOfFunctionTypes3.errors.txt new file mode 100644 index 00000000000..499d6bca387 --- /dev/null +++ b/tests/baselines/reference/arrayOfFunctionTypes3.errors.txt @@ -0,0 +1,35 @@ +tests/cases/conformance/types/specifyingTypes/typeLiterals/arrayOfFunctionTypes3.ts(17,13): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. +tests/cases/conformance/types/specifyingTypes/typeLiterals/arrayOfFunctionTypes3.ts(26,10): error TS2349: Cannot invoke an expression whose type lacks a call signature. + + +==== tests/cases/conformance/types/specifyingTypes/typeLiterals/arrayOfFunctionTypes3.ts (2 errors) ==== + // valid uses of arrays of function types + + var x = [() => 1, () => { }]; + var r2 = x[0](); + + class C { + foo: string; + } + var y = [C, C]; + var r3 = new y[0](); + + var a: { (x: number): number; (x: string): string; }; + var b: { (x: number): number; (x: string): string; }; + var c: { (x: number): number; (x: any): any; }; + var z = [a, b, c]; + var r4 = z[0]; + var r5 = r4(''); // any not string + ~~ +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'. + var r5b = r4(1); + + var a2: { (x: T): number; (x: string): string;}; + var b2: { (x: T): number; (x: string): string; }; + var c2: { (x: number): number; (x: T): any; }; + + var z2 = [a2, b2, c2]; + var r6 = z2[0]; + var r7 = r6(''); // any not string + ~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. \ No newline at end of file diff --git a/tests/baselines/reference/arrayOfFunctionTypes3.symbols b/tests/baselines/reference/arrayOfFunctionTypes3.symbols deleted file mode 100644 index d26effeb5b7..00000000000 --- a/tests/baselines/reference/arrayOfFunctionTypes3.symbols +++ /dev/null @@ -1,93 +0,0 @@ -=== tests/cases/conformance/types/specifyingTypes/typeLiterals/arrayOfFunctionTypes3.ts === -// valid uses of arrays of function types - -var x = [() => 1, () => { }]; ->x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 2, 3)) - -var r2 = x[0](); ->r2 : Symbol(r2, Decl(arrayOfFunctionTypes3.ts, 3, 3)) ->x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 2, 3)) - -class C { ->C : Symbol(C, Decl(arrayOfFunctionTypes3.ts, 3, 16)) - - foo: string; ->foo : Symbol(foo, Decl(arrayOfFunctionTypes3.ts, 5, 9)) -} -var y = [C, C]; ->y : Symbol(y, Decl(arrayOfFunctionTypes3.ts, 8, 3)) ->C : Symbol(C, Decl(arrayOfFunctionTypes3.ts, 3, 16)) ->C : Symbol(C, Decl(arrayOfFunctionTypes3.ts, 3, 16)) - -var r3 = new y[0](); ->r3 : Symbol(r3, Decl(arrayOfFunctionTypes3.ts, 9, 3)) ->y : Symbol(y, Decl(arrayOfFunctionTypes3.ts, 8, 3)) - -var a: { (x: number): number; (x: string): string; }; ->a : Symbol(a, Decl(arrayOfFunctionTypes3.ts, 11, 3)) ->x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 11, 10)) ->x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 11, 31)) - -var b: { (x: number): number; (x: string): string; }; ->b : Symbol(b, Decl(arrayOfFunctionTypes3.ts, 12, 3)) ->x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 12, 10)) ->x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 12, 31)) - -var c: { (x: number): number; (x: any): any; }; ->c : Symbol(c, Decl(arrayOfFunctionTypes3.ts, 13, 3)) ->x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 13, 10)) ->x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 13, 31)) - -var z = [a, b, c]; ->z : Symbol(z, Decl(arrayOfFunctionTypes3.ts, 14, 3)) ->a : Symbol(a, Decl(arrayOfFunctionTypes3.ts, 11, 3)) ->b : Symbol(b, Decl(arrayOfFunctionTypes3.ts, 12, 3)) ->c : Symbol(c, Decl(arrayOfFunctionTypes3.ts, 13, 3)) - -var r4 = z[0]; ->r4 : Symbol(r4, Decl(arrayOfFunctionTypes3.ts, 15, 3)) ->z : Symbol(z, Decl(arrayOfFunctionTypes3.ts, 14, 3)) - -var r5 = r4(''); // any not string ->r5 : Symbol(r5, Decl(arrayOfFunctionTypes3.ts, 16, 3)) ->r4 : Symbol(r4, Decl(arrayOfFunctionTypes3.ts, 15, 3)) - -var r5b = r4(1); ->r5b : Symbol(r5b, Decl(arrayOfFunctionTypes3.ts, 17, 3)) ->r4 : Symbol(r4, Decl(arrayOfFunctionTypes3.ts, 15, 3)) - -var a2: { (x: T): number; (x: string): string;}; ->a2 : Symbol(a2, Decl(arrayOfFunctionTypes3.ts, 19, 3)) ->T : Symbol(T, Decl(arrayOfFunctionTypes3.ts, 19, 11)) ->x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 19, 14)) ->T : Symbol(T, Decl(arrayOfFunctionTypes3.ts, 19, 11)) ->x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 19, 30)) - -var b2: { (x: T): number; (x: string): string; }; ->b2 : Symbol(b2, Decl(arrayOfFunctionTypes3.ts, 20, 3)) ->T : Symbol(T, Decl(arrayOfFunctionTypes3.ts, 20, 11)) ->x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 20, 14)) ->T : Symbol(T, Decl(arrayOfFunctionTypes3.ts, 20, 11)) ->x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 20, 30)) - -var c2: { (x: number): number; (x: T): any; }; ->c2 : Symbol(c2, Decl(arrayOfFunctionTypes3.ts, 21, 3)) ->x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 21, 11)) ->T : Symbol(T, Decl(arrayOfFunctionTypes3.ts, 21, 32)) ->x : Symbol(x, Decl(arrayOfFunctionTypes3.ts, 21, 35)) ->T : Symbol(T, Decl(arrayOfFunctionTypes3.ts, 21, 32)) - -var z2 = [a2, b2, c2]; ->z2 : Symbol(z2, Decl(arrayOfFunctionTypes3.ts, 23, 3)) ->a2 : Symbol(a2, Decl(arrayOfFunctionTypes3.ts, 19, 3)) ->b2 : Symbol(b2, Decl(arrayOfFunctionTypes3.ts, 20, 3)) ->c2 : Symbol(c2, Decl(arrayOfFunctionTypes3.ts, 21, 3)) - -var r6 = z2[0]; ->r6 : Symbol(r6, Decl(arrayOfFunctionTypes3.ts, 24, 3)) ->z2 : Symbol(z2, Decl(arrayOfFunctionTypes3.ts, 23, 3)) - -var r7 = r6(''); // any not string ->r7 : Symbol(r7, Decl(arrayOfFunctionTypes3.ts, 25, 3)) ->r6 : Symbol(r6, Decl(arrayOfFunctionTypes3.ts, 24, 3)) - diff --git a/tests/baselines/reference/arrayOfFunctionTypes3.types b/tests/baselines/reference/arrayOfFunctionTypes3.types deleted file mode 100644 index 0ed92991ed0..00000000000 --- a/tests/baselines/reference/arrayOfFunctionTypes3.types +++ /dev/null @@ -1,116 +0,0 @@ -=== tests/cases/conformance/types/specifyingTypes/typeLiterals/arrayOfFunctionTypes3.ts === -// valid uses of arrays of function types - -var x = [() => 1, () => { }]; ->x : (() => void)[] ->[() => 1, () => { }] : (() => void)[] ->() => 1 : () => number ->1 : number ->() => { } : () => void - -var r2 = x[0](); ->r2 : void ->x[0]() : void ->x[0] : () => void ->x : (() => void)[] ->0 : number - -class C { ->C : C - - foo: string; ->foo : string -} -var y = [C, C]; ->y : typeof C[] ->[C, C] : typeof C[] ->C : typeof C ->C : typeof C - -var r3 = new y[0](); ->r3 : C ->new y[0]() : C ->y[0] : typeof C ->y : typeof C[] ->0 : number - -var a: { (x: number): number; (x: string): string; }; ->a : { (x: number): number; (x: string): string; } ->x : number ->x : string - -var b: { (x: number): number; (x: string): string; }; ->b : { (x: number): number; (x: string): string; } ->x : number ->x : string - -var c: { (x: number): number; (x: any): any; }; ->c : { (x: number): number; (x: any): any; } ->x : number ->x : any - -var z = [a, b, c]; ->z : { (x: number): number; (x: any): any; }[] ->[a, b, c] : { (x: number): number; (x: any): any; }[] ->a : { (x: number): number; (x: string): string; } ->b : { (x: number): number; (x: string): string; } ->c : { (x: number): number; (x: any): any; } - -var r4 = z[0]; ->r4 : { (x: number): number; (x: any): any; } ->z[0] : { (x: number): number; (x: any): any; } ->z : { (x: number): number; (x: any): any; }[] ->0 : number - -var r5 = r4(''); // any not string ->r5 : any ->r4('') : any ->r4 : { (x: number): number; (x: any): any; } ->'' : string - -var r5b = r4(1); ->r5b : number ->r4(1) : number ->r4 : { (x: number): number; (x: any): any; } ->1 : number - -var a2: { (x: T): number; (x: string): string;}; ->a2 : { (x: T): number; (x: string): string; } ->T : T ->x : T ->T : T ->x : string - -var b2: { (x: T): number; (x: string): string; }; ->b2 : { (x: T): number; (x: string): string; } ->T : T ->x : T ->T : T ->x : string - -var c2: { (x: number): number; (x: T): any; }; ->c2 : { (x: number): number; (x: T): any; } ->x : number ->T : T ->x : T ->T : T - -var z2 = [a2, b2, c2]; ->z2 : { (x: number): number; (x: T): any; }[] ->[a2, b2, c2] : { (x: number): number; (x: T): any; }[] ->a2 : { (x: T): number; (x: string): string; } ->b2 : { (x: T): number; (x: string): string; } ->c2 : { (x: number): number; (x: T): any; } - -var r6 = z2[0]; ->r6 : { (x: number): number; (x: T): any; } ->z2[0] : { (x: number): number; (x: T): any; } ->z2 : { (x: number): number; (x: T): any; }[] ->0 : number - -var r7 = r6(''); // any not string ->r7 : any ->r6('') : any ->r6 : { (x: number): number; (x: T): any; } ->'' : string - diff --git a/tests/baselines/reference/arrowFunctionExpressions.symbols b/tests/baselines/reference/arrowFunctionExpressions.symbols index 28945e1179f..61c575933da 100644 --- a/tests/baselines/reference/arrowFunctionExpressions.symbols +++ b/tests/baselines/reference/arrowFunctionExpressions.symbols @@ -70,6 +70,7 @@ var p6 = ({ a }) => { }; var p7 = ({ a: { b } }) => { }; >p7 : Symbol(p7, Decl(arrowFunctionExpressions.ts, 21, 3)) +>a : Symbol(a) >b : Symbol(b, Decl(arrowFunctionExpressions.ts, 21, 16)) var p8 = ({ a = 1 }) => { }; @@ -78,6 +79,7 @@ var p8 = ({ a = 1 }) => { }; var p9 = ({ a: { b = 1 } = { b: 1 } }) => { }; >p9 : Symbol(p9, Decl(arrowFunctionExpressions.ts, 23, 3)) +>a : Symbol(a) >b : Symbol(b, Decl(arrowFunctionExpressions.ts, 23, 16)) >b : Symbol(b, Decl(arrowFunctionExpressions.ts, 23, 28)) diff --git a/tests/baselines/reference/asOperator1.types b/tests/baselines/reference/asOperator1.types index 3f69871ea09..cc8a49ddc55 100644 --- a/tests/baselines/reference/asOperator1.types +++ b/tests/baselines/reference/asOperator1.types @@ -24,12 +24,12 @@ var z = Date as any as string; // Should parse as a union type, not a bitwise 'or' of (32 as number) and 'string' var j = 32 as number|string; ->j : string | number ->32 as number|string : string | number +>j : number | string +>32 as number|string : number | string >32 : number j = ''; >j = '' : string ->j : string | number +>j : number | string >'' : string diff --git a/tests/baselines/reference/assignmentCompat1.errors.txt b/tests/baselines/reference/assignmentCompat1.errors.txt index 6734e6fc964..edb8d28eecc 100644 --- a/tests/baselines/reference/assignmentCompat1.errors.txt +++ b/tests/baselines/reference/assignmentCompat1.errors.txt @@ -1,18 +1,21 @@ tests/cases/compiler/assignmentCompat1.ts(4,1): error TS2322: Type '{ [index: string]: any; }' is not assignable to type '{ one: number; }'. Property 'one' is missing in type '{ [index: string]: any; }'. -tests/cases/compiler/assignmentCompat1.ts(5,1): error TS2322: Type '{ one: number; }' is not assignable to type '{ [index: string]: any; }'. - Index signature is missing in type '{ one: number; }'. +tests/cases/compiler/assignmentCompat1.ts(6,1): error TS2322: Type '{ [index: number]: any; }' is not assignable to type '{ one: number; }'. + Property 'one' is missing in type '{ [index: number]: any; }'. ==== tests/cases/compiler/assignmentCompat1.ts (2 errors) ==== - var x = {one: 1}; - var y: {[index:string]: any}; - - x = y; + var x = { one: 1 }; + var y: { [index: string]: any }; + var z: { [index: number]: any }; + x = y; // Error ~ !!! error TS2322: Type '{ [index: string]: any; }' is not assignable to type '{ one: number; }'. !!! error TS2322: Property 'one' is missing in type '{ [index: string]: any; }'. - y = x; + y = x; // Ok because index signature type is any + x = z; // Error ~ -!!! error TS2322: Type '{ one: number; }' is not assignable to type '{ [index: string]: any; }'. -!!! error TS2322: Index signature is missing in type '{ one: number; }'. \ No newline at end of file +!!! error TS2322: Type '{ [index: number]: any; }' is not assignable to type '{ one: number; }'. +!!! error TS2322: Property 'one' is missing in type '{ [index: number]: any; }'. + z = x; // Ok because index signature type is any + \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompat1.js b/tests/baselines/reference/assignmentCompat1.js index 09546b7165e..740a44cced4 100644 --- a/tests/baselines/reference/assignmentCompat1.js +++ b/tests/baselines/reference/assignmentCompat1.js @@ -1,12 +1,18 @@ //// [assignmentCompat1.ts] -var x = {one: 1}; -var y: {[index:string]: any}; - -x = y; -y = x; +var x = { one: 1 }; +var y: { [index: string]: any }; +var z: { [index: number]: any }; +x = y; // Error +y = x; // Ok because index signature type is any +x = z; // Error +z = x; // Ok because index signature type is any + //// [assignmentCompat1.js] var x = { one: 1 }; var y; -x = y; -y = x; +var z; +x = y; // Error +y = x; // Ok because index signature type is any +x = z; // Error +z = x; // Ok because index signature type is any diff --git a/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt b/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt index 03dcee9baf3..c7552c3fdb2 100644 --- a/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt +++ b/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt @@ -1,7 +1,7 @@ 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 '() => number | string' is not assignable to type '() => number'. + Type 'number | string' 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 '{}[]'. @@ -28,8 +28,8 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme ~~~~~~~~ !!! 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 '() => number | string' is not assignable to type '() => number'. +!!! error TS2322: Type 'number | string' is not assignable to type 'number'. !!! error TS2322: Type 'string' is not assignable to type 'number'. emptyObjTuple = emptyObjArray; ~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/assignmentCompatBug2.errors.txt b/tests/baselines/reference/assignmentCompatBug2.errors.txt index 15bf1111391..53e12635888 100644 --- a/tests/baselines/reference/assignmentCompatBug2.errors.txt +++ b/tests/baselines/reference/assignmentCompatBug2.errors.txt @@ -1,7 +1,9 @@ tests/cases/compiler/assignmentCompatBug2.ts(1,5): error TS2322: Type '{ a: number; }' is not assignable to type '{ b: number; }'. - Property 'b' is missing in type '{ a: number; }'. + Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'. tests/cases/compiler/assignmentCompatBug2.ts(3,1): error TS2322: Type '{ a: number; }' is not assignable to type '{ b: number; }'. - Property 'b' is missing in type '{ a: number; }'. + Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'. +tests/cases/compiler/assignmentCompatBug2.ts(5,1): error TS2322: Type '{ b: number; a: number; }' is not assignable to type '{ b: number; }'. + Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'. tests/cases/compiler/assignmentCompatBug2.ts(15,1): error TS2322: Type '{ f: (n: number) => number; g: (s: string) => number; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. Property 'm' is missing in type '{ f: (n: number) => number; g: (s: string) => number; }'. tests/cases/compiler/assignmentCompatBug2.ts(20,1): error TS2322: Type '{ f: (n: number) => number; m: number; }' is not assignable to type '{ f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }'. @@ -10,18 +12,21 @@ tests/cases/compiler/assignmentCompatBug2.ts(33,1): error TS2322: Type '{ f: (n: Property 'm' is missing in type '{ f: (n: number) => number; g: (s: string) => number; n: number; k: (a: any) => any; }'. -==== tests/cases/compiler/assignmentCompatBug2.ts (5 errors) ==== +==== tests/cases/compiler/assignmentCompatBug2.ts (6 errors) ==== var b2: { b: number;} = { a: 0 }; // error ~~ !!! error TS2322: Type '{ a: number; }' is not assignable to type '{ b: number; }'. -!!! error TS2322: Property 'b' is missing in type '{ a: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'. b2 = { a: 0 }; // error ~~ !!! error TS2322: Type '{ a: number; }' is not assignable to type '{ b: number; }'. -!!! error TS2322: Property 'b' is missing in type '{ a: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'. b2 = {b: 0, a: 0 }; + ~~ +!!! error TS2322: Type '{ b: number; a: number; }' is not assignable to type '{ b: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'. var b3: { f(n: number): number; g(s: string): number; m: number; n?: number; k?(a: any): any; }; diff --git a/tests/baselines/reference/assignmentCompatBug5.errors.txt b/tests/baselines/reference/assignmentCompatBug5.errors.txt index fd13a07a948..790848babf4 100644 --- a/tests/baselines/reference/assignmentCompatBug5.errors.txt +++ b/tests/baselines/reference/assignmentCompatBug5.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/assignmentCompatBug5.ts(2,6): error TS2345: Argument of type '{ b: number; }' is not assignable to parameter of type '{ a: number; }'. - Property 'a' is missing in type '{ b: number; }'. + Object literal may only specify known properties, and 'b' does not exist in type '{ a: number; }'. tests/cases/compiler/assignmentCompatBug5.ts(5,6): error TS2345: Argument of type 'string[]' is not assignable to parameter of type 'number[]'. Type 'string' is not assignable to type 'number'. tests/cases/compiler/assignmentCompatBug5.ts(8,6): error TS2345: Argument of type '(s: string) => void' is not assignable to parameter of type '(n: number) => number'. @@ -14,7 +14,7 @@ tests/cases/compiler/assignmentCompatBug5.ts(9,6): error TS2345: Argument of typ foo1({ b: 5 }); ~~~~~~~~ !!! error TS2345: Argument of type '{ b: number; }' is not assignable to parameter of type '{ a: number; }'. -!!! error TS2345: Property 'a' is missing in type '{ b: number; }'. +!!! error TS2345: Object literal may only specify known properties, and 'b' does not exist in type '{ a: number; }'. function foo2(x: number[]) { } foo2(["s", "t"]); diff --git a/tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt b/tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt index 0a9b50ff0b8..c5987a93ddf 100644 --- a/tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt @@ -12,12 +12,14 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(33,9): error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived'. + Type 'Base' is not assignable to type 'Derived'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(36,9): error TS2322: Type '{ [x: number]: Derived2; }' is not assignable to type 'A'. Index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(37,9): error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived2'. + Type 'Base' is not assignable to type 'Derived2'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts (6 errors) ==== @@ -72,6 +74,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived'. +!!! error TS2322: Type 'Base' is not assignable to type 'Derived'. var b2: { [x: number]: Derived2; } a = b2; // error @@ -84,6 +87,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived2'. +!!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. var b3: { [x: number]: T; } a = b3; // ok diff --git a/tests/baselines/reference/assignmentCompatWithNumericIndexer2.errors.txt b/tests/baselines/reference/assignmentCompatWithNumericIndexer2.errors.txt index b15f2f7905d..f91d0dd0c15 100644 --- a/tests/baselines/reference/assignmentCompatWithNumericIndexer2.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithNumericIndexer2.errors.txt @@ -12,12 +12,14 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(33,9): error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived'. + Type 'Base' is not assignable to type 'Derived'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(36,9): error TS2322: Type '{ [x: number]: Derived2; }' is not assignable to type 'A'. Index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(37,9): error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived2'. + Type 'Base' is not assignable to type 'Derived2'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts (6 errors) ==== @@ -72,6 +74,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived'. +!!! error TS2322: Type 'Base' is not assignable to type 'Derived'. var b2: { [x: number]: Derived2; } a = b2; // error @@ -84,6 +87,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived2'. +!!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. var b3: { [x: number]: T; } a = b3; // ok diff --git a/tests/baselines/reference/assignmentCompatWithStringIndexer.errors.txt b/tests/baselines/reference/assignmentCompatWithStringIndexer.errors.txt index f002c70e90b..51762bb9418 100644 --- a/tests/baselines/reference/assignmentCompatWithStringIndexer.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithStringIndexer.errors.txt @@ -18,12 +18,14 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(47,9): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived'. + Type 'Base' is not assignable to type 'Derived'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(50,9): error TS2322: Type '{ [x: string]: Derived2; }' is not assignable to type 'A'. Index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(51,9): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived2'. + Type 'Base' is not assignable to type 'Derived2'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts (8 errors) ==== @@ -100,6 +102,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived'. +!!! error TS2322: Type 'Base' is not assignable to type 'Derived'. var b4: { [x: string]: Derived2; }; a3 = b4; // error @@ -112,5 +115,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived2'. +!!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. } } \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithStringIndexer2.errors.txt b/tests/baselines/reference/assignmentCompatWithStringIndexer2.errors.txt index c322364280e..0b0d70d01bb 100644 --- a/tests/baselines/reference/assignmentCompatWithStringIndexer2.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithStringIndexer2.errors.txt @@ -18,12 +18,14 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(47,9): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived'. + Type 'Base' is not assignable to type 'Derived'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(50,9): error TS2322: Type '{ [x: string]: Derived2; }' is not assignable to type 'A'. Index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(51,9): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'Derived2'. + Type 'Base' is not assignable to type 'Derived2'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts (8 errors) ==== @@ -100,6 +102,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived'. +!!! error TS2322: Type 'Base' is not assignable to type 'Derived'. var b4: { [x: string]: Derived2; }; a3 = b4; // error @@ -112,5 +115,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived2'. +!!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. } } \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithStringIndexer3.errors.txt b/tests/baselines/reference/assignmentCompatWithStringIndexer3.errors.txt index a31b2ef3025..4b4c03678d7 100644 --- a/tests/baselines/reference/assignmentCompatWithStringIndexer3.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithStringIndexer3.errors.txt @@ -5,6 +5,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer3.ts(21,9): error TS2322: Type 'A' is not assignable to type '{ [x: string]: string; }'. Index signatures are incompatible. Type 'T' is not assignable to type 'string'. + Type 'Derived' is not assignable to type 'string'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer3.ts (3 errors) ==== @@ -39,5 +40,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: string; }'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'string'. +!!! error TS2322: Type 'Derived' is not assignable to type 'string'. } } \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability36.errors.txt b/tests/baselines/reference/assignmentCompatability36.errors.txt deleted file mode 100644 index 591dc072fab..00000000000 --- a/tests/baselines/reference/assignmentCompatability36.errors.txt +++ /dev/null @@ -1,17 +0,0 @@ -tests/cases/compiler/assignmentCompatability36.ts(9,1): error TS2322: Type 'interfaceWithPublicAndOptional' is not assignable to type '{ [index: string]: any; }'. - Index signature is missing in type 'interfaceWithPublicAndOptional'. - - -==== tests/cases/compiler/assignmentCompatability36.ts (1 errors) ==== - module __test1__ { - export interface interfaceWithPublicAndOptional { one: T; two?: U; }; var obj4: interfaceWithPublicAndOptional = { one: 1 };; - export var __val__obj4 = obj4; - } - module __test2__ { - export var aa:{[index:string]:any;};; - export var __val__aa = aa; - } - __test2__.__val__aa = __test1__.__val__obj4 - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type 'interfaceWithPublicAndOptional' is not assignable to type '{ [index: string]: any; }'. -!!! error TS2322: Index signature is missing in type 'interfaceWithPublicAndOptional'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability36.symbols b/tests/baselines/reference/assignmentCompatability36.symbols new file mode 100644 index 00000000000..4b4b7d75a51 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatability36.symbols @@ -0,0 +1,39 @@ +=== tests/cases/compiler/assignmentCompatability36.ts === +module __test1__ { +>__test1__ : Symbol(__test1__, Decl(assignmentCompatability36.ts, 0, 0)) + + export interface interfaceWithPublicAndOptional { one: T; two?: U; }; var obj4: interfaceWithPublicAndOptional = { one: 1 };; +>interfaceWithPublicAndOptional : Symbol(interfaceWithPublicAndOptional, Decl(assignmentCompatability36.ts, 0, 18)) +>T : Symbol(T, Decl(assignmentCompatability36.ts, 1, 52)) +>U : Symbol(U, Decl(assignmentCompatability36.ts, 1, 54)) +>one : Symbol(one, Decl(assignmentCompatability36.ts, 1, 58)) +>T : Symbol(T, Decl(assignmentCompatability36.ts, 1, 52)) +>two : Symbol(two, Decl(assignmentCompatability36.ts, 1, 66)) +>U : Symbol(U, Decl(assignmentCompatability36.ts, 1, 54)) +>obj4 : Symbol(obj4, Decl(assignmentCompatability36.ts, 1, 83)) +>interfaceWithPublicAndOptional : Symbol(interfaceWithPublicAndOptional, Decl(assignmentCompatability36.ts, 0, 18)) +>one : Symbol(one, Decl(assignmentCompatability36.ts, 1, 139)) + + export var __val__obj4 = obj4; +>__val__obj4 : Symbol(__val__obj4, Decl(assignmentCompatability36.ts, 2, 14)) +>obj4 : Symbol(obj4, Decl(assignmentCompatability36.ts, 1, 83)) +} +module __test2__ { +>__test2__ : Symbol(__test2__, Decl(assignmentCompatability36.ts, 3, 1)) + + export var aa:{[index:string]:any;};; +>aa : Symbol(aa, Decl(assignmentCompatability36.ts, 5, 14)) +>index : Symbol(index, Decl(assignmentCompatability36.ts, 5, 20)) + + export var __val__aa = aa; +>__val__aa : Symbol(__val__aa, Decl(assignmentCompatability36.ts, 6, 14)) +>aa : Symbol(aa, Decl(assignmentCompatability36.ts, 5, 14)) +} +__test2__.__val__aa = __test1__.__val__obj4 +>__test2__.__val__aa : Symbol(__test2__.__val__aa, Decl(assignmentCompatability36.ts, 6, 14)) +>__test2__ : Symbol(__test2__, Decl(assignmentCompatability36.ts, 3, 1)) +>__val__aa : Symbol(__test2__.__val__aa, Decl(assignmentCompatability36.ts, 6, 14)) +>__test1__.__val__obj4 : Symbol(__test1__.__val__obj4, Decl(assignmentCompatability36.ts, 2, 14)) +>__test1__ : Symbol(__test1__, Decl(assignmentCompatability36.ts, 0, 0)) +>__val__obj4 : Symbol(__test1__.__val__obj4, Decl(assignmentCompatability36.ts, 2, 14)) + diff --git a/tests/baselines/reference/assignmentCompatability36.types b/tests/baselines/reference/assignmentCompatability36.types new file mode 100644 index 00000000000..b67be38e2b4 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatability36.types @@ -0,0 +1,42 @@ +=== tests/cases/compiler/assignmentCompatability36.ts === +module __test1__ { +>__test1__ : typeof __test1__ + + export interface interfaceWithPublicAndOptional { one: T; two?: U; }; var obj4: interfaceWithPublicAndOptional = { one: 1 };; +>interfaceWithPublicAndOptional : interfaceWithPublicAndOptional +>T : T +>U : U +>one : T +>T : T +>two : U +>U : U +>obj4 : interfaceWithPublicAndOptional +>interfaceWithPublicAndOptional : interfaceWithPublicAndOptional +>{ one: 1 } : { one: number; } +>one : number +>1 : number + + export var __val__obj4 = obj4; +>__val__obj4 : interfaceWithPublicAndOptional +>obj4 : interfaceWithPublicAndOptional +} +module __test2__ { +>__test2__ : typeof __test2__ + + export var aa:{[index:string]:any;};; +>aa : { [index: string]: any; } +>index : string + + export var __val__aa = aa; +>__val__aa : { [index: string]: any; } +>aa : { [index: string]: any; } +} +__test2__.__val__aa = __test1__.__val__obj4 +>__test2__.__val__aa = __test1__.__val__obj4 : __test1__.interfaceWithPublicAndOptional +>__test2__.__val__aa : { [index: string]: any; } +>__test2__ : typeof __test2__ +>__val__aa : { [index: string]: any; } +>__test1__.__val__obj4 : __test1__.interfaceWithPublicAndOptional +>__test1__ : typeof __test1__ +>__val__obj4 : __test1__.interfaceWithPublicAndOptional + diff --git a/tests/baselines/reference/assignmentNonObjectTypeConstraints.js b/tests/baselines/reference/assignmentNonObjectTypeConstraints.js new file mode 100644 index 00000000000..c9d3cec38f6 --- /dev/null +++ b/tests/baselines/reference/assignmentNonObjectTypeConstraints.js @@ -0,0 +1,42 @@ +//// [assignmentNonObjectTypeConstraints.ts] +const enum E { A, B, C } + +function foo(x: T) { + var y: number = x; // Ok +} + +foo(5); +foo(E.A); + +class A { a } +class B { b } + +function bar(x: T) { + var y: A | B = x; // Ok +} + +bar(new A); +bar(new B); + + +//// [assignmentNonObjectTypeConstraints.js] +function foo(x) { + var y = x; // Ok +} +foo(5); +foo(0 /* A */); +var A = (function () { + function A() { + } + return A; +})(); +var B = (function () { + function B() { + } + return B; +})(); +function bar(x) { + var y = x; // Ok +} +bar(new A); +bar(new B); diff --git a/tests/baselines/reference/assignmentNonObjectTypeConstraints.symbols b/tests/baselines/reference/assignmentNonObjectTypeConstraints.symbols new file mode 100644 index 00000000000..d8bff5df5f2 --- /dev/null +++ b/tests/baselines/reference/assignmentNonObjectTypeConstraints.symbols @@ -0,0 +1,58 @@ +=== tests/cases/compiler/assignmentNonObjectTypeConstraints.ts === +const enum E { A, B, C } +>E : Symbol(E, Decl(assignmentNonObjectTypeConstraints.ts, 0, 0)) +>A : Symbol(E.A, Decl(assignmentNonObjectTypeConstraints.ts, 0, 14)) +>B : Symbol(E.B, Decl(assignmentNonObjectTypeConstraints.ts, 0, 17)) +>C : Symbol(E.C, Decl(assignmentNonObjectTypeConstraints.ts, 0, 20)) + +function foo(x: T) { +>foo : Symbol(foo, Decl(assignmentNonObjectTypeConstraints.ts, 0, 24)) +>T : Symbol(T, Decl(assignmentNonObjectTypeConstraints.ts, 2, 13)) +>x : Symbol(x, Decl(assignmentNonObjectTypeConstraints.ts, 2, 31)) +>T : Symbol(T, Decl(assignmentNonObjectTypeConstraints.ts, 2, 13)) + + var y: number = x; // Ok +>y : Symbol(y, Decl(assignmentNonObjectTypeConstraints.ts, 3, 7)) +>x : Symbol(x, Decl(assignmentNonObjectTypeConstraints.ts, 2, 31)) +} + +foo(5); +>foo : Symbol(foo, Decl(assignmentNonObjectTypeConstraints.ts, 0, 24)) + +foo(E.A); +>foo : Symbol(foo, Decl(assignmentNonObjectTypeConstraints.ts, 0, 24)) +>E.A : Symbol(E.A, Decl(assignmentNonObjectTypeConstraints.ts, 0, 14)) +>E : Symbol(E, Decl(assignmentNonObjectTypeConstraints.ts, 0, 0)) +>A : Symbol(E.A, Decl(assignmentNonObjectTypeConstraints.ts, 0, 14)) + +class A { a } +>A : Symbol(A, Decl(assignmentNonObjectTypeConstraints.ts, 7, 9)) +>a : Symbol(a, Decl(assignmentNonObjectTypeConstraints.ts, 9, 9)) + +class B { b } +>B : Symbol(B, Decl(assignmentNonObjectTypeConstraints.ts, 9, 13)) +>b : Symbol(b, Decl(assignmentNonObjectTypeConstraints.ts, 10, 9)) + +function bar(x: T) { +>bar : Symbol(bar, Decl(assignmentNonObjectTypeConstraints.ts, 10, 13)) +>T : Symbol(T, Decl(assignmentNonObjectTypeConstraints.ts, 12, 13)) +>A : Symbol(A, Decl(assignmentNonObjectTypeConstraints.ts, 7, 9)) +>B : Symbol(B, Decl(assignmentNonObjectTypeConstraints.ts, 9, 13)) +>x : Symbol(x, Decl(assignmentNonObjectTypeConstraints.ts, 12, 30)) +>T : Symbol(T, Decl(assignmentNonObjectTypeConstraints.ts, 12, 13)) + + var y: A | B = x; // Ok +>y : Symbol(y, Decl(assignmentNonObjectTypeConstraints.ts, 13, 7)) +>A : Symbol(A, Decl(assignmentNonObjectTypeConstraints.ts, 7, 9)) +>B : Symbol(B, Decl(assignmentNonObjectTypeConstraints.ts, 9, 13)) +>x : Symbol(x, Decl(assignmentNonObjectTypeConstraints.ts, 12, 30)) +} + +bar(new A); +>bar : Symbol(bar, Decl(assignmentNonObjectTypeConstraints.ts, 10, 13)) +>A : Symbol(A, Decl(assignmentNonObjectTypeConstraints.ts, 7, 9)) + +bar(new B); +>bar : Symbol(bar, Decl(assignmentNonObjectTypeConstraints.ts, 10, 13)) +>B : Symbol(B, Decl(assignmentNonObjectTypeConstraints.ts, 9, 13)) + diff --git a/tests/baselines/reference/assignmentNonObjectTypeConstraints.types b/tests/baselines/reference/assignmentNonObjectTypeConstraints.types new file mode 100644 index 00000000000..94391e2ea5f --- /dev/null +++ b/tests/baselines/reference/assignmentNonObjectTypeConstraints.types @@ -0,0 +1,65 @@ +=== tests/cases/compiler/assignmentNonObjectTypeConstraints.ts === +const enum E { A, B, C } +>E : E +>A : E +>B : E +>C : E + +function foo(x: T) { +>foo : (x: T) => void +>T : T +>x : T +>T : T + + var y: number = x; // Ok +>y : number +>x : T +} + +foo(5); +>foo(5) : void +>foo : (x: T) => void +>5 : number + +foo(E.A); +>foo(E.A) : void +>foo : (x: T) => void +>E.A : E +>E : typeof E +>A : E + +class A { a } +>A : A +>a : any + +class B { b } +>B : B +>b : any + +function bar(x: T) { +>bar : (x: T) => void +>T : T +>A : A +>B : B +>x : T +>T : T + + var y: A | B = x; // Ok +>y : A | B +>A : A +>B : B +>x : T +} + +bar(new A); +>bar(new A) : void +>bar : (x: T) => void +>new A : A +>A : typeof A + +bar(new B); +>bar(new B) : void +>bar : (x: T) => void +>new B : B +>B : typeof B + diff --git a/tests/baselines/reference/awaitUnion_es6.types b/tests/baselines/reference/awaitUnion_es6.types index fc7bef8a28c..d0b5b6ccfd0 100644 --- a/tests/baselines/reference/awaitUnion_es6.types +++ b/tests/baselines/reference/awaitUnion_es6.types @@ -1,6 +1,6 @@ === tests/cases/conformance/async/es6/awaitUnion_es6.ts === declare let a: number | string; ->a : string | number +>a : number | string declare let b: PromiseLike | PromiseLike; >b : PromiseLike | PromiseLike @@ -8,7 +8,7 @@ declare let b: PromiseLike | PromiseLike; >PromiseLike : PromiseLike declare let c: PromiseLike; ->c : PromiseLike +>c : PromiseLike >PromiseLike : PromiseLike declare let d: number | PromiseLike; @@ -16,29 +16,29 @@ declare let d: number | PromiseLike; >PromiseLike : PromiseLike declare let e: number | PromiseLike; ->e : number | PromiseLike +>e : number | PromiseLike >PromiseLike : PromiseLike async function f() { >f : () => Promise let await_a = await a; ->await_a : string | number +>await_a : number | string >a : any let await_b = await b; ->await_b : string | number +>await_b : number | string >b : any let await_c = await c; ->await_c : string | number +>await_c : number | string >c : any let await_d = await d; ->await_d : string | number +>await_d : number | string >d : any let await_e = await e; ->await_e : string | number +>await_e : number | string >e : any } diff --git a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types index 2a5ee6a2fe2..933d46cc802 100644 --- a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types +++ b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types @@ -46,8 +46,8 @@ var r = true ? 1 : 2; >2 : number var r3 = true ? 1 : {}; ->r3 : {} ->true ? 1 : {} : {} +>r3 : number | {} +>true ? 1 : {} : number | {} >true : boolean >1 : number >{} : {} @@ -60,15 +60,15 @@ var r4 = true ? a : b; // typeof a >b : { x: number; z?: number; } var r5 = true ? b : a; // typeof b ->r5 : { x: number; y?: number; } | { x: number; z?: number; } ->true ? b : a : { x: number; y?: number; } | { x: number; z?: number; } +>r5 : { x: number; z?: number; } | { x: number; y?: number; } +>true ? b : a : { x: number; z?: number; } | { x: number; y?: number; } >true : boolean >b : { x: number; z?: number; } >a : { x: number; y?: number; } var r6 = true ? (x: number) => { } : (x: Object) => { }; // returns number => void ->r6 : (x: number) => void ->true ? (x: number) => { } : (x: Object) => { } : (x: number) => void +>r6 : ((x: number) => void) | ((x: Object) => void) +>true ? (x: number) => { } : (x: Object) => { } : ((x: number) => void) | ((x: Object) => void) >true : boolean >(x: number) => { } : (x: number) => void >x : number @@ -80,7 +80,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: number) => void +>true ? (x: number) => { } : (x: Object) => { } : ((x: number) => void) | ((x: Object) => void) >true : boolean >(x: number) => { } : (x: number) => void >x : number @@ -89,8 +89,8 @@ var r7: (x: Object) => void = true ? (x: number) => { } : (x: Object) => { }; >Object : Object var r8 = true ? (x: Object) => { } : (x: number) => { }; // returns Object => void ->r8 : (x: Object) => void ->true ? (x: Object) => { } : (x: number) => { } : (x: Object) => void +>r8 : ((x: Object) => void) | ((x: number) => void) +>true ? (x: Object) => { } : (x: number) => { } : ((x: Object) => void) | ((x: number) => void) >true : boolean >(x: Object) => { } : (x: Object) => void >x : Object @@ -107,8 +107,8 @@ var r10: Base = true ? derived : derived2; // no error since we use the contextu >derived2 : Derived2 var r11 = true ? base : derived2; ->r11 : Base ->true ? base : derived2 : Base +>r11 : Base | Derived2 +>true ? base : derived2 : Base | Derived2 >true : boolean >base : Base >derived2 : Derived2 diff --git a/tests/baselines/reference/bestCommonTypeOfTuple.types b/tests/baselines/reference/bestCommonTypeOfTuple.types index 7b7302a9cc2..7d3330f4863 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple.types +++ b/tests/baselines/reference/bestCommonTypeOfTuple.types @@ -98,8 +98,8 @@ var e3 = t3[2]; // any >2 : number var e4 = t4[3]; // number ->e4 : number ->t4[3] : number +>e4 : E1 | E2 | number +>t4[3] : E1 | E2 | number >t4 : [E1, E2, number] >3 : number diff --git a/tests/baselines/reference/bestCommonTypeOfTuple2.types b/tests/baselines/reference/bestCommonTypeOfTuple2.types index 32196fdf668..573e3466376 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple2.types +++ b/tests/baselines/reference/bestCommonTypeOfTuple2.types @@ -66,8 +66,8 @@ var t5: [C1, F] >F : F var e11 = t1[4]; // base ->e11 : base ->t1[4] : base +>e11 : C | base +>t1[4] : C | base >t1 : [C, base] >4 : number @@ -78,20 +78,20 @@ var e21 = t2[4]; // {} >4 : number var e31 = t3[4]; // C1 ->e31 : C1 ->t3[4] : C1 +>e31 : C1 | D1 +>t3[4] : C1 | D1 >t3 : [C1, D1] >4 : number var e41 = t4[2]; // base1 ->e41 : base1 ->t4[2] : base1 +>e41 : base1 | C1 +>t4[2] : base1 | C1 >t4 : [base1, C1] >2 : number var e51 = t5[2]; // {} ->e51 : F | C1 ->t5[2] : F | C1 +>e51 : C1 | F +>t5[2] : C1 | F >t5 : [C1, F] >2 : number diff --git a/tests/baselines/reference/bestCommonTypeWithOptionalProperties.types b/tests/baselines/reference/bestCommonTypeWithOptionalProperties.types index df40291b0e5..4c47753a90d 100644 --- a/tests/baselines/reference/bestCommonTypeWithOptionalProperties.types +++ b/tests/baselines/reference/bestCommonTypeWithOptionalProperties.types @@ -27,43 +27,43 @@ var z: Z; // All these arrays should be X[] var b1 = [x, y, z]; ->b1 : X[] ->[x, y, z] : X[] +>b1 : (X | Y | Z)[] +>[x, y, z] : (X | Y | Z)[] >x : X >y : Y >z : Z var b2 = [x, z, y]; ->b2 : X[] ->[x, z, y] : X[] +>b2 : (X | Z | Y)[] +>[x, z, y] : (X | Z | Y)[] >x : X >z : Z >y : Y var b3 = [y, x, z]; ->b3 : X[] ->[y, x, z] : X[] +>b3 : (Y | X | Z)[] +>[y, x, z] : (Y | X | Z)[] >y : Y >x : X >z : Z var b4 = [y, z, x]; ->b4 : X[] ->[y, z, x] : X[] +>b4 : (Y | Z | X)[] +>[y, z, x] : (Y | Z | X)[] >y : Y >z : Z >x : X var b5 = [z, x, y]; ->b5 : X[] ->[z, x, y] : X[] +>b5 : (Z | X | Y)[] +>[z, x, y] : (Z | X | Y)[] >z : Z >x : X >y : Y var b6 = [z, y, x]; ->b6 : X[] ->[z, y, x] : X[] +>b6 : (Z | Y | X)[] +>[z, y, x] : (Z | Y | X)[] >z : Z >y : Y >x : X diff --git a/tests/baselines/reference/callWithSpread.types b/tests/baselines/reference/callWithSpread.types index f7097727204..8964708c05e 100644 --- a/tests/baselines/reference/callWithSpread.types +++ b/tests/baselines/reference/callWithSpread.types @@ -163,8 +163,8 @@ xa[1].foo(1, 2, ...a, "abc"); >xa : X[] >1 : number >foo : (x: number, y: number, ...z: string[]) => any ->...[1, 2, "abc"] : string | number ->[1, 2, "abc"] : (string | number)[] +>...[1, 2, "abc"] : number | string +>[1, 2, "abc"] : (number | string)[] >1 : number >2 : number >"abc" : string diff --git a/tests/baselines/reference/callWithSpreadES6.types b/tests/baselines/reference/callWithSpreadES6.types index ba638207e8a..9c9e795ce24 100644 --- a/tests/baselines/reference/callWithSpreadES6.types +++ b/tests/baselines/reference/callWithSpreadES6.types @@ -164,8 +164,8 @@ xa[1].foo(1, 2, ...a, "abc"); >xa : X[] >1 : number >foo : (x: number, y: number, ...z: string[]) => any ->...[1, 2, "abc"] : string | number ->[1, 2, "abc"] : (string | number)[] +>...[1, 2, "abc"] : number | string +>[1, 2, "abc"] : (number | string)[] >1 : number >2 : number >"abc" : string diff --git a/tests/baselines/reference/castingTuple.errors.txt b/tests/baselines/reference/castingTuple.errors.txt index 98be259964d..62a36c9c156 100644 --- a/tests/baselines/reference/castingTuple.errors.txt +++ b/tests/baselines/reference/castingTuple.errors.txt @@ -8,11 +8,12 @@ tests/cases/conformance/types/tuple/castingTuple.ts(28,10): error TS2352: Neithe tests/cases/conformance/types/tuple/castingTuple.ts(29,10): error TS2352: 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(30,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(30,14): error TS2352: 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 '() => number | string' is not assignable to type '() => number'. + Type 'number | string' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot find name 't4'. @@ -61,14 +62,15 @@ tests/cases/conformance/types/tuple/castingTuple.ts(31,1): error TS2304: Cannot !!! error TS2352: Neither type '[C, D]' nor type '[A, I]' is assignable to the other. !!! error TS2352: Types of property '0' are incompatible. !!! error TS2352: Type 'C' is not assignable to type 'A'. +!!! error TS2352: 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 TS2352: Neither type '[number, string]' nor type 'number[]' is assignable to the other. !!! error TS2352: Types of property 'pop' are incompatible. -!!! error TS2352: Type '() => string | number' is not assignable to type '() => number'. -!!! error TS2352: Type 'string | number' is not assignable to type 'number'. +!!! error TS2352: Type '() => number | string' is not assignable to type '() => number'. +!!! error TS2352: Type 'number | string' is not assignable to type 'number'. !!! error TS2352: Type 'string' is not assignable to type 'number'. t4[2] = 10; ~~ diff --git a/tests/baselines/reference/classExtendsNull.errors.txt b/tests/baselines/reference/classExtendsNull.errors.txt new file mode 100644 index 00000000000..7bb44774826 --- /dev/null +++ b/tests/baselines/reference/classExtendsNull.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/classExtendsNull.ts(2,5): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' + + +==== tests/cases/compiler/classExtendsNull.ts (1 errors) ==== + class C extends null { + constructor() { + ~~~~~~~~~~~~~~~ + super(); + ~~~~~~~~~~~~~~~~ + return Object.create(null); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~ +!!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null' + } + + class D extends null { + constructor() { + return Object.create(null); + } + } \ No newline at end of file diff --git a/tests/baselines/reference/classExtendsNull.js b/tests/baselines/reference/classExtendsNull.js new file mode 100644 index 00000000000..5627f10dca6 --- /dev/null +++ b/tests/baselines/reference/classExtendsNull.js @@ -0,0 +1,35 @@ +//// [classExtendsNull.ts] +class C extends null { + constructor() { + super(); + return Object.create(null); + } +} + +class D extends null { + constructor() { + return Object.create(null); + } +} + +//// [classExtendsNull.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var C = (function (_super) { + __extends(C, _super); + function C() { + _super.call(this); + return Object.create(null); + } + return C; +})(null); +var D = (function (_super) { + __extends(D, _super); + function D() { + return Object.create(null); + } + return D; +})(null); diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types index d6c97b5db81..a3a393fba0c 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types @@ -17,9 +17,9 @@ declare function foo(obj: I): T >T : T foo({ ->foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | number | boolean | (() => void) | number[] +>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | (() => void) | boolean | number | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | number | boolean | (() => void) | number[]; 0: () => void; p: string; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; 0: () => void; p: string; } p: "", >p : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types index 72a1d5ba04f..4abefe44843 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types @@ -17,9 +17,9 @@ declare function foo(obj: I): T >T : T foo({ ->foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | number | boolean | (() => void) | number[] +>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | (() => void) | boolean | number | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | number | boolean | (() => void) | number[]; 0: () => void; p: string; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; 0: () => void; p: string; } p: "", >p : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types index 5674f6aa393..ae1004c9819 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types @@ -17,9 +17,9 @@ declare function foo(obj: I): T >T : T foo({ ->foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | (() => void) | number[] +>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : (() => void) | number | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: number | (() => void) | number[]; 0: () => void; p: string; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: (() => void) | number | number[]; 0: () => void; p: string; } p: "", >p : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types index 93558c075e7..e98e0fb8941 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types @@ -17,9 +17,9 @@ declare function foo(obj: I): T >T : T foo({ ->foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | (() => void) | number[] +>foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : (() => void) | number | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: number | (() => void) | number[]; 0: () => void; p: string; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: number]: (() => void) | number | number[]; 0: () => void; p: string; } p: "", >p : string diff --git a/tests/baselines/reference/conditionalExpression1.errors.txt b/tests/baselines/reference/conditionalExpression1.errors.txt index 0e291986785..49ed2095353 100644 --- a/tests/baselines/reference/conditionalExpression1.errors.txt +++ b/tests/baselines/reference/conditionalExpression1.errors.txt @@ -1,9 +1,9 @@ -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(1,5): error TS2322: Type 'number | string' is not assignable to type 'boolean'. + Type 'number' is not assignable to type 'boolean'. ==== tests/cases/compiler/conditionalExpression1.ts (1 errors) ==== var x: boolean = (true ? 1 : ""); // should be an error ~ -!!! 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 +!!! error TS2322: Type 'number | string' is not assignable to type 'boolean'. +!!! error TS2322: Type 'number' 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 722ec13c684..d5530f98fe8 100644 --- a/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types +++ b/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types @@ -31,27 +31,27 @@ var b: B; //Cond ? Expr1 : Expr2, Expr1 is supertype //Be Not contextually typed true ? x : a; ->true ? x : a : X +>true ? x : a : X | A >true : boolean >x : X >a : A var result1 = true ? x : a; ->result1 : X ->true ? x : a : X +>result1 : X | A +>true ? x : a : X | A >true : boolean >x : X >a : A //Expr1 and Expr2 are literals true ? {} : 1; ->true ? {} : 1 : {} +>true ? {} : 1 : {} | number >true : boolean >{} : {} >1 : number true ? { a: 1 } : { a: 2, b: 'string' }; ->true ? { a: 1 } : { a: 2, b: 'string' } : { a: number; } +>true ? { a: 1 } : { a: 2, b: 'string' } : { a: number; } | { a: number; b: string; } >true : boolean >{ a: 1 } : { a: number; } >a : number @@ -63,15 +63,15 @@ true ? { a: 1 } : { a: 2, b: 'string' }; >'string' : string var result2 = true ? {} : 1; ->result2 : {} ->true ? {} : 1 : {} +>result2 : {} | number +>true ? {} : 1 : {} | number >true : boolean >{} : {} >1 : number var result3 = true ? { a: 1 } : { a: 2, b: 'string' }; ->result3 : { a: number; } ->true ? { a: 1 } : { a: 2, b: 'string' } : { a: number; } +>result3 : { a: number; } | { a: number; b: string; } +>true ? { a: 1 } : { a: 2, b: 'string' } : { a: number; } | { a: number; b: string; } >true : boolean >{ a: 1 } : { a: number; } >a : number @@ -86,7 +86,7 @@ var result3 = true ? { a: 1 } : { a: 2, b: 'string' }; var resultIsX1: X = true ? x : a; >resultIsX1 : X >X : X ->true ? x : a : X +>true ? x : a : X | A >true : boolean >x : X >a : A @@ -95,7 +95,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 : (m: A) => any +>true ? (m) => m.propertyX : (n) => n.propertyA : ((m: A) => any) | ((n: A) => number) >true : boolean >(m) => m.propertyX : (m: A) => any >m : A @@ -111,27 +111,27 @@ var result4: (t: A) => any = true ? (m) => m.propertyX : (n) => n.propertyA; //Cond ? Expr1 : Expr2, Expr2 is supertype //Be Not contextually typed true ? a : x; ->true ? a : x : X +>true ? a : x : A | X >true : boolean >a : A >x : X var result5 = true ? a : x; ->result5 : X ->true ? a : x : X +>result5 : A | X +>true ? a : x : A | X >true : boolean >a : A >x : X //Expr1 and Expr2 are literals true ? 1 : {}; ->true ? 1 : {} : {} +>true ? 1 : {} : number | {} >true : boolean >1 : number >{} : {} true ? { a: 2, b: 'string' } : { a: 1 }; ->true ? { a: 2, b: 'string' } : { a: 1 } : { a: number; } +>true ? { a: 2, b: 'string' } : { a: 1 } : { a: number; b: string; } | { a: number; } >true : boolean >{ a: 2, b: 'string' } : { a: number; b: string; } >a : number @@ -143,15 +143,15 @@ true ? { a: 2, b: 'string' } : { a: 1 }; >1 : number var result6 = true ? 1 : {}; ->result6 : {} ->true ? 1 : {} : {} +>result6 : number | {} +>true ? 1 : {} : number | {} >true : boolean >1 : number >{} : {} var result7 = true ? { a: 2, b: 'string' } : { a: 1 }; ->result7 : { a: number; } ->true ? { a: 2, b: 'string' } : { a: 1 } : { a: number; } +>result7 : { a: number; b: string; } | { a: number; } +>true ? { a: 2, b: 'string' } : { a: 1 } : { a: number; b: string; } | { a: number; } >true : boolean >{ a: 2, b: 'string' } : { a: number; b: string; } >a : number @@ -166,7 +166,7 @@ var result7 = true ? { a: 2, b: 'string' } : { a: 1 }; var resultIsX2: X = true ? x : a; >resultIsX2 : X >X : X ->true ? x : a : X +>true ? x : a : X | A >true : boolean >x : X >a : A @@ -175,7 +175,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 : (n: A) => any +>true ? (m) => m.propertyA : (n) => n.propertyX : ((m: A) => number) | ((n: A) => any) >true : boolean >(m) => m.propertyA : (m: A) => number >m : A @@ -218,7 +218,7 @@ 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' : string | number +>true ? 1 : 'string' : number | string >true : boolean >1 : number >'string' : string diff --git a/tests/baselines/reference/constEnumErrors.errors.txt b/tests/baselines/reference/constEnumErrors.errors.txt index be7dad54eeb..4236544defa 100644 --- a/tests/baselines/reference/constEnumErrors.errors.txt +++ b/tests/baselines/reference/constEnumErrors.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/constEnumErrors.ts(1,12): error TS2300: Duplicate identifier 'E'. tests/cases/compiler/constEnumErrors.ts(5,8): error TS2300: Duplicate identifier 'E'. -tests/cases/compiler/constEnumErrors.ts(12,9): error TS2474: In 'const' enum declarations member initializer must be constant expression. +tests/cases/compiler/constEnumErrors.ts(12,9): error TS2651: A member initializer in a 'const' enum declaration cannot reference members declared after it, including members defined in other 'const' enums. tests/cases/compiler/constEnumErrors.ts(14,9): error TS2474: In 'const' enum declarations member initializer must be constant expression. tests/cases/compiler/constEnumErrors.ts(15,10): error TS2474: In 'const' enum declarations member initializer must be constant expression. tests/cases/compiler/constEnumErrors.ts(22,13): error TS2476: A const enum member can only be accessed using a string literal. @@ -31,7 +31,7 @@ tests/cases/compiler/constEnumErrors.ts(42,9): error TS2478: 'const' enum member // forward reference to the element of the same enum X = Y, ~ -!!! error TS2474: In 'const' enum declarations member initializer must be constant expression. +!!! error TS2651: A member initializer in a 'const' enum declaration cannot reference members declared after it, including members defined in other 'const' enums. // forward reference to the element of the same enum Y = E1.Z, ~~~~ diff --git a/tests/baselines/reference/constEnumMergingWithValues1.js b/tests/baselines/reference/constEnumMergingWithValues1.js new file mode 100644 index 00000000000..f47fc227bae --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues1.js @@ -0,0 +1,14 @@ +//// [constEnumMergingWithValues1.ts] + +function foo() {} +module foo { + const enum E { X } +} + +export = foo + +//// [constEnumMergingWithValues1.js] +define(["require", "exports"], function (require, exports) { + function foo() { } + return foo; +}); diff --git a/tests/baselines/reference/constEnumMergingWithValues1.symbols b/tests/baselines/reference/constEnumMergingWithValues1.symbols new file mode 100644 index 00000000000..3dd1c80705c --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues1.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/constEnumMergingWithValues1.ts === + +function foo() {} +>foo : Symbol(foo, Decl(constEnumMergingWithValues1.ts, 0, 0), Decl(constEnumMergingWithValues1.ts, 1, 17)) + +module foo { +>foo : Symbol(foo, Decl(constEnumMergingWithValues1.ts, 0, 0), Decl(constEnumMergingWithValues1.ts, 1, 17)) + + const enum E { X } +>E : Symbol(E, Decl(constEnumMergingWithValues1.ts, 2, 12)) +>X : Symbol(E.X, Decl(constEnumMergingWithValues1.ts, 3, 18)) +} + +export = foo +>foo : Symbol(foo, Decl(constEnumMergingWithValues1.ts, 0, 0), Decl(constEnumMergingWithValues1.ts, 1, 17)) + diff --git a/tests/baselines/reference/constEnumMergingWithValues1.types b/tests/baselines/reference/constEnumMergingWithValues1.types new file mode 100644 index 00000000000..8d5b15795f7 --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues1.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/constEnumMergingWithValues1.ts === + +function foo() {} +>foo : typeof foo + +module foo { +>foo : typeof foo + + const enum E { X } +>E : E +>X : E +} + +export = foo +>foo : typeof foo + diff --git a/tests/baselines/reference/constEnumMergingWithValues2.js b/tests/baselines/reference/constEnumMergingWithValues2.js new file mode 100644 index 00000000000..393ab41fa1f --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues2.js @@ -0,0 +1,18 @@ +//// [constEnumMergingWithValues2.ts] + +class foo {} +module foo { + const enum E { X } +} + +export = foo + +//// [constEnumMergingWithValues2.js] +define(["require", "exports"], function (require, exports) { + var foo = (function () { + function foo() { + } + return foo; + })(); + return foo; +}); diff --git a/tests/baselines/reference/constEnumMergingWithValues2.symbols b/tests/baselines/reference/constEnumMergingWithValues2.symbols new file mode 100644 index 00000000000..bfb438a387d --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues2.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/constEnumMergingWithValues2.ts === + +class foo {} +>foo : Symbol(foo, Decl(constEnumMergingWithValues2.ts, 0, 0), Decl(constEnumMergingWithValues2.ts, 1, 12)) + +module foo { +>foo : Symbol(foo, Decl(constEnumMergingWithValues2.ts, 0, 0), Decl(constEnumMergingWithValues2.ts, 1, 12)) + + const enum E { X } +>E : Symbol(E, Decl(constEnumMergingWithValues2.ts, 2, 12)) +>X : Symbol(E.X, Decl(constEnumMergingWithValues2.ts, 3, 18)) +} + +export = foo +>foo : Symbol(foo, Decl(constEnumMergingWithValues2.ts, 0, 0), Decl(constEnumMergingWithValues2.ts, 1, 12)) + diff --git a/tests/baselines/reference/constEnumMergingWithValues2.types b/tests/baselines/reference/constEnumMergingWithValues2.types new file mode 100644 index 00000000000..dd706ef33a1 --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues2.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/constEnumMergingWithValues2.ts === + +class foo {} +>foo : foo + +module foo { +>foo : typeof foo + + const enum E { X } +>E : E +>X : E +} + +export = foo +>foo : foo + diff --git a/tests/baselines/reference/constEnumMergingWithValues3.js b/tests/baselines/reference/constEnumMergingWithValues3.js new file mode 100644 index 00000000000..d28f29f0962 --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues3.js @@ -0,0 +1,17 @@ +//// [constEnumMergingWithValues3.ts] + +enum foo { A } +module foo { + const enum E { X } +} + +export = foo + +//// [constEnumMergingWithValues3.js] +define(["require", "exports"], function (require, exports) { + var foo; + (function (foo) { + foo[foo["A"] = 0] = "A"; + })(foo || (foo = {})); + return foo; +}); diff --git a/tests/baselines/reference/constEnumMergingWithValues3.symbols b/tests/baselines/reference/constEnumMergingWithValues3.symbols new file mode 100644 index 00000000000..33e020b5679 --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues3.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/constEnumMergingWithValues3.ts === + +enum foo { A } +>foo : Symbol(foo, Decl(constEnumMergingWithValues3.ts, 0, 0), Decl(constEnumMergingWithValues3.ts, 1, 14)) +>A : Symbol(foo.A, Decl(constEnumMergingWithValues3.ts, 1, 10)) + +module foo { +>foo : Symbol(foo, Decl(constEnumMergingWithValues3.ts, 0, 0), Decl(constEnumMergingWithValues3.ts, 1, 14)) + + const enum E { X } +>E : Symbol(E, Decl(constEnumMergingWithValues3.ts, 2, 12)) +>X : Symbol(E.X, Decl(constEnumMergingWithValues3.ts, 3, 18)) +} + +export = foo +>foo : Symbol(foo, Decl(constEnumMergingWithValues3.ts, 0, 0), Decl(constEnumMergingWithValues3.ts, 1, 14)) + diff --git a/tests/baselines/reference/constEnumMergingWithValues3.types b/tests/baselines/reference/constEnumMergingWithValues3.types new file mode 100644 index 00000000000..df2e8820466 --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues3.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/constEnumMergingWithValues3.ts === + +enum foo { A } +>foo : foo +>A : foo + +module foo { +>foo : typeof foo + + const enum E { X } +>E : E +>X : E +} + +export = foo +>foo : foo + diff --git a/tests/baselines/reference/constEnumMergingWithValues4.js b/tests/baselines/reference/constEnumMergingWithValues4.js new file mode 100644 index 00000000000..7ed8b44dc76 --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues4.js @@ -0,0 +1,21 @@ +//// [constEnumMergingWithValues4.ts] + +module foo { + const enum E { X } +} + +module foo { + var x = 1; +} + + +export = foo + +//// [constEnumMergingWithValues4.js] +define(["require", "exports"], function (require, exports) { + var foo; + (function (foo) { + var x = 1; + })(foo || (foo = {})); + return foo; +}); diff --git a/tests/baselines/reference/constEnumMergingWithValues4.symbols b/tests/baselines/reference/constEnumMergingWithValues4.symbols new file mode 100644 index 00000000000..817c9aeeff3 --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues4.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/constEnumMergingWithValues4.ts === + +module foo { +>foo : Symbol(foo, Decl(constEnumMergingWithValues4.ts, 0, 0), Decl(constEnumMergingWithValues4.ts, 3, 1)) + + const enum E { X } +>E : Symbol(E, Decl(constEnumMergingWithValues4.ts, 1, 12)) +>X : Symbol(E.X, Decl(constEnumMergingWithValues4.ts, 2, 18)) +} + +module foo { +>foo : Symbol(foo, Decl(constEnumMergingWithValues4.ts, 0, 0), Decl(constEnumMergingWithValues4.ts, 3, 1)) + + var x = 1; +>x : Symbol(x, Decl(constEnumMergingWithValues4.ts, 6, 7)) +} + + +export = foo +>foo : Symbol(foo, Decl(constEnumMergingWithValues4.ts, 0, 0), Decl(constEnumMergingWithValues4.ts, 3, 1)) + diff --git a/tests/baselines/reference/constEnumMergingWithValues4.types b/tests/baselines/reference/constEnumMergingWithValues4.types new file mode 100644 index 00000000000..3da306fedbf --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues4.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/constEnumMergingWithValues4.ts === + +module foo { +>foo : typeof foo + + const enum E { X } +>E : E +>X : E +} + +module foo { +>foo : typeof foo + + var x = 1; +>x : number +>1 : number +} + + +export = foo +>foo : typeof foo + diff --git a/tests/baselines/reference/constEnumMergingWithValues5.js b/tests/baselines/reference/constEnumMergingWithValues5.js new file mode 100644 index 00000000000..378b11cfd22 --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues5.js @@ -0,0 +1,19 @@ +//// [constEnumMergingWithValues5.ts] + +module foo { + const enum E { X } +} + +export = foo + +//// [constEnumMergingWithValues5.js] +define(["require", "exports"], function (require, exports) { + var foo; + (function (foo) { + var E; + (function (E) { + E[E["X"] = 0] = "X"; + })(E || (E = {})); + })(foo || (foo = {})); + return foo; +}); diff --git a/tests/baselines/reference/constEnumMergingWithValues5.symbols b/tests/baselines/reference/constEnumMergingWithValues5.symbols new file mode 100644 index 00000000000..6354f64d834 --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues5.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/constEnumMergingWithValues5.ts === + +module foo { +>foo : Symbol(foo, Decl(constEnumMergingWithValues5.ts, 0, 0)) + + const enum E { X } +>E : Symbol(E, Decl(constEnumMergingWithValues5.ts, 1, 12)) +>X : Symbol(E.X, Decl(constEnumMergingWithValues5.ts, 2, 18)) +} + +export = foo +>foo : Symbol(foo, Decl(constEnumMergingWithValues5.ts, 0, 0)) + diff --git a/tests/baselines/reference/constEnumMergingWithValues5.types b/tests/baselines/reference/constEnumMergingWithValues5.types new file mode 100644 index 00000000000..617676ba0c0 --- /dev/null +++ b/tests/baselines/reference/constEnumMergingWithValues5.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/constEnumMergingWithValues5.ts === + +module foo { +>foo : typeof foo + + const enum E { X } +>E : E +>X : E +} + +export = foo +>foo : typeof foo + diff --git a/tests/baselines/reference/constEnumToStringNoComments.js b/tests/baselines/reference/constEnumToStringNoComments.js new file mode 100644 index 00000000000..a23be26033e --- /dev/null +++ b/tests/baselines/reference/constEnumToStringNoComments.js @@ -0,0 +1,37 @@ +//// [constEnumToStringNoComments.ts] +const enum Foo { + X = 100, + Y = 0.5, + Z = 2., + A = -1, + B = -1.5, + C = -1. +} + +let x0 = Foo.X.toString(); +let x1 = Foo["X"].toString(); +let y0 = Foo.Y.toString(); +let y1 = Foo["Y"].toString(); +let z0 = Foo.Z.toString(); +let z1 = Foo["Z"].toString(); +let a0 = Foo.A.toString(); +let a1 = Foo["A"].toString(); +let b0 = Foo.B.toString(); +let b1 = Foo["B"].toString(); +let c0 = Foo.C.toString(); +let c1 = Foo["C"].toString(); + + +//// [constEnumToStringNoComments.js] +var x0 = 100 .toString(); +var x1 = 100 .toString(); +var y0 = 0.5.toString(); +var y1 = 0.5.toString(); +var z0 = 2 .toString(); +var z1 = 2 .toString(); +var a0 = -1 .toString(); +var a1 = -1 .toString(); +var b0 = -1.5.toString(); +var b1 = -1.5.toString(); +var c0 = -1 .toString(); +var c1 = -1 .toString(); diff --git a/tests/baselines/reference/constEnumToStringNoComments.symbols b/tests/baselines/reference/constEnumToStringNoComments.symbols new file mode 100644 index 00000000000..0206e6a5d90 --- /dev/null +++ b/tests/baselines/reference/constEnumToStringNoComments.symbols @@ -0,0 +1,113 @@ +=== tests/cases/compiler/constEnumToStringNoComments.ts === +const enum Foo { +>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0)) + + X = 100, +>X : Symbol(Foo.X, Decl(constEnumToStringNoComments.ts, 0, 16)) + + Y = 0.5, +>Y : Symbol(Foo.Y, Decl(constEnumToStringNoComments.ts, 1, 12)) + + Z = 2., +>Z : Symbol(Foo.Z, Decl(constEnumToStringNoComments.ts, 2, 12)) + + A = -1, +>A : Symbol(Foo.A, Decl(constEnumToStringNoComments.ts, 3, 11)) + + B = -1.5, +>B : Symbol(Foo.B, Decl(constEnumToStringNoComments.ts, 4, 11)) + + C = -1. +>C : Symbol(Foo.C, Decl(constEnumToStringNoComments.ts, 5, 13)) +} + +let x0 = Foo.X.toString(); +>x0 : Symbol(x0, Decl(constEnumToStringNoComments.ts, 9, 3)) +>Foo.X.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo.X : Symbol(Foo.X, Decl(constEnumToStringNoComments.ts, 0, 16)) +>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0)) +>X : Symbol(Foo.X, Decl(constEnumToStringNoComments.ts, 0, 16)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let x1 = Foo["X"].toString(); +>x1 : Symbol(x1, Decl(constEnumToStringNoComments.ts, 10, 3)) +>Foo["X"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0)) +>"X" : Symbol(Foo.X, Decl(constEnumToStringNoComments.ts, 0, 16)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let y0 = Foo.Y.toString(); +>y0 : Symbol(y0, Decl(constEnumToStringNoComments.ts, 11, 3)) +>Foo.Y.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo.Y : Symbol(Foo.Y, Decl(constEnumToStringNoComments.ts, 1, 12)) +>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0)) +>Y : Symbol(Foo.Y, Decl(constEnumToStringNoComments.ts, 1, 12)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let y1 = Foo["Y"].toString(); +>y1 : Symbol(y1, Decl(constEnumToStringNoComments.ts, 12, 3)) +>Foo["Y"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0)) +>"Y" : Symbol(Foo.Y, Decl(constEnumToStringNoComments.ts, 1, 12)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let z0 = Foo.Z.toString(); +>z0 : Symbol(z0, Decl(constEnumToStringNoComments.ts, 13, 3)) +>Foo.Z.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo.Z : Symbol(Foo.Z, Decl(constEnumToStringNoComments.ts, 2, 12)) +>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0)) +>Z : Symbol(Foo.Z, Decl(constEnumToStringNoComments.ts, 2, 12)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let z1 = Foo["Z"].toString(); +>z1 : Symbol(z1, Decl(constEnumToStringNoComments.ts, 14, 3)) +>Foo["Z"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0)) +>"Z" : Symbol(Foo.Z, Decl(constEnumToStringNoComments.ts, 2, 12)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let a0 = Foo.A.toString(); +>a0 : Symbol(a0, Decl(constEnumToStringNoComments.ts, 15, 3)) +>Foo.A.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo.A : Symbol(Foo.A, Decl(constEnumToStringNoComments.ts, 3, 11)) +>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0)) +>A : Symbol(Foo.A, Decl(constEnumToStringNoComments.ts, 3, 11)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let a1 = Foo["A"].toString(); +>a1 : Symbol(a1, Decl(constEnumToStringNoComments.ts, 16, 3)) +>Foo["A"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0)) +>"A" : Symbol(Foo.A, Decl(constEnumToStringNoComments.ts, 3, 11)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let b0 = Foo.B.toString(); +>b0 : Symbol(b0, Decl(constEnumToStringNoComments.ts, 17, 3)) +>Foo.B.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo.B : Symbol(Foo.B, Decl(constEnumToStringNoComments.ts, 4, 11)) +>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0)) +>B : Symbol(Foo.B, Decl(constEnumToStringNoComments.ts, 4, 11)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let b1 = Foo["B"].toString(); +>b1 : Symbol(b1, Decl(constEnumToStringNoComments.ts, 18, 3)) +>Foo["B"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0)) +>"B" : Symbol(Foo.B, Decl(constEnumToStringNoComments.ts, 4, 11)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let c0 = Foo.C.toString(); +>c0 : Symbol(c0, Decl(constEnumToStringNoComments.ts, 19, 3)) +>Foo.C.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo.C : Symbol(Foo.C, Decl(constEnumToStringNoComments.ts, 5, 13)) +>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0)) +>C : Symbol(Foo.C, Decl(constEnumToStringNoComments.ts, 5, 13)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let c1 = Foo["C"].toString(); +>c1 : Symbol(c1, Decl(constEnumToStringNoComments.ts, 20, 3)) +>Foo["C"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo : Symbol(Foo, Decl(constEnumToStringNoComments.ts, 0, 0)) +>"C" : Symbol(Foo.C, Decl(constEnumToStringNoComments.ts, 5, 13)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + diff --git a/tests/baselines/reference/constEnumToStringNoComments.types b/tests/baselines/reference/constEnumToStringNoComments.types new file mode 100644 index 00000000000..21c4dc6c703 --- /dev/null +++ b/tests/baselines/reference/constEnumToStringNoComments.types @@ -0,0 +1,140 @@ +=== tests/cases/compiler/constEnumToStringNoComments.ts === +const enum Foo { +>Foo : Foo + + X = 100, +>X : Foo +>100 : number + + Y = 0.5, +>Y : Foo +>0.5 : number + + Z = 2., +>Z : Foo +>2. : number + + A = -1, +>A : Foo +>-1 : number +>1 : number + + B = -1.5, +>B : Foo +>-1.5 : number +>1.5 : number + + C = -1. +>C : Foo +>-1. : number +>1. : number +} + +let x0 = Foo.X.toString(); +>x0 : string +>Foo.X.toString() : string +>Foo.X.toString : (radix?: number) => string +>Foo.X : Foo +>Foo : typeof Foo +>X : Foo +>toString : (radix?: number) => string + +let x1 = Foo["X"].toString(); +>x1 : string +>Foo["X"].toString() : string +>Foo["X"].toString : (radix?: number) => string +>Foo["X"] : Foo +>Foo : typeof Foo +>"X" : string +>toString : (radix?: number) => string + +let y0 = Foo.Y.toString(); +>y0 : string +>Foo.Y.toString() : string +>Foo.Y.toString : (radix?: number) => string +>Foo.Y : Foo +>Foo : typeof Foo +>Y : Foo +>toString : (radix?: number) => string + +let y1 = Foo["Y"].toString(); +>y1 : string +>Foo["Y"].toString() : string +>Foo["Y"].toString : (radix?: number) => string +>Foo["Y"] : Foo +>Foo : typeof Foo +>"Y" : string +>toString : (radix?: number) => string + +let z0 = Foo.Z.toString(); +>z0 : string +>Foo.Z.toString() : string +>Foo.Z.toString : (radix?: number) => string +>Foo.Z : Foo +>Foo : typeof Foo +>Z : Foo +>toString : (radix?: number) => string + +let z1 = Foo["Z"].toString(); +>z1 : string +>Foo["Z"].toString() : string +>Foo["Z"].toString : (radix?: number) => string +>Foo["Z"] : Foo +>Foo : typeof Foo +>"Z" : string +>toString : (radix?: number) => string + +let a0 = Foo.A.toString(); +>a0 : string +>Foo.A.toString() : string +>Foo.A.toString : (radix?: number) => string +>Foo.A : Foo +>Foo : typeof Foo +>A : Foo +>toString : (radix?: number) => string + +let a1 = Foo["A"].toString(); +>a1 : string +>Foo["A"].toString() : string +>Foo["A"].toString : (radix?: number) => string +>Foo["A"] : Foo +>Foo : typeof Foo +>"A" : string +>toString : (radix?: number) => string + +let b0 = Foo.B.toString(); +>b0 : string +>Foo.B.toString() : string +>Foo.B.toString : (radix?: number) => string +>Foo.B : Foo +>Foo : typeof Foo +>B : Foo +>toString : (radix?: number) => string + +let b1 = Foo["B"].toString(); +>b1 : string +>Foo["B"].toString() : string +>Foo["B"].toString : (radix?: number) => string +>Foo["B"] : Foo +>Foo : typeof Foo +>"B" : string +>toString : (radix?: number) => string + +let c0 = Foo.C.toString(); +>c0 : string +>Foo.C.toString() : string +>Foo.C.toString : (radix?: number) => string +>Foo.C : Foo +>Foo : typeof Foo +>C : Foo +>toString : (radix?: number) => string + +let c1 = Foo["C"].toString(); +>c1 : string +>Foo["C"].toString() : string +>Foo["C"].toString : (radix?: number) => string +>Foo["C"] : Foo +>Foo : typeof Foo +>"C" : string +>toString : (radix?: number) => string + diff --git a/tests/baselines/reference/constEnumToStringWithComments.js b/tests/baselines/reference/constEnumToStringWithComments.js new file mode 100644 index 00000000000..e70833c9b89 --- /dev/null +++ b/tests/baselines/reference/constEnumToStringWithComments.js @@ -0,0 +1,37 @@ +//// [constEnumToStringWithComments.ts] +const enum Foo { + X = 100, + Y = 0.5, + Z = 2., + A = -1, + B = -1.5, + C = -1. +} + +let x0 = Foo.X.toString(); +let x1 = Foo["X"].toString(); +let y0 = Foo.Y.toString(); +let y1 = Foo["Y"].toString(); +let z0 = Foo.Z.toString(); +let z1 = Foo["Z"].toString(); +let a0 = Foo.A.toString(); +let a1 = Foo["A"].toString(); +let b0 = Foo.B.toString(); +let b1 = Foo["B"].toString(); +let c0 = Foo.C.toString(); +let c1 = Foo["C"].toString(); + + +//// [constEnumToStringWithComments.js] +var x0 = 100 /* X */ .toString(); +var x1 = 100 /* "X" */ .toString(); +var y0 = 0.5 /* Y */.toString(); +var y1 = 0.5 /* "Y" */.toString(); +var z0 = 2 /* Z */ .toString(); +var z1 = 2 /* "Z" */ .toString(); +var a0 = -1 /* A */ .toString(); +var a1 = -1 /* "A" */ .toString(); +var b0 = -1.5 /* B */.toString(); +var b1 = -1.5 /* "B" */.toString(); +var c0 = -1 /* C */ .toString(); +var c1 = -1 /* "C" */ .toString(); diff --git a/tests/baselines/reference/constEnumToStringWithComments.symbols b/tests/baselines/reference/constEnumToStringWithComments.symbols new file mode 100644 index 00000000000..fafb7ab4611 --- /dev/null +++ b/tests/baselines/reference/constEnumToStringWithComments.symbols @@ -0,0 +1,113 @@ +=== tests/cases/compiler/constEnumToStringWithComments.ts === +const enum Foo { +>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0)) + + X = 100, +>X : Symbol(Foo.X, Decl(constEnumToStringWithComments.ts, 0, 16)) + + Y = 0.5, +>Y : Symbol(Foo.Y, Decl(constEnumToStringWithComments.ts, 1, 12)) + + Z = 2., +>Z : Symbol(Foo.Z, Decl(constEnumToStringWithComments.ts, 2, 12)) + + A = -1, +>A : Symbol(Foo.A, Decl(constEnumToStringWithComments.ts, 3, 11)) + + B = -1.5, +>B : Symbol(Foo.B, Decl(constEnumToStringWithComments.ts, 4, 11)) + + C = -1. +>C : Symbol(Foo.C, Decl(constEnumToStringWithComments.ts, 5, 13)) +} + +let x0 = Foo.X.toString(); +>x0 : Symbol(x0, Decl(constEnumToStringWithComments.ts, 9, 3)) +>Foo.X.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo.X : Symbol(Foo.X, Decl(constEnumToStringWithComments.ts, 0, 16)) +>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0)) +>X : Symbol(Foo.X, Decl(constEnumToStringWithComments.ts, 0, 16)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let x1 = Foo["X"].toString(); +>x1 : Symbol(x1, Decl(constEnumToStringWithComments.ts, 10, 3)) +>Foo["X"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0)) +>"X" : Symbol(Foo.X, Decl(constEnumToStringWithComments.ts, 0, 16)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let y0 = Foo.Y.toString(); +>y0 : Symbol(y0, Decl(constEnumToStringWithComments.ts, 11, 3)) +>Foo.Y.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo.Y : Symbol(Foo.Y, Decl(constEnumToStringWithComments.ts, 1, 12)) +>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0)) +>Y : Symbol(Foo.Y, Decl(constEnumToStringWithComments.ts, 1, 12)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let y1 = Foo["Y"].toString(); +>y1 : Symbol(y1, Decl(constEnumToStringWithComments.ts, 12, 3)) +>Foo["Y"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0)) +>"Y" : Symbol(Foo.Y, Decl(constEnumToStringWithComments.ts, 1, 12)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let z0 = Foo.Z.toString(); +>z0 : Symbol(z0, Decl(constEnumToStringWithComments.ts, 13, 3)) +>Foo.Z.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo.Z : Symbol(Foo.Z, Decl(constEnumToStringWithComments.ts, 2, 12)) +>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0)) +>Z : Symbol(Foo.Z, Decl(constEnumToStringWithComments.ts, 2, 12)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let z1 = Foo["Z"].toString(); +>z1 : Symbol(z1, Decl(constEnumToStringWithComments.ts, 14, 3)) +>Foo["Z"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0)) +>"Z" : Symbol(Foo.Z, Decl(constEnumToStringWithComments.ts, 2, 12)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let a0 = Foo.A.toString(); +>a0 : Symbol(a0, Decl(constEnumToStringWithComments.ts, 15, 3)) +>Foo.A.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo.A : Symbol(Foo.A, Decl(constEnumToStringWithComments.ts, 3, 11)) +>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0)) +>A : Symbol(Foo.A, Decl(constEnumToStringWithComments.ts, 3, 11)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let a1 = Foo["A"].toString(); +>a1 : Symbol(a1, Decl(constEnumToStringWithComments.ts, 16, 3)) +>Foo["A"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0)) +>"A" : Symbol(Foo.A, Decl(constEnumToStringWithComments.ts, 3, 11)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let b0 = Foo.B.toString(); +>b0 : Symbol(b0, Decl(constEnumToStringWithComments.ts, 17, 3)) +>Foo.B.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo.B : Symbol(Foo.B, Decl(constEnumToStringWithComments.ts, 4, 11)) +>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0)) +>B : Symbol(Foo.B, Decl(constEnumToStringWithComments.ts, 4, 11)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let b1 = Foo["B"].toString(); +>b1 : Symbol(b1, Decl(constEnumToStringWithComments.ts, 18, 3)) +>Foo["B"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0)) +>"B" : Symbol(Foo.B, Decl(constEnumToStringWithComments.ts, 4, 11)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let c0 = Foo.C.toString(); +>c0 : Symbol(c0, Decl(constEnumToStringWithComments.ts, 19, 3)) +>Foo.C.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo.C : Symbol(Foo.C, Decl(constEnumToStringWithComments.ts, 5, 13)) +>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0)) +>C : Symbol(Foo.C, Decl(constEnumToStringWithComments.ts, 5, 13)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + +let c1 = Foo["C"].toString(); +>c1 : Symbol(c1, Decl(constEnumToStringWithComments.ts, 20, 3)) +>Foo["C"].toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) +>Foo : Symbol(Foo, Decl(constEnumToStringWithComments.ts, 0, 0)) +>"C" : Symbol(Foo.C, Decl(constEnumToStringWithComments.ts, 5, 13)) +>toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) + diff --git a/tests/baselines/reference/constEnumToStringWithComments.types b/tests/baselines/reference/constEnumToStringWithComments.types new file mode 100644 index 00000000000..72d7d367f5d --- /dev/null +++ b/tests/baselines/reference/constEnumToStringWithComments.types @@ -0,0 +1,140 @@ +=== tests/cases/compiler/constEnumToStringWithComments.ts === +const enum Foo { +>Foo : Foo + + X = 100, +>X : Foo +>100 : number + + Y = 0.5, +>Y : Foo +>0.5 : number + + Z = 2., +>Z : Foo +>2. : number + + A = -1, +>A : Foo +>-1 : number +>1 : number + + B = -1.5, +>B : Foo +>-1.5 : number +>1.5 : number + + C = -1. +>C : Foo +>-1. : number +>1. : number +} + +let x0 = Foo.X.toString(); +>x0 : string +>Foo.X.toString() : string +>Foo.X.toString : (radix?: number) => string +>Foo.X : Foo +>Foo : typeof Foo +>X : Foo +>toString : (radix?: number) => string + +let x1 = Foo["X"].toString(); +>x1 : string +>Foo["X"].toString() : string +>Foo["X"].toString : (radix?: number) => string +>Foo["X"] : Foo +>Foo : typeof Foo +>"X" : string +>toString : (radix?: number) => string + +let y0 = Foo.Y.toString(); +>y0 : string +>Foo.Y.toString() : string +>Foo.Y.toString : (radix?: number) => string +>Foo.Y : Foo +>Foo : typeof Foo +>Y : Foo +>toString : (radix?: number) => string + +let y1 = Foo["Y"].toString(); +>y1 : string +>Foo["Y"].toString() : string +>Foo["Y"].toString : (radix?: number) => string +>Foo["Y"] : Foo +>Foo : typeof Foo +>"Y" : string +>toString : (radix?: number) => string + +let z0 = Foo.Z.toString(); +>z0 : string +>Foo.Z.toString() : string +>Foo.Z.toString : (radix?: number) => string +>Foo.Z : Foo +>Foo : typeof Foo +>Z : Foo +>toString : (radix?: number) => string + +let z1 = Foo["Z"].toString(); +>z1 : string +>Foo["Z"].toString() : string +>Foo["Z"].toString : (radix?: number) => string +>Foo["Z"] : Foo +>Foo : typeof Foo +>"Z" : string +>toString : (radix?: number) => string + +let a0 = Foo.A.toString(); +>a0 : string +>Foo.A.toString() : string +>Foo.A.toString : (radix?: number) => string +>Foo.A : Foo +>Foo : typeof Foo +>A : Foo +>toString : (radix?: number) => string + +let a1 = Foo["A"].toString(); +>a1 : string +>Foo["A"].toString() : string +>Foo["A"].toString : (radix?: number) => string +>Foo["A"] : Foo +>Foo : typeof Foo +>"A" : string +>toString : (radix?: number) => string + +let b0 = Foo.B.toString(); +>b0 : string +>Foo.B.toString() : string +>Foo.B.toString : (radix?: number) => string +>Foo.B : Foo +>Foo : typeof Foo +>B : Foo +>toString : (radix?: number) => string + +let b1 = Foo["B"].toString(); +>b1 : string +>Foo["B"].toString() : string +>Foo["B"].toString : (radix?: number) => string +>Foo["B"] : Foo +>Foo : typeof Foo +>"B" : string +>toString : (radix?: number) => string + +let c0 = Foo.C.toString(); +>c0 : string +>Foo.C.toString() : string +>Foo.C.toString : (radix?: number) => string +>Foo.C : Foo +>Foo : typeof Foo +>C : Foo +>toString : (radix?: number) => string + +let c1 = Foo["C"].toString(); +>c1 : string +>Foo["C"].toString() : string +>Foo["C"].toString : (radix?: number) => string +>Foo["C"] : Foo +>Foo : typeof Foo +>"C" : string +>toString : (radix?: number) => string + diff --git a/tests/baselines/reference/contextualSignatureInstantiation.types b/tests/baselines/reference/contextualSignatureInstantiation.types index 49d6871804c..dd88a00ae3a 100644 --- a/tests/baselines/reference/contextualSignatureInstantiation.types +++ b/tests/baselines/reference/contextualSignatureInstantiation.types @@ -87,24 +87,24 @@ var a = baz(1, 1, g); // Should be number >g : (x: T, y: T) => T var b: number | string; ->b : string | number +>b : number | string var b = foo(g); // Should be number | string ->b : string | number ->foo(g) : string | number +>b : number | string +>foo(g) : number | string >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 +>b : number | string +>bar(1, "one", g) : number | string >bar : (x: T, y: U, cb: (x: T, y: U) => V) => V >1 : number >"one" : string >g : (x: T, y: T) => T var b = bar("one", 1, g); // Should be number | string ->b : string | number +>b : number | string >bar("one", 1, g) : string | number >bar : (x: T, y: U, cb: (x: T, y: U) => V) => V >"one" : string @@ -112,11 +112,11 @@ var b = bar("one", 1, g); // Should be number | string >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 +>b : number | string +>baz(b, b, g) : number | string >baz : (x: T, y: T, cb: (x: T, y: T) => U) => U ->b : string | number ->b : string | number +>b : number | string +>b : number | string >g : (x: T, y: T) => T var d: number[] | string[]; @@ -138,7 +138,7 @@ var d = bar(1, "one", h); // Should be number[] | string[] var d = bar("one", 1, h); // Should be number[] | string[] >d : number[] | string[] ->bar("one", 1, h) : number[] | string[] +>bar("one", 1, h) : string[] | number[] >bar : (x: T, y: U, cb: (x: T, y: U) => V) => V >"one" : string >1 : number diff --git a/tests/baselines/reference/contextualTypeWithTuple.errors.txt b/tests/baselines/reference/contextualTypeWithTuple.errors.txt index ff9ace5a2c0..e447ed62b39 100644 --- a/tests/baselines/reference/contextualTypeWithTuple.errors.txt +++ b/tests/baselines/reference/contextualTypeWithTuple.errors.txt @@ -1,9 +1,9 @@ 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'. + Type '() => number | string | boolean' is not assignable to type '() => number | string'. + Type 'number | string | boolean' is not assignable to type 'number | string'. + Type 'boolean' is not assignable to type 'number | string'. + Type 'boolean' is not assignable to type 'string'. tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(15,1): error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]'. tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(18,1): error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]'. Types of property '0' are incompatible. @@ -31,10 +31,10 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(25,1): error TS23 ~~~~~~~~~~~~ !!! 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'. +!!! error TS2322: Type '() => number | string | boolean' is not assignable to type '() => number | string'. +!!! error TS2322: Type 'number | string | boolean' is not assignable to type 'number | string'. +!!! error TS2322: Type 'boolean' is not assignable to type 'number | string'. +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. 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 }]]; diff --git a/tests/baselines/reference/contextualTypeWithUnionTypeCallSignatures.symbols b/tests/baselines/reference/contextualTypeWithUnionTypeCallSignatures.symbols index 3e23a7812f5..172336603ab 100644 --- a/tests/baselines/reference/contextualTypeWithUnionTypeCallSignatures.symbols +++ b/tests/baselines/reference/contextualTypeWithUnionTypeCallSignatures.symbols @@ -82,7 +82,5 @@ var x4: IWithCallSignatures | IWithCallSignatures4 = a => /*here a should be any >IWithCallSignatures : Symbol(IWithCallSignatures, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 9, 1)) >IWithCallSignatures4 : Symbol(IWithCallSignatures4, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 18, 1)) >a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 35, 52)) ->a.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) >a : Symbol(a, Decl(contextualTypeWithUnionTypeCallSignatures.ts, 35, 52)) ->toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) diff --git a/tests/baselines/reference/contextualTypeWithUnionTypeCallSignatures.types b/tests/baselines/reference/contextualTypeWithUnionTypeCallSignatures.types index 8e1915d4754..02dfecf5c08 100644 --- a/tests/baselines/reference/contextualTypeWithUnionTypeCallSignatures.types +++ b/tests/baselines/reference/contextualTypeWithUnionTypeCallSignatures.types @@ -90,10 +90,10 @@ var x4: IWithCallSignatures | IWithCallSignatures4 = a => /*here a should be any >x4 : IWithCallSignatures | IWithCallSignatures4 >IWithCallSignatures : IWithCallSignatures >IWithCallSignatures4 : IWithCallSignatures4 ->a => /*here a should be any*/ a.toString() : (a: number) => string ->a : number ->a.toString() : string ->a.toString : (radix?: number) => string ->a : number ->toString : (radix?: number) => string +>a => /*here a should be any*/ a.toString() : (a: any) => any +>a : any +>a.toString() : any +>a.toString : any +>a : any +>toString : any diff --git a/tests/baselines/reference/contextualTypeWithUnionTypeMembers.types b/tests/baselines/reference/contextualTypeWithUnionTypeMembers.types index c51227fd13a..8f2abf37e0e 100644 --- a/tests/baselines/reference/contextualTypeWithUnionTypeMembers.types +++ b/tests/baselines/reference/contextualTypeWithUnionTypeMembers.types @@ -187,7 +187,7 @@ var arrayI1OrI2: Array | I2> = [i1, i2, { // Like i1 >Array : T[] >I1 : I1 >I2 : I2 ->[i1, i2, { // Like i1 commonPropertyType: "hello", commonMethodType: a=> a, commonMethodWithTypeParameter: a => a, methodOnlyInI1: a => a, propertyOnlyInI1: "Hello", }, { // Like i2 commonPropertyType: "hello", commonMethodType: a=> a, commonMethodWithTypeParameter: a => a, methodOnlyInI2: a => a, propertyOnlyInI2: "Hello", }, { // Like i1 and i2 both commonPropertyType: "hello", commonMethodType: a=> a, commonMethodWithTypeParameter: a => a, methodOnlyInI1: a => a, propertyOnlyInI1: "Hello", methodOnlyInI2: a => a, propertyOnlyInI2: "Hello", }] : (I1 | I2)[] +>[i1, i2, { // Like i1 commonPropertyType: "hello", commonMethodType: a=> a, commonMethodWithTypeParameter: a => a, methodOnlyInI1: a => a, propertyOnlyInI1: "Hello", }, { // Like i2 commonPropertyType: "hello", commonMethodType: a=> a, commonMethodWithTypeParameter: a => a, methodOnlyInI2: a => a, propertyOnlyInI2: "Hello", }, { // Like i1 and i2 both commonPropertyType: "hello", commonMethodType: a=> a, commonMethodWithTypeParameter: a => a, methodOnlyInI1: a => a, propertyOnlyInI1: "Hello", methodOnlyInI2: a => a, propertyOnlyInI2: "Hello", }] : (I1 | I2 | { commonPropertyType: string; commonMethodType: (a: string) => string; commonMethodWithTypeParameter: (a: number) => number; methodOnlyInI1: (a: string) => string; propertyOnlyInI1: string; methodOnlyInI2: (a: string) => string; propertyOnlyInI2: string; })[] >i1 : I1 >i2 : I2 >{ // Like i1 commonPropertyType: "hello", commonMethodType: a=> a, commonMethodWithTypeParameter: a => a, methodOnlyInI1: a => a, propertyOnlyInI1: "Hello", } : { commonPropertyType: string; commonMethodType: (a: string) => string; commonMethodWithTypeParameter: (a: number) => number; methodOnlyInI1: (a: string) => string; propertyOnlyInI1: string; } diff --git a/tests/baselines/reference/contextualTyping12.errors.txt b/tests/baselines/reference/contextualTyping12.errors.txt new file mode 100644 index 00000000000..8b079ecc5e0 --- /dev/null +++ b/tests/baselines/reference/contextualTyping12.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/contextualTyping12.ts(1,13): error TS2322: Type '({ id: number; } | { id: number; name: string; })[]' is not assignable to type '{ id: number; }[]'. + Type '{ id: number; } | { id: number; name: string; }' is not assignable to type '{ id: number; }'. + Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'. + Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'. + + +==== tests/cases/compiler/contextualTyping12.ts (1 errors) ==== + class foo { public bar:{id:number;}[] = [{id:1}, {id:2, name:"foo"}]; } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '({ id: number; } | { id: number; name: string; })[]' is not assignable to type '{ id: number; }[]'. +!!! error TS2322: Type '{ id: number; } | { id: number; name: string; }' is not assignable to type '{ id: number; }'. +!!! error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping12.symbols b/tests/baselines/reference/contextualTyping12.symbols deleted file mode 100644 index bafef4c8e0a..00000000000 --- a/tests/baselines/reference/contextualTyping12.symbols +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/compiler/contextualTyping12.ts === -class foo { public bar:{id:number;}[] = [{id:1}, {id:2, name:"foo"}]; } ->foo : Symbol(foo, Decl(contextualTyping12.ts, 0, 0)) ->bar : Symbol(bar, Decl(contextualTyping12.ts, 0, 11)) ->id : Symbol(id, Decl(contextualTyping12.ts, 0, 24)) ->id : Symbol(id, Decl(contextualTyping12.ts, 0, 42)) ->id : Symbol(id, Decl(contextualTyping12.ts, 0, 50)) ->name : Symbol(name, Decl(contextualTyping12.ts, 0, 55)) - diff --git a/tests/baselines/reference/contextualTyping12.types b/tests/baselines/reference/contextualTyping12.types deleted file mode 100644 index 68e2663fb6a..00000000000 --- a/tests/baselines/reference/contextualTyping12.types +++ /dev/null @@ -1,15 +0,0 @@ -=== tests/cases/compiler/contextualTyping12.ts === -class foo { public bar:{id:number;}[] = [{id:1}, {id:2, name:"foo"}]; } ->foo : foo ->bar : { id: number; }[] ->id : number ->[{id:1}, {id:2, name:"foo"}] : { id: number; }[] ->{id:1} : { id: number; } ->id : number ->1 : number ->{id:2, name:"foo"} : { id: number; name: string; } ->id : number ->2 : number ->name : string ->"foo" : string - diff --git a/tests/baselines/reference/contextualTyping17.errors.txt b/tests/baselines/reference/contextualTyping17.errors.txt new file mode 100644 index 00000000000..24c428db58b --- /dev/null +++ b/tests/baselines/reference/contextualTyping17.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/contextualTyping17.ts(1,33): error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'. + Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'. + + +==== tests/cases/compiler/contextualTyping17.ts (1 errors) ==== + var foo: {id:number;} = {id:4}; foo = {id: 5, name:"foo"}; + ~~~ +!!! error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping17.symbols b/tests/baselines/reference/contextualTyping17.symbols deleted file mode 100644 index 55631494105..00000000000 --- a/tests/baselines/reference/contextualTyping17.symbols +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/compiler/contextualTyping17.ts === -var foo: {id:number;} = {id:4}; foo = {id: 5, name:"foo"}; ->foo : Symbol(foo, Decl(contextualTyping17.ts, 0, 3)) ->id : Symbol(id, Decl(contextualTyping17.ts, 0, 10)) ->id : Symbol(id, Decl(contextualTyping17.ts, 0, 25)) ->foo : Symbol(foo, Decl(contextualTyping17.ts, 0, 3)) ->id : Symbol(id, Decl(contextualTyping17.ts, 0, 39)) ->name : Symbol(name, Decl(contextualTyping17.ts, 0, 45)) - diff --git a/tests/baselines/reference/contextualTyping17.types b/tests/baselines/reference/contextualTyping17.types deleted file mode 100644 index 649bc339ba1..00000000000 --- a/tests/baselines/reference/contextualTyping17.types +++ /dev/null @@ -1,15 +0,0 @@ -=== tests/cases/compiler/contextualTyping17.ts === -var foo: {id:number;} = {id:4}; foo = {id: 5, name:"foo"}; ->foo : { id: number; } ->id : number ->{id:4} : { id: number; } ->id : number ->4 : number ->foo = {id: 5, name:"foo"} : { id: number; name: string; } ->foo : { id: number; } ->{id: 5, name:"foo"} : { id: number; name: string; } ->id : number ->5 : number ->name : string ->"foo" : string - diff --git a/tests/baselines/reference/contextualTyping2.errors.txt b/tests/baselines/reference/contextualTyping2.errors.txt new file mode 100644 index 00000000000..2665204b167 --- /dev/null +++ b/tests/baselines/reference/contextualTyping2.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/contextualTyping2.ts(1,5): error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'. + Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'. + + +==== tests/cases/compiler/contextualTyping2.ts (1 errors) ==== + var foo: {id:number;} = {id:4, name:"foo"}; + ~~~ +!!! error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping2.symbols b/tests/baselines/reference/contextualTyping2.symbols deleted file mode 100644 index 9c102092979..00000000000 --- a/tests/baselines/reference/contextualTyping2.symbols +++ /dev/null @@ -1,7 +0,0 @@ -=== tests/cases/compiler/contextualTyping2.ts === -var foo: {id:number;} = {id:4, name:"foo"}; ->foo : Symbol(foo, Decl(contextualTyping2.ts, 0, 3)) ->id : Symbol(id, Decl(contextualTyping2.ts, 0, 10)) ->id : Symbol(id, Decl(contextualTyping2.ts, 0, 25)) ->name : Symbol(name, Decl(contextualTyping2.ts, 0, 30)) - diff --git a/tests/baselines/reference/contextualTyping2.types b/tests/baselines/reference/contextualTyping2.types deleted file mode 100644 index 0658247c089..00000000000 --- a/tests/baselines/reference/contextualTyping2.types +++ /dev/null @@ -1,10 +0,0 @@ -=== tests/cases/compiler/contextualTyping2.ts === -var foo: {id:number;} = {id:4, name:"foo"}; ->foo : { id: number; } ->id : number ->{id:4, name:"foo"} : { id: number; name: string; } ->id : number ->4 : number ->name : string ->"foo" : string - diff --git a/tests/baselines/reference/contextualTyping20.errors.txt b/tests/baselines/reference/contextualTyping20.errors.txt new file mode 100644 index 00000000000..d723dcd1d1b --- /dev/null +++ b/tests/baselines/reference/contextualTyping20.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/contextualTyping20.ts(1,36): error TS2322: Type '({ id: number; } | { id: number; name: string; })[]' is not assignable to type '{ id: number; }[]'. + Type '{ id: number; } | { id: number; name: string; }' is not assignable to type '{ id: number; }'. + Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'. + Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'. + + +==== tests/cases/compiler/contextualTyping20.ts (1 errors) ==== + var foo:{id:number;}[] = [{id:1}]; foo = [{id:1}, {id:2, name:"foo"}]; + ~~~ +!!! error TS2322: Type '({ id: number; } | { id: number; name: string; })[]' is not assignable to type '{ id: number; }[]'. +!!! error TS2322: Type '{ id: number; } | { id: number; name: string; }' is not assignable to type '{ id: number; }'. +!!! error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping20.symbols b/tests/baselines/reference/contextualTyping20.symbols deleted file mode 100644 index 505c6a04a59..00000000000 --- a/tests/baselines/reference/contextualTyping20.symbols +++ /dev/null @@ -1,10 +0,0 @@ -=== tests/cases/compiler/contextualTyping20.ts === -var foo:{id:number;}[] = [{id:1}]; foo = [{id:1}, {id:2, name:"foo"}]; ->foo : Symbol(foo, Decl(contextualTyping20.ts, 0, 3)) ->id : Symbol(id, Decl(contextualTyping20.ts, 0, 9)) ->id : Symbol(id, Decl(contextualTyping20.ts, 0, 27)) ->foo : Symbol(foo, Decl(contextualTyping20.ts, 0, 3)) ->id : Symbol(id, Decl(contextualTyping20.ts, 0, 43)) ->id : Symbol(id, Decl(contextualTyping20.ts, 0, 51)) ->name : Symbol(name, Decl(contextualTyping20.ts, 0, 56)) - diff --git a/tests/baselines/reference/contextualTyping20.types b/tests/baselines/reference/contextualTyping20.types deleted file mode 100644 index be863db836b..00000000000 --- a/tests/baselines/reference/contextualTyping20.types +++ /dev/null @@ -1,20 +0,0 @@ -=== tests/cases/compiler/contextualTyping20.ts === -var foo:{id:number;}[] = [{id:1}]; foo = [{id:1}, {id:2, name:"foo"}]; ->foo : { id: number; }[] ->id : number ->[{id:1}] : { id: number; }[] ->{id:1} : { id: number; } ->id : number ->1 : number ->foo = [{id:1}, {id:2, name:"foo"}] : { id: number; }[] ->foo : { id: number; }[] ->[{id:1}, {id:2, name:"foo"}] : { id: number; }[] ->{id:1} : { id: number; } ->id : number ->1 : number ->{id:2, name:"foo"} : { id: number; name: string; } ->id : number ->2 : number ->name : string ->"foo" : string - diff --git a/tests/baselines/reference/contextualTyping21.errors.txt b/tests/baselines/reference/contextualTyping21.errors.txt index d40192c6240..362ead49ad3 100644 --- a/tests/baselines/reference/contextualTyping21.errors.txt +++ b/tests/baselines/reference/contextualTyping21.errors.txt @@ -1,5 +1,5 @@ -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; }'. +tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type '({ id: number; } | number)[]' is not assignable to type '{ id: number; }[]'. + Type '{ id: number; } | number' is not assignable to type '{ id: number; }'. Type 'number' is not assignable to type '{ id: number; }'. Property 'id' is missing in type 'Number'. @@ -7,7 +7,7 @@ tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type '(number | ==== tests/cases/compiler/contextualTyping21.ts (1 errors) ==== var foo:{id:number;}[] = [{id:1}]; foo = [{id:1}, 1]; ~~~ -!!! 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 '({ id: number; } | number)[]' is not assignable to type '{ id: number; }[]'. +!!! error TS2322: Type '{ id: number; } | 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 eda30769ac8..bce19c50896 100644 --- a/tests/baselines/reference/contextualTyping30.errors.txt +++ b/tests/baselines/reference/contextualTyping30.errors.txt @@ -1,11 +1,11 @@ -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'. +tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. + Type 'number | string' 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 '(string | number)[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type 'string | number' is not assignable to type 'number'. +!!! error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'number | string' 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/contextualTyping37.types b/tests/baselines/reference/contextualTyping37.types index 299b4400137..8acd4aedf04 100644 --- a/tests/baselines/reference/contextualTyping37.types +++ b/tests/baselines/reference/contextualTyping37.types @@ -3,7 +3,7 @@ var foo = <{ id: number; }[]>[{ foo: "s" }, { }]; >foo : { id: number; }[] ><{ id: number; }[]>[{ foo: "s" }, { }] : { id: number; }[] >id : number ->[{ foo: "s" }, { }] : {}[] +>[{ foo: "s" }, { }] : ({ foo: string; } | {})[] >{ foo: "s" } : { foo: string; } >foo : string >"s" : string diff --git a/tests/baselines/reference/contextualTyping4.errors.txt b/tests/baselines/reference/contextualTyping4.errors.txt new file mode 100644 index 00000000000..48eb2c406f0 --- /dev/null +++ b/tests/baselines/reference/contextualTyping4.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/contextualTyping4.ts(1,13): error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'. + Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'. + + +==== tests/cases/compiler/contextualTyping4.ts (1 errors) ==== + class foo { public bar:{id:number;} = {id:5, name:"foo"}; } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping4.symbols b/tests/baselines/reference/contextualTyping4.symbols deleted file mode 100644 index c5dcd4f1577..00000000000 --- a/tests/baselines/reference/contextualTyping4.symbols +++ /dev/null @@ -1,8 +0,0 @@ -=== tests/cases/compiler/contextualTyping4.ts === -class foo { public bar:{id:number;} = {id:5, name:"foo"}; } ->foo : Symbol(foo, Decl(contextualTyping4.ts, 0, 0)) ->bar : Symbol(bar, Decl(contextualTyping4.ts, 0, 11)) ->id : Symbol(id, Decl(contextualTyping4.ts, 0, 24)) ->id : Symbol(id, Decl(contextualTyping4.ts, 0, 39)) ->name : Symbol(name, Decl(contextualTyping4.ts, 0, 44)) - diff --git a/tests/baselines/reference/contextualTyping4.types b/tests/baselines/reference/contextualTyping4.types deleted file mode 100644 index 757c67745f1..00000000000 --- a/tests/baselines/reference/contextualTyping4.types +++ /dev/null @@ -1,11 +0,0 @@ -=== tests/cases/compiler/contextualTyping4.ts === -class foo { public bar:{id:number;} = {id:5, name:"foo"}; } ->foo : foo ->bar : { id: number; } ->id : number ->{id:5, name:"foo"} : { id: number; name: string; } ->id : number ->5 : number ->name : string ->"foo" : string - diff --git a/tests/baselines/reference/contextualTyping9.errors.txt b/tests/baselines/reference/contextualTyping9.errors.txt new file mode 100644 index 00000000000..f959d1e2e69 --- /dev/null +++ b/tests/baselines/reference/contextualTyping9.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/contextualTyping9.ts(1,5): error TS2322: Type '({ id: number; } | { id: number; name: string; })[]' is not assignable to type '{ id: number; }[]'. + Type '{ id: number; } | { id: number; name: string; }' is not assignable to type '{ id: number; }'. + Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'. + Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'. + + +==== tests/cases/compiler/contextualTyping9.ts (1 errors) ==== + var foo:{id:number;}[] = [{id:1}, {id:2, name:"foo"}]; + ~~~ +!!! error TS2322: Type '({ id: number; } | { id: number; name: string; })[]' is not assignable to type '{ id: number; }[]'. +!!! error TS2322: Type '{ id: number; } | { id: number; name: string; }' is not assignable to type '{ id: number; }'. +!!! error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping9.symbols b/tests/baselines/reference/contextualTyping9.symbols deleted file mode 100644 index f9ef2220c20..00000000000 --- a/tests/baselines/reference/contextualTyping9.symbols +++ /dev/null @@ -1,8 +0,0 @@ -=== tests/cases/compiler/contextualTyping9.ts === -var foo:{id:number;}[] = [{id:1}, {id:2, name:"foo"}]; ->foo : Symbol(foo, Decl(contextualTyping9.ts, 0, 3)) ->id : Symbol(id, Decl(contextualTyping9.ts, 0, 9)) ->id : Symbol(id, Decl(contextualTyping9.ts, 0, 27)) ->id : Symbol(id, Decl(contextualTyping9.ts, 0, 35)) ->name : Symbol(name, Decl(contextualTyping9.ts, 0, 40)) - diff --git a/tests/baselines/reference/contextualTyping9.types b/tests/baselines/reference/contextualTyping9.types deleted file mode 100644 index 46480d64b30..00000000000 --- a/tests/baselines/reference/contextualTyping9.types +++ /dev/null @@ -1,14 +0,0 @@ -=== tests/cases/compiler/contextualTyping9.ts === -var foo:{id:number;}[] = [{id:1}, {id:2, name:"foo"}]; ->foo : { id: number; }[] ->id : number ->[{id:1}, {id:2, name:"foo"}] : { id: number; }[] ->{id:1} : { id: number; } ->id : number ->1 : number ->{id:2, name:"foo"} : { id: number; name: string; } ->id : number ->2 : number ->name : string ->"foo" : string - diff --git a/tests/baselines/reference/contextualTypingArrayOfLambdas.types b/tests/baselines/reference/contextualTypingArrayOfLambdas.types index d3e5b9942e3..0bb61604336 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: B) => void) | ((x: C) => void))[] +>[(x: A) => { }, (x: B) => { }, (x: C) => { }] : (((x: A) => void) | ((x: B) => void) | ((x: C) => 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 26b06abf782..a1bfaf56336 100644 --- a/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt +++ b/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type '(number | Date)[]' is not assignable to type 'I'. +tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type '(Date | number)[]' is not assignable to type 'I'. Index signatures are incompatible. - Type 'number | Date' is not assignable to type 'Date'. + Type 'Date | number' is not assignable to type 'Date'. Type 'number' is not assignable to type 'Date'. Property 'toDateString' is missing in type 'Number'. @@ -12,9 +12,9 @@ tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Typ var x3: I = [new Date(), 1]; ~~ -!!! error TS2322: Type '(number | Date)[]' is not assignable to type 'I'. +!!! error TS2322: Type '(Date | number)[]' is not assignable to type 'I'. !!! error TS2322: Index signatures are incompatible. -!!! error TS2322: Type 'number | Date' is not assignable to type 'Date'. +!!! error TS2322: Type 'Date | number' 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]; diff --git a/tests/baselines/reference/declFileTypeAnnotationParenType.js b/tests/baselines/reference/declFileTypeAnnotationParenType.js index c61517c7339..126ec3a873e 100644 --- a/tests/baselines/reference/declFileTypeAnnotationParenType.js +++ b/tests/baselines/reference/declFileTypeAnnotationParenType.js @@ -29,4 +29,4 @@ declare class c { declare var x: (() => c)[]; declare var y: (() => c)[]; declare var k: (() => c) | string; -declare var l: string | (() => c); +declare var l: (() => c) | string; diff --git a/tests/baselines/reference/declFileTypeAnnotationParenType.types b/tests/baselines/reference/declFileTypeAnnotationParenType.types index 31b6ad03751..6776a0f492f 100644 --- a/tests/baselines/reference/declFileTypeAnnotationParenType.types +++ b/tests/baselines/reference/declFileTypeAnnotationParenType.types @@ -23,9 +23,9 @@ var y = [() => new c()]; >c : typeof c var k: (() => c) | string = (() => new c()) || ""; ->k : string | (() => c) +>k : (() => c) | string >c : c ->(() => new c()) || "" : string | (() => c) +>(() => new c()) || "" : (() => c) | string >(() => new c()) : () => c >() => new c() : () => c >new c() : c @@ -33,8 +33,8 @@ var k: (() => c) | string = (() => new c()) || ""; >"" : string var l = (() => new c()) || ""; ->l : string | (() => c) ->(() => new c()) || "" : string | (() => c) +>l : (() => c) | string +>(() => new c()) || "" : (() => c) | string >(() => new c()) : () => c >() => new c() : () => c >new c() : c diff --git a/tests/baselines/reference/declFileTypeAnnotationTypeAlias.types b/tests/baselines/reference/declFileTypeAnnotationTypeAlias.types index beef88c0ca2..e93f86dbde7 100644 --- a/tests/baselines/reference/declFileTypeAnnotationTypeAlias.types +++ b/tests/baselines/reference/declFileTypeAnnotationTypeAlias.types @@ -47,7 +47,7 @@ module M { >M : typeof M export type W = Window | string; ->W : string | Window +>W : Window | string >Window : Window export module N { @@ -57,7 +57,7 @@ module M { >Window : Window export var p: W; ->p : string | Window ->W : string | Window +>p : Window | string +>W : Window | string } } diff --git a/tests/baselines/reference/declarationEmitDestructuring1.symbols b/tests/baselines/reference/declarationEmitDestructuring1.symbols index 10920128eee..32755fdef35 100644 --- a/tests/baselines/reference/declarationEmitDestructuring1.symbols +++ b/tests/baselines/reference/declarationEmitDestructuring1.symbols @@ -23,6 +23,7 @@ function bar({a1, b1, c1}: { a1: number, b1: boolean, c1: string }): void { } function baz({a2, b2: {b1, c1}}: { a2: number, b2: { b1: boolean, c1: string } }): void { } >baz : Symbol(baz, Decl(declarationEmitDestructuring1.ts, 2, 77)) >a2 : Symbol(a2, Decl(declarationEmitDestructuring1.ts, 3, 14)) +>b2 : Symbol(b2, Decl(declarationEmitDestructuring1.ts, 3, 46)) >b1 : Symbol(b1, Decl(declarationEmitDestructuring1.ts, 3, 23)) >c1 : Symbol(c1, Decl(declarationEmitDestructuring1.ts, 3, 26)) >a2 : Symbol(a2, Decl(declarationEmitDestructuring1.ts, 3, 34)) diff --git a/tests/baselines/reference/declarationEmitDestructuring3.js b/tests/baselines/reference/declarationEmitDestructuring3.js index b21c63203c8..81cb1d96fd8 100644 --- a/tests/baselines/reference/declarationEmitDestructuring3.js +++ b/tests/baselines/reference/declarationEmitDestructuring3.js @@ -15,4 +15,4 @@ function foo(_a) { //// [declarationEmitDestructuring3.d.ts] declare function bar([x, z, ...w]: any[]): void; -declare function foo([x, ...y]?: (string | number | boolean)[]): void; +declare function foo([x, ...y]?: (number | string | boolean)[]): void; diff --git a/tests/baselines/reference/declarationEmitDestructuring3.types b/tests/baselines/reference/declarationEmitDestructuring3.types index da9fc6d6606..737bb39e078 100644 --- a/tests/baselines/reference/declarationEmitDestructuring3.types +++ b/tests/baselines/reference/declarationEmitDestructuring3.types @@ -6,10 +6,10 @@ function bar([x, z, ...w]) { } >w : any[] function foo([x, ...y] = [1, "string", true]) { } ->foo : ([x, ...y]?: (string | number | boolean)[]) => void ->x : string | number | boolean ->y : (string | number | boolean)[] ->[1, "string", true] : (string | number | boolean)[] +>foo : ([x, ...y]?: (number | string | boolean)[]) => void +>x : number | string | boolean +>y : (number | string | boolean)[] +>[1, "string", true] : (number | string | boolean)[] >1 : number >"string" : string >true : boolean diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js index 9a9be8c69da..28330d94f77 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js @@ -23,6 +23,6 @@ var x3 = a[0], y3 = a[1], z3 = a[2]; // emit x3, y3, z3 declare var x: number; declare var x1: number, y1: string; declare var z1: number; -declare var a: (string | number)[]; -declare var x2: string | number; -declare var x3: string | number, y3: string | number, z3: string | number; +declare var a: (number | string)[]; +declare var x2: number | string; +declare var x3: number | string, y3: number | string, z3: number | string; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types index 0feeaf2db1a..9629324b9f9 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types @@ -1,7 +1,7 @@ === tests/cases/compiler/declarationEmitDestructuringArrayPattern1.ts === var [] = [1, "hello"]; // Dont emit anything ->[1, "hello"] : (string | number)[] +>[1, "hello"] : (number | string)[] >1 : number >"hello" : string @@ -28,18 +28,18 @@ var [, , z1] = [0, 1, 2]; // emit z1: number >2 : number var a = [1, "hello"]; ->a : (string | number)[] ->[1, "hello"] : (string | number)[] +>a : (number | string)[] +>[1, "hello"] : (number | string)[] >1 : number >"hello" : string var [x2] = a; // emit x2: number | string ->x2 : string | number ->a : (string | number)[] +>x2 : number | string +>a : (number | string)[] var [x3, y3, z3] = a; // emit x3, y3, z3 ->x3 : string | number ->y3 : string | number ->z3 : string | number ->a : (string | number)[] +>x3 : number | string +>y3 : number | string +>z3 : number | string +>a : (number | string)[] diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js index 818b3a6f7a9..662b4625ec8 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js @@ -25,7 +25,7 @@ declare var x11: number, y11: string; declare var a11: any, b11: any, c11: any; declare var a2: number, b2: string, x12: number, c2: boolean; declare var x13: number, y13: string; -declare var a3: (string | number)[], b3: { +declare var a3: (number | string)[], b3: { x: number; y: string; }; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols index 9e0e48f89e8..0a3c6f4044d 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.symbols @@ -17,6 +17,7 @@ var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello" >a2 : Symbol(a2, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 5)) >b2 : Symbol(b2, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 10)) >x12 : Symbol(x12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 15)) +>y12 : Symbol(y12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 91)) >c2 : Symbol(c2, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 20)) >x12 : Symbol(x12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 41)) >y12 : Symbol(y12, Decl(declarationEmitDestructuringArrayPattern2.ts, 5, 50)) diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types index 9fce72751cf..eb028aacff4 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types @@ -56,10 +56,10 @@ var [x13, y13] = [1, "hello"]; >"hello" : string var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; ->a3 : (string | number)[] +>a3 : (number | string)[] >b3 : { x: number; y: string; } ->[[x13, y13], { x: x13, y: y13 }] : [(string | number)[], { x: number; y: string; }] ->[x13, y13] : (string | number)[] +>[[x13, y13], { x: x13, y: y13 }] : [(number | string)[], { x: number; y: string; }] +>[x13, y13] : (number | string)[] >x13 : number >y13 : string >{ x: x13, y: y13 } : { x: number; y: string; } diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js index 1bd07e7b974..d83c1b721d8 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js @@ -25,7 +25,7 @@ declare var a5: number[]; declare var x14: number, a6: number[]; declare var x15: number, y15: number, a7: number[]; declare var x16: number, y16: number, z16: number, a8: number[]; -declare var a9: (string | number | boolean)[]; -declare var x17: string | number | boolean, a10: (string | number | boolean)[]; -declare var x18: string | number | boolean, y18: string | number | boolean, a12: (string | number | boolean)[]; -declare var x19: string | number | boolean, y19: string | number | boolean, z19: string | number | boolean, a13: (string | number | boolean)[]; +declare var a9: (number | string | boolean)[]; +declare var x17: number | string | boolean, a10: (number | string | boolean)[]; +declare var x18: number | string | boolean, y18: number | string | boolean, a12: (number | string | boolean)[]; +declare var x19: number | string | boolean, y19: number | string | boolean, z19: number | string | boolean, a13: (number | string | boolean)[]; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types index 2cc56abcb05..1e8701eedb5 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types @@ -34,35 +34,35 @@ var [x16, y16, z16, ...a8] = [1, 2, 3]; >3 : number var [...a9] = [1, "hello", true]; ->a9 : (string | number | boolean)[] ->[1, "hello", true] : (string | number | boolean)[] +>a9 : (number | string | boolean)[] +>[1, "hello", true] : (number | string | boolean)[] >1 : number >"hello" : string >true : boolean var [x17, ...a10] = [1, "hello", true]; ->x17 : string | number | boolean ->a10 : (string | number | boolean)[] ->[1, "hello", true] : (string | number | boolean)[] +>x17 : number | string | boolean +>a10 : (number | string | boolean)[] +>[1, "hello", true] : (number | string | boolean)[] >1 : number >"hello" : string >true : boolean var [x18, y18, ...a12] = [1, "hello", true]; ->x18 : string | number | boolean ->y18 : string | number | boolean ->a12 : (string | number | boolean)[] ->[1, "hello", true] : (string | number | boolean)[] +>x18 : number | string | boolean +>y18 : number | string | boolean +>a12 : (number | string | boolean)[] +>[1, "hello", true] : (number | string | boolean)[] >1 : number >"hello" : string >true : boolean var [x19, y19, z19, ...a13] = [1, "hello", true]; ->x19 : string | number | boolean ->y19 : string | number | boolean ->z19 : string | number | boolean ->a13 : (string | number | boolean)[] ->[1, "hello", true] : (string | number | boolean)[] +>x19 : number | string | boolean +>y19 : number | string | boolean +>z19 : number | string | boolean +>a13 : (number | string | boolean)[] +>[1, "hello", true] : (number | string | boolean)[] >1 : number >"hello" : string >true : boolean diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols index 3cb4ef28c2b..0a57a93f3d0 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.symbols @@ -21,24 +21,33 @@ var { x6, y6 } = { x6: 5, y6: "hello" }; >y6 : Symbol(y6, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 4, 25)) var { x7: a1 } = { x7: 5, y7: "hello" }; +>x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 18)) >a1 : Symbol(a1, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 5)) >x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 18)) >y7 : Symbol(y7, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 5, 25)) var { y8: b1 } = { x8: 5, y8: "hello" }; +>y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 25)) >b1 : Symbol(b1, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 5)) >x8 : Symbol(x8, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 18)) >y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 6, 25)) var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; +>x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 26)) >a2 : Symbol(a2, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 5)) +>y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 33)) >b2 : Symbol(b2, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 13)) >x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 26)) >y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 7, 33)) var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; +>a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 46)) >x11 : Symbol(x11, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 5)) +>b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 52)) +>a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 57)) >y11 : Symbol(y11, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 18)) +>b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 69)) +>a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 74)) >z11 : Symbol(z11, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 31)) >a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 46)) >b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern.ts, 9, 52)) diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols index a4c43a07bc8..cac2431411e 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.symbols @@ -21,17 +21,21 @@ var { x6, y6 } = { x6: 5, y6: "hello" }; >y6 : Symbol(y6, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 4, 25)) var { x7: a1 } = { x7: 5, y7: "hello" }; +>x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 18)) >a1 : Symbol(a1, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 5)) >x7 : Symbol(x7, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 18)) >y7 : Symbol(y7, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 5, 25)) var { y8: b1 } = { x8: 5, y8: "hello" }; +>y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 25)) >b1 : Symbol(b1, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 5)) >x8 : Symbol(x8, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 18)) >y8 : Symbol(y8, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 6, 25)) var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; +>x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 26)) >a2 : Symbol(a2, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 5)) +>y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 33)) >b2 : Symbol(b2, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 13)) >x9 : Symbol(x9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 26)) >y9 : Symbol(y9, Decl(declarationEmitDestructuringObjectLiteralPattern1.ts, 7, 33)) diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.symbols b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.symbols index 76440b60038..77e26e2c9b7 100644 --- a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.symbols +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.symbols @@ -1,8 +1,13 @@ === tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern2.ts === var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; +>a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 46)) >x11 : Symbol(x11, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 5)) +>b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 52)) +>a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 57)) >y11 : Symbol(y11, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 18)) +>b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 69)) +>a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 74)) >z11 : Symbol(z11, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 31)) >a : Symbol(a, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 46)) >b : Symbol(b, Decl(declarationEmitDestructuringObjectLiteralPattern2.ts, 1, 52)) diff --git a/tests/baselines/reference/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.js b/tests/baselines/reference/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.js new file mode 100644 index 00000000000..204b1ba9a49 --- /dev/null +++ b/tests/baselines/reference/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.js @@ -0,0 +1,31 @@ +//// [decoratorMetadataForMethodWithNoReturnTypeAnnotation01.ts] + +declare var decorator: any; + +class MyClass { + constructor(test: string, test2: number) { + + } + + @decorator + doSomething() { + + } +} + + +//// [decoratorMetadataForMethodWithNoReturnTypeAnnotation01.js] +var MyClass = (function () { + function MyClass(test, test2) { + } + MyClass.prototype.doSomething = function () { + }; + Object.defineProperty(MyClass.prototype, "doSomething", + __decorate([ + decorator, + __metadata('design:type', Function), + __metadata('design:paramtypes', []), + __metadata('design:returntype', void 0) + ], MyClass.prototype, "doSomething", Object.getOwnPropertyDescriptor(MyClass.prototype, "doSomething"))); + return MyClass; +})(); diff --git a/tests/baselines/reference/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.symbols b/tests/baselines/reference/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.symbols new file mode 100644 index 00000000000..79c6fcbf24f --- /dev/null +++ b/tests/baselines/reference/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.symbols @@ -0,0 +1,23 @@ +=== tests/cases/compiler/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.ts === + +declare var decorator: any; +>decorator : Symbol(decorator, Decl(decoratorMetadataForMethodWithNoReturnTypeAnnotation01.ts, 1, 11)) + +class MyClass { +>MyClass : Symbol(MyClass, Decl(decoratorMetadataForMethodWithNoReturnTypeAnnotation01.ts, 1, 27)) + + constructor(test: string, test2: number) { +>test : Symbol(test, Decl(decoratorMetadataForMethodWithNoReturnTypeAnnotation01.ts, 4, 16)) +>test2 : Symbol(test2, Decl(decoratorMetadataForMethodWithNoReturnTypeAnnotation01.ts, 4, 29)) + + } + + @decorator +>decorator : Symbol(decorator, Decl(decoratorMetadataForMethodWithNoReturnTypeAnnotation01.ts, 1, 11)) + + doSomething() { +>doSomething : Symbol(doSomething, Decl(decoratorMetadataForMethodWithNoReturnTypeAnnotation01.ts, 6, 5)) + + } +} + diff --git a/tests/baselines/reference/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.types b/tests/baselines/reference/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.types new file mode 100644 index 00000000000..aebd8143eab --- /dev/null +++ b/tests/baselines/reference/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/decoratorMetadataForMethodWithNoReturnTypeAnnotation01.ts === + +declare var decorator: any; +>decorator : any + +class MyClass { +>MyClass : MyClass + + constructor(test: string, test2: number) { +>test : string +>test2 : number + + } + + @decorator +>decorator : any + + doSomething() { +>doSomething : () => void + + } +} + diff --git a/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt new file mode 100644 index 00000000000..be08d976eeb --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge01.errors.txt @@ -0,0 +1,49 @@ +tests/cases/conformance/es6/modules/m1.ts(2,25): error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. +tests/cases/conformance/es6/modules/m1.ts(11,18): error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. +tests/cases/conformance/es6/modules/m2.ts(5,8): error TS2304: Cannot find name 'Entity'. +tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. +tests/cases/conformance/es6/modules/m2.ts(8,8): error TS2339: Property 'x' does not exist on type '() => number'. +tests/cases/conformance/es6/modules/m2.ts(9,8): error TS2339: Property 'y' does not exist on type '() => number'. + + +==== tests/cases/conformance/es6/modules/m1.ts (2 errors) ==== + + export default function Decl() { + ~~~~ +!!! error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. + return 0; + } + + export interface Decl { + p1: number; + p2: number; + } + + export namespace Decl { + ~~~~ +!!! error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. + export var x = 10; + export var y = 20; + + interface I { + } + } + +==== tests/cases/conformance/es6/modules/m2.ts (4 errors) ==== + import Entity from "m1" + + Entity(); + + var x: Entity; + ~~~~~~ +!!! error TS2304: Cannot find name 'Entity'. + var y: Entity.I; + ~~~~~~ +!!! error TS2503: Cannot find namespace 'Entity'. + + Entity.x; + ~ +!!! error TS2339: Property 'x' does not exist on type '() => number'. + Entity.y; + ~ +!!! error TS2339: Property 'y' does not exist on type '() => number'. \ No newline at end of file diff --git a/tests/baselines/reference/defaultExportsCannotMerge01.js b/tests/baselines/reference/defaultExportsCannotMerge01.js new file mode 100644 index 00000000000..99b8ecab1d3 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge01.js @@ -0,0 +1,50 @@ +//// [tests/cases/conformance/es6/modules/defaultExportsCannotMerge01.ts] //// + +//// [m1.ts] + +export default function Decl() { + return 0; +} + +export interface Decl { + p1: number; + p2: number; +} + +export namespace Decl { + export var x = 10; + export var y = 20; + + interface I { + } +} + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; + +Entity.x; +Entity.y; + +//// [m1.js] +function Decl() { + return 0; +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = Decl; +var Decl; +(function (Decl) { + Decl.x = 10; + Decl.y = 20; +})(Decl = exports.Decl || (exports.Decl = {})); +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); +var x; +var y; +m1_1.default.x; +m1_1.default.y; diff --git a/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt new file mode 100644 index 00000000000..ad9b85c7e94 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge02.errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. +tests/cases/conformance/es6/modules/m1.ts(5,18): error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. +tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? +tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. +tests/cases/conformance/es6/modules/m2.ts(8,13): error TS2339: Property 'p1' does not exist on type 'Decl'. +tests/cases/conformance/es6/modules/m2.ts(8,20): error TS2339: Property 'p2' does not exist on type 'Decl'. + + +==== tests/cases/conformance/es6/modules/m1.ts (2 errors) ==== + + export default class Decl { + ~~~~ +!!! error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. + } + + export interface Decl { + ~~~~ +!!! error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. + p1: number; + p2: number; + } + + export namespace Decl { + interface I { + } + } + +==== tests/cases/conformance/es6/modules/m2.ts (4 errors) ==== + import Entity from "m1" + + Entity(); + ~~~~~~~~ +!!! error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? + + var x: Entity; + var y: Entity.I; + ~~~~~~ +!!! error TS2503: Cannot find namespace 'Entity'. + var z = new Entity(); + var sum = z.p1 + z.p2 + ~~ +!!! error TS2339: Property 'p1' does not exist on type 'Decl'. + ~~ +!!! error TS2339: Property 'p2' does not exist on type 'Decl'. \ No newline at end of file diff --git a/tests/baselines/reference/defaultExportsCannotMerge02.js b/tests/baselines/reference/defaultExportsCannotMerge02.js new file mode 100644 index 00000000000..e3897395c74 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge02.js @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/es6/modules/defaultExportsCannotMerge02.ts] //// + +//// [m1.ts] + +export default class Decl { +} + +export interface Decl { + p1: number; + p2: number; +} + +export namespace Decl { + interface I { + } +} + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; +var z = new Entity(); +var sum = z.p1 + z.p2 + +//// [m1.js] +var Decl = (function () { + function Decl() { + } + return Decl; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = Decl; +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); +var x; +var y; +var z = new m1_1.default(); +var sum = z.p1 + z.p2; diff --git a/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt new file mode 100644 index 00000000000..b1d405671e3 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge03.errors.txt @@ -0,0 +1,47 @@ +tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. +tests/cases/conformance/es6/modules/m1.ts(5,11): error TS2518: Only an ambient class can be merged with an interface. +tests/cases/conformance/es6/modules/m1.ts(5,11): error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. +tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? +tests/cases/conformance/es6/modules/m2.ts(6,8): error TS2503: Cannot find namespace 'Entity'. +tests/cases/conformance/es6/modules/m2.ts(8,13): error TS2339: Property 'p1' does not exist on type 'Decl'. +tests/cases/conformance/es6/modules/m2.ts(8,20): error TS2339: Property 'p2' does not exist on type 'Decl'. + + +==== tests/cases/conformance/es6/modules/m1.ts (3 errors) ==== + + export default class Decl { + ~~~~ +!!! error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. + } + + interface Decl { + ~~~~ +!!! error TS2518: Only an ambient class can be merged with an interface. + ~~~~ +!!! error TS2652: Merged declaration 'Decl' cannot include a default export declaration. Consider adding a separate 'export default Decl' declaration instead. + p1: number; + p2: number; + } + + namespace Decl { + interface I { + } + } + +==== tests/cases/conformance/es6/modules/m2.ts (4 errors) ==== + import Entity from "m1" + + Entity(); + ~~~~~~~~ +!!! error TS2348: Value of type 'typeof Decl' is not callable. Did you mean to include 'new'? + + var x: Entity; + var y: Entity.I; + ~~~~~~ +!!! error TS2503: Cannot find namespace 'Entity'. + var z = new Entity(); + var sum = z.p1 + z.p2 + ~~ +!!! error TS2339: Property 'p1' does not exist on type 'Decl'. + ~~ +!!! error TS2339: Property 'p2' does not exist on type 'Decl'. \ No newline at end of file diff --git a/tests/baselines/reference/defaultExportsCannotMerge03.js b/tests/baselines/reference/defaultExportsCannotMerge03.js new file mode 100644 index 00000000000..05e7de94120 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge03.js @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/es6/modules/defaultExportsCannotMerge03.ts] //// + +//// [m1.ts] + +export default class Decl { +} + +interface Decl { + p1: number; + p2: number; +} + +namespace Decl { + interface I { + } +} + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +var x: Entity; +var y: Entity.I; +var z = new Entity(); +var sum = z.p1 + z.p2 + +//// [m1.js] +var Decl = (function () { + function Decl() { + } + return Decl; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = Decl; +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); +var x; +var y; +var z = new m1_1.default(); +var sum = z.p1 + z.p2; diff --git a/tests/baselines/reference/defaultExportsCannotMerge04.errors.txt b/tests/baselines/reference/defaultExportsCannotMerge04.errors.txt new file mode 100644 index 00000000000..000a9b8f30e --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge04.errors.txt @@ -0,0 +1,28 @@ +tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts(2,25): error TS2652: Merged declaration 'Foo' cannot include a default export declaration. Consider adding a separate 'export default Foo' declaration instead. +tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts(5,11): error TS2652: Merged declaration 'Foo' cannot include a default export declaration. Consider adding a separate 'export default Foo' declaration instead. +tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts(9,11): error TS2395: Individual declarations in merged declaration 'Foo' must be all exported or all local. +tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts(12,18): error TS2395: Individual declarations in merged declaration 'Foo' must be all exported or all local. + + +==== tests/cases/conformance/es6/modules/defaultExportsCannotMerge04.ts (4 errors) ==== + + export default function Foo() { + ~~~ +!!! error TS2652: Merged declaration 'Foo' cannot include a default export declaration. Consider adding a separate 'export default Foo' declaration instead. + } + + namespace Foo { + ~~~ +!!! error TS2652: Merged declaration 'Foo' cannot include a default export declaration. Consider adding a separate 'export default Foo' declaration instead. + export var x; + } + + interface Foo { + ~~~ +!!! error TS2395: Individual declarations in merged declaration 'Foo' must be all exported or all local. + } + + export interface Foo { + ~~~ +!!! error TS2395: Individual declarations in merged declaration 'Foo' must be all exported or all local. + } \ No newline at end of file diff --git a/tests/baselines/reference/defaultExportsCannotMerge04.js b/tests/baselines/reference/defaultExportsCannotMerge04.js new file mode 100644 index 00000000000..eb1122a8197 --- /dev/null +++ b/tests/baselines/reference/defaultExportsCannotMerge04.js @@ -0,0 +1,23 @@ +//// [defaultExportsCannotMerge04.ts] + +export default function Foo() { +} + +namespace Foo { + export var x; +} + +interface Foo { +} + +export interface Foo { +} + +//// [defaultExportsCannotMerge04.js] +function Foo() { +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = Foo; +var Foo; +(function (Foo) { +})(Foo || (Foo = {})); diff --git a/tests/baselines/reference/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.errors.txt b/tests/baselines/reference/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.errors.txt new file mode 100644 index 00000000000..dc2db292eb5 --- /dev/null +++ b/tests/baselines/reference/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.errors.txt @@ -0,0 +1,25 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts(14,28): error TS2345: Argument of type '{ a: number; b: number; }' is not assignable to parameter of type '{ a: number; }'. + Object literal may only specify known properties, and 'b' does not exist in type '{ a: number; }'. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts (1 errors) ==== + class Base { + foo(x: { a: number }): { a: number } { + return null; + } + } + + class Derived extends Base { + foo(x: { a: number; b: number }): { a: number; b: number } { + return null; + } + + bar() { + var r = super.foo({ a: 1 }); // { a: number } + var r2 = super.foo({ a: 1, b: 2 }); // { a: number } + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ a: number; b: number; }' is not assignable to parameter of type '{ a: number; }'. +!!! error TS2345: Object literal may only specify known properties, and 'b' does not exist in type '{ a: number; }'. + var r3 = this.foo({ a: 1, b: 2 }); // { a: number; b: number; } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.symbols b/tests/baselines/reference/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.symbols deleted file mode 100644 index e935d7bf66a..00000000000 --- a/tests/baselines/reference/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.symbols +++ /dev/null @@ -1,56 +0,0 @@ -=== tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts === -class Base { ->Base : Symbol(Base, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 0, 0)) - - foo(x: { a: number }): { a: number } { ->foo : Symbol(foo, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 0, 12)) ->x : Symbol(x, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 1, 8)) ->a : Symbol(a, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 1, 12)) ->a : Symbol(a, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 1, 28)) - - return null; - } -} - -class Derived extends Base { ->Derived : Symbol(Derived, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 4, 1)) ->Base : Symbol(Base, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 0, 0)) - - foo(x: { a: number; b: number }): { a: number; b: number } { ->foo : Symbol(foo, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 6, 28)) ->x : Symbol(x, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 7, 8)) ->a : Symbol(a, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 7, 12)) ->b : Symbol(b, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 7, 23)) ->a : Symbol(a, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 7, 39)) ->b : Symbol(b, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 7, 50)) - - return null; - } - - bar() { ->bar : Symbol(bar, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 9, 5)) - - var r = super.foo({ a: 1 }); // { a: number } ->r : Symbol(r, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 12, 11)) ->super.foo : Symbol(Base.foo, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 0, 12)) ->super : Symbol(Base, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 0, 0)) ->foo : Symbol(Base.foo, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 0, 12)) ->a : Symbol(a, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 12, 27)) - - var r2 = super.foo({ a: 1, b: 2 }); // { a: number } ->r2 : Symbol(r2, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 13, 11)) ->super.foo : Symbol(Base.foo, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 0, 12)) ->super : Symbol(Base, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 0, 0)) ->foo : Symbol(Base.foo, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 0, 12)) ->a : Symbol(a, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 13, 28)) ->b : Symbol(b, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 13, 34)) - - var r3 = this.foo({ a: 1, b: 2 }); // { a: number; b: number; } ->r3 : Symbol(r3, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 14, 11)) ->this.foo : Symbol(foo, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 6, 28)) ->this : Symbol(Derived, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 4, 1)) ->foo : Symbol(foo, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 6, 28)) ->a : Symbol(a, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 14, 27)) ->b : Symbol(b, Decl(derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts, 14, 33)) - } -} diff --git a/tests/baselines/reference/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.types b/tests/baselines/reference/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.types deleted file mode 100644 index d8d9f657255..00000000000 --- a/tests/baselines/reference/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.types +++ /dev/null @@ -1,69 +0,0 @@ -=== tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/derivedTypeAccessesHiddenBaseCallViaSuperPropertyAccess.ts === -class Base { ->Base : Base - - foo(x: { a: number }): { a: number } { ->foo : (x: { a: number; }) => { a: number; } ->x : { a: number; } ->a : number ->a : number - - return null; ->null : null - } -} - -class Derived extends Base { ->Derived : Derived ->Base : Base - - foo(x: { a: number; b: number }): { a: number; b: number } { ->foo : (x: { a: number; b: number; }) => { a: number; b: number; } ->x : { a: number; b: number; } ->a : number ->b : number ->a : number ->b : number - - return null; ->null : null - } - - bar() { ->bar : () => void - - var r = super.foo({ a: 1 }); // { a: number } ->r : { a: number; } ->super.foo({ a: 1 }) : { a: number; } ->super.foo : (x: { a: number; }) => { a: number; } ->super : Base ->foo : (x: { a: number; }) => { a: number; } ->{ a: 1 } : { a: number; } ->a : number ->1 : number - - var r2 = super.foo({ a: 1, b: 2 }); // { a: number } ->r2 : { a: number; } ->super.foo({ a: 1, b: 2 }) : { a: number; } ->super.foo : (x: { a: number; }) => { a: number; } ->super : Base ->foo : (x: { a: number; }) => { a: number; } ->{ a: 1, b: 2 } : { a: number; b: number; } ->a : number ->1 : number ->b : number ->2 : number - - var r3 = this.foo({ a: 1, b: 2 }); // { a: number; b: number; } ->r3 : { a: number; b: number; } ->this.foo({ a: 1, b: 2 }) : { a: number; b: number; } ->this.foo : (x: { a: number; b: number; }) => { a: number; b: number; } ->this : Derived ->foo : (x: { a: number; b: number; }) => { a: number; b: number; } ->{ a: 1, b: 2 } : { a: number; b: number; } ->a : number ->1 : number ->b : number ->2 : number - } -} diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types index bde9c867e2b..adff61e407c 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types @@ -148,8 +148,8 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; > : undefined > : undefined > : undefined ->c10 : (string | number)[] ->[1, 2, 3, 4, "hello"] : (string | number)[] +>c10 : (number | string)[] +>[1, 2, 3, 4, "hello"] : (number | string)[] >1 : number >2 : number >3 : number @@ -157,10 +157,10 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; >"hello" : string var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : string | number ->c12 : string | number ->c13 : (string | number)[] ->[1, 2, "string"] : (string | number)[] +>c11 : number | string +>c12 : number | string +>c13 : (number | string)[] +>[1, 2, "string"] : (number | string)[] >1 : number >2 : number >"string" : string diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types index 2d5d82c5efe..0a9e75a8aed 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types @@ -149,8 +149,8 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; > : undefined > : undefined > : undefined ->c10 : (string | number)[] ->[1, 2, 3, 4, "hello"] : (string | number)[] +>c10 : (number | string)[] +>[1, 2, 3, 4, "hello"] : (number | string)[] >1 : number >2 : number >3 : number @@ -158,10 +158,10 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; >"hello" : string var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : string | number ->c12 : string | number ->c13 : (string | number)[] ->[1, 2, "string"] : (string | number)[] +>c11 : number | string +>c12 : number | string +>c13 : (number | string)[] +>[1, 2, "string"] : (number | string)[] >1 : number >2 : number >"string" : string diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols index 017a7f71e61..718af66047d 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols @@ -19,6 +19,7 @@ var { b1, } = { b1:1, }; >b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 15)) var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 44)) >b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 11)) >b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 21)) >b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 44)) @@ -32,6 +33,7 @@ var {b4 = 1}: any = { b4: 100000 }; >b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 21)) var {b5: { b52 } } = { b5: { b52 } }; +>b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 23)) >b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 10)) >b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 23)) >b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 29)) diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols index 11289210ee4..57d739cbbfc 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols @@ -19,6 +19,7 @@ var { b1, } = { b1:1, }; >b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 15)) var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 44)) >b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 11)) >b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 21)) >b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 44)) @@ -32,6 +33,7 @@ var {b4 = 1}: any = { b4: 100000 }; >b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 21)) var {b5: { b52 } } = { b5: { b52 } }; +>b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 23)) >b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 10)) >b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 23)) >b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 29)) diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt index 12f50d6886c..95524d4bf4d 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt @@ -4,8 +4,8 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,29): error TS1005: ',' expected. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(8,4): error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'. Types of property 'pop' are incompatible. - Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'. - Type 'string | number | string[][]' is not assignable to type 'number | string[][]'. + Type '() => number | string[][] | string' is not assignable to type '() => number | string[][]'. + Type 'number | string[][] | string' is not assignable to type 'number | string[][]'. Type 'string' is not assignable to type 'number | string[][]'. Type 'string' is not assignable to type 'string[][]'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. @@ -26,10 +26,10 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(37,4): error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z?: number; }'. Types of property 'z' are incompatible. Type 'boolean' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(38,4): error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: string | number; }'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(38,4): error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: number | string; }'. Types of property 'b' are incompatible. - Type 'boolean' is not assignable to type 'string | number'. - Type 'boolean' is not assignable to type 'number'. + Type 'boolean' is not assignable to type 'number | string'. + Type 'boolean' is not assignable to type 'string'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(39,4): error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. Types of property '2' are incompatible. Type 'boolean' is not assignable to type '[[any]]'. @@ -73,8 +73,8 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'. !!! error TS2345: Types of property 'pop' are incompatible. -!!! error TS2345: Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'. -!!! error TS2345: Type 'string | number | string[][]' is not assignable to type 'number | string[][]'. +!!! error TS2345: Type '() => number | string[][] | string' is not assignable to type '() => number | string[][]'. +!!! error TS2345: Type 'number | string[][] | string' is not assignable to type 'number | string[][]'. !!! error TS2345: Type 'string' is not assignable to type 'number | string[][]'. !!! error TS2345: Type 'string' is not assignable to type 'string[][]'. @@ -135,10 +135,10 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( !!! error TS2345: Type 'boolean' is not assignable to type 'number'. c3({ b: true }); // Error, implied type is { b: number|string }. ~~~~~~~~~~~ -!!! error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: string | number; }'. +!!! error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: number | string; }'. !!! error TS2345: Types of property 'b' are incompatible. -!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. -!!! error TS2345: Type 'boolean' is not assignable to type 'number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number | string'. +!!! error TS2345: Type 'boolean' is not assignable to type 'string'. c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] ~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5.types b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types index d51a0e32dc8..b8d48dcb9d4 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES5.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types @@ -23,8 +23,8 @@ type stringOrNumArray = Array; >Number : Number function a1(...x: (number|string)[]) { } ->a1 : (...x: (string | number)[]) => void ->x : (string | number)[] +>a1 : (...x: (number | string)[]) => void +>x : (number | string)[] function a2(...a) { } >a2 : (...a: any[]) => void @@ -75,8 +75,8 @@ var array = [1, 2, 3]; >3 : number var array2 = [true, false, "hello"]; ->array2 : (string | boolean)[] ->[true, false, "hello"] : (string | boolean)[] +>array2 : (boolean | string)[] +>[true, false, "hello"] : (boolean | string)[] >true : boolean >false : boolean >"hello" : string @@ -90,7 +90,7 @@ a2([...array]); a1(...array); >a1(...array) : void ->a1 : (...x: (string | number)[]) => void +>a1 : (...x: (number | string)[]) => void >...array : number >array : number[] @@ -109,7 +109,7 @@ a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]] a10([1, 2, [["string"]], false, true]); // Parameter type is any[] >a10([1, 2, [["string"]], false, true]) : void >a10 : ([a, b, [[c]], ...x]: Iterable) => void ->[1, 2, [["string"]], false, true] : (number | boolean | string[][])[] +>[1, 2, [["string"]], false, true] : (number | string[][] | boolean)[] >1 : number >2 : number >[["string"]] : string[][] diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types index 63d5d074a8d..b439c4134ba 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types @@ -23,8 +23,8 @@ type stringOrNumArray = Array; >Number : Number function a1(...x: (number|string)[]) { } ->a1 : (...x: (string | number)[]) => void ->x : (string | number)[] +>a1 : (...x: (number | string)[]) => void +>x : (number | string)[] function a2(...a) { } >a2 : (...a: any[]) => void @@ -75,8 +75,8 @@ var array = [1, 2, 3]; >3 : number var array2 = [true, false, "hello"]; ->array2 : (string | boolean)[] ->[true, false, "hello"] : (string | boolean)[] +>array2 : (boolean | string)[] +>[true, false, "hello"] : (boolean | string)[] >true : boolean >false : boolean >"hello" : string @@ -90,7 +90,7 @@ a2([...array]); a1(...array); >a1(...array) : void ->a1 : (...x: (string | number)[]) => void +>a1 : (...x: (number | string)[]) => void >...array : number >array : number[] @@ -109,7 +109,7 @@ a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]] a10([1, 2, [["string"]], false, true]); // Parameter type is any[] >a10([1, 2, [["string"]], false, true]) : void >a10 : ([a, b, [[c]], ...x]: Iterable) => void ->[1, 2, [["string"]], false, true] : (number | boolean | string[][])[] +>[1, 2, [["string"]], false, true] : (number | string[][] | boolean)[] >1 : number >2 : number >[["string"]] : string[][] diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt index 707fb005a80..7e71a2cd753 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(11,13): error TS2370: A rest parameter must be of an array type. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(13,13): error TS2370: A rest parameter must be of an array type. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(20,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. - Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(20,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number | string'. + Type 'boolean' is not assignable to type 'string'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(21,7): error TS2304: Cannot find name 'array2'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(22,4): error TS2345: Argument of type '[number, number, string, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. Types of property '2' are incompatible. @@ -9,8 +9,8 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts( Property '0' is missing in type 'String'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(23,4): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]]]'. Property '2' is missing in type '[number, number]'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(24,4): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. - Type 'string | number' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(24,4): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. + Type 'number | string' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(29,24): error TS1005: ',' expected. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(34,22): error TS2304: Cannot find name 'E1'. @@ -43,8 +43,8 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts( a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] ~~~~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. -!!! error TS2345: Type 'boolean' is not assignable to type 'number'. +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number | string'. +!!! error TS2345: Type 'boolean' is not assignable to type 'string'. a1(...array2); // Error parameter type is (number|string)[] ~~~~~~ !!! error TS2304: Cannot find name 'array2'. @@ -60,8 +60,8 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts( !!! error TS2345: Property '2' is missing in type '[number, number]'. a6([1, 2, "string"]); // Error, parameter type is 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: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'number | string' is not assignable to type 'number'. !!! error TS2345: Type 'string' is not assignable to type 'number'. diff --git a/tests/baselines/reference/destructuringParameterProperties5.errors.txt b/tests/baselines/reference/destructuringParameterProperties5.errors.txt index dca02a9a84e..47e50b1df83 100644 --- a/tests/baselines/reference/destructuringParameterProperties5.errors.txt +++ b/tests/baselines/reference/destructuringParameterProperties5.errors.txt @@ -10,7 +10,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(7 tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(11,16): error TS2345: Argument of type '[{ x1: number; x2: string; x3: boolean; }, string, boolean]' is not assignable to parameter of type '[{ x: number; y: string; z: boolean; }, number, string]'. Types of property '0' are incompatible. Type '{ x1: number; x2: string; x3: boolean; }' is not assignable to type '{ x: number; y: string; z: boolean; }'. - Property 'x' is missing in type '{ x1: number; x2: string; x3: boolean; }'. + Object literal may only specify known properties, and 'x1' does not exist in type '{ x: number; y: string; z: boolean; }'. ==== tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts (10 errors) ==== @@ -47,5 +47,5 @@ tests/cases/conformance/es6/destructuring/destructuringParameterProperties5.ts(1 !!! error TS2345: Argument of type '[{ x1: number; x2: string; x3: boolean; }, string, boolean]' is not assignable to parameter of type '[{ x: number; y: string; z: boolean; }, number, string]'. !!! error TS2345: Types of property '0' are incompatible. !!! error TS2345: Type '{ x1: number; x2: string; x3: boolean; }' is not assignable to type '{ x: number; y: string; z: boolean; }'. -!!! error TS2345: Property 'x' is missing in type '{ x1: number; x2: string; x3: boolean; }'. +!!! error TS2345: Object literal may only specify known properties, and 'x1' does not exist in type '{ x: number; y: string; z: boolean; }'. var [a_x1, a_x2, a_x3, a_y, a_z] = [a.x1, a.x2, a.x3, a.y, a.z]; \ No newline at end of file diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols b/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols index 2a2f2a358ca..924527bf1b4 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols @@ -17,6 +17,7 @@ var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; // The type T associated with a destructuring variable declaration is determined as follows: // Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 7, 44)) >b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 11)) >b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 21)) >b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 7, 44)) @@ -74,6 +75,7 @@ var [d3, d4] = [1, "string", ...temp1]; // Combining both forms of destructuring, var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +>e : Symbol(e, Decl(destructuringVariableDeclaration1ES5.ts, 31, 49)) >e1 : Symbol(e1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 9)) >e2 : Symbol(e2, Decl(destructuringVariableDeclaration1ES5.ts, 31, 12)) >e3 : Symbol(e3, Decl(destructuringVariableDeclaration1ES5.ts, 31, 16)) @@ -84,8 +86,10 @@ var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; >b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 68)) var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f : Symbol(f, Decl(destructuringVariableDeclaration1ES5.ts, 32, 41)) >f1 : Symbol(f1, Decl(destructuringVariableDeclaration1ES5.ts, 32, 9)) >f2 : Symbol(f2, Decl(destructuringVariableDeclaration1ES5.ts, 32, 12)) +>f3 : Symbol(f3, Decl(destructuringVariableDeclaration1ES5.ts, 32, 53)) >f4 : Symbol(f4, Decl(destructuringVariableDeclaration1ES5.ts, 32, 18)) >f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 26)) >f : Symbol(f, Decl(destructuringVariableDeclaration1ES5.ts, 32, 41)) @@ -96,6 +100,7 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; // an initializer expression, the type of the initializer expression is required to be assignable // to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 36)) >g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 9)) >undefined : Symbol(undefined) >g : Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 36)) @@ -104,6 +109,7 @@ var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; >g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 64)) var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 36)) >h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 9)) >undefined : Symbol(undefined) >h : Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 36)) diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types index ef3507f0f8b..a0630fee995 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types @@ -84,8 +84,8 @@ var [...c1] = [1,2,3]; >3 : number var [...c2] = [1,2,3, "string"]; ->c2 : (string | number)[] ->[1,2,3, "string"] : (string | number)[] +>c2 : (number | string)[] +>[1,2,3, "string"] : (number | string)[] >1 : number >2 : number >3 : number @@ -113,9 +113,9 @@ var temp1 = [true, false, true] >true : boolean var [d3, d4] = [1, "string", ...temp1]; ->d3 : string | number | boolean ->d4 : string | number | boolean ->[1, "string", ...temp1] : (string | number | boolean)[] +>d3 : number | string | boolean +>d4 : number | string | boolean +>[1, "string", ...temp1] : (number | string | boolean)[] >1 : number >"string" : string >...temp1 : boolean diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols b/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols index 0350ff35251..ee4f391eb7a 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols @@ -17,6 +17,7 @@ var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; // The type T associated with a destructuring variable declaration is determined as follows: // Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 7, 44)) >b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 11)) >b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 21)) >b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 7, 44)) @@ -74,6 +75,7 @@ var [d3, d4] = [1, "string", ...temp1]; // Combining both forms of destructuring, var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +>e : Symbol(e, Decl(destructuringVariableDeclaration1ES6.ts, 31, 49)) >e1 : Symbol(e1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 9)) >e2 : Symbol(e2, Decl(destructuringVariableDeclaration1ES6.ts, 31, 12)) >e3 : Symbol(e3, Decl(destructuringVariableDeclaration1ES6.ts, 31, 16)) @@ -84,8 +86,10 @@ var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; >b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 68)) var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f : Symbol(f, Decl(destructuringVariableDeclaration1ES6.ts, 32, 41)) >f1 : Symbol(f1, Decl(destructuringVariableDeclaration1ES6.ts, 32, 9)) >f2 : Symbol(f2, Decl(destructuringVariableDeclaration1ES6.ts, 32, 12)) +>f3 : Symbol(f3, Decl(destructuringVariableDeclaration1ES6.ts, 32, 53)) >f4 : Symbol(f4, Decl(destructuringVariableDeclaration1ES6.ts, 32, 18)) >f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 26)) >f : Symbol(f, Decl(destructuringVariableDeclaration1ES6.ts, 32, 41)) @@ -96,6 +100,7 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; // an initializer expression, the type of the initializer expression is required to be assignable // to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 36)) >g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 9)) >undefined : Symbol(undefined) >g : Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 36)) @@ -104,6 +109,7 @@ var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; >g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 64)) var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 36)) >h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 9)) >undefined : Symbol(undefined) >h : Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 36)) diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types index d62574c28f0..f9faf519b0a 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types @@ -84,8 +84,8 @@ var [...c1] = [1,2,3]; >3 : number var [...c2] = [1,2,3, "string"]; ->c2 : (string | number)[] ->[1,2,3, "string"] : (string | number)[] +>c2 : (number | string)[] +>[1,2,3, "string"] : (number | string)[] >1 : number >2 : number >3 : number @@ -113,9 +113,9 @@ var temp1 = [true, false, true] >true : boolean var [d3, d4] = [1, "string", ...temp1]; ->d3 : string | number | boolean ->d4 : string | number | boolean ->[1, "string", ...temp1] : (string | number | boolean)[] +>d3 : number | string | boolean +>d4 : number | string | boolean +>[1, "string", ...temp1] : (number | string | boolean)[] >1 : number >"string" : string >...temp1 : boolean diff --git a/tests/baselines/reference/downlevelLetConst12.symbols b/tests/baselines/reference/downlevelLetConst12.symbols index d1c7fe3ea5b..97d6d5eebf8 100644 --- a/tests/baselines/reference/downlevelLetConst12.symbols +++ b/tests/baselines/reference/downlevelLetConst12.symbols @@ -12,6 +12,7 @@ let [baz] = []; >baz : Symbol(baz, Decl(downlevelLetConst12.ts, 6, 5)) let {a: baz2} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst12.ts, 7, 17)) >baz2 : Symbol(baz2, Decl(downlevelLetConst12.ts, 7, 5)) >a : Symbol(a, Decl(downlevelLetConst12.ts, 7, 17)) @@ -19,6 +20,7 @@ const [baz3] = [] >baz3 : Symbol(baz3, Decl(downlevelLetConst12.ts, 9, 7)) const {a: baz4} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst12.ts, 10, 19)) >baz4 : Symbol(baz4, Decl(downlevelLetConst12.ts, 10, 7)) >a : Symbol(a, Decl(downlevelLetConst12.ts, 10, 19)) diff --git a/tests/baselines/reference/downlevelLetConst13.symbols b/tests/baselines/reference/downlevelLetConst13.symbols index 1b06184f2b3..f8cd2e548a9 100644 --- a/tests/baselines/reference/downlevelLetConst13.symbols +++ b/tests/baselines/reference/downlevelLetConst13.symbols @@ -16,10 +16,12 @@ export const [bar2] = [2]; >bar2 : Symbol(bar2, Decl(downlevelLetConst13.ts, 7, 14)) export let {a: bar3} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst13.ts, 8, 24)) >bar3 : Symbol(bar3, Decl(downlevelLetConst13.ts, 8, 12)) >a : Symbol(a, Decl(downlevelLetConst13.ts, 8, 24)) export const {a: bar4} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst13.ts, 9, 26)) >bar4 : Symbol(bar4, Decl(downlevelLetConst13.ts, 9, 14)) >a : Symbol(a, Decl(downlevelLetConst13.ts, 9, 26)) @@ -39,10 +41,12 @@ export module M { >bar6 : Symbol(bar6, Decl(downlevelLetConst13.ts, 15, 18)) export let {a: bar7} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst13.ts, 16, 28)) >bar7 : Symbol(bar7, Decl(downlevelLetConst13.ts, 16, 16)) >a : Symbol(a, Decl(downlevelLetConst13.ts, 16, 28)) export const {a: bar8} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst13.ts, 17, 30)) >bar8 : Symbol(bar8, Decl(downlevelLetConst13.ts, 17, 18)) >a : Symbol(a, Decl(downlevelLetConst13.ts, 17, 30)) } diff --git a/tests/baselines/reference/downlevelLetConst14.symbols b/tests/baselines/reference/downlevelLetConst14.symbols index bf3450af71c..135f3c1417d 100644 --- a/tests/baselines/reference/downlevelLetConst14.symbols +++ b/tests/baselines/reference/downlevelLetConst14.symbols @@ -35,6 +35,7 @@ var z0, z1, z2, z3; >z1 : Symbol(z1, Decl(downlevelLetConst14.ts, 11, 9)) let {a: z2} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst14.ts, 13, 19)) >z2 : Symbol(z2, Decl(downlevelLetConst14.ts, 13, 9)) >a : Symbol(a, Decl(downlevelLetConst14.ts, 13, 19)) @@ -43,6 +44,7 @@ var z0, z1, z2, z3; >z2 : Symbol(z2, Decl(downlevelLetConst14.ts, 13, 9)) let {a: z3} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst14.ts, 15, 19)) >z3 : Symbol(z3, Decl(downlevelLetConst14.ts, 15, 9)) >a : Symbol(a, Decl(downlevelLetConst14.ts, 15, 19)) @@ -86,6 +88,7 @@ var y = true; >y : Symbol(y, Decl(downlevelLetConst14.ts, 29, 11)) let {a: z6} = {a: 1} +>a : Symbol(a, Decl(downlevelLetConst14.ts, 30, 23)) >z6 : Symbol(z6, Decl(downlevelLetConst14.ts, 30, 13)) >a : Symbol(a, Decl(downlevelLetConst14.ts, 30, 23)) @@ -129,6 +132,7 @@ var z5 = 1; >_z : Symbol(_z, Decl(downlevelLetConst14.ts, 46, 11)) let {a: _z5} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst14.ts, 47, 24)) >_z5 : Symbol(_z5, Decl(downlevelLetConst14.ts, 47, 13)) >a : Symbol(a, Decl(downlevelLetConst14.ts, 47, 24)) diff --git a/tests/baselines/reference/downlevelLetConst15.symbols b/tests/baselines/reference/downlevelLetConst15.symbols index 159e5a6d676..00c7e122eb2 100644 --- a/tests/baselines/reference/downlevelLetConst15.symbols +++ b/tests/baselines/reference/downlevelLetConst15.symbols @@ -28,6 +28,7 @@ var z0, z1, z2, z3; >z0 : Symbol(z0, Decl(downlevelLetConst15.ts, 9, 11)) const [{a: z1}] = [{a: 1}] +>a : Symbol(a, Decl(downlevelLetConst15.ts, 11, 24)) >z1 : Symbol(z1, Decl(downlevelLetConst15.ts, 11, 12)) >a : Symbol(a, Decl(downlevelLetConst15.ts, 11, 24)) @@ -36,6 +37,7 @@ var z0, z1, z2, z3; >z1 : Symbol(z1, Decl(downlevelLetConst15.ts, 11, 12)) const {a: z2} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst15.ts, 13, 21)) >z2 : Symbol(z2, Decl(downlevelLetConst15.ts, 13, 11)) >a : Symbol(a, Decl(downlevelLetConst15.ts, 13, 21)) @@ -44,6 +46,8 @@ var z0, z1, z2, z3; >z2 : Symbol(z2, Decl(downlevelLetConst15.ts, 13, 11)) const {a: {b: z3}} = { a: {b: 1} }; +>a : Symbol(a, Decl(downlevelLetConst15.ts, 15, 26)) +>b : Symbol(b, Decl(downlevelLetConst15.ts, 15, 31)) >z3 : Symbol(z3, Decl(downlevelLetConst15.ts, 15, 15)) >a : Symbol(a, Decl(downlevelLetConst15.ts, 15, 26)) >b : Symbol(b, Decl(downlevelLetConst15.ts, 15, 31)) @@ -88,6 +92,7 @@ var y = true; >y : Symbol(y, Decl(downlevelLetConst15.ts, 29, 13)) const {a: z6} = { a: 1 } +>a : Symbol(a, Decl(downlevelLetConst15.ts, 30, 25)) >z6 : Symbol(z6, Decl(downlevelLetConst15.ts, 30, 15)) >a : Symbol(a, Decl(downlevelLetConst15.ts, 30, 25)) @@ -131,6 +136,7 @@ var z5 = 1; >_z : Symbol(_z, Decl(downlevelLetConst15.ts, 46, 13)) const {a: _z5} = { a: 1 }; +>a : Symbol(a, Decl(downlevelLetConst15.ts, 47, 26)) >_z5 : Symbol(_z5, Decl(downlevelLetConst15.ts, 47, 15)) >a : Symbol(a, Decl(downlevelLetConst15.ts, 47, 26)) diff --git a/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt b/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt index df4f8f13c31..85dd29b78a3 100644 --- a/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt +++ b/tests/baselines/reference/duplicateSymbolsExportMatching.errors.txt @@ -1,21 +1,21 @@ -tests/cases/compiler/duplicateSymbolsExportMatching.ts(24,15): error TS2395: Individual declarations in merged declaration I must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(25,22): error TS2395: Individual declarations in merged declaration I must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(26,22): error TS2395: Individual declarations in merged declaration E must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(27,15): error TS2395: Individual declarations in merged declaration E must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(32,12): error TS2395: Individual declarations in merged declaration inst must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(35,19): error TS2395: Individual declarations in merged declaration inst must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(42,9): error TS2395: Individual declarations in merged declaration v must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(43,16): error TS2395: Individual declarations in merged declaration v must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(44,9): error TS2395: Individual declarations in merged declaration w must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(45,16): error TS2395: Individual declarations in merged declaration w must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(49,12): error TS2395: Individual declarations in merged declaration F must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(24,15): error TS2395: Individual declarations in merged declaration 'I' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(25,22): error TS2395: Individual declarations in merged declaration 'I' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(26,22): error TS2395: Individual declarations in merged declaration 'E' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(27,15): error TS2395: Individual declarations in merged declaration 'E' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(32,12): error TS2395: Individual declarations in merged declaration 'inst' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(35,19): error TS2395: Individual declarations in merged declaration 'inst' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(42,9): error TS2395: Individual declarations in merged declaration 'v' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(43,16): error TS2395: Individual declarations in merged declaration 'v' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(44,9): error TS2395: Individual declarations in merged declaration 'w' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(45,16): error TS2395: Individual declarations in merged declaration 'w' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(49,12): error TS2395: Individual declarations in merged declaration 'F' must be all exported or all local. tests/cases/compiler/duplicateSymbolsExportMatching.ts(49,12): error TS2434: A namespace declaration cannot be located prior to a class or function with which it is merged -tests/cases/compiler/duplicateSymbolsExportMatching.ts(52,21): error TS2395: Individual declarations in merged declaration F must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(56,11): error TS2395: Individual declarations in merged declaration C must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(57,12): error TS2395: Individual declarations in merged declaration C must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(58,19): error TS2395: Individual declarations in merged declaration C must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(64,11): error TS2395: Individual declarations in merged declaration D must be all exported or all local. -tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Individual declarations in merged declaration D must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(52,21): error TS2395: Individual declarations in merged declaration 'F' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(56,11): error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(57,12): error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(58,19): error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(64,11): error TS2395: Individual declarations in merged declaration 'D' must be all exported or all local. +tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Individual declarations in merged declaration 'D' must be all exported or all local. ==== tests/cases/compiler/duplicateSymbolsExportMatching.ts (18 errors) ==== @@ -44,28 +44,28 @@ tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Ind module N2 { interface I { } ~ -!!! error TS2395: Individual declarations in merged declaration I must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'I' must be all exported or all local. export interface I { } // error ~ -!!! error TS2395: Individual declarations in merged declaration I must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'I' must be all exported or all local. export interface E { } ~ -!!! error TS2395: Individual declarations in merged declaration E must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'E' must be all exported or all local. interface E { } // error ~ -!!! error TS2395: Individual declarations in merged declaration E must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'E' must be all exported or all local. } // Should report error only once for instantiated module module M { module inst { ~~~~ -!!! error TS2395: Individual declarations in merged declaration inst must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'inst' must be all exported or all local. var t; } export module inst { // one error ~~~~ -!!! error TS2395: Individual declarations in merged declaration inst must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'inst' must be all exported or all local. var t; } } @@ -74,41 +74,41 @@ tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Ind module M2 { var v: string; ~ -!!! error TS2395: Individual declarations in merged declaration v must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'v' must be all exported or all local. export var v: string; // one error (visibility) ~ -!!! error TS2395: Individual declarations in merged declaration v must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'v' must be all exported or all local. var w: number; ~ -!!! error TS2395: Individual declarations in merged declaration w must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'w' must be all exported or all local. export var w: string; // two errors (visibility and type mismatch) ~ -!!! error TS2395: Individual declarations in merged declaration w must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'w' must be all exported or all local. } module M { module F { ~ -!!! error TS2395: Individual declarations in merged declaration F must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'F' must be all exported or all local. ~ !!! error TS2434: A namespace declaration cannot be located prior to a class or function with which it is merged var t; } export function F() { } // Only one error for duplicate identifier (don't consider visibility) ~ -!!! error TS2395: Individual declarations in merged declaration F must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'F' must be all exported or all local. } module M { class C { } ~ -!!! error TS2395: Individual declarations in merged declaration C must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. module C { } ~ -!!! error TS2395: Individual declarations in merged declaration C must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. export module C { // Two visibility errors (one for the clodule symbol, and one for the merged container symbol) ~ -!!! error TS2395: Individual declarations in merged declaration C must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'C' must be all exported or all local. var t; } } @@ -116,7 +116,7 @@ tests/cases/compiler/duplicateSymbolsExportMatching.ts(65,18): error TS2395: Ind // Top level interface D { } ~ -!!! error TS2395: Individual declarations in merged declaration D must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'D' must be all exported or all local. export interface D { } ~ -!!! error TS2395: Individual declarations in merged declaration D must be all exported or all local. \ No newline at end of file +!!! error TS2395: Individual declarations in merged declaration 'D' must be all exported or all local. \ No newline at end of file diff --git a/tests/baselines/reference/emitArrowFunctionES6.symbols b/tests/baselines/reference/emitArrowFunctionES6.symbols index 06f83f7f6f0..8d1603cfd82 100644 --- a/tests/baselines/reference/emitArrowFunctionES6.symbols +++ b/tests/baselines/reference/emitArrowFunctionES6.symbols @@ -56,6 +56,7 @@ var p6 = ({ a }) => { }; var p7 = ({ a: { b } }) => { }; >p7 : Symbol(p7, Decl(emitArrowFunctionES6.ts, 15, 3)) +>a : Symbol(a) >b : Symbol(b, Decl(emitArrowFunctionES6.ts, 15, 16)) var p8 = ({ a = 1 }) => { }; @@ -64,6 +65,7 @@ var p8 = ({ a = 1 }) => { }; var p9 = ({ a: { b = 1 } = { b: 1 } }) => { }; >p9 : Symbol(p9, Decl(emitArrowFunctionES6.ts, 17, 3)) +>a : Symbol(a) >b : Symbol(b, Decl(emitArrowFunctionES6.ts, 17, 16)) >b : Symbol(b, Decl(emitArrowFunctionES6.ts, 17, 28)) diff --git a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments18_ES6.symbols b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments18_ES6.symbols index 4ac60f9b429..707b99c82c1 100644 --- a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments18_ES6.symbols +++ b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments18_ES6.symbols @@ -4,6 +4,7 @@ function f() { >f : Symbol(f, Decl(emitArrowFunctionWhenUsingArguments18_ES6.ts, 0, 0)) var { arguments: args } = { arguments }; +>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments18_ES6.ts, 2, 31)) >args : Symbol(args, Decl(emitArrowFunctionWhenUsingArguments18_ES6.ts, 2, 9)) >arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments18_ES6.ts, 2, 31)) diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter01.js b/tests/baselines/reference/emptyArrayBindingPatternParameter01.js index 05b59b7d5f2..5723c74f117 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter01.js +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter01.js @@ -2,7 +2,7 @@ function f([]) { - var x, y, z; + var x, y, z; } //// [emptyArrayBindingPatternParameter01.js] diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols b/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols index 3207ca97dec..f5089ce5850 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter01.symbols @@ -4,8 +4,8 @@ function f([]) { >f : Symbol(f, Decl(emptyArrayBindingPatternParameter01.ts, 0, 0)) - var x, y, z; ->x : Symbol(x, Decl(emptyArrayBindingPatternParameter01.ts, 3, 4)) ->y : Symbol(y, Decl(emptyArrayBindingPatternParameter01.ts, 3, 7)) ->z : Symbol(z, Decl(emptyArrayBindingPatternParameter01.ts, 3, 10)) + var x, y, z; +>x : Symbol(x, Decl(emptyArrayBindingPatternParameter01.ts, 3, 7)) +>y : Symbol(y, Decl(emptyArrayBindingPatternParameter01.ts, 3, 10)) +>z : Symbol(z, Decl(emptyArrayBindingPatternParameter01.ts, 3, 13)) } diff --git a/tests/baselines/reference/emptyArrayBindingPatternParameter01.types b/tests/baselines/reference/emptyArrayBindingPatternParameter01.types index e93394b7371..7ef40d52d59 100644 --- a/tests/baselines/reference/emptyArrayBindingPatternParameter01.types +++ b/tests/baselines/reference/emptyArrayBindingPatternParameter01.types @@ -4,7 +4,7 @@ function f([]) { >f : ([]: any[]) => void - var x, y, z; + var x, y, z; >x : any >y : any >z : any diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.js new file mode 100644 index 00000000000..b89db88e5e5 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.js @@ -0,0 +1,11 @@ +//// [emptyAssignmentPatterns01_ES5.ts] + +var a: any; + +({} = a); +([] = a); + +//// [emptyAssignmentPatterns01_ES5.js] +var a; +(a); +(a); diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES5.symbols b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.symbols new file mode 100644 index 00000000000..97752a1358d --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES5.ts, 1, 3)) + +({} = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES5.ts, 1, 3)) + +([] = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES5.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES5.types b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.types new file mode 100644 index 00000000000..cbc0a25b074 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES5.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES5.ts === + +var a: any; +>a : any + +({} = a); +>({} = a) : any +>{} = a : any +>{} : {} +>a : any + +([] = a); +>([] = a) : any +>[] = a : any +>[] : undefined[] +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES6.js b/tests/baselines/reference/emptyAssignmentPatterns01_ES6.js new file mode 100644 index 00000000000..fe311ac9061 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES6.js @@ -0,0 +1,11 @@ +//// [emptyAssignmentPatterns01_ES6.ts] + +var a: any; + +({} = a); +([] = a); + +//// [emptyAssignmentPatterns01_ES6.js] +var a; +({} = a); +([] = a); diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES6.symbols b/tests/baselines/reference/emptyAssignmentPatterns01_ES6.symbols new file mode 100644 index 00000000000..345bdd52265 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES6.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES6.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES6.ts, 1, 3)) + +({} = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES6.ts, 1, 3)) + +([] = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns01_ES6.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns01_ES6.types b/tests/baselines/reference/emptyAssignmentPatterns01_ES6.types new file mode 100644 index 00000000000..c22c0e72854 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns01_ES6.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns01_ES6.ts === + +var a: any; +>a : any + +({} = a); +>({} = a) : any +>{} = a : any +>{} : {} +>a : any + +([] = a); +>([] = a) : any +>[] = a : any +>[] : undefined[] +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js new file mode 100644 index 00000000000..7b9f1f402f9 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.js @@ -0,0 +1,13 @@ +//// [emptyAssignmentPatterns02_ES5.ts] + +var a: any; +let x, y, z, a1, a2, a3; + +({} = { x, y, z } = a); +([] = [ a1, a2, a3] = a); + +//// [emptyAssignmentPatterns02_ES5.js] +var a; +var x, y, z, a1, a2, a3; +((x = a.x, y = a.y, z = a.z, a)); +((a1 = a[0], a2 = a[1], a3 = a[2], a)); diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES5.symbols b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.symbols new file mode 100644 index 00000000000..a575ea35f24 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES5.ts, 1, 3)) + +let x, y, z, a1, a2, a3; +>x : Symbol(x, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 3)) +>y : Symbol(y, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 6)) +>z : Symbol(z, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 9)) +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 20)) + +({} = { x, y, z } = a); +>x : Symbol(x, Decl(emptyAssignmentPatterns02_ES5.ts, 4, 7)) +>y : Symbol(y, Decl(emptyAssignmentPatterns02_ES5.ts, 4, 10)) +>z : Symbol(z, Decl(emptyAssignmentPatterns02_ES5.ts, 4, 13)) +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES5.ts, 1, 3)) + +([] = [ a1, a2, a3] = a); +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns02_ES5.ts, 2, 20)) +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES5.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES5.types b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.types new file mode 100644 index 00000000000..76897f8516e --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES5.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES5.ts === + +var a: any; +>a : any + +let x, y, z, a1, a2, a3; +>x : any +>y : any +>z : any +>a1 : any +>a2 : any +>a3 : any + +({} = { x, y, z } = a); +>({} = { x, y, z } = a) : any +>{} = { x, y, z } = a : any +>{} : {} +>{ x, y, z } = a : any +>{ x, y, z } : { x: any; y: any; z: any; } +>x : any +>y : any +>z : any +>a : any + +([] = [ a1, a2, a3] = a); +>([] = [ a1, a2, a3] = a) : any +>[] = [ a1, a2, a3] = a : any +>[] : undefined[] +>[ a1, a2, a3] = a : any +>[ a1, a2, a3] : [any, any, any] +>a1 : any +>a2 : any +>a3 : any +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES6.js b/tests/baselines/reference/emptyAssignmentPatterns02_ES6.js new file mode 100644 index 00000000000..e9783c7e57d --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES6.js @@ -0,0 +1,13 @@ +//// [emptyAssignmentPatterns02_ES6.ts] + +var a: any; +let x, y, z, a1, a2, a3; + +({} = { x, y, z } = a); +([] = [ a1, a2, a3] = a); + +//// [emptyAssignmentPatterns02_ES6.js] +var a; +let x, y, z, a1, a2, a3; +({} = { x, y, z } = a); +([] = [a1, a2, a3] = a); diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES6.symbols b/tests/baselines/reference/emptyAssignmentPatterns02_ES6.symbols new file mode 100644 index 00000000000..e55339cb658 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES6.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES6.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES6.ts, 1, 3)) + +let x, y, z, a1, a2, a3; +>x : Symbol(x, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 3)) +>y : Symbol(y, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 6)) +>z : Symbol(z, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 9)) +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 20)) + +({} = { x, y, z } = a); +>x : Symbol(x, Decl(emptyAssignmentPatterns02_ES6.ts, 4, 7)) +>y : Symbol(y, Decl(emptyAssignmentPatterns02_ES6.ts, 4, 10)) +>z : Symbol(z, Decl(emptyAssignmentPatterns02_ES6.ts, 4, 13)) +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES6.ts, 1, 3)) + +([] = [ a1, a2, a3] = a); +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns02_ES6.ts, 2, 20)) +>a : Symbol(a, Decl(emptyAssignmentPatterns02_ES6.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns02_ES6.types b/tests/baselines/reference/emptyAssignmentPatterns02_ES6.types new file mode 100644 index 00000000000..48c9146e154 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns02_ES6.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns02_ES6.ts === + +var a: any; +>a : any + +let x, y, z, a1, a2, a3; +>x : any +>y : any +>z : any +>a1 : any +>a2 : any +>a3 : any + +({} = { x, y, z } = a); +>({} = { x, y, z } = a) : any +>{} = { x, y, z } = a : any +>{} : {} +>{ x, y, z } = a : any +>{ x, y, z } : { x: any; y: any; z: any; } +>x : any +>y : any +>z : any +>a : any + +([] = [ a1, a2, a3] = a); +>([] = [ a1, a2, a3] = a) : any +>[] = [ a1, a2, a3] = a : any +>[] : undefined[] +>[ a1, a2, a3] = a : any +>[ a1, a2, a3] : [any, any, any] +>a1 : any +>a2 : any +>a3 : any +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js new file mode 100644 index 00000000000..d9ff8ba9ede --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.js @@ -0,0 +1,11 @@ +//// [emptyAssignmentPatterns03_ES5.ts] + +var a: any; + +({} = {} = a); +([] = [] = a); + +//// [emptyAssignmentPatterns03_ES5.js] +var a; +(a); +(a); diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES5.symbols b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.symbols new file mode 100644 index 00000000000..c57365bc7d0 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES5.ts, 1, 3)) + +({} = {} = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES5.ts, 1, 3)) + +([] = [] = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES5.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES5.types b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.types new file mode 100644 index 00000000000..4f32b0555ef --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES5.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES5.ts === + +var a: any; +>a : any + +({} = {} = a); +>({} = {} = a) : any +>{} = {} = a : any +>{} : {} +>{} = a : any +>{} : {} +>a : any + +([] = [] = a); +>([] = [] = a) : any +>[] = [] = a : any +>[] : undefined[] +>[] = a : any +>[] : undefined[] +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES6.js b/tests/baselines/reference/emptyAssignmentPatterns03_ES6.js new file mode 100644 index 00000000000..95bfdfefa52 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES6.js @@ -0,0 +1,11 @@ +//// [emptyAssignmentPatterns03_ES6.ts] + +var a: any; + +({} = {} = a); +([] = [] = a); + +//// [emptyAssignmentPatterns03_ES6.js] +var a; +({} = {} = a); +([] = [] = a); diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES6.symbols b/tests/baselines/reference/emptyAssignmentPatterns03_ES6.symbols new file mode 100644 index 00000000000..3e32848207a --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES6.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES6.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES6.ts, 1, 3)) + +({} = {} = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES6.ts, 1, 3)) + +([] = [] = a); +>a : Symbol(a, Decl(emptyAssignmentPatterns03_ES6.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns03_ES6.types b/tests/baselines/reference/emptyAssignmentPatterns03_ES6.types new file mode 100644 index 00000000000..1f1d005aac5 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns03_ES6.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns03_ES6.ts === + +var a: any; +>a : any + +({} = {} = a); +>({} = {} = a) : any +>{} = {} = a : any +>{} : {} +>{} = a : any +>{} : {} +>a : any + +([] = [] = a); +>([] = [] = a) : any +>[] = [] = a : any +>[] : undefined[] +>[] = a : any +>[] : undefined[] +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js new file mode 100644 index 00000000000..7e342d08e39 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.js @@ -0,0 +1,14 @@ +//// [emptyAssignmentPatterns04_ES5.ts] + +var a: any; +let x, y, z, a1, a2, a3; + +({ x, y, z } = {} = a); +([ a1, a2, a3] = [] = a); + +//// [emptyAssignmentPatterns04_ES5.js] +var a; +var x, y, z, a1, a2, a3; +(_a = a, x = _a.x, y = _a.y, z = _a.z, _a); +(_b = a, a1 = _b[0], a2 = _b[1], a3 = _b[2], _b); +var _a, _b; diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES5.symbols b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.symbols new file mode 100644 index 00000000000..20ea8c037c3 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES5.ts, 1, 3)) + +let x, y, z, a1, a2, a3; +>x : Symbol(x, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 3)) +>y : Symbol(y, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 6)) +>z : Symbol(z, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 9)) +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 20)) + +({ x, y, z } = {} = a); +>x : Symbol(x, Decl(emptyAssignmentPatterns04_ES5.ts, 4, 2)) +>y : Symbol(y, Decl(emptyAssignmentPatterns04_ES5.ts, 4, 5)) +>z : Symbol(z, Decl(emptyAssignmentPatterns04_ES5.ts, 4, 8)) +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES5.ts, 1, 3)) + +([ a1, a2, a3] = [] = a); +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns04_ES5.ts, 2, 20)) +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES5.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES5.types b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.types new file mode 100644 index 00000000000..5ae2f0674fa --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES5.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES5.ts === + +var a: any; +>a : any + +let x, y, z, a1, a2, a3; +>x : any +>y : any +>z : any +>a1 : any +>a2 : any +>a3 : any + +({ x, y, z } = {} = a); +>({ x, y, z } = {} = a) : any +>{ x, y, z } = {} = a : any +>{ x, y, z } : { x: any; y: any; z: any; } +>x : any +>y : any +>z : any +>{} = a : any +>{} : {} +>a : any + +([ a1, a2, a3] = [] = a); +>([ a1, a2, a3] = [] = a) : any +>[ a1, a2, a3] = [] = a : any +>[ a1, a2, a3] : [any, any, any] +>a1 : any +>a2 : any +>a3 : any +>[] = a : any +>[] : undefined[] +>a : any + diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES6.js b/tests/baselines/reference/emptyAssignmentPatterns04_ES6.js new file mode 100644 index 00000000000..eabc2678c05 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES6.js @@ -0,0 +1,13 @@ +//// [emptyAssignmentPatterns04_ES6.ts] + +var a: any; +let x, y, z, a1, a2, a3; + +({ x, y, z } = {} = a); +([ a1, a2, a3] = [] = a); + +//// [emptyAssignmentPatterns04_ES6.js] +var a; +let x, y, z, a1, a2, a3; +({ x, y, z } = {} = a); +([a1, a2, a3] = [] = a); diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES6.symbols b/tests/baselines/reference/emptyAssignmentPatterns04_ES6.symbols new file mode 100644 index 00000000000..ee793cd3187 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES6.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES6.ts === + +var a: any; +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES6.ts, 1, 3)) + +let x, y, z, a1, a2, a3; +>x : Symbol(x, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 3)) +>y : Symbol(y, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 6)) +>z : Symbol(z, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 9)) +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 20)) + +({ x, y, z } = {} = a); +>x : Symbol(x, Decl(emptyAssignmentPatterns04_ES6.ts, 4, 2)) +>y : Symbol(y, Decl(emptyAssignmentPatterns04_ES6.ts, 4, 5)) +>z : Symbol(z, Decl(emptyAssignmentPatterns04_ES6.ts, 4, 8)) +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES6.ts, 1, 3)) + +([ a1, a2, a3] = [] = a); +>a1 : Symbol(a1, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 12)) +>a2 : Symbol(a2, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 16)) +>a3 : Symbol(a3, Decl(emptyAssignmentPatterns04_ES6.ts, 2, 20)) +>a : Symbol(a, Decl(emptyAssignmentPatterns04_ES6.ts, 1, 3)) + diff --git a/tests/baselines/reference/emptyAssignmentPatterns04_ES6.types b/tests/baselines/reference/emptyAssignmentPatterns04_ES6.types new file mode 100644 index 00000000000..6bd85593748 --- /dev/null +++ b/tests/baselines/reference/emptyAssignmentPatterns04_ES6.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es6/destructuring/emptyAssignmentPatterns04_ES6.ts === + +var a: any; +>a : any + +let x, y, z, a1, a2, a3; +>x : any +>y : any +>z : any +>a1 : any +>a2 : any +>a3 : any + +({ x, y, z } = {} = a); +>({ x, y, z } = {} = a) : any +>{ x, y, z } = {} = a : any +>{ x, y, z } : { x: any; y: any; z: any; } +>x : any +>y : any +>z : any +>{} = a : any +>{} : {} +>a : any + +([ a1, a2, a3] = [] = a); +>([ a1, a2, a3] = [] = a) : any +>[ a1, a2, a3] = [] = a : any +>[ a1, a2, a3] : [any, any, any] +>a1 : any +>a2 : any +>a3 : any +>[] = a : any +>[] : undefined[] +>a : any + diff --git a/tests/baselines/reference/enumBasics.types b/tests/baselines/reference/enumBasics.types index 6a147f01062..87f6f12b6b2 100644 --- a/tests/baselines/reference/enumBasics.types +++ b/tests/baselines/reference/enumBasics.types @@ -172,8 +172,8 @@ enum E9 { // (refer to .js to validate) // Enum constant members are propagated var doNotPropagate = [ ->doNotPropagate : (E3 | E4 | E7 | E8)[] ->[ E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : (E3 | E4 | E7 | E8)[] +>doNotPropagate : (E8 | E7 | E4 | E3)[] +>[ E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : (E8 | E7 | E4 | E3)[] E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z >E8.B : E8 @@ -198,8 +198,8 @@ var doNotPropagate = [ ]; // Enum computed members are not propagated var doPropagate = [ ->doPropagate : (E5 | E6 | E9)[] ->[ E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : (E5 | E6 | E9)[] +>doPropagate : (E9 | E6 | E5)[] +>[ E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : (E9 | E6 | E5)[] 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/errorSuperPropertyAccess.js b/tests/baselines/reference/errorSuperPropertyAccess.js index 57a574d8a06..6e35248cd35 100644 --- a/tests/baselines/reference/errorSuperPropertyAccess.js +++ b/tests/baselines/reference/errorSuperPropertyAccess.js @@ -139,14 +139,14 @@ var __extends = (this && this.__extends) || function (d, b) { //super property access in instance member accessor(get and set) of class with no base type var NoBase = (function () { function NoBase() { - this.m = _super.prototype; - this.n = _super.hasOwnProperty.call(this, ''); - var a = _super.prototype; - var b = _super.hasOwnProperty.call(this, ''); + this.m = _super.prototype.prototype; + this.n = _super.prototype.hasOwnProperty.call(this, ''); + var a = _super.prototype.prototype; + var b = _super.prototype.hasOwnProperty.call(this, ''); } NoBase.prototype.fn = function () { - var a = _super.prototype; - var b = _super.hasOwnProperty.call(this, ''); + var a = _super.prototype.prototype; + var b = _super.prototype.hasOwnProperty.call(this, ''); }; //super static property access in static member function of class with no base type //super static property access in static member accessor(get and set) of class with no base type diff --git a/tests/baselines/reference/es5-commonjs.js b/tests/baselines/reference/es5-commonjs.js new file mode 100644 index 00000000000..2a0c6d924ca --- /dev/null +++ b/tests/baselines/reference/es5-commonjs.js @@ -0,0 +1,27 @@ +//// [es5-commonjs.ts] + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + + +//// [es5-commonjs.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = A; diff --git a/tests/baselines/reference/es5-commonjs.symbols b/tests/baselines/reference/es5-commonjs.symbols new file mode 100644 index 00000000000..41e4484afcd --- /dev/null +++ b/tests/baselines/reference/es5-commonjs.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es5-commonjs.ts === + +export default class A +>A : Symbol(A, Decl(es5-commonjs.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-commonjs.ts, 6, 5)) + { + return 42; + } +} + diff --git a/tests/baselines/reference/es5-commonjs.types b/tests/baselines/reference/es5-commonjs.types new file mode 100644 index 00000000000..4c1bc922917 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es5-commonjs.ts === + +export default class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + diff --git a/tests/baselines/reference/es5-commonjs2.js b/tests/baselines/reference/es5-commonjs2.js new file mode 100644 index 00000000000..174665b4125 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs2.js @@ -0,0 +1,8 @@ +//// [es5-commonjs2.ts] + +export default 1; + + +//// [es5-commonjs2.js] +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = 1; diff --git a/tests/baselines/reference/es5-commonjs2.symbols b/tests/baselines/reference/es5-commonjs2.symbols new file mode 100644 index 00000000000..ee57f9ad5cd --- /dev/null +++ b/tests/baselines/reference/es5-commonjs2.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es5-commonjs2.ts === + +No type information for this code.export default 1; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es5-commonjs2.types b/tests/baselines/reference/es5-commonjs2.types new file mode 100644 index 00000000000..ee57f9ad5cd --- /dev/null +++ b/tests/baselines/reference/es5-commonjs2.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es5-commonjs2.ts === + +No type information for this code.export default 1; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es5-commonjs3.js b/tests/baselines/reference/es5-commonjs3.js new file mode 100644 index 00000000000..cc3d0b1527a --- /dev/null +++ b/tests/baselines/reference/es5-commonjs3.js @@ -0,0 +1,9 @@ +//// [es5-commonjs3.ts] + +export default "test"; +export var __esModule = 1; + + +//// [es5-commonjs3.js] +exports.default = "test"; +exports.__esModule = 1; diff --git a/tests/baselines/reference/es5-commonjs3.symbols b/tests/baselines/reference/es5-commonjs3.symbols new file mode 100644 index 00000000000..9d5bc830099 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs3.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/es5-commonjs3.ts === + +export default "test"; +export var __esModule = 1; +>__esModule : Symbol(__esModule, Decl(es5-commonjs3.ts, 2, 10)) + diff --git a/tests/baselines/reference/es5-commonjs3.types b/tests/baselines/reference/es5-commonjs3.types new file mode 100644 index 00000000000..facdfae00ce --- /dev/null +++ b/tests/baselines/reference/es5-commonjs3.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5-commonjs3.ts === + +export default "test"; +export var __esModule = 1; +>__esModule : number +>1 : number + diff --git a/tests/baselines/reference/es5-commonjs4.js b/tests/baselines/reference/es5-commonjs4.js new file mode 100644 index 00000000000..50a4c49e464 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs4.js @@ -0,0 +1,28 @@ +//// [es5-commonjs4.ts] + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} +export var __esModule = 1; + + +//// [es5-commonjs4.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +exports.default = A; +exports.__esModule = 1; diff --git a/tests/baselines/reference/es5-commonjs4.symbols b/tests/baselines/reference/es5-commonjs4.symbols new file mode 100644 index 00000000000..22d41128d74 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs4.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/es5-commonjs4.ts === + +export default class A +>A : Symbol(A, Decl(es5-commonjs4.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-commonjs4.ts, 6, 5)) + { + return 42; + } +} +export var __esModule = 1; +>__esModule : Symbol(__esModule, Decl(es5-commonjs4.ts, 13, 10)) + diff --git a/tests/baselines/reference/es5-commonjs4.types b/tests/baselines/reference/es5-commonjs4.types new file mode 100644 index 00000000000..d3471afbfeb --- /dev/null +++ b/tests/baselines/reference/es5-commonjs4.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/es5-commonjs4.ts === + +export default class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} +export var __esModule = 1; +>__esModule : number +>1 : number + diff --git a/tests/baselines/reference/es5-commonjs5.js b/tests/baselines/reference/es5-commonjs5.js new file mode 100644 index 00000000000..ead6079eff1 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs5.js @@ -0,0 +1,13 @@ +//// [es5-commonjs5.ts] + +export default function () { + return "test"; +} + + +//// [es5-commonjs5.js] +function default_1() { + return "test"; +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = default_1; diff --git a/tests/baselines/reference/es5-commonjs5.symbols b/tests/baselines/reference/es5-commonjs5.symbols new file mode 100644 index 00000000000..b134e216668 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs5.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5-commonjs5.ts === + +No type information for this code.export default function () { +No type information for this code. return "test"; +No type information for this code.} +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es5-commonjs5.types b/tests/baselines/reference/es5-commonjs5.types new file mode 100644 index 00000000000..d8094e1e0ea --- /dev/null +++ b/tests/baselines/reference/es5-commonjs5.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5-commonjs5.ts === + +export default function () { + return "test"; +>"test" : string +} + diff --git a/tests/baselines/reference/es5-commonjs6.js b/tests/baselines/reference/es5-commonjs6.js new file mode 100644 index 00000000000..7c2c8b21779 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs6.js @@ -0,0 +1,10 @@ +//// [es5-commonjs6.ts] + +export default "test"; +var __esModule = 1; + + +//// [es5-commonjs6.js] +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = "test"; +var __esModule = 1; diff --git a/tests/baselines/reference/es5-commonjs6.symbols b/tests/baselines/reference/es5-commonjs6.symbols new file mode 100644 index 00000000000..7a2847e0f25 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs6.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/es5-commonjs6.ts === + +export default "test"; +var __esModule = 1; +>__esModule : Symbol(__esModule, Decl(es5-commonjs6.ts, 2, 3)) + diff --git a/tests/baselines/reference/es5-commonjs6.types b/tests/baselines/reference/es5-commonjs6.types new file mode 100644 index 00000000000..904b69dec22 --- /dev/null +++ b/tests/baselines/reference/es5-commonjs6.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5-commonjs6.ts === + +export default "test"; +var __esModule = 1; +>__esModule : number +>1 : number + diff --git a/tests/baselines/reference/es5-system.js b/tests/baselines/reference/es5-system.js new file mode 100644 index 00000000000..2674527722a --- /dev/null +++ b/tests/baselines/reference/es5-system.js @@ -0,0 +1,34 @@ +//// [es5-system.ts] + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + + +//// [es5-system.js] +System.register([], function(exports_1) { + var A; + return { + setters:[], + execute: function() { + A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; + })(); + exports_1("default", A); + } + } +}); diff --git a/tests/baselines/reference/es5-system.symbols b/tests/baselines/reference/es5-system.symbols new file mode 100644 index 00000000000..5211e3c4259 --- /dev/null +++ b/tests/baselines/reference/es5-system.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es5-system.ts === + +export default class A +>A : Symbol(A, Decl(es5-system.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-system.ts, 6, 5)) + { + return 42; + } +} + diff --git a/tests/baselines/reference/es5-system.types b/tests/baselines/reference/es5-system.types new file mode 100644 index 00000000000..eae884a78b4 --- /dev/null +++ b/tests/baselines/reference/es5-system.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es5-system.ts === + +export default class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + diff --git a/tests/baselines/reference/es5-umd3.js b/tests/baselines/reference/es5-umd3.js index 3abb92f816f..92ac306698a 100644 --- a/tests/baselines/reference/es5-umd3.js +++ b/tests/baselines/reference/es5-umd3.js @@ -31,5 +31,6 @@ export default class A }; return A; })(); + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = A; }); diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js index b5cfdb02f78..0d4076e39a1 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js @@ -12,6 +12,7 @@ var C = (function () { C.prototype.method = function () { }; return C; })(); +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = C; diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js index de0d109dadf..5e5eeae1f0f 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js @@ -12,6 +12,7 @@ var default_1 = (function () { default_1.prototype.method = function () { }; return default_1; })(); +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js index bff80940a02..a977447f9ad 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration3.js @@ -24,6 +24,7 @@ var C = (function () { }; return C; })(); +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = C; var after = new C(); var t = C; diff --git a/tests/baselines/reference/es5ExportDefaultExpression.js b/tests/baselines/reference/es5ExportDefaultExpression.js index 944b6fc71a5..a825e45971b 100644 --- a/tests/baselines/reference/es5ExportDefaultExpression.js +++ b/tests/baselines/reference/es5ExportDefaultExpression.js @@ -4,6 +4,7 @@ export default (1 + 2); //// [es5ExportDefaultExpression.js] +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = (1 + 2); diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js index 673cc3cb453..afc44ac53f5 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js @@ -5,6 +5,7 @@ export default function f() { } //// [es5ExportDefaultFunctionDeclaration.js] function f() { } +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js index ad1334e810b..10f1db6a0eb 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js @@ -5,6 +5,7 @@ export default function () { } //// [es5ExportDefaultFunctionDeclaration2.js] function default_1() { } +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js index 1fc57976439..af437c08766 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js @@ -13,6 +13,7 @@ var before = func(); function func() { return func; } +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = func; var after = func(); diff --git a/tests/baselines/reference/es5ExportDefaultIdentifier.js b/tests/baselines/reference/es5ExportDefaultIdentifier.js index 739f3d6c109..c8fb6b3be27 100644 --- a/tests/baselines/reference/es5ExportDefaultIdentifier.js +++ b/tests/baselines/reference/es5ExportDefaultIdentifier.js @@ -8,6 +8,7 @@ export default f; //// [es5ExportDefaultIdentifier.js] function f() { } exports.f = f; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f; diff --git a/tests/baselines/reference/es6ImportDefaultBindingAmd.js b/tests/baselines/reference/es6ImportDefaultBindingAmd.js index 70e4f7e2f57..9c8cbec9db5 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingAmd.js +++ b/tests/baselines/reference/es6ImportDefaultBindingAmd.js @@ -14,6 +14,7 @@ import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; // elide this import //// [es6ImportDefaultBindingAmd_0.js] define(["require", "exports"], function (require, exports) { var a = 10; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; }); //// [es6ImportDefaultBindingAmd_1.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingDts.js index caa46ed30ef..a5e8d509da1 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingDts.js +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.js @@ -17,6 +17,7 @@ var c = (function () { } return c; })(); +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = c; //// [client.js] var server_1 = require("server"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js index 15ca1284a1e..7090b7a0663 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js @@ -22,6 +22,7 @@ var x: number = defaultBinding6; //// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.js] var a = 10; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.js] var es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0_1 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js index b6b03176df1..2b0e3ebbeb5 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js @@ -22,6 +22,7 @@ export var x1: number = defaultBinding6; //// [server.js] var a = 10; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [client.js] var server_1 = require("server"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js index e6211ac1ebe..dad034c618c 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js @@ -25,6 +25,7 @@ var a = (function () { } return a; })(); +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [client.js] var server_1 = require("server"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js index 90521007735..b7da05d7dbb 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js @@ -27,6 +27,7 @@ define(["require", "exports"], function (require, exports) { exports.a = 10; exports.x = exports.a; exports.m = exports.a; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = {}; }); //// [client.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js index c2bd5476a7c..4a987110224 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js @@ -11,6 +11,7 @@ var x: number = defaultBinding; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.js] var a = 10; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js] var es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0_1 = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"), nameSpaceBinding = es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0_1; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js index ed40582e923..a032325fbb4 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js @@ -12,6 +12,7 @@ export var x: number = defaultBinding; //// [server.js] define(["require", "exports"], function (require, exports) { var a = 10; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; }); //// [client.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js index e03ded5fd5a..639ffce59fd 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js @@ -16,6 +16,7 @@ define(["require", "exports"], function (require, exports) { } return a; })(); + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; }); //// [client.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js index 1208ace5dde..10b8bec03c7 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js +++ b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js @@ -18,6 +18,7 @@ import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // SHould be //// [es6ImportDefaultBindingMergeErrors_0.js] var a = 10; +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; //// [es6ImportDefaultBindingMergeErrors_1.js] var es6ImportDefaultBindingMergeErrors_0_1 = require("es6ImportDefaultBindingMergeErrors_0"); diff --git a/tests/baselines/reference/es6ImportDefaultBindingWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingWithExport.js index e2c5fab4c94..2fb7f0644b9 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingWithExport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingWithExport.js @@ -13,6 +13,7 @@ export import defaultBinding2 from "server"; // non referenced //// [server.js] define(["require", "exports"], function (require, exports) { var a = 10; + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = a; }); //// [client.js] diff --git a/tests/baselines/reference/exportAndImport-es3-amd.js b/tests/baselines/reference/exportAndImport-es3-amd.js index a4552e70d68..d2293a56e23 100644 --- a/tests/baselines/reference/exportAndImport-es3-amd.js +++ b/tests/baselines/reference/exportAndImport-es3-amd.js @@ -16,6 +16,7 @@ export default function f2() { define(["require", "exports"], function (require, exports) { function f1() { } + exports.__esModule = true; exports["default"] = f1; }); //// [m2.js] @@ -23,5 +24,6 @@ define(["require", "exports", "./m1"], function (require, exports, m1_1) { function f2() { m1_1["default"](); } + exports.__esModule = true; exports["default"] = f2; }); diff --git a/tests/baselines/reference/exportAndImport-es3.js b/tests/baselines/reference/exportAndImport-es3.js index 5f467509b68..1be548bc930 100644 --- a/tests/baselines/reference/exportAndImport-es3.js +++ b/tests/baselines/reference/exportAndImport-es3.js @@ -15,10 +15,12 @@ export default function f2() { //// [m1.js] function f1() { } +exports.__esModule = true; exports["default"] = f1; //// [m2.js] var m1_1 = require("./m1"); function f2() { m1_1["default"](); } +exports.__esModule = true; exports["default"] = f2; diff --git a/tests/baselines/reference/exportAndImport-es5-amd.js b/tests/baselines/reference/exportAndImport-es5-amd.js index 4966af874f7..447356b1230 100644 --- a/tests/baselines/reference/exportAndImport-es5-amd.js +++ b/tests/baselines/reference/exportAndImport-es5-amd.js @@ -16,6 +16,7 @@ export default function f2() { define(["require", "exports"], function (require, exports) { function f1() { } + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f1; }); //// [m2.js] @@ -23,5 +24,6 @@ define(["require", "exports", "./m1"], function (require, exports, m1_1) { function f2() { m1_1.default(); } + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f2; }); diff --git a/tests/baselines/reference/exportAndImport-es5.js b/tests/baselines/reference/exportAndImport-es5.js index 02d0e43e5a9..c0bacb94aee 100644 --- a/tests/baselines/reference/exportAndImport-es5.js +++ b/tests/baselines/reference/exportAndImport-es5.js @@ -15,10 +15,12 @@ export default function f2() { //// [m1.js] function f1() { } +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f1; //// [m2.js] var m1_1 = require("./m1"); function f2() { m1_1.default(); } +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = f2; diff --git a/tests/baselines/reference/exportStar-amd.js b/tests/baselines/reference/exportStar-amd.js index dcd2d126a35..534a23b4d5b 100644 --- a/tests/baselines/reference/exportStar-amd.js +++ b/tests/baselines/reference/exportStar-amd.js @@ -36,6 +36,7 @@ define(["require", "exports"], function (require, exports) { }); //// [t2.js] define(["require", "exports"], function (require, exports) { + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = "hello"; function foo() { } exports.foo = foo; diff --git a/tests/baselines/reference/exportStar.js b/tests/baselines/reference/exportStar.js index d219a3650e7..74cf24a0f97 100644 --- a/tests/baselines/reference/exportStar.js +++ b/tests/baselines/reference/exportStar.js @@ -33,6 +33,7 @@ foo; exports.x = 1; exports.y = 2; //// [t2.js] +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = "hello"; function foo() { } exports.foo = foo; diff --git a/tests/baselines/reference/exportsAndImports4-amd.js b/tests/baselines/reference/exportsAndImports4-amd.js index db28ed5b350..e6a431854b2 100644 --- a/tests/baselines/reference/exportsAndImports4-amd.js +++ b/tests/baselines/reference/exportsAndImports4-amd.js @@ -41,6 +41,7 @@ export { a, b, c, d, e1, e2, f1, f2 }; //// [t1.js] define(["require", "exports"], function (require, exports) { + Object.defineProperty(exports, "__esModule", { value: true }); exports.default = "hello"; }); //// [t3.js] diff --git a/tests/baselines/reference/exportsAndImports4.js b/tests/baselines/reference/exportsAndImports4.js index ea5f34b882b..7358b31eace 100644 --- a/tests/baselines/reference/exportsAndImports4.js +++ b/tests/baselines/reference/exportsAndImports4.js @@ -40,6 +40,7 @@ export { a, b, c, d, e1, e2, f1, f2 }; //// [t1.js] +Object.defineProperty(exports, "__esModule", { value: true }); exports.default = "hello"; //// [t3.js] var a = require("./t1"); diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.errors.txt b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.errors.txt index 5934ab52ccf..b32a7b67b61 100644 --- a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.errors.txt +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.errors.txt @@ -1,10 +1,9 @@ tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts(1,9): error TS1016: A required parameter cannot follow an optional parameter. tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts(2,8): error TS1047: A rest parameter cannot be optional. tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts(4,5): error TS1048: A rest parameter cannot have an initializer. -tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts(7,12): error TS1016: A required parameter cannot follow an optional parameter. -==== tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts (4 errors) ==== +==== tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts (3 errors) ==== (arg1?, arg2) => 101; ~~~~ !!! error TS1016: A required parameter cannot follow an optional parameter. @@ -16,7 +15,5 @@ tests/cases/compiler/fatarrowfunctionsOptionalArgsErrors1.ts(7,12): error TS1016 ~~~ !!! error TS1048: A rest parameter cannot have an initializer. - // Non optional parameter following an optional one - (arg1 = 1, arg2) => 1; - ~~~~ -!!! error TS1016: A required parameter cannot follow an optional parameter. \ No newline at end of file + // Uninitialized parameter makes the initialized one required + (arg1 = 1, arg2) => 1; \ No newline at end of file diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.js b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.js index e746b24a066..4d27f8230eb 100644 --- a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.js +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors1.js @@ -4,7 +4,7 @@ (...arg) => 103; (...arg:number [] = []) => 104; -// Non optional parameter following an optional one +// Uninitialized parameter makes the initialized one required (arg1 = 1, arg2) => 1; //// [fatarrowfunctionsOptionalArgsErrors1.js] @@ -30,7 +30,7 @@ } return 104; }); -// Non optional parameter following an optional one +// Uninitialized parameter makes the initialized one required (function (arg1, arg2) { if (arg1 === void 0) { arg1 = 1; } return 1; diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly1.js b/tests/baselines/reference/fixingTypeParametersRepeatedly1.js new file mode 100644 index 00000000000..93ab8ba9888 --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly1.js @@ -0,0 +1,12 @@ +//// [fixingTypeParametersRepeatedly1.ts] +declare function f(x: T, y: (p: T) => T, z: (p: T) => T): T; +f("", x => null, x => x.toLowerCase()); + +// First overload of g should type check just like f +declare function g(x: T, y: (p: T) => T, z: (p: T) => T): T; +declare function g(); +g("", x => null, x => x.toLowerCase()); + +//// [fixingTypeParametersRepeatedly1.js] +f("", function (x) { return null; }, function (x) { return x.toLowerCase(); }); +g("", function (x) { return null; }, function (x) { return x.toLowerCase(); }); diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly1.symbols b/tests/baselines/reference/fixingTypeParametersRepeatedly1.symbols new file mode 100644 index 00000000000..998e59c0b8f --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly1.symbols @@ -0,0 +1,51 @@ +=== tests/cases/compiler/fixingTypeParametersRepeatedly1.ts === +declare function f(x: T, y: (p: T) => T, z: (p: T) => T): T; +>f : Symbol(f, Decl(fixingTypeParametersRepeatedly1.ts, 0, 0)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 0, 19)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 0, 22)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 0, 19)) +>y : Symbol(y, Decl(fixingTypeParametersRepeatedly1.ts, 0, 27)) +>p : Symbol(p, Decl(fixingTypeParametersRepeatedly1.ts, 0, 32)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 0, 19)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 0, 19)) +>z : Symbol(z, Decl(fixingTypeParametersRepeatedly1.ts, 0, 43)) +>p : Symbol(p, Decl(fixingTypeParametersRepeatedly1.ts, 0, 48)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 0, 19)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 0, 19)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 0, 19)) + +f("", x => null, x => x.toLowerCase()); +>f : Symbol(f, Decl(fixingTypeParametersRepeatedly1.ts, 0, 0)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 1, 5)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 1, 16)) +>x.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, 399, 51)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 1, 16)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, 399, 51)) + +// First overload of g should type check just like f +declare function g(x: T, y: (p: T) => T, z: (p: T) => T): T; +>g : Symbol(g, Decl(fixingTypeParametersRepeatedly1.ts, 1, 39), Decl(fixingTypeParametersRepeatedly1.ts, 4, 63)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 4, 19)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 4, 22)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 4, 19)) +>y : Symbol(y, Decl(fixingTypeParametersRepeatedly1.ts, 4, 27)) +>p : Symbol(p, Decl(fixingTypeParametersRepeatedly1.ts, 4, 32)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 4, 19)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 4, 19)) +>z : Symbol(z, Decl(fixingTypeParametersRepeatedly1.ts, 4, 43)) +>p : Symbol(p, Decl(fixingTypeParametersRepeatedly1.ts, 4, 48)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 4, 19)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 4, 19)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly1.ts, 4, 19)) + +declare function g(); +>g : Symbol(g, Decl(fixingTypeParametersRepeatedly1.ts, 1, 39), Decl(fixingTypeParametersRepeatedly1.ts, 4, 63)) + +g("", x => null, x => x.toLowerCase()); +>g : Symbol(g, Decl(fixingTypeParametersRepeatedly1.ts, 1, 39), Decl(fixingTypeParametersRepeatedly1.ts, 4, 63)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 6, 5)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 6, 16)) +>x.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, 399, 51)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 6, 16)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, 399, 51)) + diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly1.types b/tests/baselines/reference/fixingTypeParametersRepeatedly1.types new file mode 100644 index 00000000000..273c66b342d --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly1.types @@ -0,0 +1,63 @@ +=== tests/cases/compiler/fixingTypeParametersRepeatedly1.ts === +declare function f(x: T, y: (p: T) => T, z: (p: T) => T): T; +>f : (x: T, y: (p: T) => T, z: (p: T) => T) => T +>T : T +>x : T +>T : T +>y : (p: T) => T +>p : T +>T : T +>T : T +>z : (p: T) => T +>p : T +>T : T +>T : T +>T : T + +f("", x => null, x => x.toLowerCase()); +>f("", x => null, x => x.toLowerCase()) : string +>f : (x: T, y: (p: T) => T, z: (p: T) => T) => T +>"" : string +>x => null : (x: string) => any +>x : string +>null : null +>x => x.toLowerCase() : (x: string) => string +>x : string +>x.toLowerCase() : string +>x.toLowerCase : () => string +>x : string +>toLowerCase : () => string + +// First overload of g should type check just like f +declare function g(x: T, y: (p: T) => T, z: (p: T) => T): T; +>g : { (x: T, y: (p: T) => T, z: (p: T) => T): T; (): any; } +>T : T +>x : T +>T : T +>y : (p: T) => T +>p : T +>T : T +>T : T +>z : (p: T) => T +>p : T +>T : T +>T : T +>T : T + +declare function g(); +>g : { (x: T, y: (p: T) => T, z: (p: T) => T): T; (): any; } + +g("", x => null, x => x.toLowerCase()); +>g("", x => null, x => x.toLowerCase()) : string +>g : { (x: T, y: (p: T) => T, z: (p: T) => T): T; (): any; } +>"" : string +>x => null : (x: string) => any +>x : string +>null : null +>x => x.toLowerCase() : (x: string) => string +>x : string +>x.toLowerCase() : string +>x.toLowerCase : () => string +>x : string +>toLowerCase : () => string + diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly2.errors.txt b/tests/baselines/reference/fixingTypeParametersRepeatedly2.errors.txt new file mode 100644 index 00000000000..e56b58a268d --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly2.errors.txt @@ -0,0 +1,32 @@ +tests/cases/compiler/fixingTypeParametersRepeatedly2.ts(11,27): error TS2345: Argument of type '(d: Derived) => Base' is not assignable to parameter of type '(p: Derived) => Derived'. + Type 'Base' is not assignable to type 'Derived'. + Property 'toBase' is missing in type 'Base'. +tests/cases/compiler/fixingTypeParametersRepeatedly2.ts(17,27): error TS2345: Argument of type '(d: Derived) => Base' is not assignable to parameter of type '(p: Derived) => Derived'. + Type 'Base' is not assignable to type 'Derived'. + + +==== tests/cases/compiler/fixingTypeParametersRepeatedly2.ts (2 errors) ==== + interface Base { + baseProp; + } + interface Derived extends Base { + toBase(): Base; + } + + var derived: Derived; + + declare function foo(x: T, func: (p: T) => T): T; + var result = foo(derived, d => d.toBase()); + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(d: Derived) => Base' is not assignable to parameter of type '(p: Derived) => Derived'. +!!! error TS2345: Type 'Base' is not assignable to type 'Derived'. +!!! error TS2345: Property 'toBase' is missing in type 'Base'. + + // bar should type check just like foo. + // The same error should be observed in both cases. + declare function bar(x: T, func: (p: T) => T): T; + declare function bar(x: T, func: (p: T) => T): T; + var result = bar(derived, d => d.toBase()); + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(d: Derived) => Base' is not assignable to parameter of type '(p: Derived) => Derived'. +!!! error TS2345: Type 'Base' is not assignable to type 'Derived'. \ No newline at end of file diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly2.js b/tests/baselines/reference/fixingTypeParametersRepeatedly2.js new file mode 100644 index 00000000000..9ebf426bbd2 --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly2.js @@ -0,0 +1,23 @@ +//// [fixingTypeParametersRepeatedly2.ts] +interface Base { + baseProp; +} +interface Derived extends Base { + toBase(): Base; +} + +var derived: Derived; + +declare function foo(x: T, func: (p: T) => T): T; +var result = foo(derived, d => d.toBase()); + +// bar should type check just like foo. +// The same error should be observed in both cases. +declare function bar(x: T, func: (p: T) => T): T; +declare function bar(x: T, func: (p: T) => T): T; +var result = bar(derived, d => d.toBase()); + +//// [fixingTypeParametersRepeatedly2.js] +var derived; +var result = foo(derived, function (d) { return d.toBase(); }); +var result = bar(derived, function (d) { return d.toBase(); }); diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly3.js b/tests/baselines/reference/fixingTypeParametersRepeatedly3.js new file mode 100644 index 00000000000..83a47c92c34 --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly3.js @@ -0,0 +1,23 @@ +//// [fixingTypeParametersRepeatedly3.ts] +interface Base { + baseProp; +} +interface Derived extends Base { + toBase?(): Base; +} + +var derived: Derived; + +declare function foo(x: T, func: (p: T) => T): T; +var result = foo(derived, d => d.toBase()); + +// bar should type check just like foo. +// result2 should have the same type as result +declare function bar(x: T, func: (p: T) => T): T; +declare function bar(x: T, func: (p: T) => T): T; +var result2 = bar(derived, d => d.toBase()); + +//// [fixingTypeParametersRepeatedly3.js] +var derived; +var result = foo(derived, function (d) { return d.toBase(); }); +var result2 = bar(derived, function (d) { return d.toBase(); }); diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly3.symbols b/tests/baselines/reference/fixingTypeParametersRepeatedly3.symbols new file mode 100644 index 00000000000..a849adb6235 --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly3.symbols @@ -0,0 +1,73 @@ +=== tests/cases/compiler/fixingTypeParametersRepeatedly3.ts === +interface Base { +>Base : Symbol(Base, Decl(fixingTypeParametersRepeatedly3.ts, 0, 0)) + + baseProp; +>baseProp : Symbol(baseProp, Decl(fixingTypeParametersRepeatedly3.ts, 0, 16)) +} +interface Derived extends Base { +>Derived : Symbol(Derived, Decl(fixingTypeParametersRepeatedly3.ts, 2, 1)) +>Base : Symbol(Base, Decl(fixingTypeParametersRepeatedly3.ts, 0, 0)) + + toBase?(): Base; +>toBase : Symbol(toBase, Decl(fixingTypeParametersRepeatedly3.ts, 3, 32)) +>Base : Symbol(Base, Decl(fixingTypeParametersRepeatedly3.ts, 0, 0)) +} + +var derived: Derived; +>derived : Symbol(derived, Decl(fixingTypeParametersRepeatedly3.ts, 7, 3)) +>Derived : Symbol(Derived, Decl(fixingTypeParametersRepeatedly3.ts, 2, 1)) + +declare function foo(x: T, func: (p: T) => T): T; +>foo : Symbol(foo, Decl(fixingTypeParametersRepeatedly3.ts, 7, 21)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 9, 21)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly3.ts, 9, 24)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 9, 21)) +>func : Symbol(func, Decl(fixingTypeParametersRepeatedly3.ts, 9, 29)) +>p : Symbol(p, Decl(fixingTypeParametersRepeatedly3.ts, 9, 37)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 9, 21)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 9, 21)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 9, 21)) + +var result = foo(derived, d => d.toBase()); +>result : Symbol(result, Decl(fixingTypeParametersRepeatedly3.ts, 10, 3)) +>foo : Symbol(foo, Decl(fixingTypeParametersRepeatedly3.ts, 7, 21)) +>derived : Symbol(derived, Decl(fixingTypeParametersRepeatedly3.ts, 7, 3)) +>d : Symbol(d, Decl(fixingTypeParametersRepeatedly3.ts, 10, 25)) +>d.toBase : Symbol(Derived.toBase, Decl(fixingTypeParametersRepeatedly3.ts, 3, 32)) +>d : Symbol(d, Decl(fixingTypeParametersRepeatedly3.ts, 10, 25)) +>toBase : Symbol(Derived.toBase, Decl(fixingTypeParametersRepeatedly3.ts, 3, 32)) + +// bar should type check just like foo. +// result2 should have the same type as result +declare function bar(x: T, func: (p: T) => T): T; +>bar : Symbol(bar, Decl(fixingTypeParametersRepeatedly3.ts, 10, 43), Decl(fixingTypeParametersRepeatedly3.ts, 14, 52)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 14, 21)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly3.ts, 14, 24)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 14, 21)) +>func : Symbol(func, Decl(fixingTypeParametersRepeatedly3.ts, 14, 29)) +>p : Symbol(p, Decl(fixingTypeParametersRepeatedly3.ts, 14, 37)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 14, 21)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 14, 21)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 14, 21)) + +declare function bar(x: T, func: (p: T) => T): T; +>bar : Symbol(bar, Decl(fixingTypeParametersRepeatedly3.ts, 10, 43), Decl(fixingTypeParametersRepeatedly3.ts, 14, 52)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 15, 21)) +>x : Symbol(x, Decl(fixingTypeParametersRepeatedly3.ts, 15, 24)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 15, 21)) +>func : Symbol(func, Decl(fixingTypeParametersRepeatedly3.ts, 15, 29)) +>p : Symbol(p, Decl(fixingTypeParametersRepeatedly3.ts, 15, 37)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 15, 21)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 15, 21)) +>T : Symbol(T, Decl(fixingTypeParametersRepeatedly3.ts, 15, 21)) + +var result2 = bar(derived, d => d.toBase()); +>result2 : Symbol(result2, Decl(fixingTypeParametersRepeatedly3.ts, 16, 3)) +>bar : Symbol(bar, Decl(fixingTypeParametersRepeatedly3.ts, 10, 43), Decl(fixingTypeParametersRepeatedly3.ts, 14, 52)) +>derived : Symbol(derived, Decl(fixingTypeParametersRepeatedly3.ts, 7, 3)) +>d : Symbol(d, Decl(fixingTypeParametersRepeatedly3.ts, 16, 26)) +>d.toBase : Symbol(Derived.toBase, Decl(fixingTypeParametersRepeatedly3.ts, 3, 32)) +>d : Symbol(d, Decl(fixingTypeParametersRepeatedly3.ts, 16, 26)) +>toBase : Symbol(Derived.toBase, Decl(fixingTypeParametersRepeatedly3.ts, 3, 32)) + diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly3.types b/tests/baselines/reference/fixingTypeParametersRepeatedly3.types new file mode 100644 index 00000000000..3bf926276d2 --- /dev/null +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly3.types @@ -0,0 +1,79 @@ +=== tests/cases/compiler/fixingTypeParametersRepeatedly3.ts === +interface Base { +>Base : Base + + baseProp; +>baseProp : any +} +interface Derived extends Base { +>Derived : Derived +>Base : Base + + toBase?(): Base; +>toBase : () => Base +>Base : Base +} + +var derived: Derived; +>derived : Derived +>Derived : Derived + +declare function foo(x: T, func: (p: T) => T): T; +>foo : (x: T, func: (p: T) => T) => T +>T : T +>x : T +>T : T +>func : (p: T) => T +>p : T +>T : T +>T : T +>T : T + +var result = foo(derived, d => d.toBase()); +>result : Derived +>foo(derived, d => d.toBase()) : Derived +>foo : (x: T, func: (p: T) => T) => T +>derived : Derived +>d => d.toBase() : (d: Derived) => Base +>d : Derived +>d.toBase() : Base +>d.toBase : () => Base +>d : Derived +>toBase : () => Base + +// bar should type check just like foo. +// result2 should have the same type as result +declare function bar(x: T, func: (p: T) => T): T; +>bar : { (x: T, func: (p: T) => T): T; (x: T, func: (p: T) => T): T; } +>T : T +>x : T +>T : T +>func : (p: T) => T +>p : T +>T : T +>T : T +>T : T + +declare function bar(x: T, func: (p: T) => T): T; +>bar : { (x: T, func: (p: T) => T): T; (x: T, func: (p: T) => T): T; } +>T : T +>x : T +>T : T +>func : (p: T) => T +>p : T +>T : T +>T : T +>T : T + +var result2 = bar(derived, d => d.toBase()); +>result2 : Derived +>bar(derived, d => d.toBase()) : Derived +>bar : { (x: T, func: (p: T) => T): T; (x: T, func: (p: T) => T): T; } +>derived : Derived +>d => d.toBase() : (d: Derived) => Base +>d : Derived +>d.toBase() : Base +>d.toBase : () => Base +>d : Derived +>toBase : () => Base + diff --git a/tests/baselines/reference/for-of11.errors.txt b/tests/baselines/reference/for-of11.errors.txt index dc527e73efe..7c00e454d4e 100644 --- a/tests/baselines/reference/for-of11.errors.txt +++ b/tests/baselines/reference/for-of11.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/for-ofStatements/for-of11.ts(2,6): error TS2322: Type 'string | number' is not assignable to type 'string'. +tests/cases/conformance/es6/for-ofStatements/for-of11.ts(2,6): error TS2322: Type 'number | string' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. @@ -6,5 +6,5 @@ tests/cases/conformance/es6/for-ofStatements/for-of11.ts(2,6): error TS2322: Typ var v: string; for (v of [0, ""]) { } ~ -!!! error TS2322: Type 'string | number' is not assignable to type 'string'. +!!! error TS2322: Type 'number | string' 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/for-of12.errors.txt b/tests/baselines/reference/for-of12.errors.txt index f19fa5ed014..6100564ba58 100644 --- a/tests/baselines/reference/for-of12.errors.txt +++ b/tests/baselines/reference/for-of12.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/for-ofStatements/for-of12.ts(2,6): error TS2322: Type 'string | number' is not assignable to type 'string'. +tests/cases/conformance/es6/for-ofStatements/for-of12.ts(2,6): error TS2322: Type 'number | string' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. @@ -6,5 +6,5 @@ tests/cases/conformance/es6/for-ofStatements/for-of12.ts(2,6): error TS2322: Typ var v: string; for (v of [0, ""].values()) { } ~ -!!! error TS2322: Type 'string | number' is not assignable to type 'string'. +!!! error TS2322: Type 'number | string' 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/for-of41.symbols b/tests/baselines/reference/for-of41.symbols index cf8db913919..046361653bb 100644 --- a/tests/baselines/reference/for-of41.symbols +++ b/tests/baselines/reference/for-of41.symbols @@ -6,7 +6,9 @@ var array = [{x: [0], y: {p: ""}}] >p : Symbol(p, Decl(for-of41.ts, 0, 26)) for (var {x: [a], y: {p}} of array) { +>x : Symbol(x, Decl(for-of41.ts, 0, 14)) >a : Symbol(a, Decl(for-of41.ts, 1, 14)) +>y : Symbol(y, Decl(for-of41.ts, 0, 21)) >p : Symbol(p, Decl(for-of41.ts, 1, 22)) >array : Symbol(array, Decl(for-of41.ts, 0, 3)) diff --git a/tests/baselines/reference/for-of42.symbols b/tests/baselines/reference/for-of42.symbols index b310fb1044f..5310f4970b9 100644 --- a/tests/baselines/reference/for-of42.symbols +++ b/tests/baselines/reference/for-of42.symbols @@ -5,7 +5,9 @@ var array = [{ x: "", y: 0 }] >y : Symbol(y, Decl(for-of42.ts, 0, 21)) for (var {x: a, y: b} of array) { +>x : Symbol(x, Decl(for-of42.ts, 0, 14)) >a : Symbol(a, Decl(for-of42.ts, 1, 10)) +>y : Symbol(y, Decl(for-of42.ts, 0, 21)) >b : Symbol(b, Decl(for-of42.ts, 1, 15)) >array : Symbol(array, Decl(for-of42.ts, 0, 3)) diff --git a/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt b/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt index 53ecb88363d..098afe94b47 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 '(C | D)[]'. +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 | C2 | 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 '(C | D)[]'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '(C | C2 | D)[]'. for(var arr2 = [new D()];;){} for( var arr2 = new Array>();;){} diff --git a/tests/baselines/reference/functionConstraintSatisfaction2.errors.txt b/tests/baselines/reference/functionConstraintSatisfaction2.errors.txt index 03ce9952938..871368da9fe 100644 --- a/tests/baselines/reference/functionConstraintSatisfaction2.errors.txt +++ b/tests/baselines/reference/functionConstraintSatisfaction2.errors.txt @@ -14,7 +14,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstrain tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(34,16): error TS2345: Argument of type 'F2' is not assignable to parameter of type '(x: string) => string'. tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(36,38): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(37,10): error TS2345: Argument of type 'T' is not assignable to parameter of type '(x: string) => string'. - Type 'void' is not assignable to type 'string'. + Type '() => void' is not assignable to type '(x: string) => string'. tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstraintSatisfaction2.ts(38,10): error TS2345: Argument of type 'U' is not assignable to parameter of type '(x: string) => string'. @@ -85,7 +85,7 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/functionConstrain foo2(x); ~ !!! error TS2345: Argument of type 'T' is not assignable to parameter of type '(x: string) => string'. -!!! error TS2345: Type 'void' is not assignable to type 'string'. +!!! error TS2345: Type '() => void' is not assignable to type '(x: string) => string'. foo2(y); ~ !!! error TS2345: Argument of type 'U' is not assignable to parameter of type '(x: string) => string'. diff --git a/tests/baselines/reference/functionImplementations.types b/tests/baselines/reference/functionImplementations.types index f277821d696..4facd65bda7 100644 --- a/tests/baselines/reference/functionImplementations.types +++ b/tests/baselines/reference/functionImplementations.types @@ -324,7 +324,7 @@ class AnotherClass { private x } var f7: (x: number) => string | number = x => { // should be (x: number) => number | string >f7 : (x: number) => string | number >x : number ->x => { // should be (x: number) => number | string if (x < 0) { return x; } return x.toString();} : (x: number) => string | number +>x => { // should be (x: number) => number | string if (x < 0) { return x; } return x.toString();} : (x: number) => number | string >x : number if (x < 0) { return x; } @@ -342,7 +342,7 @@ var f7: (x: number) => string | number = x => { // should be (x: number) => numb var f8: (x: number) => any = x => { // should be (x: number) => Base >f8 : (x: number) => any >x : number ->x => { // should be (x: number) => Base return new Base(); return new Derived2();} : (x: number) => Base +>x => { // should be (x: number) => Base return new Base(); return new Derived2();} : (x: number) => Base | Derived2 >x : number return new Base(); @@ -356,7 +356,7 @@ var f8: (x: number) => any = x => { // should be (x: number) => Base var f9: (x: number) => any = x => { // should be (x: number) => Base >f9 : (x: number) => any >x : number ->x => { // should be (x: number) => Base return new Base(); return new Derived(); return new Derived2();} : (x: number) => Base +>x => { // should be (x: number) => Base return new Base(); return new Derived(); return new Derived2();} : (x: number) => Base | Derived | Derived2 >x : number return new Base(); diff --git a/tests/baselines/reference/generatedContextualTyping.types b/tests/baselines/reference/generatedContextualTyping.types index e8f434d31a8..06745d0d7aa 100644 --- a/tests/baselines/reference/generatedContextualTyping.types +++ b/tests/baselines/reference/generatedContextualTyping.types @@ -2125,8 +2125,8 @@ var x216 = >{ func: n => { return [d1, d2]; } }; >d2 : Derived2 var x217 = (<() => Base[]>undefined) || function() { return [d1, d2] }; ->x217 : () => Base[] ->(<() => Base[]>undefined) || function() { return [d1, d2] } : () => Base[] +>x217 : (() => Base[]) | (() => (Derived1 | Derived2)[]) +>(<() => Base[]>undefined) || function() { return [d1, d2] } : (() => Base[]) | (() => (Derived1 | Derived2)[]) >(<() => Base[]>undefined) : () => Base[] ><() => Base[]>undefined : () => Base[] >Base : Base @@ -2137,8 +2137,8 @@ var x217 = (<() => Base[]>undefined) || function() { return [d1, d2] }; >d2 : Derived2 var x218 = (<() => Base[]>undefined) || function named() { return [d1, d2] }; ->x218 : () => Base[] ->(<() => Base[]>undefined) || function named() { return [d1, d2] } : () => Base[] +>x218 : (() => Base[]) | (() => (Derived1 | Derived2)[]) +>(<() => Base[]>undefined) || function named() { return [d1, d2] } : (() => Base[]) | (() => (Derived1 | Derived2)[]) >(<() => Base[]>undefined) : () => Base[] ><() => Base[]>undefined : () => Base[] >Base : Base @@ -2150,8 +2150,8 @@ var x218 = (<() => Base[]>undefined) || function named() { return [d1, d2] }; >d2 : Derived2 var x219 = (<{ (): Base[]; }>undefined) || function() { return [d1, d2] }; ->x219 : () => Base[] ->(<{ (): Base[]; }>undefined) || function() { return [d1, d2] } : () => Base[] +>x219 : (() => Base[]) | (() => (Derived1 | Derived2)[]) +>(<{ (): Base[]; }>undefined) || function() { return [d1, d2] } : (() => Base[]) | (() => (Derived1 | Derived2)[]) >(<{ (): Base[]; }>undefined) : () => Base[] ><{ (): Base[]; }>undefined : () => Base[] >Base : Base @@ -2162,8 +2162,8 @@ var x219 = (<{ (): Base[]; }>undefined) || function() { return [d1, d2] }; >d2 : Derived2 var x220 = (<{ (): Base[]; }>undefined) || function named() { return [d1, d2] }; ->x220 : () => Base[] ->(<{ (): Base[]; }>undefined) || function named() { return [d1, d2] } : () => Base[] +>x220 : (() => Base[]) | (() => (Derived1 | Derived2)[]) +>(<{ (): Base[]; }>undefined) || function named() { return [d1, d2] } : (() => Base[]) | (() => (Derived1 | Derived2)[]) >(<{ (): Base[]; }>undefined) : () => Base[] ><{ (): Base[]; }>undefined : () => Base[] >Base : Base @@ -2175,8 +2175,8 @@ var x220 = (<{ (): Base[]; }>undefined) || function named() { return [d1, d2] }; >d2 : Derived2 var x221 = (undefined) || [d1, d2]; ->x221 : Base[] ->(undefined) || [d1, d2] : Base[] +>x221 : Base[] | (Derived1 | Derived2)[] +>(undefined) || [d1, d2] : Base[] | (Derived1 | Derived2)[] >(undefined) : Base[] >undefined : Base[] >Base : Base @@ -2186,8 +2186,8 @@ var x221 = (undefined) || [d1, d2]; >d2 : Derived2 var x222 = (>undefined) || [d1, d2]; ->x222 : Base[] ->(>undefined) || [d1, d2] : Base[] +>x222 : Base[] | (Derived1 | Derived2)[] +>(>undefined) || [d1, d2] : Base[] | (Derived1 | Derived2)[] >(>undefined) : Base[] >>undefined : Base[] >Array : T[] @@ -2198,8 +2198,8 @@ var x222 = (>undefined) || [d1, d2]; >d2 : Derived2 var x223 = (<{ [n: number]: Base; }>undefined) || [d1, d2]; ->x223 : { [n: number]: Base; } ->(<{ [n: number]: Base; }>undefined) || [d1, d2] : { [n: number]: Base; } +>x223 : { [n: number]: Base; } | (Derived1 | Derived2)[] +>(<{ [n: number]: Base; }>undefined) || [d1, d2] : { [n: number]: Base; } | (Derived1 | Derived2)[] >(<{ [n: number]: Base; }>undefined) : { [n: number]: Base; } ><{ [n: number]: Base; }>undefined : { [n: number]: Base; } >n : number @@ -2210,8 +2210,8 @@ var x223 = (<{ [n: number]: Base; }>undefined) || [d1, d2]; >d2 : Derived2 var x224 = (<{n: Base[]; } >undefined) || { n: [d1, d2] }; ->x224 : { n: Base[]; } ->(<{n: Base[]; } >undefined) || { n: [d1, d2] } : { n: Base[]; } +>x224 : { n: Base[]; } | { n: (Derived1 | Derived2)[]; } +>(<{n: Base[]; } >undefined) || { n: [d1, d2] } : { n: Base[]; } | { n: (Derived1 | Derived2)[]; } >(<{n: Base[]; } >undefined) : { n: Base[]; } ><{n: Base[]; } >undefined : { n: Base[]; } >n : Base[] diff --git a/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types b/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types index c5fd984d327..5c7500fb5ed 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'] : (string | number | boolean)[] +>[true, 1, null, 'yes'] : (boolean | number | string)[] >true : boolean >1 : number >null : null diff --git a/tests/baselines/reference/genericCallWithArrayLiteralArgs.types b/tests/baselines/reference/genericCallWithArrayLiteralArgs.types index 48a7150ef44..c8e8b41b5fd 100644 --- a/tests/baselines/reference/genericCallWithArrayLiteralArgs.types +++ b/tests/baselines/reference/genericCallWithArrayLiteralArgs.types @@ -46,10 +46,10 @@ var r3 = foo([]); // number[] >[] : undefined[] var r4 = foo([1, '']); // {}[] ->r4 : (string | number)[] ->foo([1, '']) : (string | number)[] +>r4 : (number | string)[] +>foo([1, '']) : (number | string)[] >foo : (t: T) => T ->[1, ''] : (string | number)[] +>[1, ''] : (number | string)[] >1 : number >'' : string @@ -57,7 +57,7 @@ var r5 = foo([1, '']); // any[] >r5 : any[] >foo([1, '']) : any[] >foo : (t: T) => T ->[1, ''] : (string | number)[] +>[1, ''] : (number | string)[] >1 : number >'' : string @@ -66,7 +66,7 @@ var r6 = foo([1, '']); // Object[] >foo([1, '']) : Object[] >foo : (t: T) => T >Object : Object ->[1, ''] : (string | number)[] +>[1, ''] : (number | string)[] >1 : number >'' : string diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt index f9f230b5776..c264058ad9f 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt @@ -5,7 +5,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen 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'. Types of parameters 'a' and 'x' are incompatible. Type 'T' is not assignable to type 'Date'. - Property 'toDateString' is missing in type 'RegExp'. + Type 'RegExp' is not assignable to type 'Date'. + Property 'toDateString' is missing in type 'RegExp'. 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'. Type 'F' is not assignable to type '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'. @@ -13,6 +14,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen 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'. Types of parameters 'a' and 'x' are incompatible. Type 'T' is not assignable to type 'Date'. + Type 'RegExp' is not assignable to type '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'. @@ -54,7 +56,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen !!! error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. !!! error TS2345: Types of parameters 'a' and 'x' are incompatible. !!! error TS2345: Type 'T' is not assignable to type 'Date'. -!!! error TS2345: Property 'toDateString' is missing in type 'RegExp'. +!!! error TS2345: Type 'RegExp' is not assignable to type 'Date'. +!!! error TS2345: Property 'toDateString' is missing in type 'RegExp'. var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date } @@ -101,6 +104,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen !!! error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'. !!! error TS2345: Types of parameters 'a' and 'x' are incompatible. !!! error TS2345: Type 'T' is not assignable to type 'Date'. +!!! error TS2345: Type 'RegExp' is not assignable to type 'Date'. var r7b = foo2((a) => a, (b) => b); } diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexersErrors.errors.txt b/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexersErrors.errors.txt index 2a7bfd696cc..b0c0bee94fd 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexersErrors.errors.txt +++ b/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexersErrors.errors.txt @@ -1,9 +1,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndIndexersErrors.ts(15,17): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndIndexersErrors.ts(18,9): error TS2413: Numeric index type 'T' is not assignable to string index type 'Object'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndIndexersErrors.ts(23,9): error TS2322: Type 'T' is not assignable to type 'U'. -==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndIndexersErrors.ts (3 errors) ==== +==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndIndexersErrors.ts (2 errors) ==== // Type inference infers from indexers in target type, error cases function foo(x: T) { @@ -24,8 +23,6 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObj var b: { [x: string]: Object; [x: number]: T; - ~~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'T' is not assignable to string index type 'Object'. }; var r2 = foo(b); var d = r2[1]; diff --git a/tests/baselines/reference/genericTypeArgumentInference1.types b/tests/baselines/reference/genericTypeArgumentInference1.types index 2d64c8f5c58..405c328bc45 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 : string | number | boolean ->_.all([true, 1, null, 'yes'], _.identity) : string | number | boolean +>r : boolean | number | string +>_.all([true, 1, null, 'yes'], _.identity) : boolean | number | string >_.all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T >_ : Underscore.Static >all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T ->[true, 1, null, 'yes'] : (string | number | boolean)[] +>[true, 1, null, 'yes'] : (boolean | number | string)[] >true : boolean >1 : number >null : null diff --git a/tests/baselines/reference/genericTypeAssertions6.errors.txt b/tests/baselines/reference/genericTypeAssertions6.errors.txt index 93677b9ab84..29ca99ecb1a 100644 --- a/tests/baselines/reference/genericTypeAssertions6.errors.txt +++ b/tests/baselines/reference/genericTypeAssertions6.errors.txt @@ -1,6 +1,7 @@ tests/cases/compiler/genericTypeAssertions6.ts(8,13): error TS2352: Neither type 'U' nor type 'T' is assignable to the other. tests/cases/compiler/genericTypeAssertions6.ts(9,13): error TS2352: Neither type 'T' nor type 'U' is assignable to the other. tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2352: Neither type 'U' nor type 'T' is assignable to the other. + Type 'Date' is not assignable to type 'T'. ==== tests/cases/compiler/genericTypeAssertions6.ts (3 errors) ==== @@ -29,6 +30,7 @@ tests/cases/compiler/genericTypeAssertions6.ts(19,17): error TS2352: Neither typ var e = new Date(); ~~~~~~~~~~~~~~~~ !!! error TS2352: Neither type 'U' nor type 'T' is assignable to the other. +!!! error TS2352: Type 'Date' is not assignable to type 'T'. } } diff --git a/tests/baselines/reference/genericTypeWithNonGenericBaseMisMatch.errors.txt b/tests/baselines/reference/genericTypeWithNonGenericBaseMisMatch.errors.txt index ae93d059f9a..0fe15afcf33 100644 --- a/tests/baselines/reference/genericTypeWithNonGenericBaseMisMatch.errors.txt +++ b/tests/baselines/reference/genericTypeWithNonGenericBaseMisMatch.errors.txt @@ -3,8 +3,9 @@ tests/cases/compiler/genericTypeWithNonGenericBaseMisMatch.ts(4,7): error TS2420 Type '(a: T) => void' is not assignable to type '(a: { a: number; }) => void'. Types of parameters 'a' and 'a' are incompatible. Type 'T' is not assignable to type '{ a: number; }'. - Types of property 'a' are incompatible. - Type 'string' is not assignable to type 'number'. + Type '{ a: string; }' is not assignable to type '{ a: number; }'. + Types of property 'a' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/compiler/genericTypeWithNonGenericBaseMisMatch.ts(8,5): error TS2322: Type 'X<{ a: string; }>' is not assignable to type 'I'. Types of property 'f' are incompatible. Type '(a: { a: string; }) => void' is not assignable to type '(a: { a: number; }) => void'. @@ -25,8 +26,9 @@ tests/cases/compiler/genericTypeWithNonGenericBaseMisMatch.ts(8,5): error TS2322 !!! error TS2420: Type '(a: T) => void' is not assignable to type '(a: { a: number; }) => void'. !!! error TS2420: Types of parameters 'a' and 'a' are incompatible. !!! error TS2420: Type 'T' is not assignable to type '{ a: number; }'. -!!! error TS2420: Types of property 'a' are incompatible. -!!! error TS2420: Type 'string' is not assignable to type 'number'. +!!! error TS2420: Type '{ a: string; }' is not assignable to type '{ a: number; }'. +!!! error TS2420: Types of property 'a' are incompatible. +!!! error TS2420: Type 'string' is not assignable to type 'number'. f(a: T): void { } } var x = new X<{ a: string }>(); diff --git a/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt b/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt index e5c2be7a598..20e113faf2a 100644 --- a/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt +++ b/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt @@ -1,5 +1,5 @@ -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'. +tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'string[]'. + Type 'number | string' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. @@ -14,8 +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 '(string | number)[]' is not assignable to parameter of type 'string[]'. -!!! error TS2345: Type 'string | number' is not assignable to type 'string'. +!!! error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'string[]'. +!!! error TS2345: Type 'number | string' 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 ecfbf75e864..952200d74f8 100644 --- a/tests/baselines/reference/heterogeneousArrayLiterals.types +++ b/tests/baselines/reference/heterogeneousArrayLiterals.types @@ -2,8 +2,8 @@ // type of an array is the best common type of its elements (plus its contextual type if it exists) var a = [1, '']; // {}[] ->a : (string | number)[] ->[1, ''] : (string | number)[] +>a : (number | string)[] +>[1, ''] : (number | string)[] >1 : number >'' : string @@ -14,21 +14,21 @@ var b = [1, null]; // number[] >null : null var c = [1, '', null]; // {}[] ->c : (string | number)[] ->[1, '', null] : (string | number)[] +>c : (number | string)[] +>[1, '', null] : (number | string)[] >1 : number >'' : string >null : null var d = [{}, 1]; // {}[] ->d : {}[] ->[{}, 1] : {}[] +>d : ({} | number)[] +>[{}, 1] : ({} | number)[] >{} : {} >1 : number var e = [{}, Object]; // {}[] ->e : {}[] ->[{}, Object] : {}[] +>e : ({} | ObjectConstructor)[] +>[{}, Object] : ({} | ObjectConstructor)[] >{} : {} >Object : ObjectConstructor @@ -48,8 +48,8 @@ var g = [[1], ['']]; // {}[] >'' : string var h = [{ foo: 1, bar: '' }, { foo: 2 }]; // {foo: number}[] ->h : { foo: number; }[] ->[{ foo: 1, bar: '' }, { foo: 2 }] : { foo: number; }[] +>h : ({ foo: number; bar: string; } | { foo: number; })[] +>[{ foo: 1, bar: '' }, { foo: 2 }] : ({ foo: number; bar: string; } | { foo: number; })[] >{ foo: 1, bar: '' } : { foo: number; bar: string; } >foo : number >1 : number @@ -88,16 +88,16 @@ var k = [() => 1, () => 1]; // { (): number }[] >1 : number var l = [() => 1, () => null]; // { (): any }[] ->l : (() => any)[] ->[() => 1, () => null] : (() => any)[] +>l : ((() => number) | (() => any))[] +>[() => 1, () => null] : ((() => number) | (() => any))[] >() => 1 : () => number >1 : number >() => null : () => any >null : null var m = [() => 1, () => '', () => null]; // { (): any }[] ->m : (() => any)[] ->[() => 1, () => '', () => null] : (() => any)[] +>m : ((() => number) | (() => string) | (() => any))[] +>[() => 1, () => '', () => null] : ((() => number) | (() => string) | (() => any))[] >() => 1 : () => number >1 : number >() => '' : () => string @@ -145,8 +145,8 @@ module Derived { >Derived : typeof Derived var h = [{ foo: base, basear: derived }, { foo: base }]; // {foo: Base}[] ->h : { foo: Base; }[] ->[{ foo: base, basear: derived }, { foo: base }] : { foo: Base; }[] +>h : ({ foo: Base; basear: Derived; } | { foo: Base; })[] +>[{ foo: base, basear: derived }, { foo: base }] : ({ foo: Base; basear: Derived; } | { foo: Base; })[] >{ foo: base, basear: derived } : { foo: Base; basear: Derived; } >foo : Base >base : Base @@ -169,8 +169,8 @@ module Derived { >derived : Derived var j = [() => base, () => derived]; // { {}: Base } ->j : (() => Base)[] ->[() => base, () => derived] : (() => Base)[] +>j : ((() => Base) | (() => Derived))[] +>[() => base, () => derived] : ((() => Base) | (() => Derived))[] >() => base : () => Base >base : Base >() => derived : () => Derived @@ -185,16 +185,16 @@ module Derived { >1 : number var l = [() => base, () => null]; // { (): any }[] ->l : (() => any)[] ->[() => base, () => null] : (() => any)[] +>l : ((() => Base) | (() => any))[] +>[() => base, () => null] : ((() => Base) | (() => any))[] >() => base : () => Base >base : Base >() => null : () => any >null : null var m = [() => base, () => derived, () => null]; // { (): any }[] ->m : (() => any)[] ->[() => base, () => derived, () => null] : (() => any)[] +>m : ((() => Base) | (() => Derived) | (() => any))[] +>[() => base, () => derived, () => null] : ((() => Base) | (() => Derived) | (() => any))[] >() => base : () => Base >base : Base >() => derived : () => Derived @@ -203,8 +203,8 @@ module Derived { >null : null var n = [[() => base], [() => derived]]; // { (): Base }[] ->n : (() => Base)[][] ->[[() => base], [() => derived]] : (() => Base)[][] +>n : ((() => Base)[] | (() => Derived)[])[] +>[[() => base], [() => derived]] : ((() => Base)[] | (() => Derived)[])[] >[() => base] : (() => Base)[] >() => base : () => Base >base : Base @@ -219,8 +219,8 @@ module Derived { >derived2 : Derived2 var p = [derived, derived2, base]; // Base[] ->p : Base[] ->[derived, derived2, base] : Base[] +>p : (Derived | Derived2 | Base)[] +>[derived, derived2, base] : (Derived | Derived2 | Base)[] >derived : Derived >derived2 : Derived2 >base : Base @@ -296,8 +296,8 @@ function foo(t: T, u: U) { >u : U var d = [t, 1]; // {}[] ->d : (number | T)[] ->[t, 1] : (number | T)[] +>d : (T | number)[] +>[t, 1] : (T | number)[] >t : T >1 : number @@ -310,8 +310,8 @@ function foo(t: T, u: U) { >u : U var f = [() => t, () => u, () => null]; // { (): any }[] ->f : (() => any)[] ->[() => t, () => u, () => null] : (() => any)[] +>f : ((() => T) | (() => U) | (() => any))[] +>[() => t, () => u, () => null] : ((() => T) | (() => U) | (() => any))[] >() => t : () => T >t : T >() => u : () => U @@ -350,8 +350,8 @@ function foo2(t: T, u: U) { >u : U var d = [t, 1]; // {}[] ->d : (number | T)[] ->[t, 1] : (number | T)[] +>d : (T | number)[] +>[t, 1] : (T | number)[] >t : T >1 : number @@ -364,8 +364,8 @@ function foo2(t: T, u: U) { >u : U var f = [() => t, () => u, () => null]; // { (): any }[] ->f : (() => any)[] ->[() => t, () => u, () => null] : (() => any)[] +>f : ((() => T) | (() => U) | (() => any))[] +>[() => t, () => u, () => null] : ((() => T) | (() => U) | (() => any))[] >() => t : () => T >t : T >() => u : () => U @@ -374,26 +374,26 @@ function foo2(t: T, u: U) { >null : null var g = [t, base]; // Base[] ->g : Base[] ->[t, base] : Base[] +>g : (T | Base)[] +>[t, base] : (T | Base)[] >t : T >base : Base var h = [t, derived]; // Derived[] ->h : (Derived | T)[] ->[t, derived] : (Derived | T)[] +>h : (T | Derived)[] +>[t, derived] : (T | Derived)[] >t : T >derived : Derived var i = [u, base]; // Base[] ->i : Base[] ->[u, base] : Base[] +>i : (U | Base)[] +>[u, base] : (U | Base)[] >u : U >base : Base var j = [u, derived]; // Derived[] ->j : Derived[] ->[u, derived] : Derived[] +>j : (U | Derived)[] +>[u, derived] : (U | Derived)[] >u : U >derived : Derived } @@ -428,8 +428,8 @@ function foo3(t: T, u: U) { >u : U var d = [t, 1]; // {}[] ->d : (number | T)[] ->[t, 1] : (number | T)[] +>d : (T | number)[] +>[t, 1] : (T | number)[] >t : T >1 : number @@ -442,8 +442,8 @@ function foo3(t: T, u: U) { >u : U var f = [() => t, () => u, () => null]; // { (): any }[] ->f : (() => any)[] ->[() => t, () => u, () => null] : (() => any)[] +>f : ((() => T) | (() => U) | (() => any))[] +>[() => t, () => u, () => null] : ((() => T) | (() => U) | (() => any))[] >() => t : () => T >t : T >() => u : () => U @@ -452,26 +452,26 @@ function foo3(t: T, u: U) { >null : null var g = [t, base]; // Base[] ->g : Base[] ->[t, base] : Base[] +>g : (T | Base)[] +>[t, base] : (T | Base)[] >t : T >base : Base var h = [t, derived]; // Derived[] ->h : Derived[] ->[t, derived] : Derived[] +>h : (T | Derived)[] +>[t, derived] : (T | Derived)[] >t : T >derived : Derived var i = [u, base]; // Base[] ->i : Base[] ->[u, base] : Base[] +>i : (U | Base)[] +>[u, base] : (U | Base)[] >u : U >base : Base var j = [u, derived]; // Derived[] ->j : Derived[] ->[u, derived] : Derived[] +>j : (U | Derived)[] +>[u, derived] : (U | Derived)[] >u : U >derived : Derived } @@ -506,8 +506,8 @@ function foo4(t: T, u: U) { >u : U var d = [t, 1]; // {}[] ->d : (number | T)[] ->[t, 1] : (number | T)[] +>d : (T | number)[] +>[t, 1] : (T | number)[] >t : T >1 : number @@ -520,8 +520,8 @@ function foo4(t: T, u: U) { >u : U var f = [() => t, () => u, () => null]; // { (): any }[] ->f : (() => any)[] ->[() => t, () => u, () => null] : (() => any)[] +>f : ((() => T) | (() => U) | (() => any))[] +>[() => t, () => u, () => null] : ((() => T) | (() => U) | (() => any))[] >() => t : () => T >t : T >() => u : () => U @@ -530,26 +530,26 @@ function foo4(t: T, u: U) { >null : null var g = [t, base]; // Base[] ->g : Base[] ->[t, base] : Base[] +>g : (T | Base)[] +>[t, base] : (T | Base)[] >t : T >base : Base var h = [t, derived]; // Derived[] ->h : (Derived | T)[] ->[t, derived] : (Derived | T)[] +>h : (T | Derived)[] +>[t, derived] : (T | Derived)[] >t : T >derived : Derived var i = [u, base]; // Base[] ->i : Base[] ->[u, base] : Base[] +>i : (U | Base)[] +>[u, base] : (U | Base)[] >u : U >base : Base var j = [u, derived]; // Derived[] ->j : (Derived | U)[] ->[u, derived] : (Derived | U)[] +>j : (U | Derived)[] +>[u, derived] : (U | Derived)[] >u : U >derived : Derived diff --git a/tests/baselines/reference/incompatibleTypes.errors.txt b/tests/baselines/reference/incompatibleTypes.errors.txt index 504ff0088fa..e8763b0d54c 100644 --- a/tests/baselines/reference/incompatibleTypes.errors.txt +++ b/tests/baselines/reference/incompatibleTypes.errors.txt @@ -19,9 +19,9 @@ tests/cases/compiler/incompatibleTypes.ts(42,5): error TS2345: Argument of type Type '() => string' is not assignable to type '(s: string) => number'. Type 'string' is not assignable to type 'number'. tests/cases/compiler/incompatibleTypes.ts(49,5): error TS2345: Argument of type '{ e: number; f: number; }' is not assignable to parameter of type '{ c: { b: string; }; d: string; }'. - Property 'c' is missing in type '{ e: number; f: number; }'. + Object literal may only specify known properties, and 'e' does not exist in type '{ c: { b: string; }; d: string; }'. tests/cases/compiler/incompatibleTypes.ts(66,5): error TS2322: Type '{ e: number; f: number; }' is not assignable to type '{ a: { a: string; }; b: string; }'. - Property 'a' is missing in type '{ e: number; f: number; }'. + Object literal may only specify known properties, and 'e' does not exist in type '{ a: { a: string; }; b: string; }'. tests/cases/compiler/incompatibleTypes.ts(72,5): error TS2322: Type 'number' is not assignable to type '() => string'. tests/cases/compiler/incompatibleTypes.ts(74,5): error TS2322: Type '(a: any) => number' is not assignable to type '() => any'. @@ -103,7 +103,7 @@ tests/cases/compiler/incompatibleTypes.ts(74,5): error TS2322: Type '(a: any) => of1({ e: 0, f: 0 }); ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ e: number; f: number; }' is not assignable to parameter of type '{ c: { b: string; }; d: string; }'. -!!! error TS2345: Property 'c' is missing in type '{ e: number; f: number; }'. +!!! error TS2345: Object literal may only specify known properties, and 'e' does not exist in type '{ c: { b: string; }; d: string; }'. interface IMap { [key:string]:string; @@ -123,7 +123,7 @@ tests/cases/compiler/incompatibleTypes.ts(74,5): error TS2322: Type '(a: any) => var o1: { a: { a: string; }; b: string; } = { e: 0, f: 0 }; ~~ !!! error TS2322: Type '{ e: number; f: number; }' is not assignable to type '{ a: { a: string; }; b: string; }'. -!!! error TS2322: Property 'a' is missing in type '{ e: number; f: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'e' does not exist in type '{ a: { a: string; }; b: string; }'. var a1 = [{ e: 0, f: 0 }, { e: 0, f: 0 }, { e: 0, g: 0 }]; diff --git a/tests/baselines/reference/indexTypeCheck.errors.txt b/tests/baselines/reference/indexTypeCheck.errors.txt index 9f4b403ca2e..9e003197e41 100644 --- a/tests/baselines/reference/indexTypeCheck.errors.txt +++ b/tests/baselines/reference/indexTypeCheck.errors.txt @@ -1,14 +1,13 @@ tests/cases/compiler/indexTypeCheck.ts(2,2): error TS1021: An index signature must have a type annotation. tests/cases/compiler/indexTypeCheck.ts(3,2): error TS1021: An index signature must have a type annotation. tests/cases/compiler/indexTypeCheck.ts(17,2): error TS2413: Numeric index type 'number' is not assignable to string index type 'string'. -tests/cases/compiler/indexTypeCheck.ts(22,2): error TS2413: Numeric index type 'Orange' is not assignable to string index type 'Yellow'. tests/cases/compiler/indexTypeCheck.ts(27,2): error TS2413: Numeric index type 'number' is not assignable to string index type 'string'. tests/cases/compiler/indexTypeCheck.ts(32,3): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/indexTypeCheck.ts(36,3): error TS1023: An index signature parameter type must be 'string' or 'number'. tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol, or 'any'. -==== tests/cases/compiler/indexTypeCheck.ts (8 errors) ==== +==== tests/cases/compiler/indexTypeCheck.ts (7 errors) ==== interface Red { [n:number]; // ok ~~~~~~~~~~~ @@ -37,8 +36,6 @@ tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression interface Green { [n:number]: Orange; // error - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'Orange' is not assignable to string index type 'Yellow'. [s:string]: Yellow; // ok } diff --git a/tests/baselines/reference/indexerWithTuple.types b/tests/baselines/reference/indexerWithTuple.types index 4faae2cda29..7605fba0518 100644 --- a/tests/baselines/reference/indexerWithTuple.types +++ b/tests/baselines/reference/indexerWithTuple.types @@ -101,20 +101,20 @@ var eleUnion11 = unionTuple1[1]; // string | number >1 : number var eleUnion12 = unionTuple1[2]; // string | number ->eleUnion12 : string | number ->unionTuple1[2] : string | number +>eleUnion12 : number | string +>unionTuple1[2] : number | string >unionTuple1 : [number, string | number] >2 : number var eleUnion13 = unionTuple1[idx0]; // string | number ->eleUnion13 : string | number ->unionTuple1[idx0] : string | number +>eleUnion13 : number | string +>unionTuple1[idx0] : number | string >unionTuple1 : [number, string | number] >idx0 : number var eleUnion14 = unionTuple1[idx1]; // string | number ->eleUnion14 : string | number ->unionTuple1[idx1] : string | number +>eleUnion14 : number | string +>unionTuple1[idx1] : number | string >unionTuple1 : [number, string | number] >idx1 : number @@ -143,20 +143,20 @@ var eleUnion21 = unionTuple2[1]; // string | number >1 : number var eleUnion22 = unionTuple2[2]; // string | number | boolean ->eleUnion22 : string | number | boolean ->unionTuple2[2] : string | number | boolean +>eleUnion22 : boolean | string | number +>unionTuple2[2] : boolean | string | number >unionTuple2 : [boolean, string | number] >2 : number var eleUnion23 = unionTuple2[idx0]; // string | number | boolean ->eleUnion23 : string | number | boolean ->unionTuple2[idx0] : string | number | boolean +>eleUnion23 : boolean | string | number +>unionTuple2[idx0] : boolean | string | number >unionTuple2 : [boolean, string | number] >idx0 : number var eleUnion24 = unionTuple2[idx1]; // string | number | boolean ->eleUnion24 : string | number | boolean ->unionTuple2[idx1] : string | number | boolean +>eleUnion24 : boolean | string | number +>unionTuple2[idx1] : boolean | string | number >unionTuple2 : [boolean, string | number] >idx1 : number diff --git a/tests/baselines/reference/inferentialTypingUsingApparentType2.types b/tests/baselines/reference/inferentialTypingUsingApparentType2.types index 597f5885f5a..5841e021c3a 100644 --- a/tests/baselines/reference/inferentialTypingUsingApparentType2.types +++ b/tests/baselines/reference/inferentialTypingUsingApparentType2.types @@ -13,7 +13,7 @@ function foo(x: T): T { } foo({ m(x) { return x.length } }); ->foo({ m(x) { return x.length } }) : { } +>foo({ m(x) { return x.length } }) : { m(x: string): number; } >foo : (x: T) => T >{ m(x) { return x.length } } : { m(x: string): number; } >m : (x: string) => number diff --git a/tests/baselines/reference/inferentialTypingUsingApparentType3.types b/tests/baselines/reference/inferentialTypingUsingApparentType3.types index 7d0da8f4b06..9e0a4ceaea6 100644 --- a/tests/baselines/reference/inferentialTypingUsingApparentType3.types +++ b/tests/baselines/reference/inferentialTypingUsingApparentType3.types @@ -49,10 +49,10 @@ class ObjectField }> { } var person = new ObjectField({ ->person : ObjectField<{}, { [x: string]: CharField | NumberField; id: NumberField; name: CharField; }> ->new ObjectField({ id: new NumberField(), name: new CharField()}) : ObjectField<{}, { [x: string]: CharField | NumberField; id: NumberField; name: CharField; }> +>person : ObjectField<{}, { [x: string]: NumberField | CharField; id: NumberField; name: CharField; }> +>new ObjectField({ id: new NumberField(), name: new CharField()}) : ObjectField<{}, { [x: string]: NumberField | CharField; id: NumberField; name: CharField; }> >ObjectField : typeof ObjectField ->{ id: new NumberField(), name: new CharField()} : { [x: string]: CharField | NumberField; id: NumberField; name: CharField; } +>{ id: new NumberField(), name: new CharField()} : { [x: string]: NumberField | CharField; id: NumberField; name: CharField; } id: new NumberField(), >id : NumberField @@ -68,8 +68,8 @@ var person = new ObjectField({ person.fields.id; >person.fields.id : NumberField ->person.fields : { [x: string]: CharField | NumberField; id: NumberField; name: CharField; } ->person : ObjectField<{}, { [x: string]: CharField | NumberField; id: NumberField; name: CharField; }> ->fields : { [x: string]: CharField | NumberField; id: NumberField; name: CharField; } +>person.fields : { [x: string]: NumberField | CharField; id: NumberField; name: CharField; } +>person : ObjectField<{}, { [x: string]: NumberField | CharField; id: NumberField; name: CharField; }> +>fields : { [x: string]: NumberField | CharField; id: NumberField; name: CharField; } >id : NumberField diff --git a/tests/baselines/reference/inferringAnyFunctionType1.js b/tests/baselines/reference/inferringAnyFunctionType1.js new file mode 100644 index 00000000000..6b48cf2db58 --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType1.js @@ -0,0 +1,12 @@ +//// [inferringAnyFunctionType1.ts] +function f number }>(p: T): T { + return p; +} + +var v = f([x => x]); + +//// [inferringAnyFunctionType1.js] +function f(p) { + return p; +} +var v = f([function (x) { return x; }]); diff --git a/tests/baselines/reference/inferringAnyFunctionType1.symbols b/tests/baselines/reference/inferringAnyFunctionType1.symbols new file mode 100644 index 00000000000..6a43952d770 --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType1.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/inferringAnyFunctionType1.ts === +function f number }>(p: T): T { +>f : Symbol(f, Decl(inferringAnyFunctionType1.ts, 0, 0)) +>T : Symbol(T, Decl(inferringAnyFunctionType1.ts, 0, 11)) +>p1 : Symbol(p1, Decl(inferringAnyFunctionType1.ts, 0, 29)) +>p : Symbol(p, Decl(inferringAnyFunctionType1.ts, 0, 54)) +>T : Symbol(T, Decl(inferringAnyFunctionType1.ts, 0, 11)) +>T : Symbol(T, Decl(inferringAnyFunctionType1.ts, 0, 11)) + + return p; +>p : Symbol(p, Decl(inferringAnyFunctionType1.ts, 0, 54)) +} + +var v = f([x => x]); +>v : Symbol(v, Decl(inferringAnyFunctionType1.ts, 4, 3)) +>f : Symbol(f, Decl(inferringAnyFunctionType1.ts, 0, 0)) +>x : Symbol(x, Decl(inferringAnyFunctionType1.ts, 4, 11)) +>x : Symbol(x, Decl(inferringAnyFunctionType1.ts, 4, 11)) + diff --git a/tests/baselines/reference/inferringAnyFunctionType1.types b/tests/baselines/reference/inferringAnyFunctionType1.types new file mode 100644 index 00000000000..16402cc3ced --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType1.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/inferringAnyFunctionType1.ts === +function f number }>(p: T): T { +>f : number; }>(p: T) => T +>T : T +>p1 : number +>p : T +>T : T +>T : T + + return p; +>p : T +} + +var v = f([x => x]); +>v : [(x: number) => number] +>f([x => x]) : [(x: number) => number] +>f : number; }>(p: T) => T +>[x => x] : [(x: number) => number] +>x => x : (x: number) => number +>x : number +>x : number + diff --git a/tests/baselines/reference/inferringAnyFunctionType2.js b/tests/baselines/reference/inferringAnyFunctionType2.js new file mode 100644 index 00000000000..3841793233e --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType2.js @@ -0,0 +1,12 @@ +//// [inferringAnyFunctionType2.ts] +function f number]>(p: T): T { + return p; +} + +var v = f([x => x]); + +//// [inferringAnyFunctionType2.js] +function f(p) { + return p; +} +var v = f([function (x) { return x; }]); diff --git a/tests/baselines/reference/inferringAnyFunctionType2.symbols b/tests/baselines/reference/inferringAnyFunctionType2.symbols new file mode 100644 index 00000000000..9bdb627d46d --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType2.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/inferringAnyFunctionType2.ts === +function f number]>(p: T): T { +>f : Symbol(f, Decl(inferringAnyFunctionType2.ts, 0, 0)) +>T : Symbol(T, Decl(inferringAnyFunctionType2.ts, 0, 11)) +>p1 : Symbol(p1, Decl(inferringAnyFunctionType2.ts, 0, 23)) +>p : Symbol(p, Decl(inferringAnyFunctionType2.ts, 0, 47)) +>T : Symbol(T, Decl(inferringAnyFunctionType2.ts, 0, 11)) +>T : Symbol(T, Decl(inferringAnyFunctionType2.ts, 0, 11)) + + return p; +>p : Symbol(p, Decl(inferringAnyFunctionType2.ts, 0, 47)) +} + +var v = f([x => x]); +>v : Symbol(v, Decl(inferringAnyFunctionType2.ts, 4, 3)) +>f : Symbol(f, Decl(inferringAnyFunctionType2.ts, 0, 0)) +>x : Symbol(x, Decl(inferringAnyFunctionType2.ts, 4, 11)) +>x : Symbol(x, Decl(inferringAnyFunctionType2.ts, 4, 11)) + diff --git a/tests/baselines/reference/inferringAnyFunctionType2.types b/tests/baselines/reference/inferringAnyFunctionType2.types new file mode 100644 index 00000000000..7884bdfc6ba --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType2.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/inferringAnyFunctionType2.ts === +function f number]>(p: T): T { +>f : number]>(p: T) => T +>T : T +>p1 : number +>p : T +>T : T +>T : T + + return p; +>p : T +} + +var v = f([x => x]); +>v : [(x: number) => number] +>f([x => x]) : [(x: number) => number] +>f : number]>(p: T) => T +>[x => x] : [(x: number) => number] +>x => x : (x: number) => number +>x : number +>x : number + diff --git a/tests/baselines/reference/inferringAnyFunctionType3.js b/tests/baselines/reference/inferringAnyFunctionType3.js new file mode 100644 index 00000000000..ed1c4348dfc --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType3.js @@ -0,0 +1,12 @@ +//// [inferringAnyFunctionType3.ts] +function f number)[]>(p: T): T { + return p; +} + +var v = f([x => x]); + +//// [inferringAnyFunctionType3.js] +function f(p) { + return p; +} +var v = f([function (x) { return x; }]); diff --git a/tests/baselines/reference/inferringAnyFunctionType3.symbols b/tests/baselines/reference/inferringAnyFunctionType3.symbols new file mode 100644 index 00000000000..472d170b81d --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType3.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/inferringAnyFunctionType3.ts === +function f number)[]>(p: T): T { +>f : Symbol(f, Decl(inferringAnyFunctionType3.ts, 0, 0)) +>T : Symbol(T, Decl(inferringAnyFunctionType3.ts, 0, 11)) +>p1 : Symbol(p1, Decl(inferringAnyFunctionType3.ts, 0, 23)) +>p : Symbol(p, Decl(inferringAnyFunctionType3.ts, 0, 49)) +>T : Symbol(T, Decl(inferringAnyFunctionType3.ts, 0, 11)) +>T : Symbol(T, Decl(inferringAnyFunctionType3.ts, 0, 11)) + + return p; +>p : Symbol(p, Decl(inferringAnyFunctionType3.ts, 0, 49)) +} + +var v = f([x => x]); +>v : Symbol(v, Decl(inferringAnyFunctionType3.ts, 4, 3)) +>f : Symbol(f, Decl(inferringAnyFunctionType3.ts, 0, 0)) +>x : Symbol(x, Decl(inferringAnyFunctionType3.ts, 4, 11)) +>x : Symbol(x, Decl(inferringAnyFunctionType3.ts, 4, 11)) + diff --git a/tests/baselines/reference/inferringAnyFunctionType3.types b/tests/baselines/reference/inferringAnyFunctionType3.types new file mode 100644 index 00000000000..1edcfc34643 --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType3.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/inferringAnyFunctionType3.ts === +function f number)[]>(p: T): T { +>f : number)[]>(p: T) => T +>T : T +>p1 : number +>p : T +>T : T +>T : T + + return p; +>p : T +} + +var v = f([x => x]); +>v : ((x: number) => number)[] +>f([x => x]) : ((x: number) => number)[] +>f : number)[]>(p: T) => T +>[x => x] : ((x: number) => number)[] +>x => x : (x: number) => number +>x : number +>x : number + diff --git a/tests/baselines/reference/inferringAnyFunctionType4.js b/tests/baselines/reference/inferringAnyFunctionType4.js new file mode 100644 index 00000000000..dccc51920b0 --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType4.js @@ -0,0 +1,12 @@ +//// [inferringAnyFunctionType4.ts] +function f number>(p: T): T { + return p; +} + +var v = f(x => x); + +//// [inferringAnyFunctionType4.js] +function f(p) { + return p; +} +var v = f(function (x) { return x; }); diff --git a/tests/baselines/reference/inferringAnyFunctionType4.symbols b/tests/baselines/reference/inferringAnyFunctionType4.symbols new file mode 100644 index 00000000000..bfbacfc277c --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType4.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/inferringAnyFunctionType4.ts === +function f number>(p: T): T { +>f : Symbol(f, Decl(inferringAnyFunctionType4.ts, 0, 0)) +>T : Symbol(T, Decl(inferringAnyFunctionType4.ts, 0, 11)) +>p1 : Symbol(p1, Decl(inferringAnyFunctionType4.ts, 0, 22)) +>p : Symbol(p, Decl(inferringAnyFunctionType4.ts, 0, 45)) +>T : Symbol(T, Decl(inferringAnyFunctionType4.ts, 0, 11)) +>T : Symbol(T, Decl(inferringAnyFunctionType4.ts, 0, 11)) + + return p; +>p : Symbol(p, Decl(inferringAnyFunctionType4.ts, 0, 45)) +} + +var v = f(x => x); +>v : Symbol(v, Decl(inferringAnyFunctionType4.ts, 4, 3)) +>f : Symbol(f, Decl(inferringAnyFunctionType4.ts, 0, 0)) +>x : Symbol(x, Decl(inferringAnyFunctionType4.ts, 4, 10)) +>x : Symbol(x, Decl(inferringAnyFunctionType4.ts, 4, 10)) + diff --git a/tests/baselines/reference/inferringAnyFunctionType4.types b/tests/baselines/reference/inferringAnyFunctionType4.types new file mode 100644 index 00000000000..49d46d0433e --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType4.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/inferringAnyFunctionType4.ts === +function f number>(p: T): T { +>f : number>(p: T) => T +>T : T +>p1 : number +>p : T +>T : T +>T : T + + return p; +>p : T +} + +var v = f(x => x); +>v : (x: number) => number +>f(x => x) : (x: number) => number +>f : number>(p: T) => T +>x => x : (x: number) => number +>x : number +>x : number + diff --git a/tests/baselines/reference/inferringAnyFunctionType5.js b/tests/baselines/reference/inferringAnyFunctionType5.js new file mode 100644 index 00000000000..babbab1be9e --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType5.js @@ -0,0 +1,12 @@ +//// [inferringAnyFunctionType5.ts] +function f number }>(p: T): T { + return p; +} + +var v = f({ q: x => x }); + +//// [inferringAnyFunctionType5.js] +function f(p) { + return p; +} +var v = f({ q: function (x) { return x; } }); diff --git a/tests/baselines/reference/inferringAnyFunctionType5.symbols b/tests/baselines/reference/inferringAnyFunctionType5.symbols new file mode 100644 index 00000000000..abf0fe68f46 --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType5.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/inferringAnyFunctionType5.ts === +function f number }>(p: T): T { +>f : Symbol(f, Decl(inferringAnyFunctionType5.ts, 0, 0)) +>T : Symbol(T, Decl(inferringAnyFunctionType5.ts, 0, 11)) +>q : Symbol(q, Decl(inferringAnyFunctionType5.ts, 0, 22)) +>p1 : Symbol(p1, Decl(inferringAnyFunctionType5.ts, 0, 27)) +>p : Symbol(p, Decl(inferringAnyFunctionType5.ts, 0, 52)) +>T : Symbol(T, Decl(inferringAnyFunctionType5.ts, 0, 11)) +>T : Symbol(T, Decl(inferringAnyFunctionType5.ts, 0, 11)) + + return p; +>p : Symbol(p, Decl(inferringAnyFunctionType5.ts, 0, 52)) +} + +var v = f({ q: x => x }); +>v : Symbol(v, Decl(inferringAnyFunctionType5.ts, 4, 3)) +>f : Symbol(f, Decl(inferringAnyFunctionType5.ts, 0, 0)) +>q : Symbol(q, Decl(inferringAnyFunctionType5.ts, 4, 11)) +>x : Symbol(x, Decl(inferringAnyFunctionType5.ts, 4, 14)) +>x : Symbol(x, Decl(inferringAnyFunctionType5.ts, 4, 14)) + diff --git a/tests/baselines/reference/inferringAnyFunctionType5.types b/tests/baselines/reference/inferringAnyFunctionType5.types new file mode 100644 index 00000000000..8f7ae123eac --- /dev/null +++ b/tests/baselines/reference/inferringAnyFunctionType5.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/inferringAnyFunctionType5.ts === +function f number }>(p: T): T { +>f : number; }>(p: T) => T +>T : T +>q : (p1: number) => number +>p1 : number +>p : T +>T : T +>T : T + + return p; +>p : T +} + +var v = f({ q: x => x }); +>v : { q: (x: number) => number; } +>f({ q: x => x }) : { q: (x: number) => number; } +>f : number; }>(p: T) => T +>{ q: x => x } : { q: (x: number) => number; } +>q : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number + diff --git a/tests/baselines/reference/initializePropertiesWithRenamedLet.symbols b/tests/baselines/reference/initializePropertiesWithRenamedLet.symbols index 203508ddf98..f16d8cfc9e0 100644 --- a/tests/baselines/reference/initializePropertiesWithRenamedLet.symbols +++ b/tests/baselines/reference/initializePropertiesWithRenamedLet.symbols @@ -24,6 +24,7 @@ var x, y, z; if (true) { let { x: x } = { x: 0 }; +>x : Symbol(x, Decl(initializePropertiesWithRenamedLet.ts, 10, 20)) >x : Symbol(x, Decl(initializePropertiesWithRenamedLet.ts, 10, 9)) >x : Symbol(x, Decl(initializePropertiesWithRenamedLet.ts, 10, 20)) diff --git a/tests/baselines/reference/innerModExport2.errors.txt b/tests/baselines/reference/innerModExport2.errors.txt index 52a9d01c997..f9568bb45a4 100644 --- a/tests/baselines/reference/innerModExport2.errors.txt +++ b/tests/baselines/reference/innerModExport2.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/innerModExport2.ts(5,5): error TS2304: Cannot find name 'module'. tests/cases/compiler/innerModExport2.ts(5,12): error TS1005: ';' expected. -tests/cases/compiler/innerModExport2.ts(7,20): error TS2395: Individual declarations in merged declaration export_var must be all exported or all local. -tests/cases/compiler/innerModExport2.ts(13,9): error TS2395: Individual declarations in merged declaration export_var must be all exported or all local. +tests/cases/compiler/innerModExport2.ts(7,20): error TS2395: Individual declarations in merged declaration 'export_var' must be all exported or all local. +tests/cases/compiler/innerModExport2.ts(13,9): error TS2395: Individual declarations in merged declaration 'export_var' must be all exported or all local. tests/cases/compiler/innerModExport2.ts(20,7): error TS2339: Property 'NonExportFunc' does not exist on type 'typeof Outer'. @@ -18,7 +18,7 @@ tests/cases/compiler/innerModExport2.ts(20,7): error TS2339: Property 'NonExport var non_export_var = 0; export var export_var = 1; ~~~~~~~~~~ -!!! error TS2395: Individual declarations in merged declaration export_var must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'export_var' must be all exported or all local. function NonExportFunc() { return 0; } @@ -26,7 +26,7 @@ tests/cases/compiler/innerModExport2.ts(20,7): error TS2339: Property 'NonExport } var export_var: number; ~~~~~~~~~~ -!!! error TS2395: Individual declarations in merged declaration export_var must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'export_var' must be all exported or all local. export var outer_var_export = 0; export function outerFuncExport() { return 0; } diff --git a/tests/baselines/reference/instanceOfAssignability.js b/tests/baselines/reference/instanceOfAssignability.js new file mode 100644 index 00000000000..4a1e8b9e9de --- /dev/null +++ b/tests/baselines/reference/instanceOfAssignability.js @@ -0,0 +1,187 @@ +//// [instanceOfAssignability.ts] +interface Base { + foo: string|number; + optional?: number; +} + +// Derived1 is assignable to, but not a subtype of, Base +class Derived1 implements Base { + foo: string; +} +// Derived2 is a subtype of Base that is not assignable to Derived1 +class Derived2 implements Base { + foo: number; + optional: number; +} + +class Animal { + move; +} +class Mammal extends Animal { milk; } +class Giraffe extends Mammal { neck; } + +function fn1(x: Array|Array|boolean) { + if(x instanceof Array) { + // 1.5: y: Array|Array + // Want: y: Array|Array + let y = x; + } +} + +function fn2(x: Base) { + if(x instanceof Derived1) { + // 1.5: y: Base + // Want: y: Derived1 + let y = x; + } +} + +function fn3(x: Base|Derived1) { + if(x instanceof Derived2) { + // 1.5: y: Derived2 + // Want: Derived2 + let y = x; + } +} + +function fn4(x: Base|Derived2) { + if(x instanceof Derived1) { + // 1.5: y: {} + // Want: Derived1 + let y = x; + } +} + +function fn5(x: Derived1) { + if(x instanceof Derived2) { + // 1.5: y: Derived1 + // Want: ??? + let y = x; + } +} + +function fn6(x: Animal|Mammal) { + if(x instanceof Giraffe) { + // 1.5: y: Derived1 + // Want: ??? + let y = x; + } +} + +function fn7(x: Array|Array) { + if(x instanceof Array) { + // 1.5: y: Array|Array + // Want: y: Array|Array + let y = x; + } +} + +interface Alpha { a } +interface Beta { b } +interface Gamma { c } +class ABC { a; b; c; } +function fn8(x: Alpha|Beta|Gamma) { + if(x instanceof ABC) { + let y = x; + } +} + + + + +//// [instanceOfAssignability.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +// Derived1 is assignable to, but not a subtype of, Base +var Derived1 = (function () { + function Derived1() { + } + return Derived1; +})(); +// Derived2 is a subtype of Base that is not assignable to Derived1 +var Derived2 = (function () { + function Derived2() { + } + return Derived2; +})(); +var Animal = (function () { + function Animal() { + } + return Animal; +})(); +var Mammal = (function (_super) { + __extends(Mammal, _super); + function Mammal() { + _super.apply(this, arguments); + } + return Mammal; +})(Animal); +var Giraffe = (function (_super) { + __extends(Giraffe, _super); + function Giraffe() { + _super.apply(this, arguments); + } + return Giraffe; +})(Mammal); +function fn1(x) { + if (x instanceof Array) { + // 1.5: y: Array|Array + // Want: y: Array|Array + var y = x; + } +} +function fn2(x) { + if (x instanceof Derived1) { + // 1.5: y: Base + // Want: y: Derived1 + var y = x; + } +} +function fn3(x) { + if (x instanceof Derived2) { + // 1.5: y: Derived2 + // Want: Derived2 + var y = x; + } +} +function fn4(x) { + if (x instanceof Derived1) { + // 1.5: y: {} + // Want: Derived1 + var y = x; + } +} +function fn5(x) { + if (x instanceof Derived2) { + // 1.5: y: Derived1 + // Want: ??? + var y = x; + } +} +function fn6(x) { + if (x instanceof Giraffe) { + // 1.5: y: Derived1 + // Want: ??? + var y = x; + } +} +function fn7(x) { + if (x instanceof Array) { + // 1.5: y: Array|Array + // Want: y: Array|Array + var y = x; + } +} +var ABC = (function () { + function ABC() { + } + return ABC; +})(); +function fn8(x) { + if (x instanceof ABC) { + var y = x; + } +} diff --git a/tests/baselines/reference/instanceOfAssignability.symbols b/tests/baselines/reference/instanceOfAssignability.symbols new file mode 100644 index 00000000000..b01f29a5faf --- /dev/null +++ b/tests/baselines/reference/instanceOfAssignability.symbols @@ -0,0 +1,208 @@ +=== tests/cases/compiler/instanceOfAssignability.ts === +interface Base { +>Base : Symbol(Base, Decl(instanceOfAssignability.ts, 0, 0)) + + foo: string|number; +>foo : Symbol(foo, Decl(instanceOfAssignability.ts, 0, 16)) + + optional?: number; +>optional : Symbol(optional, Decl(instanceOfAssignability.ts, 1, 20)) +} + +// Derived1 is assignable to, but not a subtype of, Base +class Derived1 implements Base { +>Derived1 : Symbol(Derived1, Decl(instanceOfAssignability.ts, 3, 1)) +>Base : Symbol(Base, Decl(instanceOfAssignability.ts, 0, 0)) + + foo: string; +>foo : Symbol(foo, Decl(instanceOfAssignability.ts, 6, 32)) +} +// Derived2 is a subtype of Base that is not assignable to Derived1 +class Derived2 implements Base { +>Derived2 : Symbol(Derived2, Decl(instanceOfAssignability.ts, 8, 1)) +>Base : Symbol(Base, Decl(instanceOfAssignability.ts, 0, 0)) + + foo: number; +>foo : Symbol(foo, Decl(instanceOfAssignability.ts, 10, 32)) + + optional: number; +>optional : Symbol(optional, Decl(instanceOfAssignability.ts, 11, 13)) +} + +class Animal { +>Animal : Symbol(Animal, Decl(instanceOfAssignability.ts, 13, 1)) + + move; +>move : Symbol(move, Decl(instanceOfAssignability.ts, 15, 14)) +} +class Mammal extends Animal { milk; } +>Mammal : Symbol(Mammal, Decl(instanceOfAssignability.ts, 17, 1)) +>Animal : Symbol(Animal, Decl(instanceOfAssignability.ts, 13, 1)) +>milk : Symbol(milk, Decl(instanceOfAssignability.ts, 18, 29)) + +class Giraffe extends Mammal { neck; } +>Giraffe : Symbol(Giraffe, Decl(instanceOfAssignability.ts, 18, 37)) +>Mammal : Symbol(Mammal, Decl(instanceOfAssignability.ts, 17, 1)) +>neck : Symbol(neck, Decl(instanceOfAssignability.ts, 19, 30)) + +function fn1(x: Array|Array|boolean) { +>fn1 : Symbol(fn1, Decl(instanceOfAssignability.ts, 19, 38)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 21, 13)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) + + if(x instanceof Array) { +>x : Symbol(x, Decl(instanceOfAssignability.ts, 21, 13)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) + + // 1.5: y: Array|Array + // Want: y: Array|Array + let y = x; +>y : Symbol(y, Decl(instanceOfAssignability.ts, 25, 5)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 21, 13)) + } +} + +function fn2(x: Base) { +>fn2 : Symbol(fn2, Decl(instanceOfAssignability.ts, 27, 1)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 29, 13)) +>Base : Symbol(Base, Decl(instanceOfAssignability.ts, 0, 0)) + + if(x instanceof Derived1) { +>x : Symbol(x, Decl(instanceOfAssignability.ts, 29, 13)) +>Derived1 : Symbol(Derived1, Decl(instanceOfAssignability.ts, 3, 1)) + + // 1.5: y: Base + // Want: y: Derived1 + let y = x; +>y : Symbol(y, Decl(instanceOfAssignability.ts, 33, 5)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 29, 13)) + } +} + +function fn3(x: Base|Derived1) { +>fn3 : Symbol(fn3, Decl(instanceOfAssignability.ts, 35, 1)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 37, 13)) +>Base : Symbol(Base, Decl(instanceOfAssignability.ts, 0, 0)) +>Derived1 : Symbol(Derived1, Decl(instanceOfAssignability.ts, 3, 1)) + + if(x instanceof Derived2) { +>x : Symbol(x, Decl(instanceOfAssignability.ts, 37, 13)) +>Derived2 : Symbol(Derived2, Decl(instanceOfAssignability.ts, 8, 1)) + + // 1.5: y: Derived2 + // Want: Derived2 + let y = x; +>y : Symbol(y, Decl(instanceOfAssignability.ts, 41, 5)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 37, 13)) + } +} + +function fn4(x: Base|Derived2) { +>fn4 : Symbol(fn4, Decl(instanceOfAssignability.ts, 43, 1)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 45, 13)) +>Base : Symbol(Base, Decl(instanceOfAssignability.ts, 0, 0)) +>Derived2 : Symbol(Derived2, Decl(instanceOfAssignability.ts, 8, 1)) + + if(x instanceof Derived1) { +>x : Symbol(x, Decl(instanceOfAssignability.ts, 45, 13)) +>Derived1 : Symbol(Derived1, Decl(instanceOfAssignability.ts, 3, 1)) + + // 1.5: y: {} + // Want: Derived1 + let y = x; +>y : Symbol(y, Decl(instanceOfAssignability.ts, 49, 5)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 45, 13)) + } +} + +function fn5(x: Derived1) { +>fn5 : Symbol(fn5, Decl(instanceOfAssignability.ts, 51, 1)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 53, 13)) +>Derived1 : Symbol(Derived1, Decl(instanceOfAssignability.ts, 3, 1)) + + if(x instanceof Derived2) { +>x : Symbol(x, Decl(instanceOfAssignability.ts, 53, 13)) +>Derived2 : Symbol(Derived2, Decl(instanceOfAssignability.ts, 8, 1)) + + // 1.5: y: Derived1 + // Want: ??? + let y = x; +>y : Symbol(y, Decl(instanceOfAssignability.ts, 57, 5)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 53, 13)) + } +} + +function fn6(x: Animal|Mammal) { +>fn6 : Symbol(fn6, Decl(instanceOfAssignability.ts, 59, 1)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 61, 13)) +>Animal : Symbol(Animal, Decl(instanceOfAssignability.ts, 13, 1)) +>Mammal : Symbol(Mammal, Decl(instanceOfAssignability.ts, 17, 1)) + + if(x instanceof Giraffe) { +>x : Symbol(x, Decl(instanceOfAssignability.ts, 61, 13)) +>Giraffe : Symbol(Giraffe, Decl(instanceOfAssignability.ts, 18, 37)) + + // 1.5: y: Derived1 + // Want: ??? + let y = x; +>y : Symbol(y, Decl(instanceOfAssignability.ts, 65, 5)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 61, 13)) + } +} + +function fn7(x: Array|Array) { +>fn7 : Symbol(fn7, Decl(instanceOfAssignability.ts, 67, 1)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 69, 13)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) + + if(x instanceof Array) { +>x : Symbol(x, Decl(instanceOfAssignability.ts, 69, 13)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) + + // 1.5: y: Array|Array + // Want: y: Array|Array + let y = x; +>y : Symbol(y, Decl(instanceOfAssignability.ts, 73, 5)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 69, 13)) + } +} + +interface Alpha { a } +>Alpha : Symbol(Alpha, Decl(instanceOfAssignability.ts, 75, 1)) +>a : Symbol(a, Decl(instanceOfAssignability.ts, 77, 17)) + +interface Beta { b } +>Beta : Symbol(Beta, Decl(instanceOfAssignability.ts, 77, 21)) +>b : Symbol(b, Decl(instanceOfAssignability.ts, 78, 16)) + +interface Gamma { c } +>Gamma : Symbol(Gamma, Decl(instanceOfAssignability.ts, 78, 20)) +>c : Symbol(c, Decl(instanceOfAssignability.ts, 79, 17)) + +class ABC { a; b; c; } +>ABC : Symbol(ABC, Decl(instanceOfAssignability.ts, 79, 21)) +>a : Symbol(a, Decl(instanceOfAssignability.ts, 80, 11)) +>b : Symbol(b, Decl(instanceOfAssignability.ts, 80, 14)) +>c : Symbol(c, Decl(instanceOfAssignability.ts, 80, 17)) + +function fn8(x: Alpha|Beta|Gamma) { +>fn8 : Symbol(fn8, Decl(instanceOfAssignability.ts, 80, 22)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 81, 13)) +>Alpha : Symbol(Alpha, Decl(instanceOfAssignability.ts, 75, 1)) +>Beta : Symbol(Beta, Decl(instanceOfAssignability.ts, 77, 21)) +>Gamma : Symbol(Gamma, Decl(instanceOfAssignability.ts, 78, 20)) + + if(x instanceof ABC) { +>x : Symbol(x, Decl(instanceOfAssignability.ts, 81, 13)) +>ABC : Symbol(ABC, Decl(instanceOfAssignability.ts, 79, 21)) + + let y = x; +>y : Symbol(y, Decl(instanceOfAssignability.ts, 83, 5)) +>x : Symbol(x, Decl(instanceOfAssignability.ts, 81, 13)) + } +} + + + diff --git a/tests/baselines/reference/instanceOfAssignability.types b/tests/baselines/reference/instanceOfAssignability.types new file mode 100644 index 00000000000..12b2d326062 --- /dev/null +++ b/tests/baselines/reference/instanceOfAssignability.types @@ -0,0 +1,216 @@ +=== tests/cases/compiler/instanceOfAssignability.ts === +interface Base { +>Base : Base + + foo: string|number; +>foo : string | number + + optional?: number; +>optional : number +} + +// Derived1 is assignable to, but not a subtype of, Base +class Derived1 implements Base { +>Derived1 : Derived1 +>Base : Base + + foo: string; +>foo : string +} +// Derived2 is a subtype of Base that is not assignable to Derived1 +class Derived2 implements Base { +>Derived2 : Derived2 +>Base : Base + + foo: number; +>foo : number + + optional: number; +>optional : number +} + +class Animal { +>Animal : Animal + + move; +>move : any +} +class Mammal extends Animal { milk; } +>Mammal : Mammal +>Animal : Animal +>milk : any + +class Giraffe extends Mammal { neck; } +>Giraffe : Giraffe +>Mammal : Mammal +>neck : any + +function fn1(x: Array|Array|boolean) { +>fn1 : (x: number[] | string[] | boolean) => void +>x : number[] | string[] | boolean +>Array : T[] +>Array : T[] + + if(x instanceof Array) { +>x instanceof Array : boolean +>x : number[] | string[] | boolean +>Array : ArrayConstructor + + // 1.5: y: Array|Array + // Want: y: Array|Array + let y = x; +>y : number[] | string[] +>x : number[] | string[] + } +} + +function fn2(x: Base) { +>fn2 : (x: Base) => void +>x : Base +>Base : Base + + if(x instanceof Derived1) { +>x instanceof Derived1 : boolean +>x : Base +>Derived1 : typeof Derived1 + + // 1.5: y: Base + // Want: y: Derived1 + let y = x; +>y : Derived1 +>x : Derived1 + } +} + +function fn3(x: Base|Derived1) { +>fn3 : (x: Base | Derived1) => void +>x : Base | Derived1 +>Base : Base +>Derived1 : Derived1 + + if(x instanceof Derived2) { +>x instanceof Derived2 : boolean +>x : Base | Derived1 +>Derived2 : typeof Derived2 + + // 1.5: y: Derived2 + // Want: Derived2 + let y = x; +>y : Derived2 +>x : Derived2 + } +} + +function fn4(x: Base|Derived2) { +>fn4 : (x: Base | Derived2) => void +>x : Base | Derived2 +>Base : Base +>Derived2 : Derived2 + + if(x instanceof Derived1) { +>x instanceof Derived1 : boolean +>x : Base | Derived2 +>Derived1 : typeof Derived1 + + // 1.5: y: {} + // Want: Derived1 + let y = x; +>y : Derived1 +>x : Derived1 + } +} + +function fn5(x: Derived1) { +>fn5 : (x: Derived1) => void +>x : Derived1 +>Derived1 : Derived1 + + if(x instanceof Derived2) { +>x instanceof Derived2 : boolean +>x : Derived1 +>Derived2 : typeof Derived2 + + // 1.5: y: Derived1 + // Want: ??? + let y = x; +>y : Derived1 +>x : Derived1 + } +} + +function fn6(x: Animal|Mammal) { +>fn6 : (x: Animal | Mammal) => void +>x : Animal | Mammal +>Animal : Animal +>Mammal : Mammal + + if(x instanceof Giraffe) { +>x instanceof Giraffe : boolean +>x : Animal | Mammal +>Giraffe : typeof Giraffe + + // 1.5: y: Derived1 + // Want: ??? + let y = x; +>y : Giraffe +>x : Giraffe + } +} + +function fn7(x: Array|Array) { +>fn7 : (x: number[] | string[]) => void +>x : number[] | string[] +>Array : T[] +>Array : T[] + + if(x instanceof Array) { +>x instanceof Array : boolean +>x : number[] | string[] +>Array : ArrayConstructor + + // 1.5: y: Array|Array + // Want: y: Array|Array + let y = x; +>y : number[] | string[] +>x : number[] | string[] + } +} + +interface Alpha { a } +>Alpha : Alpha +>a : any + +interface Beta { b } +>Beta : Beta +>b : any + +interface Gamma { c } +>Gamma : Gamma +>c : any + +class ABC { a; b; c; } +>ABC : ABC +>a : any +>b : any +>c : any + +function fn8(x: Alpha|Beta|Gamma) { +>fn8 : (x: Alpha | Beta | Gamma) => void +>x : Alpha | Beta | Gamma +>Alpha : Alpha +>Beta : Beta +>Gamma : Gamma + + if(x instanceof ABC) { +>x instanceof ABC : boolean +>x : Alpha | Beta | Gamma +>ABC : typeof ABC + + let y = x; +>y : ABC +>x : ABC + } +} + + + diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index bd8b2048045..7f1cc88e2a2 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -29,15 +29,7 @@ tests/cases/compiler/intTypeCheck.ts(134,5): error TS2322: Type 'boolean' is not tests/cases/compiler/intTypeCheck.ts(134,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(134,22): error TS2304: Cannot find name 'i3'. tests/cases/compiler/intTypeCheck.ts(135,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(141,5): error TS2322: Type 'Object' is not assignable to type 'i4'. - Index signature is missing in type 'Object'. tests/cases/compiler/intTypeCheck.ts(142,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(143,5): error TS2322: Type 'Base' is not assignable to type 'i4'. - Index signature is missing in type 'Base'. -tests/cases/compiler/intTypeCheck.ts(145,5): error TS2322: Type '() => void' is not assignable to type 'i4'. - Index signature is missing in type '() => void'. -tests/cases/compiler/intTypeCheck.ts(148,5): error TS2322: Type 'boolean' is not assignable to type 'i4'. - Index signature is missing in type 'Boolean'. tests/cases/compiler/intTypeCheck.ts(148,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(148,22): error TS2304: Cannot find name 'i4'. tests/cases/compiler/intTypeCheck.ts(149,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -73,21 +65,13 @@ tests/cases/compiler/intTypeCheck.ts(190,5): error TS2322: Type 'boolean' is not tests/cases/compiler/intTypeCheck.ts(190,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(190,22): error TS2304: Cannot find name 'i7'. tests/cases/compiler/intTypeCheck.ts(191,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(197,5): error TS2322: Type 'Object' is not assignable to type 'i8'. - Index signature is missing in type 'Object'. tests/cases/compiler/intTypeCheck.ts(198,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/compiler/intTypeCheck.ts(199,5): error TS2322: Type 'Base' is not assignable to type 'i8'. - Index signature is missing in type 'Base'. -tests/cases/compiler/intTypeCheck.ts(201,5): error TS2322: Type '() => void' is not assignable to type 'i8'. - Index signature is missing in type '() => void'. -tests/cases/compiler/intTypeCheck.ts(204,5): error TS2322: Type 'boolean' is not assignable to type 'i8'. - Index signature is missing in type 'Boolean'. tests/cases/compiler/intTypeCheck.ts(204,21): error TS1109: Expression expected. tests/cases/compiler/intTypeCheck.ts(204,22): error TS2304: Cannot find name 'i8'. tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -==== tests/cases/compiler/intTypeCheck.ts (69 errors) ==== +==== tests/cases/compiler/intTypeCheck.ts (61 errors) ==== interface i1 { //Property Signatures p; @@ -287,27 +271,15 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj33: i4; var obj34: i4 = {}; var obj35: i4 = new Object(); - ~~~~~ -!!! error TS2322: Type 'Object' is not assignable to type 'i4'. -!!! error TS2322: Index signature is missing in type 'Object'. var obj36: i4 = new obj33; ~~~~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. var obj37: i4 = new Base; - ~~~~~ -!!! error TS2322: Type 'Base' is not assignable to type 'i4'. -!!! error TS2322: Index signature is missing in type 'Base'. var obj38: i4 = null; var obj39: i4 = function () { }; - ~~~~~ -!!! error TS2322: Type '() => void' is not assignable to type 'i4'. -!!! error TS2322: Index signature is missing in type '() => void'. //var obj40: i4 = function foo() { }; var obj41: i4 = anyVar; var obj42: i4 = new anyVar; - ~~~~~ -!!! error TS2322: Type 'boolean' is not assignable to type 'i4'. -!!! error TS2322: Index signature is missing in type 'Boolean'. ~ !!! error TS1109: Expression expected. ~~ @@ -421,27 +393,15 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj77: i8; var obj78: i8 = {}; var obj79: i8 = new Object(); - ~~~~~ -!!! error TS2322: Type 'Object' is not assignable to type 'i8'. -!!! error TS2322: Index signature is missing in type 'Object'. var obj80: i8 = new obj77; ~~~~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. var obj81: i8 = new Base; - ~~~~~ -!!! error TS2322: Type 'Base' is not assignable to type 'i8'. -!!! error TS2322: Index signature is missing in type 'Base'. var obj82: i8 = null; var obj83: i8 = function () { }; - ~~~~~ -!!! error TS2322: Type '() => void' is not assignable to type 'i8'. -!!! error TS2322: Index signature is missing in type '() => void'. //var obj84: i8 = function foo() { }; var obj85: i8 = anyVar; var obj86: i8 = new anyVar; - ~~~~~ -!!! error TS2322: Type 'boolean' is not assignable to type 'i8'. -!!! error TS2322: Index signature is missing in type 'Boolean'. ~ !!! error TS1109: Expression expected. ~~ diff --git a/tests/baselines/reference/interfaceWithMultipleBaseTypes.errors.txt b/tests/baselines/reference/interfaceWithMultipleBaseTypes.errors.txt index 95adbbf6717..138f3d92096 100644 --- a/tests/baselines/reference/interfaceWithMultipleBaseTypes.errors.txt +++ b/tests/baselines/reference/interfaceWithMultipleBaseTypes.errors.txt @@ -18,11 +18,9 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithMultipleBa tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithMultipleBaseTypes.ts(60,15): error TS2430: Interface 'Derived5' incorrectly extends interface 'Base1'. Types of property 'x' are incompatible. Type 'T' is not assignable to type '{ a: T; }'. - Property 'a' is missing in type '{}'. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithMultipleBaseTypes.ts(60,15): error TS2430: Interface 'Derived5' incorrectly extends interface 'Base2'. Types of property 'x' are incompatible. Type 'T' is not assignable to type '{ b: T; }'. - Property 'b' is missing in type '{}'. ==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithMultipleBaseTypes.ts (6 errors) ==== @@ -111,12 +109,10 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithMultipleBa !!! error TS2430: Interface 'Derived5' incorrectly extends interface 'Base1'. !!! error TS2430: Types of property 'x' are incompatible. !!! error TS2430: Type 'T' is not assignable to type '{ a: T; }'. -!!! error TS2430: Property 'a' is missing in type '{}'. ~~~~~~~~ !!! error TS2430: Interface 'Derived5' incorrectly extends interface 'Base2'. !!! error TS2430: Types of property 'x' are incompatible. !!! error TS2430: Type 'T' is not assignable to type '{ b: T; }'. -!!! error TS2430: Property 'b' is missing in type '{}'. x: T; } } \ No newline at end of file diff --git a/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt b/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt index 3ec718f3b25..0c4b95214b0 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 '(C | D)[]'. +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 | C2 | 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 '(C | D)[]'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '(C | C2 | D)[]'. var arr2 = [new D()]; var arr2 = new Array>(); diff --git a/tests/baselines/reference/isolatedModulesSourceMap.errors.txt b/tests/baselines/reference/isolatedModulesSourceMap.errors.txt deleted file mode 100644 index 6383e85ecd5..00000000000 --- a/tests/baselines/reference/isolatedModulesSourceMap.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -error TS5043: Option 'sourceMap' cannot be specified with option 'isolatedModules'. - - -!!! error TS5043: Option 'sourceMap' cannot be specified with option 'isolatedModules'. -==== tests/cases/compiler/isolatedModulesSourceMap.ts (0 errors) ==== - - export var x; \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesSourceMap.js b/tests/baselines/reference/isolatedModulesSourceMap.js index ca6f4b4190e..2722a3ce7ab 100644 --- a/tests/baselines/reference/isolatedModulesSourceMap.js +++ b/tests/baselines/reference/isolatedModulesSourceMap.js @@ -1,7 +1,7 @@ //// [isolatedModulesSourceMap.ts] -export var x; +export var x = 1; //// [isolatedModulesSourceMap.js] -export var x; +export var x = 1; //# sourceMappingURL=isolatedModulesSourceMap.js.map \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesSourceMap.js.map b/tests/baselines/reference/isolatedModulesSourceMap.js.map index 8e505dcda7a..9fa3e0da0d6 100644 --- a/tests/baselines/reference/isolatedModulesSourceMap.js.map +++ b/tests/baselines/reference/isolatedModulesSourceMap.js.map @@ -1,2 +1,2 @@ //// [isolatedModulesSourceMap.js.map] -{"version":3,"file":"isolatedModulesSourceMap.js","sourceRoot":"","sources":["isolatedModulesSourceMap.ts"],"names":[],"mappings":"AACA,WAAW,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"isolatedModulesSourceMap.js","sourceRoot":"","sources":["isolatedModulesSourceMap.ts"],"names":[],"mappings":"AACA,WAAW,CAAC,GAAG,CAAC,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesSourceMap.sourcemap.txt b/tests/baselines/reference/isolatedModulesSourceMap.sourcemap.txt index 5c6b7659bc6..d31445505f7 100644 --- a/tests/baselines/reference/isolatedModulesSourceMap.sourcemap.txt +++ b/tests/baselines/reference/isolatedModulesSourceMap.sourcemap.txt @@ -8,20 +8,26 @@ sources: isolatedModulesSourceMap.ts emittedFile:tests/cases/compiler/isolatedModulesSourceMap.js sourceFile:isolatedModulesSourceMap.ts ------------------------------------------------------------------- ->>>export var x; +>>>export var x = 1; 1 > 2 >^^^^^^^^^^^ 3 > ^ -4 > ^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +4 > ^^^ +5 > ^ +6 > ^ +7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >export var 3 > x -4 > ; +4 > = +5 > 1 +6 > ; 1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) 2 >Emitted(1, 12) Source(2, 12) + SourceIndex(0) 3 >Emitted(1, 13) Source(2, 13) + SourceIndex(0) -4 >Emitted(1, 14) Source(2, 14) + SourceIndex(0) +4 >Emitted(1, 16) Source(2, 16) + SourceIndex(0) +5 >Emitted(1, 17) Source(2, 17) + SourceIndex(0) +6 >Emitted(1, 18) Source(2, 18) + SourceIndex(0) --- >>>//# sourceMappingURL=isolatedModulesSourceMap.js.map \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesSourceMap.symbols b/tests/baselines/reference/isolatedModulesSourceMap.symbols new file mode 100644 index 00000000000..d4ae3c34cf1 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesSourceMap.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/isolatedModulesSourceMap.ts === + +export var x = 1; +>x : Symbol(x, Decl(isolatedModulesSourceMap.ts, 1, 10)) + diff --git a/tests/baselines/reference/isolatedModulesSourceMap.types b/tests/baselines/reference/isolatedModulesSourceMap.types new file mode 100644 index 00000000000..1955fe5da6e --- /dev/null +++ b/tests/baselines/reference/isolatedModulesSourceMap.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/isolatedModulesSourceMap.ts === + +export var x = 1; +>x : number +>1 : number + diff --git a/tests/baselines/reference/iteratorSpreadInCall12.types b/tests/baselines/reference/iteratorSpreadInCall12.types index fcc4bbc3d45..4307daa78b0 100644 --- a/tests/baselines/reference/iteratorSpreadInCall12.types +++ b/tests/baselines/reference/iteratorSpreadInCall12.types @@ -1,9 +1,9 @@ === tests/cases/conformance/es6/spread/iteratorSpreadInCall12.ts === new Foo(...[...new SymbolIterator, ...[...new StringIterator]]); ->new Foo(...[...new SymbolIterator, ...[...new StringIterator]]) : Foo +>new Foo(...[...new SymbolIterator, ...[...new StringIterator]]) : Foo >Foo : typeof Foo ->...[...new SymbolIterator, ...[...new StringIterator]] : string | symbol ->[...new SymbolIterator, ...[...new StringIterator]] : (string | symbol)[] +>...[...new SymbolIterator, ...[...new StringIterator]] : symbol | string +>[...new SymbolIterator, ...[...new StringIterator]] : (symbol | string)[] >...new SymbolIterator : symbol >new SymbolIterator : SymbolIterator >SymbolIterator : typeof SymbolIterator diff --git a/tests/baselines/reference/iteratorSpreadInCall5.types b/tests/baselines/reference/iteratorSpreadInCall5.types index 2401a41cca8..631ad940554 100644 --- a/tests/baselines/reference/iteratorSpreadInCall5.types +++ b/tests/baselines/reference/iteratorSpreadInCall5.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/spread/iteratorSpreadInCall5.ts === foo(...new SymbolIterator, ...new StringIterator); >foo(...new SymbolIterator, ...new StringIterator) : void ->foo : (...s: (string | symbol)[]) => void +>foo : (...s: (symbol | string)[]) => void >...new SymbolIterator : symbol >new SymbolIterator : SymbolIterator >SymbolIterator : typeof SymbolIterator @@ -10,8 +10,8 @@ foo(...new SymbolIterator, ...new StringIterator); >StringIterator : typeof StringIterator function foo(...s: (symbol | string)[]) { } ->foo : (...s: (string | symbol)[]) => void ->s : (string | symbol)[] +>foo : (...s: (symbol | string)[]) => void +>s : (symbol | string)[] class SymbolIterator { >SymbolIterator : SymbolIterator diff --git a/tests/baselines/reference/iteratorSpreadInCall6.errors.txt b/tests/baselines/reference/iteratorSpreadInCall6.errors.txt index be085beb632..0a0da985ace 100644 --- a/tests/baselines/reference/iteratorSpreadInCall6.errors.txt +++ b/tests/baselines/reference/iteratorSpreadInCall6.errors.txt @@ -1,12 +1,12 @@ -tests/cases/conformance/es6/spread/iteratorSpreadInCall6.ts(1,28): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number | symbol'. - Type 'string' is not assignable to type 'symbol'. +tests/cases/conformance/es6/spread/iteratorSpreadInCall6.ts(1,28): error TS2345: Argument of type 'string' is not assignable to parameter of type 'symbol | number'. + Type 'string' is not assignable to type 'number'. ==== tests/cases/conformance/es6/spread/iteratorSpreadInCall6.ts (1 errors) ==== foo(...new SymbolIterator, ...new StringIterator); ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number | symbol'. -!!! error TS2345: Type 'string' is not assignable to type 'symbol'. +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'symbol | number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. function foo(...s: (symbol | number)[]) { } class SymbolIterator { diff --git a/tests/baselines/reference/jsxImportInAttribute.js b/tests/baselines/reference/jsxImportInAttribute.js new file mode 100644 index 00000000000..40b21e87c3f --- /dev/null +++ b/tests/baselines/reference/jsxImportInAttribute.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/jsxImportInAttribute.tsx] //// + +//// [component.d.ts] + +declare module "Test" { + export default class Text { } +} + +//// [consumer.tsx] +/// +import Test from 'Test'; + +let x = Test; // emit test_1.default +; // ? + + +//// [consumer.jsx] +/// +var Test_1 = require('Test'); +var x = Test_1["default"]; // emit test_1.default +; // ? diff --git a/tests/baselines/reference/jsxImportInAttribute.symbols b/tests/baselines/reference/jsxImportInAttribute.symbols new file mode 100644 index 00000000000..8481771f085 --- /dev/null +++ b/tests/baselines/reference/jsxImportInAttribute.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/consumer.tsx === +/// +import Test from 'Test'; +>Test : Symbol(Test, Decl(consumer.tsx, 1, 6)) + +let x = Test; // emit test_1.default +>x : Symbol(x, Decl(consumer.tsx, 3, 3)) +>Test : Symbol(Test, Decl(consumer.tsx, 1, 6)) + +; // ? +>attr : Symbol(unknown) + +=== tests/cases/compiler/component.d.ts === + +declare module "Test" { + export default class Text { } +>Text : Symbol(Text, Decl(component.d.ts, 1, 23)) +} + diff --git a/tests/baselines/reference/jsxImportInAttribute.types b/tests/baselines/reference/jsxImportInAttribute.types new file mode 100644 index 00000000000..8dfbe292fe0 --- /dev/null +++ b/tests/baselines/reference/jsxImportInAttribute.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/consumer.tsx === +/// +import Test from 'Test'; +>Test : typeof Test + +let x = Test; // emit test_1.default +>x : typeof Test +>Test : typeof Test + +; // ? +> : any +>anything : any +>attr : any +>Test : any + +=== tests/cases/compiler/component.d.ts === + +declare module "Test" { + export default class Text { } +>Text : Text +} + diff --git a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt index 3e2a10e9931..99ae5056a4c 100644 --- a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt +++ b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.errors.txt @@ -30,6 +30,7 @@ tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(11,12): error TS2304: tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(11,16): error TS1109: Expression expected. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(12,2): error TS2304: Cannot find name 'a'. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(12,5): error TS1003: Identifier expected. +tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(12,10): error TS2304: Cannot find name 'a'. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(12,13): error TS1005: '>' expected. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(12,14): error TS2304: Cannot find name 'c'. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(12,16): error TS1109: Expression expected. @@ -43,6 +44,7 @@ tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(14,8): error TS2304: tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(14,10): error TS1109: Expression expected. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(15,2): error TS2304: Cannot find name 'a'. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(15,4): error TS1003: Identifier expected. +tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(15,7): error TS2304: Cannot find name 'a'. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(15,9): error TS1003: Identifier expected. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(16,3): error TS1003: Identifier expected. tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(16,4): error TS2304: Cannot find name 'foo'. @@ -71,7 +73,7 @@ tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(35,4): error TS1003: tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(35,21): error TS17002: Expected corresponding JSX closing tag for 'a'. -==== tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx (71 errors) ==== +==== tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx (73 errors) ==== declare var React: any; ; @@ -148,6 +150,8 @@ tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(35,21): error TS17002 !!! error TS2304: Cannot find name 'a'. ~ !!! error TS1003: Identifier expected. + ~ +!!! error TS2304: Cannot find name 'a'. ~ !!! error TS1005: '>' expected. ~ @@ -177,6 +181,8 @@ tests/cases/conformance/jsx/jsxInvalidEsprimaTestSuite.tsx(35,21): error TS17002 !!! error TS2304: Cannot find name 'a'. ~ !!! error TS1003: Identifier expected. + ~ +!!! error TS2304: Cannot find name 'a'. ~ !!! error TS1003: Identifier expected. ; diff --git a/tests/baselines/reference/jsxReactTestSuite.symbols b/tests/baselines/reference/jsxReactTestSuite.symbols index 9e382742f0d..ba329949939 100644 --- a/tests/baselines/reference/jsxReactTestSuite.symbols +++ b/tests/baselines/reference/jsxReactTestSuite.symbols @@ -45,6 +45,7 @@ declare var hasOwnProperty:any;

{foo}
{bar}
+>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11)) >Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
@@ -56,6 +57,7 @@ declare var hasOwnProperty:any; {this.props.children} ; +>Composite : Symbol(Composite, Decl(jsxReactTestSuite.tsx, 3, 11)) >Composite : Symbol(Composite, Decl(jsxReactTestSuite.tsx, 3, 11)) @@ -64,6 +66,7 @@ declare var hasOwnProperty:any; >Composite2 : Symbol(Composite2, Decl(jsxReactTestSuite.tsx, 4, 11)) ; +>Composite : Symbol(Composite, Decl(jsxReactTestSuite.tsx, 3, 11)) var x = >x : Symbol(x, Decl(jsxReactTestSuite.tsx, 10, 11), Decl(jsxReactTestSuite.tsx, 35, 3)) @@ -181,6 +184,7 @@ var x = >x : Symbol(unknown) >y : Symbol(unknown) >Child : Symbol(Child, Decl(jsxReactTestSuite.tsx, 5, 11)) +>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11)) Text; >Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11)) @@ -189,6 +193,7 @@ var x = >y : Symbol(y, Decl(jsxReactTestSuite.tsx, 113, 27)) >z : Symbol(z, Decl(jsxReactTestSuite.tsx, 11, 11)) >z : Symbol(unknown) +>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11)) diff --git a/tests/baselines/reference/jsxViaImport.errors.txt b/tests/baselines/reference/jsxViaImport.errors.txt new file mode 100644 index 00000000000..8fa22809a44 --- /dev/null +++ b/tests/baselines/reference/jsxViaImport.errors.txt @@ -0,0 +1,27 @@ +tests/cases/compiler/consumer.tsx(5,17): error TS2604: JSX element type 'BaseComponent' does not have any construct or call signatures. + + +==== tests/cases/compiler/consumer.tsx (1 errors) ==== + /// + import BaseComponent = require('BaseComponent'); + class TestComponent extends React.Component { + render() { + return ; + ~~~~~~~~~~~~~ +!!! error TS2604: JSX element type 'BaseComponent' does not have any construct or call signatures. + } + } + +==== tests/cases/compiler/component.d.ts (0 errors) ==== + + declare module JSX { + interface ElementAttributesProperty { props; } + } + declare module React { + class Component { } + } + declare module "BaseComponent" { + var base: React.Component; + export = base; + } + \ No newline at end of file diff --git a/tests/baselines/reference/jsxViaImport.js b/tests/baselines/reference/jsxViaImport.js new file mode 100644 index 00000000000..6bf61af67f5 --- /dev/null +++ b/tests/baselines/reference/jsxViaImport.js @@ -0,0 +1,43 @@ +//// [tests/cases/compiler/jsxViaImport.tsx] //// + +//// [component.d.ts] + +declare module JSX { + interface ElementAttributesProperty { props; } +} +declare module React { + class Component { } +} +declare module "BaseComponent" { + var base: React.Component; + export = base; +} + +//// [consumer.tsx] +/// +import BaseComponent = require('BaseComponent'); +class TestComponent extends React.Component { + render() { + return ; + } +} + + +//// [consumer.jsx] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +/// +var BaseComponent = require('BaseComponent'); +var TestComponent = (function (_super) { + __extends(TestComponent, _super); + function TestComponent() { + _super.apply(this, arguments); + } + TestComponent.prototype.render = function () { + return ; + }; + return TestComponent; +})(React.Component); diff --git a/tests/baselines/reference/letInNonStrictMode.symbols b/tests/baselines/reference/letInNonStrictMode.symbols index 2b854a8c03f..47ba4465d1b 100644 --- a/tests/baselines/reference/letInNonStrictMode.symbols +++ b/tests/baselines/reference/letInNonStrictMode.symbols @@ -3,6 +3,7 @@ let [x] = [1]; >x : Symbol(x, Decl(letInNonStrictMode.ts, 0, 5)) let {a: y} = {a: 1}; +>a : Symbol(a, Decl(letInNonStrictMode.ts, 1, 14)) >y : Symbol(y, Decl(letInNonStrictMode.ts, 1, 5)) >a : Symbol(a, Decl(letInNonStrictMode.ts, 1, 14)) diff --git a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.errors.txt b/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.errors.txt new file mode 100644 index 00000000000..bd210c55570 --- /dev/null +++ b/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/expressions/binaryOperators/logicalOrOperator/logicalOrExpressionIsContextuallyTyped.ts(6,5): error TS2322: Type '{ a: string; b: number; } | { a: string; b: boolean; }' is not assignable to type '{ a: string; }'. + Type '{ a: string; b: number; }' is not assignable to type '{ a: string; }'. + Object literal may only specify known properties, and 'b' does not exist in type '{ a: string; }'. + + +==== tests/cases/conformance/expressions/binaryOperators/logicalOrOperator/logicalOrExpressionIsContextuallyTyped.ts (1 errors) ==== + // The || operator permits the operands to be of any type. + // If the || expression is contextually typed, the operands are contextually typed by the + // same type and the result is of the best common type of the contextual type and the two + // operand types. + + var r: { a: string } = { a: '', b: 123 } || { a: '', b: true }; + ~ +!!! error TS2322: Type '{ a: string; b: number; } | { a: string; b: boolean; }' is not assignable to type '{ a: string; }'. +!!! error TS2322: Type '{ a: string; b: number; }' is not assignable to type '{ a: string; }'. +!!! error TS2322: Object literal may only specify known properties, and 'b' does not exist in type '{ a: string; }'. \ No newline at end of file diff --git a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.symbols b/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.symbols deleted file mode 100644 index 90fc4ac163c..00000000000 --- a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.symbols +++ /dev/null @@ -1,14 +0,0 @@ -=== tests/cases/conformance/expressions/binaryOperators/logicalOrOperator/logicalOrExpressionIsContextuallyTyped.ts === -// The || operator permits the operands to be of any type. -// If the || expression is contextually typed, the operands are contextually typed by the -// same type and the result is of the best common type of the contextual type and the two -// operand types. - -var r: { a: string } = { a: '', b: 123 } || { a: '', b: true }; ->r : Symbol(r, Decl(logicalOrExpressionIsContextuallyTyped.ts, 5, 3)) ->a : Symbol(a, Decl(logicalOrExpressionIsContextuallyTyped.ts, 5, 8)) ->a : Symbol(a, Decl(logicalOrExpressionIsContextuallyTyped.ts, 5, 24)) ->b : Symbol(b, Decl(logicalOrExpressionIsContextuallyTyped.ts, 5, 31)) ->a : Symbol(a, Decl(logicalOrExpressionIsContextuallyTyped.ts, 5, 45)) ->b : Symbol(b, Decl(logicalOrExpressionIsContextuallyTyped.ts, 5, 52)) - diff --git a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types b/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types deleted file mode 100644 index 52315226bb6..00000000000 --- a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types +++ /dev/null @@ -1,21 +0,0 @@ -=== tests/cases/conformance/expressions/binaryOperators/logicalOrOperator/logicalOrExpressionIsContextuallyTyped.ts === -// The || operator permits the operands to be of any type. -// If the || expression is contextually typed, the operands are contextually typed by the -// same type and the result is of the best common type of the contextual type and the two -// operand types. - -var r: { a: string } = { a: '', b: 123 } || { a: '', b: true }; ->r : { a: string; } ->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 ->'' : string ->b : number ->123 : number ->{ a: '', b: true } : { a: string; b: boolean; } ->a : string ->'' : string ->b : boolean ->true : boolean - diff --git a/tests/baselines/reference/logicalOrOperatorWithEveryType.types b/tests/baselines/reference/logicalOrOperatorWithEveryType.types index ecf6b23e729..04bc188e308 100644 --- a/tests/baselines/reference/logicalOrOperatorWithEveryType.types +++ b/tests/baselines/reference/logicalOrOperatorWithEveryType.types @@ -121,26 +121,26 @@ var rb4 = a4 || a2; // string || boolean is string | boolean >a2 : boolean var rb5 = a5 || a2; // void || boolean is void | boolean ->rb5 : boolean | void ->a5 || a2 : boolean | void +>rb5 : void | boolean +>a5 || a2 : void | boolean >a5 : void >a2 : boolean var rb6 = a6 || a2; // enum || boolean is E | boolean ->rb6 : boolean | E ->a6 || a2 : boolean | E +>rb6 : E | boolean +>a6 || a2 : E | boolean >a6 : E >a2 : boolean var rb7 = a7 || a2; // object || boolean is object | boolean ->rb7 : boolean | { a: string; } ->a7 || a2 : boolean | { a: string; } +>rb7 : { a: string; } | boolean +>a7 || a2 : { a: string; } | boolean >a7 : { a: string; } >a2 : boolean var rb8 = a8 || a2; // array || boolean is array | boolean ->rb8 : boolean | string[] ->a8 || a2 : boolean | string[] +>rb8 : string[] | boolean +>a8 || a2 : string[] | boolean >a8 : string[] >a2 : boolean @@ -163,8 +163,8 @@ var rc1 = a1 || a3; // any || number is any >a3 : number var rc2 = a2 || a3; // boolean || number is boolean | number ->rc2 : number | boolean ->a2 || a3 : number | boolean +>rc2 : boolean | number +>a2 || a3 : boolean | number >a2 : boolean >a3 : number @@ -181,26 +181,26 @@ var rc4 = a4 || a3; // string || number is string | number >a3 : number var rc5 = a5 || a3; // void || number is void | number ->rc5 : number | void ->a5 || a3 : number | void +>rc5 : void | number +>a5 || a3 : void | number >a5 : void >a3 : number var rc6 = a6 || a3; // enum || number is number ->rc6 : number ->a6 || a3 : number +>rc6 : E | number +>a6 || a3 : E | number >a6 : E >a3 : number var rc7 = a7 || a3; // object || number is object | number ->rc7 : number | { a: string; } ->a7 || a3 : number | { a: string; } +>rc7 : { a: string; } | number +>a7 || a3 : { a: string; } | number >a7 : { a: string; } >a3 : number var rc8 = a8 || a3; // array || number is array | number ->rc8 : number | string[] ->a8 || a3 : number | string[] +>rc8 : string[] | number +>a8 || a3 : string[] | number >a8 : string[] >a3 : number @@ -223,14 +223,14 @@ var rd1 = a1 || a4; // any || string is any >a4 : string var rd2 = a2 || a4; // boolean || string is boolean | string ->rd2 : string | boolean ->a2 || a4 : string | boolean +>rd2 : boolean | string +>a2 || a4 : boolean | string >a2 : boolean >a4 : string var rd3 = a3 || a4; // number || string is number | string ->rd3 : string | number ->a3 || a4 : string | number +>rd3 : number | string +>a3 || a4 : number | string >a3 : number >a4 : string @@ -241,26 +241,26 @@ var rd4 = a4 || a4; // string || string is string >a4 : string var rd5 = a5 || a4; // void || string is void | string ->rd5 : string | void ->a5 || a4 : string | void +>rd5 : void | string +>a5 || a4 : void | string >a5 : void >a4 : string var rd6 = a6 || a4; // enum || string is enum | string ->rd6 : string | E ->a6 || a4 : string | E +>rd6 : E | string +>a6 || a4 : E | string >a6 : E >a4 : string var rd7 = a7 || a4; // object || string is object | string ->rd7 : string | { a: string; } ->a7 || a4 : string | { a: string; } +>rd7 : { a: string; } | string +>a7 || a4 : { a: string; } | string >a7 : { a: string; } >a4 : string var rd8 = a8 || a4; // array || string is array | string ->rd8 : string | string[] ->a8 || a4 : string | string[] +>rd8 : string[] | string +>a8 || a4 : string[] | string >a8 : string[] >a4 : string @@ -307,20 +307,20 @@ var re5 = a5 || a5; // void || void is void >a5 : void var re6 = a6 || a5; // enum || void is enum | void ->re6 : void | E ->a6 || a5 : void | E +>re6 : E | void +>a6 || a5 : E | void >a6 : E >a5 : void var re7 = a7 || a5; // object || void is object | void ->re7 : void | { a: string; } ->a7 || a5 : void | { a: string; } +>re7 : { a: string; } | void +>a7 || a5 : { a: string; } | void >a7 : { a: string; } >a5 : void var re8 = a8 || a5; // array || void is array | void ->re8 : void | string[] ->a8 || a5 : void | string[] +>re8 : string[] | void +>a8 || a5 : string[] | void >a8 : string[] >a5 : void @@ -349,8 +349,8 @@ var rg2 = a2 || a6; // boolean || enum is boolean | enum >a6 : E var rg3 = a3 || a6; // number || enum is number ->rg3 : number ->a3 || a6 : number +>rg3 : number | E +>a3 || a6 : number | E >a3 : number >a6 : E @@ -373,14 +373,14 @@ var rg6 = a6 || a6; // enum || enum is E >a6 : E var rg7 = a7 || a6; // object || enum is object | enum ->rg7 : E | { a: string; } ->a7 || a6 : E | { a: string; } +>rg7 : { a: string; } | E +>a7 || a6 : { a: string; } | E >a7 : { a: string; } >a6 : E var rg8 = a8 || a6; // array || enum is array | enum ->rg8 : E | string[] ->a8 || a6 : E | string[] +>rg8 : string[] | E +>a8 || a6 : string[] | E >a8 : string[] >a6 : E @@ -439,8 +439,8 @@ var rh7 = a7 || a7; // object || object is object >a7 : { a: string; } var rh8 = a8 || a7; // array || object is array | object ->rh8 : { a: string; } | string[] ->a8 || a7 : { a: string; } | string[] +>rh8 : string[] | { a: string; } +>a8 || a7 : string[] | { a: string; } >a8 : string[] >a7 : { a: string; } diff --git a/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types b/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types index f887ad7ae14..df8f6cac6db 100644 --- a/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types +++ b/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types @@ -107,8 +107,8 @@ function fn3u : U var r3 = t || { a: '' }; ->r3 : { a: string; } ->t || { a: '' } : { a: string; } +>r3 : T | { a: string; } +>t || { a: '' } : T | { a: string; } >t : T >{ a: '' } : { a: string; } >a : string diff --git a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt index 2fb7bd1bfbb..7445ab85a54 100644 --- a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt +++ b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt @@ -1,10 +1,11 @@ -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'. +tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(7,30): error TS2349: Cannot invoke an expression whose type lacks a call signature. +tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,30): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. + Type 'number | string' 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. -==== tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts (2 errors) ==== +==== tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts (3 errors) ==== function map(xs: T[], f: (x: T) => U) { var ys: U[] = []; xs.forEach(x => ys.push(f(x))); @@ -12,12 +13,14 @@ tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): e } var r0 = map([1, ""], (x) => x.toString()); + ~~~~~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. var r5 = map([1, ""], (x) => x.toString()); var r6 = map([1, ""], (x) => x.toString()); var r7 = map([1, ""], (x) => x.toString()); // error ~~~~~~~ -!!! 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: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'number | string' is not assignable to type 'number'. !!! error TS2345: Type 'string' is not assignable to type 'number'. var r7b = map([1, ""], (x) => x.toString()); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/multipleDefaultExports01.errors.txt b/tests/baselines/reference/multipleDefaultExports01.errors.txt new file mode 100644 index 00000000000..7b49afe1a4e --- /dev/null +++ b/tests/baselines/reference/multipleDefaultExports01.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/es6/modules/m1.ts(2,22): error TS2300: Duplicate identifier 'foo'. +tests/cases/conformance/es6/modules/m1.ts(6,25): error TS2300: Duplicate identifier 'bar'. +tests/cases/conformance/es6/modules/m1.ts(11,1): error TS2300: Duplicate identifier 'default'. +tests/cases/conformance/es6/modules/m2.ts(3,1): error TS2348: Value of type 'typeof foo' is not callable. Did you mean to include 'new'? + + +==== tests/cases/conformance/es6/modules/m1.ts (3 errors) ==== + + export default class foo { + ~~~ +!!! error TS2300: Duplicate identifier 'foo'. + + } + + export default function bar() { + ~~~ +!!! error TS2300: Duplicate identifier 'bar'. + + } + + var x = 10; + export default x; + ~~~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'default'. + +==== tests/cases/conformance/es6/modules/m2.ts (1 errors) ==== + import Entity from "m1" + + Entity(); + ~~~~~~~~ +!!! error TS2348: Value of type 'typeof foo' is not callable. Did you mean to include 'new'? \ No newline at end of file diff --git a/tests/baselines/reference/multipleDefaultExports01.js b/tests/baselines/reference/multipleDefaultExports01.js new file mode 100644 index 00000000000..e633cf69f55 --- /dev/null +++ b/tests/baselines/reference/multipleDefaultExports01.js @@ -0,0 +1,38 @@ +//// [tests/cases/conformance/es6/modules/multipleDefaultExports01.ts] //// + +//// [m1.ts] + +export default class foo { + +} + +export default function bar() { + +} + +var x = 10; +export default x; + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +//// [m1.js] +var foo = (function () { + function foo() { + } + return foo; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = foo; +function bar() { +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = bar; +var x = 10; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = x; +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); diff --git a/tests/baselines/reference/multipleDefaultExports02.errors.txt b/tests/baselines/reference/multipleDefaultExports02.errors.txt new file mode 100644 index 00000000000..51220ecfae2 --- /dev/null +++ b/tests/baselines/reference/multipleDefaultExports02.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es6/modules/m1.ts(2,25): error TS2393: Duplicate function implementation. +tests/cases/conformance/es6/modules/m1.ts(6,25): error TS2393: Duplicate function implementation. + + +==== tests/cases/conformance/es6/modules/m1.ts (2 errors) ==== + + export default function foo() { + ~~~ +!!! error TS2393: Duplicate function implementation. + + } + + export default function bar() { + ~~~ +!!! error TS2393: Duplicate function implementation. + + } + +==== tests/cases/conformance/es6/modules/m2.ts (0 errors) ==== + import Entity from "m1" + + Entity(); \ No newline at end of file diff --git a/tests/baselines/reference/multipleDefaultExports02.js b/tests/baselines/reference/multipleDefaultExports02.js new file mode 100644 index 00000000000..3d1b84ff6a6 --- /dev/null +++ b/tests/baselines/reference/multipleDefaultExports02.js @@ -0,0 +1,29 @@ +//// [tests/cases/conformance/es6/modules/multipleDefaultExports02.ts] //// + +//// [m1.ts] + +export default function foo() { + +} + +export default function bar() { + +} + +//// [m2.ts] +import Entity from "m1" + +Entity(); + +//// [m1.js] +function foo() { +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = foo; +function bar() { +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = bar; +//// [m2.js] +var m1_1 = require("m1"); +m1_1.default(); diff --git a/tests/baselines/reference/multivar.errors.txt b/tests/baselines/reference/multivar.errors.txt index 931e61de5ae..44061b9d74c 100644 --- a/tests/baselines/reference/multivar.errors.txt +++ b/tests/baselines/reference/multivar.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/multivar.ts(6,19): error TS2395: Individual declarations in merged declaration b2 must be all exported or all local. -tests/cases/compiler/multivar.ts(22,9): error TS2395: Individual declarations in merged declaration b2 must be all exported or all local. +tests/cases/compiler/multivar.ts(6,19): error TS2395: Individual declarations in merged declaration 'b2' must be all exported or all local. +tests/cases/compiler/multivar.ts(22,9): error TS2395: Individual declarations in merged declaration 'b2' must be all exported or all local. ==== tests/cases/compiler/multivar.ts (2 errors) ==== @@ -10,7 +10,7 @@ tests/cases/compiler/multivar.ts(22,9): error TS2395: Individual declarations in export var a, b2: number = 10, b; ~~ -!!! error TS2395: Individual declarations in merged declaration b2 must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'b2' must be all exported or all local. var m1; var a2, b22: number = 10, b222; var m3; @@ -28,7 +28,7 @@ tests/cases/compiler/multivar.ts(22,9): error TS2395: Individual declarations in declare var d1, d2; var b2; ~~ -!!! error TS2395: Individual declarations in merged declaration b2 must be all exported or all local. +!!! error TS2395: Individual declarations in merged declaration 'b2' must be all exported or all local. declare var v1; } diff --git a/tests/baselines/reference/narrowTypeByInstanceof.types b/tests/baselines/reference/narrowTypeByInstanceof.types index b98b1e4d234..e6a3466b88f 100644 --- a/tests/baselines/reference/narrowTypeByInstanceof.types +++ b/tests/baselines/reference/narrowTypeByInstanceof.types @@ -22,24 +22,24 @@ } type FileMatchOrMatch = FileMatch | Match; ->FileMatchOrMatch : Match | FileMatch +>FileMatchOrMatch : FileMatch | Match >FileMatch : FileMatch >Match : Match let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch; ->elementA : Match | FileMatch ->FileMatchOrMatch : Match | FileMatch ->elementB : Match | FileMatch ->FileMatchOrMatch : Match | FileMatch +>elementA : FileMatch | Match +>FileMatchOrMatch : FileMatch | Match +>elementB : FileMatch | Match +>FileMatchOrMatch : FileMatch | Match if (elementA instanceof FileMatch && elementB instanceof FileMatch) { >elementA instanceof FileMatch && elementB instanceof FileMatch : boolean >elementA instanceof FileMatch : boolean ->elementA : Match | FileMatch +>elementA : FileMatch | Match >FileMatch : typeof FileMatch >elementB instanceof FileMatch : boolean ->elementB : Match | FileMatch +>elementB : FileMatch | Match >FileMatch : typeof FileMatch let a = elementA.resource().path; @@ -63,10 +63,10 @@ if (elementA instanceof FileMatch && elementB instanceof FileMatch) { } else if (elementA instanceof Match && elementB instanceof Match) { >elementA instanceof Match && elementB instanceof Match : boolean >elementA instanceof Match : boolean ->elementA : Match | FileMatch +>elementA : FileMatch | Match >Match : typeof Match >elementB instanceof Match : boolean ->elementB : Match | FileMatch +>elementB : FileMatch | Match >Match : typeof Match let a = elementA.range(); diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt index 7f73ac6da0a..71e164d5d62 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt @@ -1,9 +1,9 @@ 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(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(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(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; }'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(39,5): error TS2322: Type '{ [x: number]: A | B | number; 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 'number | A' is not assignable to type 'A'. + Type 'A | B | number' is not assignable to type 'A'. Type 'number' is not assignable to type 'A'. @@ -54,9 +54,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo // error var b: { [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: Type '{ [x: number]: A | B | 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: Index signatures are incompatible. -!!! error TS2322: Type 'number | A' is not assignable to type 'A'. +!!! error TS2322: Type 'A | B | number' is not assignable to type 'A'. !!! error TS2322: Type 'number' is not assignable to type 'A'. 1.0: new A(), 2.0: new B(), diff --git a/tests/baselines/reference/objectBindingPatternKeywordIdentifiers06.symbols b/tests/baselines/reference/objectBindingPatternKeywordIdentifiers06.symbols index 7cee5f3009b..f0546012498 100644 --- a/tests/baselines/reference/objectBindingPatternKeywordIdentifiers06.symbols +++ b/tests/baselines/reference/objectBindingPatternKeywordIdentifiers06.symbols @@ -1,6 +1,7 @@ === tests/cases/conformance/es6/destructuring/objectBindingPatternKeywordIdentifiers06.ts === var { as: as } = { as: 1 } +>as : Symbol(as, Decl(objectBindingPatternKeywordIdentifiers06.ts, 1, 18)) >as : Symbol(as, Decl(objectBindingPatternKeywordIdentifiers06.ts, 1, 5)) >as : Symbol(as, Decl(objectBindingPatternKeywordIdentifiers06.ts, 1, 18)) diff --git a/tests/baselines/reference/objectLitStructuralTypeMismatch.errors.txt b/tests/baselines/reference/objectLitStructuralTypeMismatch.errors.txt index 0b218d3227b..465c4d6d9f6 100644 --- a/tests/baselines/reference/objectLitStructuralTypeMismatch.errors.txt +++ b/tests/baselines/reference/objectLitStructuralTypeMismatch.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/objectLitStructuralTypeMismatch.ts(2,5): error TS2322: Type '{ b: number; }' is not assignable to type '{ a: number; }'. - Property 'a' is missing in type '{ b: number; }'. + Object literal may only specify known properties, and 'b' does not exist in type '{ a: number; }'. ==== tests/cases/compiler/objectLitStructuralTypeMismatch.ts (1 errors) ==== @@ -7,4 +7,4 @@ tests/cases/compiler/objectLitStructuralTypeMismatch.ts(2,5): error TS2322: Type var x: { a: number; } = { b: 5 }; ~ !!! error TS2322: Type '{ b: number; }' is not assignable to type '{ a: number; }'. -!!! error TS2322: Property 'a' is missing in type '{ b: number; }'. \ No newline at end of file +!!! error TS2322: Object literal may only specify known properties, and 'b' does not exist in type '{ a: number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralFunctionArgContextualTyping.errors.txt b/tests/baselines/reference/objectLiteralFunctionArgContextualTyping.errors.txt index f031031b0a8..149aca43a42 100644 --- a/tests/baselines/reference/objectLiteralFunctionArgContextualTyping.errors.txt +++ b/tests/baselines/reference/objectLiteralFunctionArgContextualTyping.errors.txt @@ -1,5 +1,7 @@ tests/cases/compiler/objectLiteralFunctionArgContextualTyping.ts(8,4): error TS2345: Argument of type '{ hello: number; }' is not assignable to parameter of type 'I'. - Property 'value' is missing in type '{ hello: number; }'. + Object literal may only specify known properties, and 'hello' does not exist in type 'I'. +tests/cases/compiler/objectLiteralFunctionArgContextualTyping.ts(10,4): error TS2345: Argument of type '{ value: string; what: number; }' is not assignable to parameter of type 'I'. + Object literal may only specify known properties, and 'what' does not exist in type 'I'. tests/cases/compiler/objectLiteralFunctionArgContextualTyping.ts(11,4): error TS2345: Argument of type '{ toString: (s: string) => string; }' is not assignable to parameter of type 'I'. Property 'value' is missing in type '{ toString: (s: string) => string; }'. tests/cases/compiler/objectLiteralFunctionArgContextualTyping.ts(12,4): error TS2345: Argument of type '{ toString: (s: string) => string; }' is not assignable to parameter of type 'I'. @@ -7,7 +9,7 @@ tests/cases/compiler/objectLiteralFunctionArgContextualTyping.ts(12,4): error TS tests/cases/compiler/objectLiteralFunctionArgContextualTyping.ts(13,36): error TS2339: Property 'uhhh' does not exist on type 'string'. -==== tests/cases/compiler/objectLiteralFunctionArgContextualTyping.ts (4 errors) ==== +==== tests/cases/compiler/objectLiteralFunctionArgContextualTyping.ts (5 errors) ==== interface I { value: string; toString: (t: string) => string; @@ -18,9 +20,12 @@ tests/cases/compiler/objectLiteralFunctionArgContextualTyping.ts(13,36): error T f2({ hello: 1 }) // error ~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ hello: number; }' is not assignable to parameter of type 'I'. -!!! error TS2345: Property 'value' is missing in type '{ hello: number; }'. +!!! error TS2345: Object literal may only specify known properties, and 'hello' does not exist in type 'I'. f2({ value: '' }) // missing toString satisfied by Object's member f2({ value: '', what: 1 }) // missing toString satisfied by Object's member + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ value: string; what: number; }' is not assignable to parameter of type 'I'. +!!! error TS2345: Object literal may only specify known properties, and 'what' does not exist in type 'I'. f2({ toString: (s) => s }) // error, missing property value from ArgsString ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ toString: (s: string) => string; }' is not assignable to parameter of type 'I'. diff --git a/tests/baselines/reference/objectLiteralFunctionArgContextualTyping2.errors.txt b/tests/baselines/reference/objectLiteralFunctionArgContextualTyping2.errors.txt index 7cb3304aa2f..367a676abc6 100644 --- a/tests/baselines/reference/objectLiteralFunctionArgContextualTyping2.errors.txt +++ b/tests/baselines/reference/objectLiteralFunctionArgContextualTyping2.errors.txt @@ -1,9 +1,9 @@ tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(8,4): error TS2345: Argument of type '{ hello: number; }' is not assignable to parameter of type 'I2'. - Property 'value' is missing in type '{ hello: number; }'. + Object literal may only specify known properties, and 'hello' does not exist in type 'I2'. tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(9,4): error TS2345: Argument of type '{ value: string; }' is not assignable to parameter of type 'I2'. Property 'doStuff' is missing in type '{ value: string; }'. tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(10,4): error TS2345: Argument of type '{ value: string; what: number; }' is not assignable to parameter of type 'I2'. - Property 'doStuff' is missing in type '{ value: string; what: number; }'. + Object literal may only specify known properties, and 'what' does not exist in type 'I2'. tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(11,4): error TS2345: Argument of type '{ toString: (s: any) => any; }' is not assignable to parameter of type 'I2'. Property 'value' is missing in type '{ toString: (s: any) => any; }'. tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(12,4): error TS2345: Argument of type '{ toString: (s: string) => string; }' is not assignable to parameter of type 'I2'. @@ -23,7 +23,7 @@ tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(13,4): error T f2({ hello: 1 }) ~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ hello: number; }' is not assignable to parameter of type 'I2'. -!!! error TS2345: Property 'value' is missing in type '{ hello: number; }'. +!!! error TS2345: Object literal may only specify known properties, and 'hello' does not exist in type 'I2'. f2({ value: '' }) ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ value: string; }' is not assignable to parameter of type 'I2'. @@ -31,7 +31,7 @@ tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(13,4): error T f2({ value: '', what: 1 }) ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ value: string; what: number; }' is not assignable to parameter of type 'I2'. -!!! error TS2345: Property 'doStuff' is missing in type '{ value: string; what: number; }'. +!!! error TS2345: Object literal may only specify known properties, and 'what' does not exist in type 'I2'. f2({ toString: (s) => s }) ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ toString: (s: any) => any; }' is not assignable to parameter of type 'I2'. diff --git a/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt b/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt index c35e49f02a3..edb6d031b1f 100644 --- a/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/objectLiteralIndexerErrors.ts(13,5): error TS2322: Type '{ [x: string]: A; [x: number]: A; 0: A; x: B; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. +tests/cases/compiler/objectLiteralIndexerErrors.ts(13,5): error TS2322: Type '{ [x: string]: B | A; [x: number]: A; 0: A; x: B; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. Index signatures are incompatible. Type 'A' is not assignable to type 'B'. @@ -18,7 +18,7 @@ tests/cases/compiler/objectLiteralIndexerErrors.ts(13,5): error TS2322: Type '{ var o1: { [s: string]: A;[n: number]: B; } = { x: b, 0: a }; // both indexers are A ~~ -!!! error TS2322: Type '{ [x: string]: A; [x: number]: A; 0: A; x: B; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. +!!! error TS2322: Type '{ [x: string]: B | A; [x: number]: A; 0: A; x: B; }' is not assignable to type '{ [s: string]: A; [n: number]: B; }'. !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'A' is not assignable to type 'B'. o1 = { x: c, 0: a }; // string indexer is any, number indexer is A \ No newline at end of file diff --git a/tests/baselines/reference/objectLiteralIndexers.types b/tests/baselines/reference/objectLiteralIndexers.types index d5add00ebaf..55cec857c70 100644 --- a/tests/baselines/reference/objectLiteralIndexers.types +++ b/tests/baselines/reference/objectLiteralIndexers.types @@ -31,7 +31,7 @@ var o1: { [s: string]: A;[n: number]: B; } = { x: a, 0: b }; // string indexer i >A : A >n : number >B : B ->{ x: a, 0: b } : { [x: string]: A; [x: number]: B; 0: B; x: A; } +>{ x: a, 0: b } : { [x: string]: A | B; [x: number]: B; 0: B; x: A; } >x : A >a : A >b : B diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.errors.txt b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.errors.txt index f12e29f5117..d00a8ddf074 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.errors.txt +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentError.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(4,5): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'. - Property 'b' is missing in type '{ name: string; id: number; }'. + Object literal may only specify known properties, and 'name' does not exist in type '{ b: string; id: number; }'. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,16): error TS1131: Property or signature expected. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,22): error TS2403: Subsequent variable declarations must have the same type. Variable 'id' must be of type 'number', but here has type 'any'. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentError.ts(5,25): error TS1128: Declaration or statement expected. @@ -18,7 +18,7 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr var person: { b: string; id: number } = { name, id }; // error ~~~~~~ !!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'. -!!! error TS2322: Property 'b' is missing in type '{ name: string; id: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ b: string; id: number; }'. var person1: { name, id }; // error: can't use short-hand property assignment in type position ~~~~ !!! error TS1131: Property or signature expected. diff --git a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.errors.txt b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.errors.txt index 26b0224f2b0..f6f4f625c45 100644 --- a/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.errors.txt +++ b/tests/baselines/reference/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(4,5): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'. - Property 'b' is missing in type '{ name: string; id: number; }'. + Object literal may only specify known properties, and 'name' does not exist in type '{ b: string; id: number; }'. tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPropertiesAssignmentErrorFromMissingIdentifier.ts(5,79): error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ name: number; id: string; }'. Types of property 'name' are incompatible. Type 'string' is not assignable to type 'number'. @@ -18,7 +18,7 @@ tests/cases/conformance/es6/shorthandPropertyAssignment/objectLiteralShorthandPr var person: { b: string; id: number } = { name, id }; // error ~~~~~~ !!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ b: string; id: number; }'. -!!! error TS2322: Property 'b' is missing in type '{ name: string; id: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ b: string; id: number; }'. function bar(name: string, id: number): { name: number, id: string } { return { name, id }; } // error ~~~~~~~~~~~~ !!! error TS2322: Type '{ name: string; id: number; }' is not assignable to type '{ name: number; id: string; }'. diff --git a/tests/baselines/reference/objectTypeWithRecursiveWrappedPropertyCheckedNominally.errors.txt b/tests/baselines/reference/objectTypeWithRecursiveWrappedPropertyCheckedNominally.errors.txt index 91a92dbd54c..1f2f432c9da 100644 --- a/tests/baselines/reference/objectTypeWithRecursiveWrappedPropertyCheckedNominally.errors.txt +++ b/tests/baselines/reference/objectTypeWithRecursiveWrappedPropertyCheckedNominally.errors.txt @@ -5,9 +5,12 @@ tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRec Types of property 'data' are incompatible. Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedPropertyCheckedNominally.ts(30,5): error TS2322: Type 'U' is not assignable to type 'T'. + Type 'MyList' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedPropertyCheckedNominally.ts(31,5): error TS2322: Type 'T' is not assignable to type 'U'. + Type 'List' is not assignable to type 'U'. tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedPropertyCheckedNominally.ts(41,15): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedPropertyCheckedNominally.ts(42,5): error TS2322: Type 'U' is not assignable to type 'T'. + Type 'MyList' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedPropertyCheckedNominally.ts(43,5): error TS2322: Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedPropertyCheckedNominally.ts(48,5): error TS2322: Type 'T' is not assignable to type 'List'. tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedPropertyCheckedNominally.ts(50,5): error TS2322: Type 'T' is not assignable to type 'MyList'. @@ -54,9 +57,11 @@ tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRec t = u; // error ~ !!! error TS2322: Type 'U' is not assignable to type 'T'. +!!! error TS2322: Type 'MyList' is not assignable to type 'T'. u = t; // error ~ !!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'List' is not assignable to type 'U'. var a: List; var b: MyList; @@ -72,6 +77,7 @@ tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRec t = u; // error ~ !!! error TS2322: Type 'U' is not assignable to type 'T'. +!!! error TS2322: Type 'MyList' is not assignable to type 'T'. u = t; // was error, ok after constraint made illegal, doesn't matter ~ !!! error TS2322: Type 'T' is not assignable to type 'U'. diff --git a/tests/baselines/reference/optionalParamArgsTest.errors.txt b/tests/baselines/reference/optionalParamArgsTest.errors.txt index 3c4d2e37be9..05fefa85065 100644 --- a/tests/baselines/reference/optionalParamArgsTest.errors.txt +++ b/tests/baselines/reference/optionalParamArgsTest.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/optionalParamArgsTest.ts(31,12): error TS2393: Duplicate function implementation. -tests/cases/compiler/optionalParamArgsTest.ts(35,12): error TS2393: Duplicate function implementation. -tests/cases/compiler/optionalParamArgsTest.ts(35,47): error TS1016: A required parameter cannot follow an optional parameter. +tests/cases/compiler/optionalParamArgsTest.ts(34,12): error TS2393: Duplicate function implementation. +tests/cases/compiler/optionalParamArgsTest.ts(98,1): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/optionalParamArgsTest.ts(99,1): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/optionalParamArgsTest.ts(100,1): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/optionalParamArgsTest.ts(101,1): error TS2346: Supplied parameters do not match any signature of call target. @@ -20,10 +20,9 @@ tests/cases/compiler/optionalParamArgsTest.ts(114,1): error TS2346: Supplied par tests/cases/compiler/optionalParamArgsTest.ts(115,1): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/optionalParamArgsTest.ts(116,1): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/compiler/optionalParamArgsTest.ts(117,1): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/compiler/optionalParamArgsTest.ts(118,1): error TS2346: Supplied parameters do not match any signature of call target. -==== tests/cases/compiler/optionalParamArgsTest.ts (23 errors) ==== +==== tests/cases/compiler/optionalParamArgsTest.ts (22 errors) ==== // Optional parameter and default argument tests // Key: @@ -58,13 +57,10 @@ tests/cases/compiler/optionalParamArgsTest.ts(118,1): error TS2346: Supplied par ~~~~ !!! error TS2393: Duplicate function implementation. - // Negative test - // "Optional parameters may only be followed by other optional parameters" + // Uninitialized parameter makes the initialized one required public C1M5(C1M5A1:number,C1M5A2:number=0,C1M5A3:number) { return C1M5A1 + C1M5A2; } ~~~~ !!! error TS2393: Duplicate function implementation. - ~~~~~~ -!!! error TS1016: A required parameter cannot follow an optional parameter. } class C2 extends C1 { diff --git a/tests/baselines/reference/optionalParamArgsTest.js b/tests/baselines/reference/optionalParamArgsTest.js index 414f474598d..0c5a5d82814 100644 --- a/tests/baselines/reference/optionalParamArgsTest.js +++ b/tests/baselines/reference/optionalParamArgsTest.js @@ -31,8 +31,7 @@ class C1 { public C1M5(C1M5A1:number,C1M5A2:number=0,C1M5A3?:number) { return C1M5A1 + C1M5A2; } - // Negative test - // "Optional parameters may only be followed by other optional parameters" + // Uninitialized parameter makes the initialized one required public C1M5(C1M5A1:number,C1M5A2:number=0,C1M5A3:number) { return C1M5A1 + C1M5A2; } } @@ -152,8 +151,7 @@ var C1 = (function () { if (C1M5A2 === void 0) { C1M5A2 = 0; } return C1M5A1 + C1M5A2; }; - // Negative test - // "Optional parameters may only be followed by other optional parameters" + // Uninitialized parameter makes the initialized one required C1.prototype.C1M5 = function (C1M5A1, C1M5A2, C1M5A3) { if (C1M5A2 === void 0) { C1M5A2 = 0; } return C1M5A1 + C1M5A2; diff --git a/tests/baselines/reference/orderMattersForSignatureGroupIdentity.errors.txt b/tests/baselines/reference/orderMattersForSignatureGroupIdentity.errors.txt index b7b9f437735..47401a7ae8b 100644 --- a/tests/baselines/reference/orderMattersForSignatureGroupIdentity.errors.txt +++ b/tests/baselines/reference/orderMattersForSignatureGroupIdentity.errors.txt @@ -1,7 +1,11 @@ +tests/cases/compiler/orderMattersForSignatureGroupIdentity.ts(19,3): error TS2345: Argument of type '{ s: string; n: number; }' is not assignable to parameter of type '{ n: number; }'. + Object literal may only specify known properties, and 's' does not exist in type '{ n: number; }'. tests/cases/compiler/orderMattersForSignatureGroupIdentity.ts(22,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'w' must be of type 'A', but here has type 'C'. +tests/cases/compiler/orderMattersForSignatureGroupIdentity.ts(24,3): error TS2345: Argument of type '{ s: string; n: number; }' is not assignable to parameter of type '{ n: number; }'. + Object literal may only specify known properties, and 's' does not exist in type '{ n: number; }'. -==== tests/cases/compiler/orderMattersForSignatureGroupIdentity.ts (1 errors) ==== +==== tests/cases/compiler/orderMattersForSignatureGroupIdentity.ts (3 errors) ==== interface A { (x: { s: string }): string (x: { n: number }): number @@ -21,10 +25,16 @@ tests/cases/compiler/orderMattersForSignatureGroupIdentity.ts(22,5): error TS240 var v: B; v({ s: "", n: 0 }).toLowerCase(); + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ s: string; n: number; }' is not assignable to parameter of type '{ n: number; }'. +!!! error TS2345: Object literal may only specify known properties, and 's' does not exist in type '{ n: number; }'. var w: A; var w: C; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'w' must be of type 'A', but here has type 'C'. - w({ s: "", n: 0 }).toLowerCase(); \ No newline at end of file + w({ s: "", n: 0 }).toLowerCase(); + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ s: string; n: number; }' is not assignable to parameter of type '{ n: number; }'. +!!! error TS2345: Object literal may only specify known properties, and 's' does not exist in type '{ n: number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/parenthesizedContexualTyping1.types b/tests/baselines/reference/parenthesizedContexualTyping1.types index b7307eaf3e7..1423901a28f 100644 --- a/tests/baselines/reference/parenthesizedContexualTyping1.types +++ b/tests/baselines/reference/parenthesizedContexualTyping1.types @@ -146,11 +146,11 @@ var h = fun((((x => x))), ((x => x)), 10); // Ternaries in parens var i = fun((Math.random() < 0.5 ? x => x : x => undefined), 10); ->i : any ->fun((Math.random() < 0.5 ? x => x : x => undefined), 10) : any +>i : number +>fun((Math.random() < 0.5 ? x => x : x => undefined), 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } ->(Math.random() < 0.5 ? x => x : x => undefined) : (x: number) => any ->Math.random() < 0.5 ? x => x : x => undefined : (x: number) => any +>(Math.random() < 0.5 ? x => x : x => undefined) : ((x: number) => number) | ((x: number) => any) +>Math.random() < 0.5 ? x => x : x => undefined : ((x: number) => number) | ((x: number) => any) >Math.random() < 0.5 : boolean >Math.random() : number >Math.random : () => number @@ -166,11 +166,11 @@ var i = fun((Math.random() < 0.5 ? x => x : x => undefined), 10); >10 : number var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10); ->j : any ->fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10) : any +>j : number +>fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } ->(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: number) => any ->Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: number) => any +>(Math.random() < 0.5 ? (x => x) : (x => undefined)) : ((x: number) => number) | ((x: number) => any) +>Math.random() < 0.5 ? (x => x) : (x => undefined) : ((x: number) => number) | ((x: number) => any) >Math.random() < 0.5 : boolean >Math.random() : number >Math.random : () => number @@ -188,11 +188,11 @@ var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10); >10 : number var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10); ->k : any ->fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10) : any +>k : number +>fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } ->(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: number) => any ->Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: number) => any +>(Math.random() < 0.5 ? (x => x) : (x => undefined)) : ((x: number) => number) | ((x: number) => any) +>Math.random() < 0.5 ? (x => x) : (x => undefined) : ((x: number) => number) | ((x: number) => any) >Math.random() < 0.5 : boolean >Math.random() : number >Math.random : () => number @@ -207,18 +207,18 @@ var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10); >x => undefined : (x: number) => any >x : number >undefined : undefined ->x => x : (x: any) => any ->x : any ->x : any +>x => x : (x: number) => number +>x : number +>x : number >10 : number var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10); ->l : any ->fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10) : any +>l : number +>fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } ->((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))) : (x: number) => any ->(Math.random() < 0.5 ? ((x => x)) : ((x => undefined))) : (x: number) => any ->Math.random() < 0.5 ? ((x => x)) : ((x => undefined)) : (x: number) => any +>((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))) : ((x: number) => number) | ((x: number) => any) +>(Math.random() < 0.5 ? ((x => x)) : ((x => undefined))) : ((x: number) => number) | ((x: number) => any) +>Math.random() < 0.5 ? ((x => x)) : ((x => undefined)) : ((x: number) => number) | ((x: number) => any) >Math.random() < 0.5 : boolean >Math.random() : number >Math.random : () => number @@ -235,11 +235,11 @@ var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x) >x => undefined : (x: number) => any >x : number >undefined : undefined ->((x => x)) : (x: any) => any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number >10 : number var lambda1: (x: number) => number = x => x; diff --git a/tests/baselines/reference/parenthesizedContexualTyping2.types b/tests/baselines/reference/parenthesizedContexualTyping2.types index a055f2f1bbd..344933ea1fc 100644 --- a/tests/baselines/reference/parenthesizedContexualTyping2.types +++ b/tests/baselines/reference/parenthesizedContexualTyping2.types @@ -186,8 +186,8 @@ var i = fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x >i : number >fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined), 10) : number >fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } ->(Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined) : (x: (p: T) => T) => any ->Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined : (x: (p: T) => T) => any +>(Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined) : ((x: (p: T) => T) => (p: T) => T) | ((x: (p: T) => T) => any) +>Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined : ((x: (p: T) => T) => (p: T) => T) | ((x: (p: T) => T) => any) >Math.random() < 0.5 : boolean >Math.random() : number >Math.random : () => number @@ -209,8 +209,8 @@ var j = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : >j : number >fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), 10) : number >fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } ->(Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)) : (x: (p: T) => T) => any ->Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined) : (x: (p: T) => T) => any +>(Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)) : ((x: (p: T) => T) => (p: T) => T) | ((x: (p: T) => T) => any) +>Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined) : ((x: (p: T) => T) => (p: T) => T) | ((x: (p: T) => T) => any) >Math.random() < 0.5 : boolean >Math.random() : number >Math.random : () => number @@ -234,8 +234,8 @@ var k = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : >k : number >fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10) : number >fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } ->(Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)) : (x: (p: T) => T) => any ->Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined) : (x: (p: T) => T) => any +>(Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)) : ((x: (p: T) => T) => (p: T) => T) | ((x: (p: T) => T) => any) +>Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined) : ((x: (p: T) => T) => (p: T) => T) | ((x: (p: T) => T) => any) >Math.random() < 0.5 : boolean >Math.random() : number >Math.random : () => number @@ -265,9 +265,9 @@ var l = fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) >l : number >fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10) : number >fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } ->((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))) : (x: (p: T) => T) => any ->(Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined))) : (x: (p: T) => T) => any ->Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)) : (x: (p: T) => T) => any +>((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))) : ((x: (p: T) => T) => (p: T) => T) | ((x: (p: T) => T) => any) +>(Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined))) : ((x: (p: T) => T) => (p: T) => T) | ((x: (p: T) => T) => any) +>Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)) : ((x: (p: T) => T) => (p: T) => T) | ((x: (p: T) => T) => any) >Math.random() < 0.5 : boolean >Math.random() : number >Math.random : () => number diff --git a/tests/baselines/reference/parserSuperExpression1.js b/tests/baselines/reference/parserSuperExpression1.js index 0d312f79104..0d219afad37 100644 --- a/tests/baselines/reference/parserSuperExpression1.js +++ b/tests/baselines/reference/parserSuperExpression1.js @@ -18,7 +18,7 @@ var C = (function () { function C() { } C.prototype.foo = function () { - _super.foo.call(this); + _super.prototype.foo.call(this); }; return C; })(); @@ -30,7 +30,7 @@ var M1; function C() { } C.prototype.foo = function () { - _super.foo.call(this); + _super.prototype.foo.call(this); }; return C; })(); diff --git a/tests/baselines/reference/parserSuperExpression2.js b/tests/baselines/reference/parserSuperExpression2.js index 7a77c28ef52..eb3c2c697e6 100644 --- a/tests/baselines/reference/parserSuperExpression2.js +++ b/tests/baselines/reference/parserSuperExpression2.js @@ -10,7 +10,7 @@ var C = (function () { function C() { } C.prototype.M = function () { - _super..call(this, 0); + _super.prototype..call(this, 0); }; return C; })(); diff --git a/tests/baselines/reference/parserSuperExpression4.js b/tests/baselines/reference/parserSuperExpression4.js index 46ffc65f57c..59ba63bb2cf 100644 --- a/tests/baselines/reference/parserSuperExpression4.js +++ b/tests/baselines/reference/parserSuperExpression4.js @@ -18,7 +18,7 @@ var C = (function () { function C() { } C.prototype.foo = function () { - _super.foo = 1; + _super.prototype.foo = 1; }; return C; })(); @@ -30,7 +30,7 @@ var M1; function C() { } C.prototype.foo = function () { - _super.foo = 1; + _super.prototype.foo = 1; }; return C; })(); diff --git a/tests/baselines/reference/requiredInitializedParameter1.errors.txt b/tests/baselines/reference/requiredInitializedParameter1.errors.txt new file mode 100644 index 00000000000..ef958dbdec9 --- /dev/null +++ b/tests/baselines/reference/requiredInitializedParameter1.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/requiredInitializedParameter1.ts(11,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/requiredInitializedParameter1.ts(16,1): error TS2346: Supplied parameters do not match any signature of call target. + + +==== tests/cases/compiler/requiredInitializedParameter1.ts (2 errors) ==== + function f1(a, b = 0, c) { } + function f2(a, b = 0, c = 0) { } + function f3(a, b = 0, c?) { } + function f4(a, b = 0, ...c) { } + + f1(0, 1, 2); + f2(0, 1, 2); + f3(0, 1, 2); + f4(0, 1, 2); + + f1(0, 1); + ~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + f2(0, 1); + f3(0, 1); + f4(0, 1); + + f1(0); + ~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + f2(0); + f3(0); + f4(0); \ No newline at end of file diff --git a/tests/baselines/reference/requiredInitializedParameter1.js b/tests/baselines/reference/requiredInitializedParameter1.js new file mode 100644 index 00000000000..0fe07503056 --- /dev/null +++ b/tests/baselines/reference/requiredInitializedParameter1.js @@ -0,0 +1,51 @@ +//// [requiredInitializedParameter1.ts] +function f1(a, b = 0, c) { } +function f2(a, b = 0, c = 0) { } +function f3(a, b = 0, c?) { } +function f4(a, b = 0, ...c) { } + +f1(0, 1, 2); +f2(0, 1, 2); +f3(0, 1, 2); +f4(0, 1, 2); + +f1(0, 1); +f2(0, 1); +f3(0, 1); +f4(0, 1); + +f1(0); +f2(0); +f3(0); +f4(0); + +//// [requiredInitializedParameter1.js] +function f1(a, b, c) { + if (b === void 0) { b = 0; } +} +function f2(a, b, c) { + if (b === void 0) { b = 0; } + if (c === void 0) { c = 0; } +} +function f3(a, b, c) { + if (b === void 0) { b = 0; } +} +function f4(a, b) { + if (b === void 0) { b = 0; } + var c = []; + for (var _i = 2; _i < arguments.length; _i++) { + c[_i - 2] = arguments[_i]; + } +} +f1(0, 1, 2); +f2(0, 1, 2); +f3(0, 1, 2); +f4(0, 1, 2); +f1(0, 1); +f2(0, 1); +f3(0, 1); +f4(0, 1); +f1(0); +f2(0); +f3(0); +f4(0); diff --git a/tests/baselines/reference/requiredInitializedParameter2.errors.txt b/tests/baselines/reference/requiredInitializedParameter2.errors.txt new file mode 100644 index 00000000000..5dcec536e1b --- /dev/null +++ b/tests/baselines/reference/requiredInitializedParameter2.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/requiredInitializedParameter2.ts(5,7): error TS2420: Class 'C1' incorrectly implements interface 'I1'. + Types of property 'method' are incompatible. + Type '(a: number, b: any) => void' is not assignable to type '() => any'. + + +==== tests/cases/compiler/requiredInitializedParameter2.ts (1 errors) ==== + interface I1 { + method(); + } + + class C1 implements I1 { + ~~ +!!! error TS2420: Class 'C1' incorrectly implements interface 'I1'. +!!! error TS2420: Types of property 'method' are incompatible. +!!! error TS2420: Type '(a: number, b: any) => void' is not assignable to type '() => any'. + method(a = 0, b) { } + } \ No newline at end of file diff --git a/tests/baselines/reference/requiredInitializedParameter2.js b/tests/baselines/reference/requiredInitializedParameter2.js new file mode 100644 index 00000000000..3c69d54e1d9 --- /dev/null +++ b/tests/baselines/reference/requiredInitializedParameter2.js @@ -0,0 +1,18 @@ +//// [requiredInitializedParameter2.ts] +interface I1 { + method(); +} + +class C1 implements I1 { + method(a = 0, b) { } +} + +//// [requiredInitializedParameter2.js] +var C1 = (function () { + function C1() { + } + C1.prototype.method = function (a, b) { + if (a === void 0) { a = 0; } + }; + return C1; +})(); diff --git a/tests/baselines/reference/requiredInitializedParameter3.js b/tests/baselines/reference/requiredInitializedParameter3.js new file mode 100644 index 00000000000..68e1aa696ea --- /dev/null +++ b/tests/baselines/reference/requiredInitializedParameter3.js @@ -0,0 +1,27 @@ +//// [requiredInitializedParameter3.ts] +interface I1 { + method(); +} + +class C1 implements I1 { + method(a = 0, b?) { } +} + +//// [requiredInitializedParameter3.js] +var C1 = (function () { + function C1() { + } + C1.prototype.method = function (a, b) { + if (a === void 0) { a = 0; } + }; + return C1; +})(); + + +//// [requiredInitializedParameter3.d.ts] +interface I1 { + method(): any; +} +declare class C1 implements I1 { + method(a?: number, b?: any): void; +} diff --git a/tests/baselines/reference/requiredInitializedParameter3.symbols b/tests/baselines/reference/requiredInitializedParameter3.symbols new file mode 100644 index 00000000000..e9f35b21bcf --- /dev/null +++ b/tests/baselines/reference/requiredInitializedParameter3.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/requiredInitializedParameter3.ts === +interface I1 { +>I1 : Symbol(I1, Decl(requiredInitializedParameter3.ts, 0, 0)) + + method(); +>method : Symbol(method, Decl(requiredInitializedParameter3.ts, 0, 14)) +} + +class C1 implements I1 { +>C1 : Symbol(C1, Decl(requiredInitializedParameter3.ts, 2, 1)) +>I1 : Symbol(I1, Decl(requiredInitializedParameter3.ts, 0, 0)) + + method(a = 0, b?) { } +>method : Symbol(method, Decl(requiredInitializedParameter3.ts, 4, 24)) +>a : Symbol(a, Decl(requiredInitializedParameter3.ts, 5, 11)) +>b : Symbol(b, Decl(requiredInitializedParameter3.ts, 5, 17)) +} diff --git a/tests/baselines/reference/requiredInitializedParameter3.types b/tests/baselines/reference/requiredInitializedParameter3.types new file mode 100644 index 00000000000..aa37f5e13dd --- /dev/null +++ b/tests/baselines/reference/requiredInitializedParameter3.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/requiredInitializedParameter3.ts === +interface I1 { +>I1 : I1 + + method(); +>method : () => any +} + +class C1 implements I1 { +>C1 : C1 +>I1 : I1 + + method(a = 0, b?) { } +>method : (a?: number, b?: any) => void +>a : number +>0 : number +>b : any +} diff --git a/tests/baselines/reference/requiredInitializedParameter4.js b/tests/baselines/reference/requiredInitializedParameter4.js new file mode 100644 index 00000000000..3b23f119391 --- /dev/null +++ b/tests/baselines/reference/requiredInitializedParameter4.js @@ -0,0 +1,20 @@ +//// [requiredInitializedParameter4.ts] +class C1 { + method(a = 0, b) { } +} + +//// [requiredInitializedParameter4.js] +var C1 = (function () { + function C1() { + } + C1.prototype.method = function (a, b) { + if (a === void 0) { a = 0; } + }; + return C1; +})(); + + +//// [requiredInitializedParameter4.d.ts] +declare class C1 { + method(a: number, b: any): void; +} diff --git a/tests/baselines/reference/requiredInitializedParameter4.symbols b/tests/baselines/reference/requiredInitializedParameter4.symbols new file mode 100644 index 00000000000..2790b33698c --- /dev/null +++ b/tests/baselines/reference/requiredInitializedParameter4.symbols @@ -0,0 +1,9 @@ +=== tests/cases/compiler/requiredInitializedParameter4.ts === +class C1 { +>C1 : Symbol(C1, Decl(requiredInitializedParameter4.ts, 0, 0)) + + method(a = 0, b) { } +>method : Symbol(method, Decl(requiredInitializedParameter4.ts, 0, 10)) +>a : Symbol(a, Decl(requiredInitializedParameter4.ts, 1, 11)) +>b : Symbol(b, Decl(requiredInitializedParameter4.ts, 1, 17)) +} diff --git a/tests/baselines/reference/requiredInitializedParameter4.types b/tests/baselines/reference/requiredInitializedParameter4.types new file mode 100644 index 00000000000..c483146a1ba --- /dev/null +++ b/tests/baselines/reference/requiredInitializedParameter4.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/requiredInitializedParameter4.ts === +class C1 { +>C1 : C1 + + method(a = 0, b) { } +>method : (a: number, b: any) => void +>a : number +>0 : number +>b : any +} diff --git a/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName1.js b/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName1.js new file mode 100644 index 00000000000..9349da082e8 --- /dev/null +++ b/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName1.js @@ -0,0 +1,7 @@ +//// [resolveInterfaceNameWithSameLetDeclarationName1.ts] +interface bar { } +let bar: bar; + + +//// [resolveInterfaceNameWithSameLetDeclarationName1.js] +var bar; diff --git a/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName1.symbols b/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName1.symbols new file mode 100644 index 00000000000..bcabaef55ce --- /dev/null +++ b/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName1.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/resolveInterfaceNameWithSameLetDeclarationName1.ts === +interface bar { } +>bar : Symbol(bar, Decl(resolveInterfaceNameWithSameLetDeclarationName1.ts, 0, 0), Decl(resolveInterfaceNameWithSameLetDeclarationName1.ts, 1, 3)) + +let bar: bar; +>bar : Symbol(bar, Decl(resolveInterfaceNameWithSameLetDeclarationName1.ts, 0, 0), Decl(resolveInterfaceNameWithSameLetDeclarationName1.ts, 1, 3)) +>bar : Symbol(bar, Decl(resolveInterfaceNameWithSameLetDeclarationName1.ts, 0, 0), Decl(resolveInterfaceNameWithSameLetDeclarationName1.ts, 1, 3)) + diff --git a/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName1.types b/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName1.types new file mode 100644 index 00000000000..29de2a9f5b4 --- /dev/null +++ b/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName1.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/resolveInterfaceNameWithSameLetDeclarationName1.ts === +interface bar { } +>bar : bar + +let bar: bar; +>bar : bar +>bar : bar + diff --git a/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName2.js b/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName2.js new file mode 100644 index 00000000000..8f43889191a --- /dev/null +++ b/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName2.js @@ -0,0 +1,9 @@ +//// [resolveInterfaceNameWithSameLetDeclarationName2.ts] +interface foo { } +interface bar { } +let bar: bar | foo; +let foo: bar | foo; + +//// [resolveInterfaceNameWithSameLetDeclarationName2.js] +var bar; +var foo; diff --git a/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName2.symbols b/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName2.symbols new file mode 100644 index 00000000000..785a464839f --- /dev/null +++ b/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName2.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/resolveInterfaceNameWithSameLetDeclarationName2.ts === +interface foo { } +>foo : Symbol(foo, Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 0, 0), Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 3, 3)) + +interface bar { } +>bar : Symbol(bar, Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 0, 17), Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 2, 3)) + +let bar: bar | foo; +>bar : Symbol(bar, Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 0, 17), Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 2, 3)) +>bar : Symbol(bar, Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 0, 17), Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 2, 3)) +>foo : Symbol(foo, Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 0, 0), Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 3, 3)) + +let foo: bar | foo; +>foo : Symbol(foo, Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 0, 0), Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 3, 3)) +>bar : Symbol(bar, Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 0, 17), Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 2, 3)) +>foo : Symbol(foo, Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 0, 0), Decl(resolveInterfaceNameWithSameLetDeclarationName2.ts, 3, 3)) + diff --git a/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName2.types b/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName2.types new file mode 100644 index 00000000000..6c52661ef49 --- /dev/null +++ b/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName2.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/resolveInterfaceNameWithSameLetDeclarationName2.ts === +interface foo { } +>foo : foo + +interface bar { } +>bar : bar + +let bar: bar | foo; +>bar : bar | foo +>bar : bar +>foo : foo + +let foo: bar | foo; +>foo : bar | foo +>bar : bar +>foo : foo + diff --git a/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName1.js b/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName1.js new file mode 100644 index 00000000000..b3dc4f12519 --- /dev/null +++ b/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName1.js @@ -0,0 +1,12 @@ +//// [resolveModuleNameWithSameLetDeclarationName1.ts] +declare module foo { + + interface Bar { + + } +} + +let foo: foo.Bar; + +//// [resolveModuleNameWithSameLetDeclarationName1.js] +var foo; diff --git a/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName1.symbols b/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName1.symbols new file mode 100644 index 00000000000..21ff88ac388 --- /dev/null +++ b/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName1.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/resolveModuleNameWithSameLetDeclarationName1.ts === +declare module foo { +>foo : Symbol(foo, Decl(resolveModuleNameWithSameLetDeclarationName1.ts, 0, 0), Decl(resolveModuleNameWithSameLetDeclarationName1.ts, 7, 3)) + + interface Bar { +>Bar : Symbol(Bar, Decl(resolveModuleNameWithSameLetDeclarationName1.ts, 0, 20)) + + } +} + +let foo: foo.Bar; +>foo : Symbol(foo, Decl(resolveModuleNameWithSameLetDeclarationName1.ts, 0, 0), Decl(resolveModuleNameWithSameLetDeclarationName1.ts, 7, 3)) +>foo : Symbol(foo, Decl(resolveModuleNameWithSameLetDeclarationName1.ts, 0, 0), Decl(resolveModuleNameWithSameLetDeclarationName1.ts, 7, 3)) +>Bar : Symbol(foo.Bar, Decl(resolveModuleNameWithSameLetDeclarationName1.ts, 0, 20)) + diff --git a/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName1.types b/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName1.types new file mode 100644 index 00000000000..c278f460201 --- /dev/null +++ b/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName1.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/resolveModuleNameWithSameLetDeclarationName1.ts === +declare module foo { +>foo : Bar + + interface Bar { +>Bar : Bar + + } +} + +let foo: foo.Bar; +>foo : foo.Bar +>foo : any +>Bar : foo.Bar + diff --git a/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName2.js b/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName2.js new file mode 100644 index 00000000000..46b5f58788a --- /dev/null +++ b/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName2.js @@ -0,0 +1,11 @@ +//// [resolveModuleNameWithSameLetDeclarationName2.ts] +declare module "punycode" { + interface ucs2 { + decode(string: string): string; + encode(codePoints: number[]): string; + } + + export let ucs2: ucs2; +} + +//// [resolveModuleNameWithSameLetDeclarationName2.js] diff --git a/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName2.symbols b/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName2.symbols new file mode 100644 index 00000000000..e98437abb9a --- /dev/null +++ b/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName2.symbols @@ -0,0 +1,18 @@ +=== tests/cases/compiler/resolveModuleNameWithSameLetDeclarationName2.ts === +declare module "punycode" { + interface ucs2 { +>ucs2 : Symbol(ucs2, Decl(resolveModuleNameWithSameLetDeclarationName2.ts, 0, 27), Decl(resolveModuleNameWithSameLetDeclarationName2.ts, 6, 14)) + + decode(string: string): string; +>decode : Symbol(decode, Decl(resolveModuleNameWithSameLetDeclarationName2.ts, 1, 20)) +>string : Symbol(string, Decl(resolveModuleNameWithSameLetDeclarationName2.ts, 2, 15)) + + encode(codePoints: number[]): string; +>encode : Symbol(encode, Decl(resolveModuleNameWithSameLetDeclarationName2.ts, 2, 39)) +>codePoints : Symbol(codePoints, Decl(resolveModuleNameWithSameLetDeclarationName2.ts, 3, 15)) + } + + export let ucs2: ucs2; +>ucs2 : Symbol(ucs2, Decl(resolveModuleNameWithSameLetDeclarationName2.ts, 0, 27), Decl(resolveModuleNameWithSameLetDeclarationName2.ts, 6, 14)) +>ucs2 : Symbol(ucs2, Decl(resolveModuleNameWithSameLetDeclarationName2.ts, 0, 27), Decl(resolveModuleNameWithSameLetDeclarationName2.ts, 6, 14)) +} diff --git a/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName2.types b/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName2.types new file mode 100644 index 00000000000..835e4656f5f --- /dev/null +++ b/tests/baselines/reference/resolveModuleNameWithSameLetDeclarationName2.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/resolveModuleNameWithSameLetDeclarationName2.ts === +declare module "punycode" { + interface ucs2 { +>ucs2 : ucs2 + + decode(string: string): string; +>decode : (string: string) => string +>string : string + + encode(codePoints: number[]): string; +>encode : (codePoints: number[]) => string +>codePoints : number[] + } + + export let ucs2: ucs2; +>ucs2 : ucs2 +>ucs2 : ucs2 +} diff --git a/tests/baselines/reference/resolveTypeAliasWithSameLetDeclarationName1.js b/tests/baselines/reference/resolveTypeAliasWithSameLetDeclarationName1.js new file mode 100644 index 00000000000..ac73145ee50 --- /dev/null +++ b/tests/baselines/reference/resolveTypeAliasWithSameLetDeclarationName1.js @@ -0,0 +1,13 @@ +//// [resolveTypeAliasWithSameLetDeclarationName1.ts] +class C { } +type baz = C; +let baz: baz; + + +//// [resolveTypeAliasWithSameLetDeclarationName1.js] +var C = (function () { + function C() { + } + return C; +})(); +var baz; diff --git a/tests/baselines/reference/resolveTypeAliasWithSameLetDeclarationName1.symbols b/tests/baselines/reference/resolveTypeAliasWithSameLetDeclarationName1.symbols new file mode 100644 index 00000000000..cd5c05301c0 --- /dev/null +++ b/tests/baselines/reference/resolveTypeAliasWithSameLetDeclarationName1.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/resolveTypeAliasWithSameLetDeclarationName1.ts === +class C { } +>C : Symbol(C, Decl(resolveTypeAliasWithSameLetDeclarationName1.ts, 0, 0)) + +type baz = C; +>baz : Symbol(baz, Decl(resolveTypeAliasWithSameLetDeclarationName1.ts, 0, 11), Decl(resolveTypeAliasWithSameLetDeclarationName1.ts, 2, 3)) +>C : Symbol(C, Decl(resolveTypeAliasWithSameLetDeclarationName1.ts, 0, 0)) + +let baz: baz; +>baz : Symbol(baz, Decl(resolveTypeAliasWithSameLetDeclarationName1.ts, 0, 11), Decl(resolveTypeAliasWithSameLetDeclarationName1.ts, 2, 3)) +>baz : Symbol(baz, Decl(resolveTypeAliasWithSameLetDeclarationName1.ts, 0, 11), Decl(resolveTypeAliasWithSameLetDeclarationName1.ts, 2, 3)) + diff --git a/tests/baselines/reference/resolveTypeAliasWithSameLetDeclarationName1.types b/tests/baselines/reference/resolveTypeAliasWithSameLetDeclarationName1.types new file mode 100644 index 00000000000..7bb61e29a20 --- /dev/null +++ b/tests/baselines/reference/resolveTypeAliasWithSameLetDeclarationName1.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/resolveTypeAliasWithSameLetDeclarationName1.ts === +class C { } +>C : C + +type baz = C; +>baz : C +>C : C + +let baz: baz; +>baz : C +>baz : C + diff --git a/tests/baselines/reference/shebang.js b/tests/baselines/reference/shebang.js new file mode 100644 index 00000000000..d7e3a4d8351 --- /dev/null +++ b/tests/baselines/reference/shebang.js @@ -0,0 +1,8 @@ +//// [shebang.ts] +#!/usr/bin/env node +var foo = 'I wish the generated JS to be executed in node'; + + +//// [shebang.js] +#!/usr/bin/env node +var foo = 'I wish the generated JS to be executed in node'; diff --git a/tests/baselines/reference/shebang.symbols b/tests/baselines/reference/shebang.symbols new file mode 100644 index 00000000000..37ad5436674 --- /dev/null +++ b/tests/baselines/reference/shebang.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/shebang.ts === +#!/usr/bin/env node +var foo = 'I wish the generated JS to be executed in node'; +>foo : Symbol(foo, Decl(shebang.ts, 1, 3)) + diff --git a/tests/baselines/reference/shebang.types b/tests/baselines/reference/shebang.types new file mode 100644 index 00000000000..5fd6f0533ec --- /dev/null +++ b/tests/baselines/reference/shebang.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/shebang.ts === +#!/usr/bin/env node +var foo = 'I wish the generated JS to be executed in node'; +>foo : string +>'I wish the generated JS to be executed in node' : string + diff --git a/tests/baselines/reference/shebangError.errors.txt b/tests/baselines/reference/shebangError.errors.txt new file mode 100644 index 00000000000..e8197d8bc5f --- /dev/null +++ b/tests/baselines/reference/shebangError.errors.txt @@ -0,0 +1,20 @@ +tests/cases/compiler/shebangError.ts(2,1): error TS1127: Invalid character. +tests/cases/compiler/shebangError.ts(2,2): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/compiler/shebangError.ts(2,12): error TS2304: Cannot find name 'env'. +tests/cases/compiler/shebangError.ts(2,16): error TS1005: ';' expected. +tests/cases/compiler/shebangError.ts(2,16): error TS2304: Cannot find name 'node'. + + +==== tests/cases/compiler/shebangError.ts (5 errors) ==== + var foo = 'Shebang is only allowed on the first line'; + #!/usr/bin/env node + +!!! error TS1127: Invalid character. + ~~~~~~~~~ +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + ~~~ +!!! error TS2304: Cannot find name 'env'. + ~~~~ +!!! error TS1005: ';' expected. + ~~~~ +!!! error TS2304: Cannot find name 'node'. \ No newline at end of file diff --git a/tests/baselines/reference/shebangError.js b/tests/baselines/reference/shebangError.js new file mode 100644 index 00000000000..a8fb376d8a9 --- /dev/null +++ b/tests/baselines/reference/shebangError.js @@ -0,0 +1,8 @@ +//// [shebangError.ts] +var foo = 'Shebang is only allowed on the first line'; +#!/usr/bin/env node + +//// [shebangError.js] +var foo = 'Shebang is only allowed on the first line'; +!/usr/bin / env; +node; diff --git a/tests/baselines/reference/strictModeInConstructor.errors.txt b/tests/baselines/reference/strictModeInConstructor.errors.txt index 11ba2e26a68..9a80732842a 100644 --- a/tests/baselines/reference/strictModeInConstructor.errors.txt +++ b/tests/baselines/reference/strictModeInConstructor.errors.txt @@ -1,8 +1,7 @@ -tests/cases/compiler/strictModeInConstructor.ts(9,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. tests/cases/compiler/strictModeInConstructor.ts(27,5): error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. -==== tests/cases/compiler/strictModeInConstructor.ts (2 errors) ==== +==== tests/cases/compiler/strictModeInConstructor.ts (1 errors) ==== class A { } @@ -12,14 +11,9 @@ tests/cases/compiler/strictModeInConstructor.ts(27,5): error TS2376: A 'super' c public s: number = 9; constructor () { - ~~~~~~~~~~~~~~~~ "use strict"; // No error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ super(); - ~~~~~~~~~~~~~~~~ } - ~~~~~ -!!! error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties. } class C extends A { diff --git a/tests/baselines/reference/stringIncludes.js b/tests/baselines/reference/stringIncludes.js new file mode 100644 index 00000000000..055d7d8beeb --- /dev/null +++ b/tests/baselines/reference/stringIncludes.js @@ -0,0 +1,10 @@ +//// [stringIncludes.ts] + +var includes: boolean; +includes = "abcde".includes("cd"); +includes = "abcde".includes("cd", 2); + +//// [stringIncludes.js] +var includes; +includes = "abcde".includes("cd"); +includes = "abcde".includes("cd", 2); diff --git a/tests/baselines/reference/stringIncludes.symbols b/tests/baselines/reference/stringIncludes.symbols new file mode 100644 index 00000000000..d0fa641c857 --- /dev/null +++ b/tests/baselines/reference/stringIncludes.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/stringIncludes.ts === + +var includes: boolean; +>includes : Symbol(includes, Decl(stringIncludes.ts, 1, 3)) + +includes = "abcde".includes("cd"); +>includes : Symbol(includes, Decl(stringIncludes.ts, 1, 3)) +>"abcde".includes : Symbol(String.includes, Decl(lib.d.ts, 1569, 37)) +>includes : Symbol(String.includes, Decl(lib.d.ts, 1569, 37)) + +includes = "abcde".includes("cd", 2); +>includes : Symbol(includes, Decl(stringIncludes.ts, 1, 3)) +>"abcde".includes : Symbol(String.includes, Decl(lib.d.ts, 1569, 37)) +>includes : Symbol(String.includes, Decl(lib.d.ts, 1569, 37)) + diff --git a/tests/baselines/reference/stringIncludes.types b/tests/baselines/reference/stringIncludes.types new file mode 100644 index 00000000000..0d1e5ffea4d --- /dev/null +++ b/tests/baselines/reference/stringIncludes.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/stringIncludes.ts === + +var includes: boolean; +>includes : boolean + +includes = "abcde".includes("cd"); +>includes = "abcde".includes("cd") : boolean +>includes : boolean +>"abcde".includes("cd") : boolean +>"abcde".includes : (searchString: string, position?: number) => boolean +>"abcde" : string +>includes : (searchString: string, position?: number) => boolean +>"cd" : string + +includes = "abcde".includes("cd", 2); +>includes = "abcde".includes("cd", 2) : boolean +>includes : boolean +>"abcde".includes("cd", 2) : boolean +>"abcde".includes : (searchString: string, position?: number) => boolean +>"abcde" : string +>includes : (searchString: string, position?: number) => boolean +>"cd" : string +>2 : number + diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt index e3dfd6133c9..e6cba35be25 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt @@ -22,9 +22,9 @@ 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]: 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; }'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ [x: string]: string | number | (() => void) | MyString | (() => 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; }'. Index signatures are incompatible. - Type 'string | number | MyString | (() => void)' is not assignable to type 'string'. + Type 'string | number | (() => void) | MyString | (() => string)' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(90,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(93,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -160,9 +160,9 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon // error var b: { [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: Type '{ [x: string]: string | number | (() => void) | MyString | (() => 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: Index signatures are incompatible. -!!! error TS2322: Type 'string | number | MyString | (() => void)' is not assignable to type 'string'. +!!! error TS2322: Type 'string | number | (() => void) | MyString | (() => string)' is not assignable to type 'string'. !!! error TS2322: Type 'number' is not assignable to type 'string'. a: '', b: 1, diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt index faef7905453..13d5adcf1f5 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt @@ -4,10 +4,11 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(24,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(31,5): error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(32,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(36,5): error TS2322: Type '{ [x: string]: typeof A; a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(36,5): error TS2322: Type '{ [x: string]: typeof A | typeof B; a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }'. Index signatures are incompatible. - Type 'typeof A' is not assignable to type 'A'. - Property 'foo' is missing in type 'typeof A'. + Type 'typeof A | typeof B' is not assignable to type 'A'. + Type 'typeof A' is not assignable to type 'A'. + Property 'foo' is missing in type 'typeof A'. ==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts (7 errors) ==== @@ -60,10 +61,11 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon // error var b: { [x: string]: A } = { ~ -!!! error TS2322: Type '{ [x: string]: typeof A; a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }'. +!!! error TS2322: Type '{ [x: string]: typeof A | typeof B; a: typeof A; b: typeof B; }' is not assignable to type '{ [x: string]: A; }'. !!! error TS2322: Index signatures are incompatible. -!!! error TS2322: Type 'typeof A' is not assignable to type 'A'. -!!! error TS2322: Property 'foo' is missing in type 'typeof A'. +!!! error TS2322: Type 'typeof A | typeof B' is not assignable to type 'A'. +!!! error TS2322: Type 'typeof A' is not assignable to type 'A'. +!!! error TS2322: Property 'foo' is missing in type 'typeof A'. a: A, b: B } \ No newline at end of file diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt index eeedf58ab73..2bb0db83e6d 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt @@ -101,12 +101,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(132,7): error TS2415: Class 'D23' incorrectly extends base class 'C3'. Types of property 'foo' are incompatible. Type 'V' is not assignable to type 'T'. + Type 'Date' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(132,11): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(132,24): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(137,7): error TS2415: Class 'D24' incorrectly extends base class 'C3'. Types of property 'foo' are incompatible. Type 'V' is not assignable to type 'U'. + Type 'Date' is not assignable to type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(137,11): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(137,24): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. @@ -441,6 +443,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2415: Class 'D23' incorrectly extends base class 'C3'. !!! error TS2415: Types of property 'foo' are incompatible. !!! error TS2415: Type 'V' is not assignable to type 'T'. +!!! error TS2415: Type 'Date' is not assignable to type 'T'. ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. ~~~~~~~~~~~ @@ -456,6 +459,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2415: Class 'D24' incorrectly extends base class 'C3'. !!! error TS2415: Types of property 'foo' are incompatible. !!! error TS2415: Type 'V' is not assignable to type 'U'. +!!! error TS2415: Type 'Date' is not assignable to type 'U'. ~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. ~~~~~~~~~~~ diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt index a9b025ccc77..7b3d706606d 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt @@ -1,11 +1,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(45,7): error TS2415: Class 'D3' incorrectly extends base class 'B1'. Types of property 'foo' are incompatible. Type 'V' is not assignable to type 'Foo'. - Property 'foo' is missing in type '{}'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'Foo'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(55,7): error TS2415: Class 'D5' incorrectly extends base class 'B1'. Types of property 'foo' are incompatible. Type 'U' is not assignable to type 'T'. + Type 'Foo' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(60,7): error TS2415: Class 'D6' incorrectly extends base class 'B1'. Types of property 'foo' are incompatible. @@ -14,6 +14,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(65,7): error TS2415: Class 'D7' incorrectly extends base class 'B1'. Types of property 'foo' are incompatible. Type 'T' is not assignable to type 'U'. + Type 'Foo' is not assignable to type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(75,7): error TS2415: Class 'D9' incorrectly extends base class 'B1'. Types of property 'foo' are incompatible. @@ -71,7 +72,6 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2415: Class 'D3' incorrectly extends base class 'B1'. !!! error TS2415: Types of property 'foo' are incompatible. !!! error TS2415: Type 'V' is not assignable to type 'Foo'. -!!! error TS2415: Property 'foo' is missing in type '{}'. [x: string]: Foo; foo: V; // error ~~~~~~~ @@ -88,6 +88,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2415: Class 'D5' incorrectly extends base class 'B1'. !!! error TS2415: Types of property 'foo' are incompatible. !!! error TS2415: Type 'U' is not assignable to type 'T'. +!!! error TS2415: Type 'Foo' is not assignable to type 'T'. [x: string]: T; foo: U; // error ~~~~~~~ @@ -110,6 +111,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2415: Class 'D7' incorrectly extends base class 'B1'. !!! error TS2415: Types of property 'foo' are incompatible. !!! error TS2415: Type 'T' is not assignable to type 'U'. +!!! error TS2415: Type 'Foo' is not assignable to type 'U'. [x: string]: U; foo: T; // error ~~~~~~~ diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt index 867b622cf1a..22b8c3cfb35 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt @@ -7,6 +7,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(66,11): error TS2415: Class 'D2' incorrectly extends base class 'Base'. Types of property 'foo' are incompatible. Type 'U' is not assignable to type 'T'. + Type 'Foo' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(66,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(66,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(66,50): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. @@ -14,6 +15,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(71,11): error TS2415: Class 'D3' incorrectly extends base class 'Base'. Types of property 'foo' are incompatible. Type 'V' is not assignable to type 'T'. + Type 'Foo' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(71,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(71,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(71,50): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. @@ -21,6 +23,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(76,11): error TS2415: Class 'D4' incorrectly extends base class 'Base'. Types of property 'foo' are incompatible. Type 'T' is not assignable to type 'U'. + Type 'Foo' is not assignable to type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(76,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(76,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(76,50): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. @@ -31,6 +34,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(86,11): error TS2415: Class 'D6' incorrectly extends base class 'Base'. Types of property 'foo' are incompatible. Type 'V' is not assignable to type 'U'. + Type 'Foo' is not assignable to type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(86,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(86,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(86,50): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. @@ -38,6 +42,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(91,11): error TS2415: Class 'D7' incorrectly extends base class 'Base'. Types of property 'foo' are incompatible. Type 'T' is not assignable to type 'V'. + Type 'Foo' is not assignable to type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(91,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(91,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(91,50): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. @@ -45,6 +50,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(96,11): error TS2415: Class 'D8' incorrectly extends base class 'Base'. Types of property 'foo' are incompatible. Type 'U' is not assignable to type 'V'. + Type 'Foo' is not assignable to type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(96,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(96,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(96,50): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. @@ -170,6 +176,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2415: Class 'D2' incorrectly extends base class 'Base'. !!! error TS2415: Types of property 'foo' are incompatible. !!! error TS2415: Type 'U' is not assignable to type 'T'. +!!! error TS2415: Type 'Foo' is not assignable to type 'T'. ~~~~~~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. ~~~~~~~~~~~~~~~~ @@ -187,6 +194,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2415: Class 'D3' incorrectly extends base class 'Base'. !!! error TS2415: Types of property 'foo' are incompatible. !!! error TS2415: Type 'V' is not assignable to type 'T'. +!!! error TS2415: Type 'Foo' is not assignable to type 'T'. ~~~~~~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. ~~~~~~~~~~~~~~~~ @@ -204,6 +212,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2415: Class 'D4' incorrectly extends base class 'Base'. !!! error TS2415: Types of property 'foo' are incompatible. !!! error TS2415: Type 'T' is not assignable to type 'U'. +!!! error TS2415: Type 'Foo' is not assignable to type 'U'. ~~~~~~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. ~~~~~~~~~~~~~~~~ @@ -232,6 +241,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2415: Class 'D6' incorrectly extends base class 'Base'. !!! error TS2415: Types of property 'foo' are incompatible. !!! error TS2415: Type 'V' is not assignable to type 'U'. +!!! error TS2415: Type 'Foo' is not assignable to type 'U'. ~~~~~~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. ~~~~~~~~~~~~~~~~ @@ -249,6 +259,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2415: Class 'D7' incorrectly extends base class 'Base'. !!! error TS2415: Types of property 'foo' are incompatible. !!! error TS2415: Type 'T' is not assignable to type 'V'. +!!! error TS2415: Type 'Foo' is not assignable to type 'V'. ~~~~~~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. ~~~~~~~~~~~~~~~~ @@ -266,6 +277,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2415: Class 'D8' incorrectly extends base class 'Base'. !!! error TS2415: Types of property 'foo' are incompatible. !!! error TS2415: Type 'U' is not assignable to type 'V'. +!!! error TS2415: Type 'Foo' is not assignable to type 'V'. ~~~~~~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. ~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/subtypesOfUnion.errors.txt b/tests/baselines/reference/subtypesOfUnion.errors.txt index fade5377814..7c2e88ec8fd 100644 --- a/tests/baselines/reference/subtypesOfUnion.errors.txt +++ b/tests/baselines/reference/subtypesOfUnion.errors.txt @@ -12,21 +12,21 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(28,5): error TS2411: Property 'foo16' of type 'T' is not assignable to string index type 'string | number'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(29,5): error TS2411: Property 'foo17' of type 'Object' is not assignable to string index type 'string | number'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(30,5): error TS2411: Property 'foo18' of type '{}' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(35,5): error TS2411: Property 'foo2' of type 'string' is not assignable to string index type 'number | E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(37,5): error TS2411: Property 'foo4' of type 'boolean' is not assignable to string index type 'number | E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(39,5): error TS2411: Property 'foo6' of type 'Date' is not assignable to string index type 'number | E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(40,5): error TS2411: Property 'foo7' of type 'RegExp' is not assignable to string index type 'number | E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(41,5): error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to string index type 'number | E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(42,5): error TS2411: Property 'foo9' of type 'I8' is not assignable to string index type 'number | E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(43,5): error TS2411: Property 'foo10' of type 'A' is not assignable to string index type 'number | E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(44,5): error TS2411: Property 'foo11' of type 'A2' is not assignable to string index type 'number | E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(45,5): error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to string index type 'number | E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(46,5): error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to string index type 'number | E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(47,5): error TS2411: Property 'foo14' of type 'typeof f' is not assignable to string index type 'number | E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(48,5): error TS2411: Property 'foo15' of type 'typeof c' is not assignable to string index type 'number | E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(49,5): error TS2411: Property 'foo16' of type 'T' is not assignable to string index type 'number | E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(50,5): error TS2411: Property 'foo17' of type 'Object' is not assignable to string index type 'number | E'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(51,5): error TS2411: Property 'foo18' of type '{}' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(35,5): error TS2411: Property 'foo2' of type 'string' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(37,5): error TS2411: Property 'foo4' of type 'boolean' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(39,5): error TS2411: Property 'foo6' of type 'Date' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(40,5): error TS2411: Property 'foo7' of type 'RegExp' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(41,5): error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(42,5): error TS2411: Property 'foo9' of type 'I8' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(43,5): error TS2411: Property 'foo10' of type 'A' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(44,5): error TS2411: Property 'foo11' of type 'A2' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(45,5): error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(46,5): error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(47,5): error TS2411: Property 'foo14' of type 'typeof f' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(48,5): error TS2411: Property 'foo15' of type 'typeof c' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(49,5): error TS2411: Property 'foo16' of type 'T' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(50,5): error TS2411: Property 'foo17' of type 'Object' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(51,5): error TS2411: Property 'foo18' of type '{}' is not assignable to string index type 'E | number'. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts (29 errors) ==== @@ -94,49 +94,49 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf foo: any; // ok foo2: string; // error ~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'string' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo2' of type 'string' is not assignable to string index type 'E | number'. foo3: number; // ok foo4: boolean; // error ~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo4' of type 'boolean' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo4' of type 'boolean' is not assignable to string index type 'E | number'. foo5: E; // ok foo6: Date; // error ~~~~~~~~~~~ -!!! error TS2411: Property 'foo6' of type 'Date' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo6' of type 'Date' is not assignable to string index type 'E | number'. foo7: RegExp; // error ~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo7' of type 'RegExp' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo7' of type 'RegExp' is not assignable to string index type 'E | number'. foo8: { bar: number }; // error ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to string index type 'E | number'. foo9: I8; // error ~~~~~~~~~ -!!! error TS2411: Property 'foo9' of type 'I8' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo9' of type 'I8' is not assignable to string index type 'E | number'. foo10: A; // error ~~~~~~~~~ -!!! error TS2411: Property 'foo10' of type 'A' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo10' of type 'A' is not assignable to string index type 'E | number'. foo11: A2; // error ~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo11' of type 'A2' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo11' of type 'A2' is not assignable to string index type 'E | number'. foo12: (x) => number; //error ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to string index type 'E | number'. foo13: (x: T) => T; // error ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to string index type 'E | number'. foo14: typeof f; // error ~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo14' of type 'typeof f' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo14' of type 'typeof f' is not assignable to string index type 'E | number'. foo15: typeof c; // error ~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo15' of type 'typeof c' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo15' of type 'typeof c' is not assignable to string index type 'E | number'. foo16: T; // error ~~~~~~~~~ -!!! error TS2411: Property 'foo16' of type 'T' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo16' of type 'T' is not assignable to string index type 'E | number'. foo17: Object; // error ~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo17' of type 'Object' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo17' of type 'Object' is not assignable to string index type 'E | number'. foo18: {}; // error ~~~~~~~~~~ -!!! error TS2411: Property 'foo18' of type '{}' is not assignable to string index type 'number | E'. +!!! error TS2411: Property 'foo18' of type '{}' is not assignable to string index type 'E | number'. } \ No newline at end of file diff --git a/tests/baselines/reference/subtypingWithCallSignatures2.types b/tests/baselines/reference/subtypingWithCallSignatures2.types index 8a56e05a9c2..e43382766ac 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures2.types +++ b/tests/baselines/reference/subtypingWithCallSignatures2.types @@ -331,14 +331,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: number) => number[]) | ((x: T) => T[]))[] +>[r1arg2, r1arg1] : (((x: number) => number[]) | ((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[]) | ((x: number) => number[]))[] +>[r1arg1, r1arg2] : (((x: T) => T[]) | ((x: number) => number[]))[] >r1arg1 : (x: T) => T[] >r1arg2 : (x: number) => number[] @@ -365,14 +365,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[]) | ((x: number) => string[]))[] +>[r2arg1, r2arg2] : (((x: T) => string[]) | ((x: number) => string[]))[] >r2arg1 : (x: T) => string[] >r2arg2 : (x: number) => string[] var r2b = [r2arg2, r2arg1]; ->r2b : ((x: T) => string[])[] ->[r2arg2, r2arg1] : ((x: T) => string[])[] +>r2b : (((x: number) => string[]) | ((x: T) => string[]))[] +>[r2arg2, r2arg1] : (((x: number) => string[]) | ((x: T) => string[]))[] >r2arg2 : (x: number) => string[] >r2arg1 : (x: T) => string[] @@ -396,14 +396,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) | ((x: number) => void))[] +>[r3arg1, r3arg2] : (((x: T) => T) | ((x: number) => void))[] >r3arg1 : (x: T) => T >r3arg2 : (x: number) => void var r3b = [r3arg2, r3arg1]; ->r3b : ((x: T) => T)[] ->[r3arg2, r3arg1] : ((x: T) => T)[] +>r3b : (((x: number) => void) | ((x: T) => T))[] +>[r3arg2, r3arg1] : (((x: number) => void) | ((x: T) => T))[] >r3arg2 : (x: number) => void >r3arg1 : (x: T) => T @@ -432,14 +432,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) | ((x: string, y: number) => string))[] +>[r4arg1, r4arg2] : (((x: T, y: U) => T) | ((x: string, y: number) => string))[] >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: string, y: number) => string) | ((x: T, y: U) => T))[] +>[r4arg2, r4arg1] : (((x: string, y: number) => string) | ((x: T, y: U) => T))[] >r4arg2 : (x: string, y: number) => string >r4arg1 : (x: T, y: U) => T @@ -470,14 +470,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) | ((x: (arg: string) => number) => string))[] +>[r5arg1, r5arg2] : (((x: (arg: T) => U) => T) | ((x: (arg: string) => number) => string))[] >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: string) => number) => string) | ((x: (arg: T) => U) => T))[] +>[r5arg2, r5arg1] : (((x: (arg: string) => number) => string) | ((x: (arg: T) => U) => T))[] >r5arg2 : (x: (arg: string) => number) => string >r5arg1 : (x: (arg: T) => U) => T @@ -514,14 +514,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) | ((x: (arg: Base) => Derived) => Base))[] +>[r6arg1, r6arg2] : (((x: (arg: T) => U) => T) | ((x: (arg: Base) => Derived) => Base))[] >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: Base) => Derived) => Base) | ((x: (arg: T) => U) => T))[] +>[r6arg2, r6arg1] : (((x: (arg: Base) => Derived) => Base) | ((x: (arg: T) => U) => T))[] >r6arg2 : (x: (arg: Base) => Derived) => Base >r6arg1 : (x: (arg: T) => U) => T @@ -564,14 +564,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) | ((x: (arg: Base) => Derived) => (r: Base) => Derived))[] +>[r7arg1, r7arg2] : (((x: (arg: T) => U) => (r: T) => U) | ((x: (arg: Base) => Derived) => (r: Base) => Derived))[] >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: Base) => Derived) => (r: Base) => Derived) | ((x: (arg: T) => U) => (r: T) => U))[] +>[r7arg2, r7arg1] : (((x: (arg: Base) => Derived) => (r: Base) => Derived) | ((x: (arg: T) => U) => (r: T) => U))[] >r7arg2 : (x: (arg: Base) => Derived) => (r: Base) => Derived >r7arg1 : (x: (arg: T) => U) => (r: T) => U @@ -622,14 +622,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) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] +>[r8arg1, r8arg2] : (((x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] >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: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived) | ((x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U))[] +>[r8arg2, r8arg1] : (((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived) | ((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 @@ -681,14 +681,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) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] +>[r9arg1, r9arg2] : (((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U) | ((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 >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: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived) | ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U))[] +>[r9arg2, r9arg1] : (((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived) | ((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 @@ -719,14 +719,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) | ((...x: Derived[]) => Derived))[] +>[r10arg1, r10arg2] : (((...x: T[]) => T) | ((...x: Derived[]) => Derived))[] >r10arg1 : (...x: T[]) => T >r10arg2 : (...x: Derived[]) => Derived var r10b = [r10arg2, r10arg1]; ->r10b : ((...x: T[]) => T)[] ->[r10arg2, r10arg1] : ((...x: T[]) => T)[] +>r10b : (((...x: Derived[]) => Derived) | ((...x: T[]) => T))[] +>[r10arg2, r10arg1] : (((...x: Derived[]) => Derived) | ((...x: T[]) => T))[] >r10arg2 : (...x: Derived[]) => Derived >r10arg1 : (...x: T[]) => T @@ -760,14 +760,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) | ((x: { foo: string; }, y: { foo: string; bar: string; }) => Base))[] +>[r11arg1, r11arg2] : (((x: T, y: T) => T) | ((x: { foo: string; }, y: { foo: string; bar: string; }) => Base))[] >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: { foo: string; }, y: { foo: string; bar: string; }) => Base) | ((x: T, y: T) => T))[] +>[r11arg2, r11arg1] : (((x: { foo: string; }, y: { foo: string; bar: string; }) => Base) | ((x: T, y: T) => T))[] >r11arg2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >r11arg1 : (x: T, y: T) => T @@ -808,14 +808,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[]) | ((x: Base[], y: Derived2[]) => Derived[]))[] +>[r12arg1, r12arg2] : (((x: Base[], y: T) => Derived[]) | ((x: Base[], y: Derived2[]) => Derived[]))[] >r12arg1 : (x: Base[], y: T) => Derived[] >r12arg2 : (x: Base[], y: Derived2[]) => Derived[] var r12b = [r12arg2, r12arg1]; ->r12b : ((x: Base[], y: T) => Derived[])[] ->[r12arg2, r12arg1] : ((x: Base[], y: T) => Derived[])[] +>r12b : (((x: Base[], y: Derived2[]) => Derived[]) | ((x: Base[], y: T) => Derived[]))[] +>[r12arg2, r12arg1] : (((x: Base[], y: Derived2[]) => Derived[]) | ((x: Base[], y: T) => Derived[]))[] >r12arg2 : (x: Base[], y: Derived2[]) => Derived[] >r12arg1 : (x: Base[], y: T) => Derived[] @@ -853,14 +853,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) | ((x: Base[], y: Derived[]) => Derived[]))[] +>[r13arg1, r13arg2] : (((x: Base[], y: T) => T) | ((x: Base[], y: Derived[]) => Derived[]))[] >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: Derived[]) => Derived[]) | ((x: Base[], y: T) => T))[] +>[r13arg2, r13arg1] : (((x: Base[], y: Derived[]) => Derived[]) | ((x: Base[], y: T) => T))[] >r13arg2 : (x: Base[], y: Derived[]) => Derived[] >r13arg1 : (x: Base[], y: T) => T @@ -894,14 +894,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) | ((x: { a: string; b: number; }) => Object))[] +>[r14arg1, r14arg2] : (((x: { a: T; b: T; }) => T) | ((x: { a: string; b: number; }) => Object))[] >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: string; b: number; }) => Object) | ((x: { a: T; b: T; }) => T))[] +>[r14arg2, r14arg1] : (((x: { a: string; b: number; }) => Object) | ((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 379810b2541..0d3a84ac99c 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures3.types +++ b/tests/baselines/reference/subtypingWithCallSignatures3.types @@ -219,8 +219,8 @@ module Errors { >null : null var r1a = [(x: number) => [''], (x: T) => null]; ->r1a : ((x: T) => U[])[] ->[(x: number) => [''], (x: T) => null] : ((x: T) => U[])[] +>r1a : (((x: number) => string[]) | ((x: T) => U[]))[] +>[(x: number) => [''], (x: T) => null] : (((x: number) => string[]) | ((x: T) => U[]))[] >(x: number) => [''] : (x: number) => string[] >x : number >[''] : string[] @@ -235,8 +235,8 @@ module Errors { >null : null var r1b = [(x: T) => null, (x: number) => ['']]; ->r1b : ((x: T) => U[])[] ->[(x: T) => null, (x: number) => ['']] : ((x: T) => U[])[] +>r1b : (((x: T) => U[]) | ((x: number) => string[]))[] +>[(x: T) => null, (x: number) => ['']] : (((x: T) => U[]) | ((x: number) => string[]))[] >(x: T) => null : (x: T) => U[] >T : T >U : U @@ -291,14 +291,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: Base) => Derived) => (r: Base) => Derived2) | ((x: (arg: T) => U) => (r: T) => V))[] +>[r2arg2, r2arg] : (((x: (arg: Base) => Derived) => (r: Base) => Derived2) | ((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) | ((x: (arg: Base) => Derived) => (r: Base) => Derived2))[] +>[r2arg, r2arg2] : (((x: (arg: T) => U) => (r: T) => V) | ((x: (arg: Base) => Derived) => (r: Base) => Derived2))[] >r2arg : (x: (arg: T) => U) => (r: T) => V >r2arg2 : (x: (arg: Base) => Derived) => (r: Base) => Derived2 @@ -349,8 +349,8 @@ module Errors { >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U var 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))[] +>r3a : (((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived) | ((x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U))[] +>[r3arg2, r3arg] : (((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived) | ((x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U))[] >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 @@ -387,14 +387,14 @@ module Errors { >r4arg : (...x: T[]) => T var r4a = [r4arg2, r4arg]; ->r4a : ((...x: T[]) => T)[] ->[r4arg2, r4arg] : ((...x: T[]) => T)[] +>r4a : (((...x: Base[]) => Base) | ((...x: T[]) => T))[] +>[r4arg2, r4arg] : (((...x: Base[]) => Base) | ((...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) | ((...x: Base[]) => Base))[] +>[r4arg, r4arg2] : (((...x: T[]) => T) | ((...x: Base[]) => Base))[] >r4arg : (...x: T[]) => T >r4arg2 : (...x: Base[]) => Base @@ -430,14 +430,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: { foo: string; }, y: { foo: string; bar: string; }) => Base) | ((x: T, y: T) => T))[] +>[r5arg2, r5arg] : (((x: { foo: string; }, y: { foo: string; bar: string; }) => Base) | ((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) | ((x: { foo: string; }, y: { foo: string; bar: string; }) => Base))[] +>[r5arg, r5arg2] : (((x: T, y: T) => T) | ((x: { foo: string; }, y: { foo: string; bar: string; }) => Base))[] >r5arg : (x: T, y: T) => T >r5arg2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base @@ -478,14 +478,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) | ((x: Base[], y: Derived2[]) => Derived[]))[] +>[r6arg2, r6arg] : (((x: Base[], y: Base[]) => T) | ((x: Base[], y: Derived2[]) => Derived[]))[] >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: Derived2[]) => Derived[]) | ((x: Base[], y: Base[]) => T))[] +>[r6arg, r6arg2] : (((x: Base[], y: Derived2[]) => Derived[]) | ((x: Base[], y: Base[]) => T))[] >r6arg : (x: Base[], y: Derived2[]) => Derived[] >r6arg2 : (x: Base[], y: Base[]) => T @@ -517,14 +517,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: string; b: number; }) => number) | ((x: { a: T; b: T; }) => T))[] +>[r7arg2, r7arg] : (((x: { a: string; b: number; }) => number) | ((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) | ((x: { a: string; b: number; }) => number))[] +>[r7arg, r7arg2] : (((x: { a: T; b: T; }) => T) | ((x: { a: string; b: number; }) => number))[] >r7arg : (x: { a: T; b: T; }) => T >r7arg2 : (x: { a: string; b: number; }) => number @@ -547,14 +547,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) | ((x: { a: T; b: T; }) => number))[] +>[r7arg2, r7arg3] : (((x: { a: string; b: number; }) => number) | ((x: { a: T; b: T; }) => number))[] >r7arg2 : (x: { a: string; b: number; }) => number >r7arg3 : (x: { a: T; b: T; }) => number var r7e = [r7arg3, r7arg2]; ->r7e : ((x: { a: string; b: number; }) => number)[] ->[r7arg3, r7arg2] : ((x: { a: string; b: number; }) => number)[] +>r7e : (((x: { a: T; b: T; }) => number) | ((x: { a: string; b: number; }) => number))[] +>[r7arg3, r7arg2] : (((x: { a: T; b: T; }) => number) | ((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 e76d36114e9..830f065f556 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures4.types +++ b/tests/baselines/reference/subtypingWithCallSignatures4.types @@ -317,14 +317,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) | ((x: T) => void))[] +>[r3arg, r3arg2] : (((x: T) => T) | ((x: T) => void))[] >r3arg : (x: T) => T >r3arg2 : (x: T) => void var r3b = [r3arg2, r3arg]; ->r3b : ((x: T) => T)[] ->[r3arg2, r3arg] : ((x: T) => T)[] +>r3b : (((x: T) => void) | ((x: T) => T))[] +>[r3arg2, r3arg] : (((x: T) => void) | ((x: T) => T))[] >r3arg2 : (x: T) => void >r3arg : (x: T) => T @@ -447,14 +447,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) | ((x: (arg: T) => Derived) => T))[] +>[r6arg, r6arg2] : (((x: (arg: T) => U) => T) | ((x: (arg: T) => Derived) => T))[] >r6arg : (x: (arg: T) => U) => T >r6arg2 : (x: (arg: T) => Derived) => T var r6b = [r6arg2, r6arg]; ->r6b : ((x: (arg: T) => U) => T)[] ->[r6arg2, r6arg] : ((x: (arg: T) => U) => T)[] +>r6b : (((x: (arg: T) => Derived) => T) | ((x: (arg: T) => U) => T))[] +>[r6arg2, r6arg] : (((x: (arg: T) => Derived) => T) | ((x: (arg: T) => U) => T))[] >r6arg2 : (x: (arg: T) => Derived) => T >r6arg : (x: (arg: T) => U) => T @@ -498,14 +498,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) | ((x: { foo: T; }, y: { foo: T; bar: T; }) => Base))[] +>[r11arg, r11arg2] : (((x: { foo: T; }, y: { foo: U; bar: U; }) => Base) | ((x: { foo: T; }, y: { foo: T; bar: T; }) => 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: U; bar: U; }) => Base)[] ->[r11arg2, r11arg] : ((x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] +>r11b : (((x: { foo: T; }, y: { foo: T; bar: T; }) => Base) | ((x: { foo: T; }, y: { foo: U; bar: U; }) => Base))[] +>[r11arg2, r11arg] : (((x: { foo: T; }, y: { foo: T; bar: T; }) => Base) | ((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 @@ -543,14 +543,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[]) | ((x: { a: T; b: T; }) => T[]))[] +>[r15arg, r15arg2] : (((x: { a: U; b: V; }) => U[]) | ((x: { a: T; b: T; }) => T[]))[] >r15arg : (x: { a: U; b: V; }) => U[] >r15arg2 : (x: { a: T; b: T; }) => T[] var r15b = [r15arg2, r15arg]; ->r15b : ((x: { a: U; b: V; }) => U[])[] ->[r15arg2, r15arg] : ((x: { a: U; b: V; }) => U[])[] +>r15b : (((x: { a: T; b: T; }) => T[]) | ((x: { a: U; b: V; }) => U[]))[] +>[r15arg2, r15arg] : (((x: { a: T; b: T; }) => T[]) | ((x: { a: U; b: V; }) => U[]))[] >r15arg2 : (x: { a: T; b: T; }) => T[] >r15arg : (x: { a: U; b: V; }) => U[] diff --git a/tests/baselines/reference/subtypingWithConstructSignatures2.types b/tests/baselines/reference/subtypingWithConstructSignatures2.types index d723a367ecb..f00ad0332ca 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: number) => number[]) | (new (x: T) => T[]))[] +>[r1arg2, r1arg1] : ((new (x: number) => number[]) | (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[]) | (new (x: number) => number[]))[] +>[r1arg1, r1arg2] : ((new (x: T) => T[]) | (new (x: number) => number[]))[] >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[]) | (new (x: number) => string[]))[] +>[r2arg1, r2arg2] : ((new (x: T) => string[]) | (new (x: number) => string[]))[] >r2arg1 : new (x: T) => string[] >r2arg2 : new (x: number) => string[] var r2b = [r2arg2, r2arg1]; ->r2b : (new (x: T) => string[])[] ->[r2arg2, r2arg1] : (new (x: T) => string[])[] +>r2b : ((new (x: number) => string[]) | (new (x: T) => string[]))[] +>[r2arg2, r2arg1] : ((new (x: number) => string[]) | (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) | (new (x: number) => void))[] +>[r3arg1, r3arg2] : ((new (x: T) => T) | (new (x: number) => void))[] >r3arg1 : new (x: T) => T >r3arg2 : new (x: number) => void var r3b = [r3arg2, r3arg1]; ->r3b : (new (x: T) => T)[] ->[r3arg2, r3arg1] : (new (x: T) => T)[] +>r3b : ((new (x: number) => void) | (new (x: T) => T))[] +>[r3arg2, r3arg1] : ((new (x: number) => void) | (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) | (new (x: string, y: number) => string))[] +>[r4arg1, r4arg2] : ((new (x: T, y: U) => T) | (new (x: string, y: number) => string))[] >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: string, y: number) => string) | (new (x: T, y: U) => T))[] +>[r4arg2, r4arg1] : ((new (x: string, y: number) => string) | (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) | (new (x: new (arg: string) => number) => string))[] +>[r5arg1, r5arg2] : ((new (x: new (arg: T) => U) => T) | (new (x: new (arg: string) => number) => string))[] >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: string) => number) => string) | (new (x: new (arg: T) => U) => T))[] +>[r5arg2, r5arg1] : ((new (x: new (arg: string) => number) => string) | (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) | (new (x: new (arg: Base) => Derived) => Base))[] +>[r6arg1, r6arg2] : ((new (x: new (arg: T) => U) => T) | (new (x: new (arg: Base) => Derived) => Base))[] >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: Base) => Derived) => Base) | (new (x: new (arg: T) => U) => T))[] +>[r6arg2, r6arg1] : ((new (x: new (arg: Base) => Derived) => Base) | (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) | (new (x: new (arg: Base) => Derived) => new (r: Base) => Derived))[] +>[r7arg1, r7arg2] : ((new (x: new (arg: T) => U) => new (r: T) => U) | (new (x: new (arg: Base) => Derived) => new (r: Base) => Derived))[] >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: Base) => Derived) => new (r: Base) => Derived) | (new (x: new (arg: T) => U) => new (r: T) => U))[] +>[r7arg2, r7arg1] : ((new (x: new (arg: Base) => Derived) => new (r: Base) => Derived) | (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) | (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] +>[r8arg1, r8arg2] : ((new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U) | (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 >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: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived) | (new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U))[] +>[r8arg2, r8arg1] : ((new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived) | (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 @@ -636,8 +636,8 @@ var r9a = [r9arg1, r9arg2]; >r9arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived var 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))[] +>r9b : ((new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived) | (new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U))[] +>[r9arg2, r9arg1] : ((new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived) | (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 >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) | (new (...x: Derived[]) => Derived))[] +>[r10arg1, r10arg2] : ((new (...x: T[]) => T) | (new (...x: Derived[]) => Derived))[] >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: Derived[]) => Derived) | (new (...x: T[]) => T))[] +>[r10arg2, r10arg1] : ((new (...x: Derived[]) => Derived) | (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) | (new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base))[] +>[r11arg1, r11arg2] : ((new (x: T, y: T) => T) | (new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base))[] >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: { foo: string; }, y: { foo: string; bar: string; }) => Base) | (new (x: T, y: T) => T))[] +>[r11arg2, r11arg1] : ((new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base) | (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[]) | (new (x: Base[], y: Derived2[]) => Derived[]))[] +>[r12arg1, r12arg2] : ((new (x: Base[], y: T) => Derived[]) | (new (x: Base[], y: Derived2[]) => Derived[]))[] >r12arg1 : new (x: Base[], y: T) => Derived[] >r12arg2 : new (x: Base[], y: Derived2[]) => Derived[] var r12b = [r12arg2, r12arg1]; ->r12b : (new (x: Base[], y: T) => Derived[])[] ->[r12arg2, r12arg1] : (new (x: Base[], y: T) => Derived[])[] +>r12b : ((new (x: Base[], y: Derived2[]) => Derived[]) | (new (x: Base[], y: T) => Derived[]))[] +>[r12arg2, r12arg1] : ((new (x: Base[], y: Derived2[]) => Derived[]) | (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) | (new (x: Base[], y: Derived[]) => Derived[]))[] +>[r13arg1, r13arg2] : ((new (x: Base[], y: T) => T) | (new (x: Base[], y: Derived[]) => Derived[]))[] >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: Derived[]) => Derived[]) | (new (x: Base[], y: T) => T))[] +>[r13arg2, r13arg1] : ((new (x: Base[], y: Derived[]) => Derived[]) | (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) | (new (x: { a: string; b: number; }) => Object))[] +>[r14arg1, r14arg2] : ((new (x: { a: T; b: T; }) => T) | (new (x: { a: string; b: number; }) => Object))[] >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: string; b: number; }) => Object) | (new (x: { a: T; b: T; }) => T))[] +>[r14arg2, r14arg1] : ((new (x: { a: string; b: number; }) => Object) | (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 b0f0680c7a0..b7c90d8697e 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: number) => string[]) | (new (x: T) => U[]))[] +>[r1arg2, r1arg1] : ((new (x: number) => string[]) | (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[]) | (new (x: number) => string[]))[] +>[r1arg1, r1arg2] : ((new (x: T) => U[]) | (new (x: number) => string[]))[] >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: Base) => Derived) => new (r: Base) => Derived2) | (new (x: new (arg: T) => U) => new (r: T) => V))[] +>[r2arg2, r2arg1] : ((new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2) | (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) | (new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2))[] +>[r2arg1, r2arg2] : ((new (x: new (arg: T) => U) => new (r: T) => V) | (new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2))[] >r2arg1 : new (x: new (arg: T) => U) => new (r: T) => V >r2arg2 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2 @@ -318,8 +318,8 @@ module Errors { >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U var 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))[] +>r3a : ((new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived) | (new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U))[] +>[r3arg2, r3arg1] : ((new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived) | (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 >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U @@ -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: Base[]) => Base) | (new (...x: T[]) => T))[] +>[r4arg2, r4arg1] : ((new (...x: Base[]) => Base) | (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) | (new (...x: Base[]) => Base))[] +>[r4arg1, r4arg2] : ((new (...x: T[]) => T) | (new (...x: Base[]) => Base))[] >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: { foo: string; }, y: { foo: string; bar: string; }) => Base) | (new (x: T, y: T) => T))[] +>[r5arg2, r5arg1] : ((new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base) | (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) | (new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base))[] +>[r5arg1, r5arg2] : ((new (x: T, y: T) => T) | (new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base))[] >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) | (new (x: Base[], y: Derived2[]) => Derived[]))[] +>[r6arg2, r6arg1] : ((new (x: Base[], y: Base[]) => T) | (new (x: Base[], y: Derived2[]) => Derived[]))[] >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: Derived2[]) => Derived[]) | (new (x: Base[], y: Base[]) => T))[] +>[r6arg1, r6arg2] : ((new (x: Base[], y: Derived2[]) => Derived[]) | (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: string; b: number; }) => number) | (new (x: { a: T; b: T; }) => T))[] +>[r7arg2, r7arg1] : ((new (x: { a: string; b: number; }) => number) | (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) | (new (x: { a: string; b: number; }) => number))[] +>[r7arg1, r7arg2] : ((new (x: { a: T; b: T; }) => T) | (new (x: { a: string; b: number; }) => number))[] >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) | (new (x: { a: T; b: T; }) => number))[] +>[r7arg2, r7arg3] : ((new (x: { a: string; b: number; }) => number) | (new (x: { a: T; b: T; }) => 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: string; b: number; }) => number)[] ->[r7arg3, r7arg2] : (new (x: { a: string; b: number; }) => number)[] +>r7e : ((new (x: { a: T; b: T; }) => number) | (new (x: { a: string; b: number; }) => number))[] +>[r7arg3, r7arg2] : ((new (x: { a: T; b: T; }) => number) | (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 21a40ecf7fc..328dadad41c 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures4.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures4.types @@ -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) | (new (x: T) => void))[] +>[r3arg, r3arg2] : ((new (x: T) => T) | (new (x: T) => void))[] >r3arg : new (x: T) => T >r3arg2 : new (x: T) => void var r3b = [r3arg2, r3arg]; ->r3b : (new (x: T) => T)[] ->[r3arg2, r3arg] : (new (x: T) => T)[] +>r3b : ((new (x: T) => void) | (new (x: T) => T))[] +>[r3arg2, r3arg] : ((new (x: T) => void) | (new (x: T) => T))[] >r3arg2 : new (x: T) => void >r3arg : new (x: T) => 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) | (new (x: new (arg: T) => Derived) => T))[] +>[r6arg, r6arg2] : ((new (x: new (arg: T) => U) => T) | (new (x: new (arg: T) => Derived) => 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) => U) => T)[] ->[r6arg2, r6arg] : (new (x: new (arg: T) => U) => T)[] +>r6b : ((new (x: new (arg: T) => Derived) => T) | (new (x: new (arg: T) => U) => T))[] +>[r6arg2, r6arg] : ((new (x: new (arg: T) => Derived) => T) | (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) | (new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base))[] +>[r11arg, r11arg2] : ((new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base) | (new (x: { foo: T; }, y: { foo: T; bar: T; }) => 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: U; bar: U; }) => Base)[] ->[r11arg2, r11arg] : (new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] +>r11b : ((new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base) | (new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base))[] +>[r11arg2, r11arg] : ((new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base) | (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[]) | (new (x: { a: T; b: T; }) => T[]))[] +>[r15arg, r15arg2] : ((new (x: { a: U; b: V; }) => U[]) | (new (x: { a: T; b: T; }) => T[]))[] >r15arg : new (x: { a: U; b: V; }) => U[] >r15arg2 : new (x: { a: T; b: T; }) => T[] var r15b = [r15arg2, r15arg]; ->r15b : (new (x: { a: U; b: V; }) => U[])[] ->[r15arg2, r15arg] : (new (x: { a: U; b: V; }) => U[])[] +>r15b : ((new (x: { a: T; b: T; }) => T[]) | (new (x: { a: U; b: V; }) => U[]))[] +>[r15arg2, r15arg] : ((new (x: { a: T; b: T; }) => T[]) | (new (x: { a: U; b: V; }) => U[]))[] >r15arg2 : new (x: { a: T; b: T; }) => T[] >r15arg : new (x: { a: U; b: V; }) => U[] diff --git a/tests/baselines/reference/subtypingWithObjectMembersOptionality.types b/tests/baselines/reference/subtypingWithObjectMembersOptionality.types index 815f2d60740..0d55d78e266 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersOptionality.types +++ b/tests/baselines/reference/subtypingWithObjectMembersOptionality.types @@ -85,8 +85,8 @@ var b = { Foo: null }; >null : null var r = true ? a : b; ->r : { Foo?: Base; } ->true ? a : b : { Foo?: Base; } +>r : { Foo?: Base; } | { Foo: Derived; } +>true ? a : b : { Foo?: Base; } | { Foo: Derived; } >true : boolean >a : { Foo?: Base; } >b : { Foo: Derived; } @@ -156,8 +156,8 @@ module TwoLevels { >null : null var r = true ? a : b; ->r : { Foo?: Base; } ->true ? a : b : { Foo?: Base; } +>r : { Foo?: Base; } | { Foo: Derived2; } +>true ? a : b : { Foo?: Base; } | { Foo: Derived2; } >true : boolean >a : { Foo?: Base; } >b : { Foo: Derived2; } diff --git a/tests/baselines/reference/super.js b/tests/baselines/reference/super.js index a6b698413ec..1d060672ceb 100644 --- a/tests/baselines/reference/super.js +++ b/tests/baselines/reference/super.js @@ -79,7 +79,7 @@ var Base2 = (function () { function Base2() { } Base2.prototype.foo = function () { - _super.foo.call(this); + _super.prototype.foo.call(this); }; return Base2; })(); diff --git a/tests/baselines/reference/super1.js b/tests/baselines/reference/super1.js index 6a52cfcd9e7..5c2182d8afb 100644 --- a/tests/baselines/reference/super1.js +++ b/tests/baselines/reference/super1.js @@ -165,7 +165,7 @@ var Base4; function Sub4E() { } Sub4E.prototype.x = function () { - return _super.x.call(this); + return _super.prototype.x.call(this); }; return Sub4E; })(); diff --git a/tests/baselines/reference/superCallInsideClassDeclaration.errors.txt b/tests/baselines/reference/superCallInsideClassDeclaration.errors.txt new file mode 100644 index 00000000000..ddb877f3f4e --- /dev/null +++ b/tests/baselines/reference/superCallInsideClassDeclaration.errors.txt @@ -0,0 +1,29 @@ +tests/cases/compiler/superCallInsideClassDeclaration.ts(8,5): error TS2377: Constructors for derived classes must contain a 'super' call. + + +==== tests/cases/compiler/superCallInsideClassDeclaration.ts (1 errors) ==== + class A { + } + + class C { + } + + class B extends A { + constructor() { + ~~~~~~~~~~~~~~~ + + + class D extends C { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + constructor() { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + super(); + ~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + } + ~~~~~~~~~ + } + ~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. + } \ No newline at end of file diff --git a/tests/baselines/reference/superCallInsideClassDeclaration.js b/tests/baselines/reference/superCallInsideClassDeclaration.js new file mode 100644 index 00000000000..6d16aceb247 --- /dev/null +++ b/tests/baselines/reference/superCallInsideClassDeclaration.js @@ -0,0 +1,47 @@ +//// [superCallInsideClassDeclaration.ts] +class A { +} + +class C { +} + +class B extends A { + constructor() { + + class D extends C { + constructor() { + super(); + } + } + } +} + +//// [superCallInsideClassDeclaration.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var A = (function () { + function A() { + } + return A; +})(); +var C = (function () { + function C() { + } + return C; +})(); +var B = (function (_super) { + __extends(B, _super); + function B() { + var D = (function (_super) { + __extends(D, _super); + function D() { + _super.call(this); + } + return D; + })(C); + } + return B; +})(A); diff --git a/tests/baselines/reference/superCallInsideClassExpression.errors.txt b/tests/baselines/reference/superCallInsideClassExpression.errors.txt new file mode 100644 index 00000000000..736f31c4d0f --- /dev/null +++ b/tests/baselines/reference/superCallInsideClassExpression.errors.txt @@ -0,0 +1,29 @@ +tests/cases/compiler/superCallInsideClassExpression.ts(8,5): error TS2377: Constructors for derived classes must contain a 'super' call. + + +==== tests/cases/compiler/superCallInsideClassExpression.ts (1 errors) ==== + class A { + } + + class C { + } + + class B extends A { + constructor() { + ~~~~~~~~~~~~~~~ + + + var D = class extends C { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + constructor() { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + super(); + ~~~~~~~~~~~~~~~~~~~~~~~~ + } + ~~~~~~~~~~~~~ + } + ~~~~~~~~~ + } + ~~~~~ +!!! error TS2377: Constructors for derived classes must contain a 'super' call. + } \ No newline at end of file diff --git a/tests/baselines/reference/superCallInsideClassExpression.js b/tests/baselines/reference/superCallInsideClassExpression.js new file mode 100644 index 00000000000..ea24003d9b7 --- /dev/null +++ b/tests/baselines/reference/superCallInsideClassExpression.js @@ -0,0 +1,47 @@ +//// [superCallInsideClassExpression.ts] +class A { +} + +class C { +} + +class B extends A { + constructor() { + + var D = class extends C { + constructor() { + super(); + } + } + } +} + +//// [superCallInsideClassExpression.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var A = (function () { + function A() { + } + return A; +})(); +var C = (function () { + function C() { + } + return C; +})(); +var B = (function (_super) { + __extends(B, _super); + function B() { + var D = (function (_super) { + __extends(class_1, _super); + function class_1() { + _super.call(this); + } + return class_1; + })(C); + } + return B; +})(A); diff --git a/tests/baselines/reference/superCallInsideObjectLiteralExpression.js b/tests/baselines/reference/superCallInsideObjectLiteralExpression.js new file mode 100644 index 00000000000..60513cf43ee --- /dev/null +++ b/tests/baselines/reference/superCallInsideObjectLiteralExpression.js @@ -0,0 +1,36 @@ +//// [superCallInsideObjectLiteralExpression.ts] +class A { + foo() { + } +} + +class B extends A { + constructor() { + var x = { + x: super() + } + } +} + +//// [superCallInsideObjectLiteralExpression.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var A = (function () { + function A() { + } + A.prototype.foo = function () { + }; + return A; +})(); +var B = (function (_super) { + __extends(B, _super); + function B() { + var x = { + x: _super.call(this) + }; + } + return B; +})(A); diff --git a/tests/baselines/reference/superCallInsideObjectLiteralExpression.symbols b/tests/baselines/reference/superCallInsideObjectLiteralExpression.symbols new file mode 100644 index 00000000000..d01899ecfef --- /dev/null +++ b/tests/baselines/reference/superCallInsideObjectLiteralExpression.symbols @@ -0,0 +1,23 @@ +=== tests/cases/compiler/superCallInsideObjectLiteralExpression.ts === +class A { +>A : Symbol(A, Decl(superCallInsideObjectLiteralExpression.ts, 0, 0)) + + foo() { +>foo : Symbol(foo, Decl(superCallInsideObjectLiteralExpression.ts, 0, 9)) + } +} + +class B extends A { +>B : Symbol(B, Decl(superCallInsideObjectLiteralExpression.ts, 3, 1)) +>A : Symbol(A, Decl(superCallInsideObjectLiteralExpression.ts, 0, 0)) + + constructor() { + var x = { +>x : Symbol(x, Decl(superCallInsideObjectLiteralExpression.ts, 7, 11)) + + x: super() +>x : Symbol(x, Decl(superCallInsideObjectLiteralExpression.ts, 7, 17)) +>super : Symbol(A, Decl(superCallInsideObjectLiteralExpression.ts, 0, 0)) + } + } +} diff --git a/tests/baselines/reference/superCallInsideObjectLiteralExpression.types b/tests/baselines/reference/superCallInsideObjectLiteralExpression.types new file mode 100644 index 00000000000..6cbb8d3ae56 --- /dev/null +++ b/tests/baselines/reference/superCallInsideObjectLiteralExpression.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/superCallInsideObjectLiteralExpression.ts === +class A { +>A : A + + foo() { +>foo : () => void + } +} + +class B extends A { +>B : B +>A : A + + constructor() { + var x = { +>x : { x: void; } +>{ x: super() } : { x: void; } + + x: super() +>x : void +>super() : void +>super : typeof A + } + } +} diff --git a/tests/baselines/reference/superCallWithMissingBaseClass.errors.txt b/tests/baselines/reference/superCallWithMissingBaseClass.errors.txt new file mode 100644 index 00000000000..0f4e4b7dd13 --- /dev/null +++ b/tests/baselines/reference/superCallWithMissingBaseClass.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/superCallWithMissingBaseClass.ts(1,19): error TS2304: Cannot find name 'Bar'. + + +==== tests/cases/compiler/superCallWithMissingBaseClass.ts (1 errors) ==== + class Foo extends Bar { + ~~~ +!!! error TS2304: Cannot find name 'Bar'. + m1() { + return super.m1(); + } + + static m2() { + return super.m2(); + } + } \ No newline at end of file diff --git a/tests/baselines/reference/superCallWithMissingBaseClass.js b/tests/baselines/reference/superCallWithMissingBaseClass.js new file mode 100644 index 00000000000..101e709653e --- /dev/null +++ b/tests/baselines/reference/superCallWithMissingBaseClass.js @@ -0,0 +1,30 @@ +//// [superCallWithMissingBaseClass.ts] +class Foo extends Bar { + m1() { + return super.m1(); + } + + static m2() { + return super.m2(); + } +} + +//// [superCallWithMissingBaseClass.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Foo = (function (_super) { + __extends(Foo, _super); + function Foo() { + _super.apply(this, arguments); + } + Foo.prototype.m1 = function () { + return _super.prototype.m1.call(this); + }; + Foo.m2 = function () { + return _super.m2.call(this); + }; + return Foo; +})(Bar); diff --git a/tests/baselines/reference/switchStatements.errors.txt b/tests/baselines/reference/switchStatements.errors.txt new file mode 100644 index 00000000000..aa5b796e252 --- /dev/null +++ b/tests/baselines/reference/switchStatements.errors.txt @@ -0,0 +1,63 @@ +tests/cases/conformance/statements/switchStatements/switchStatements.ts(35,10): error TS2322: Type '{ id: number; name: string; }' is not assignable to type 'C'. + Object literal may only specify known properties, and 'name' does not exist in type 'C'. + + +==== tests/cases/conformance/statements/switchStatements/switchStatements.ts (1 errors) ==== + module M { + export function fn(x: number) { + return ''; + } + } + + var x: any; + switch (x) { + case '': + case 12: + case true: + case null: + case undefined: + case new Date(12): + case new Object(): + case /[a-z]/: + case[]: + case {}: + case { id: 12 }: + case['a']: + case typeof x: + case typeof M: + case M.fn(1): + case (x: number) => '': + case ((x: number) => '')(2): + default: + } + + // basic assignable check, rest covered in tests for 'assignement compatibility' + class C { id: number; } + class D extends C { name: string } + + switch (new C()) { + case new D(): + case { id: 12, name: '' }: + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ id: number; name: string; }' is not assignable to type 'C'. +!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type 'C'. + case new C(): + } + + switch ('') { } + switch (12) { } + switch (true) { } + switch (null) { } + switch (undefined) { } + switch (new Date(12)) { } + switch (new Object()) { } + switch (/[a-z]/) { } + switch ([]) { } + switch ({}) { } + switch ({ id: 12 }) { } + switch (['a']) { } + switch ((x: number) => '') { } + switch (((x: T) => '')(1)) { } + + + \ No newline at end of file diff --git a/tests/baselines/reference/switchStatements.symbols b/tests/baselines/reference/switchStatements.symbols deleted file mode 100644 index fc8f076a12c..00000000000 --- a/tests/baselines/reference/switchStatements.symbols +++ /dev/null @@ -1,115 +0,0 @@ -=== tests/cases/conformance/statements/switchStatements/switchStatements.ts === -module M { ->M : Symbol(M, Decl(switchStatements.ts, 0, 0)) - - export function fn(x: number) { ->fn : Symbol(fn, Decl(switchStatements.ts, 0, 10)) ->x : Symbol(x, Decl(switchStatements.ts, 1, 23)) - - return ''; - } -} - -var x: any; ->x : Symbol(x, Decl(switchStatements.ts, 6, 3)) - -switch (x) { ->x : Symbol(x, Decl(switchStatements.ts, 6, 3)) - - case '': - case 12: - case true: - case null: - case undefined: ->undefined : Symbol(undefined) - - case new Date(12): ->Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11)) - - case new Object(): ->Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11)) - - case /[a-z]/: - case[]: - case {}: - case { id: 12 }: ->id : Symbol(id, Decl(switchStatements.ts, 18, 10)) - - case['a']: - case typeof x: ->x : Symbol(x, Decl(switchStatements.ts, 6, 3)) - - case typeof M: ->M : Symbol(M, Decl(switchStatements.ts, 0, 0)) - - case M.fn(1): ->M.fn : Symbol(M.fn, Decl(switchStatements.ts, 0, 10)) ->M : Symbol(M, Decl(switchStatements.ts, 0, 0)) ->fn : Symbol(M.fn, Decl(switchStatements.ts, 0, 10)) - - case (x: number) => '': ->T : Symbol(T, Decl(switchStatements.ts, 23, 10)) ->x : Symbol(x, Decl(switchStatements.ts, 23, 13)) - - case ((x: number) => '')(2): ->T : Symbol(T, Decl(switchStatements.ts, 24, 11)) ->x : Symbol(x, Decl(switchStatements.ts, 24, 14)) - - default: -} - -// basic assignable check, rest covered in tests for 'assignement compatibility' -class C { id: number; } ->C : Symbol(C, Decl(switchStatements.ts, 26, 1)) ->id : Symbol(id, Decl(switchStatements.ts, 29, 9)) - -class D extends C { name: string } ->D : Symbol(D, Decl(switchStatements.ts, 29, 23)) ->C : Symbol(C, Decl(switchStatements.ts, 26, 1)) ->name : Symbol(name, Decl(switchStatements.ts, 30, 19)) - -switch (new C()) { ->C : Symbol(C, Decl(switchStatements.ts, 26, 1)) - - case new D(): ->D : Symbol(D, Decl(switchStatements.ts, 29, 23)) - - case { id: 12, name: '' }: ->id : Symbol(id, Decl(switchStatements.ts, 34, 10)) ->name : Symbol(name, Decl(switchStatements.ts, 34, 18)) - - case new C(): ->C : Symbol(C, Decl(switchStatements.ts, 26, 1)) -} - -switch ('') { } -switch (12) { } -switch (true) { } -switch (null) { } -switch (undefined) { } ->undefined : Symbol(undefined) - -switch (new Date(12)) { } ->Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11)) - -switch (new Object()) { } ->Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11)) - -switch (/[a-z]/) { } -switch ([]) { } -switch ({}) { } -switch ({ id: 12 }) { } ->id : Symbol(id, Decl(switchStatements.ts, 48, 9)) - -switch (['a']) { } -switch ((x: number) => '') { } ->T : Symbol(T, Decl(switchStatements.ts, 50, 9)) ->x : Symbol(x, Decl(switchStatements.ts, 50, 12)) - -switch (((x: T) => '')(1)) { } ->T : Symbol(T, Decl(switchStatements.ts, 51, 10)) ->x : Symbol(x, Decl(switchStatements.ts, 51, 13)) ->T : Symbol(T, Decl(switchStatements.ts, 51, 10)) - - - diff --git a/tests/baselines/reference/switchStatements.types b/tests/baselines/reference/switchStatements.types deleted file mode 100644 index a5679547c12..00000000000 --- a/tests/baselines/reference/switchStatements.types +++ /dev/null @@ -1,184 +0,0 @@ -=== tests/cases/conformance/statements/switchStatements/switchStatements.ts === -module M { ->M : typeof M - - export function fn(x: number) { ->fn : (x: number) => string ->x : number - - return ''; ->'' : string - } -} - -var x: any; ->x : any - -switch (x) { ->x : any - - case '': ->'' : string - - case 12: ->12 : number - - case true: ->true : boolean - - case null: ->null : null - - case undefined: ->undefined : undefined - - case new Date(12): ->new Date(12) : Date ->Date : DateConstructor ->12 : number - - case new Object(): ->new Object() : Object ->Object : ObjectConstructor - - case /[a-z]/: ->/[a-z]/ : RegExp - - case[]: ->[] : undefined[] - - case {}: ->{} : {} - - case { id: 12 }: ->{ id: 12 } : { id: number; } ->id : number ->12 : number - - case['a']: ->['a'] : string[] ->'a' : string - - case typeof x: ->typeof x : string ->x : any - - case typeof M: ->typeof M : string ->M : typeof M - - case M.fn(1): ->M.fn(1) : string ->M.fn : (x: number) => string ->M : typeof M ->fn : (x: number) => string ->1 : number - - case (x: number) => '': ->(x: number) => '' : (x: number) => string ->T : T ->x : number ->'' : string - - case ((x: number) => '')(2): ->((x: number) => '')(2) : string ->((x: number) => '') : (x: number) => string ->(x: number) => '' : (x: number) => string ->T : T ->x : number ->'' : string ->2 : number - - default: -} - -// basic assignable check, rest covered in tests for 'assignement compatibility' -class C { id: number; } ->C : C ->id : number - -class D extends C { name: string } ->D : D ->C : C ->name : string - -switch (new C()) { ->new C() : C ->C : typeof C - - case new D(): ->new D() : D ->D : typeof D - - case { id: 12, name: '' }: ->{ id: 12, name: '' } : { id: number; name: string; } ->id : number ->12 : number ->name : string ->'' : string - - case new C(): ->new C() : C ->C : typeof C -} - -switch ('') { } ->'' : string - -switch (12) { } ->12 : number - -switch (true) { } ->true : boolean - -switch (null) { } ->null : null - -switch (undefined) { } ->undefined : undefined - -switch (new Date(12)) { } ->new Date(12) : Date ->Date : DateConstructor ->12 : number - -switch (new Object()) { } ->new Object() : Object ->Object : ObjectConstructor - -switch (/[a-z]/) { } ->/[a-z]/ : RegExp - -switch ([]) { } ->[] : undefined[] - -switch ({}) { } ->{} : {} - -switch ({ id: 12 }) { } ->{ id: 12 } : { id: number; } ->id : number ->12 : number - -switch (['a']) { } ->['a'] : string[] ->'a' : string - -switch ((x: number) => '') { } ->(x: number) => '' : (x: number) => string ->T : T ->x : number ->'' : string - -switch (((x: T) => '')(1)) { } ->((x: T) => '')(1) : string ->((x: T) => '') : (x: T) => string ->(x: T) => '' : (x: T) => string ->T : T ->x : T ->T : T ->'' : string ->1 : number - - - diff --git a/tests/baselines/reference/symbolProperty21.errors.txt b/tests/baselines/reference/symbolProperty21.errors.txt new file mode 100644 index 00000000000..b9162acc84f --- /dev/null +++ b/tests/baselines/reference/symbolProperty21.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/es6/Symbols/symbolProperty21.ts(8,5): error TS2345: Argument of type '{ [Symbol.isConcatSpreadable]: string; [Symbol.toPrimitive]: number; [Symbol.unscopables]: boolean; }' is not assignable to parameter of type 'I'. + Object literal may only specify known properties, and '[Symbol.toPrimitive]' does not exist in type 'I'. + + +==== tests/cases/conformance/es6/Symbols/symbolProperty21.ts (1 errors) ==== + interface I { + [Symbol.unscopables]: T; + [Symbol.isConcatSpreadable]: U; + } + + declare function foo(p: I): { t: T; u: U }; + + foo({ + ~ + [Symbol.isConcatSpreadable]: "", + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + [Symbol.toPrimitive]: 0, + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + [Symbol.unscopables]: true + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + }); + ~ +!!! error TS2345: Argument of type '{ [Symbol.isConcatSpreadable]: string; [Symbol.toPrimitive]: number; [Symbol.unscopables]: boolean; }' is not assignable to parameter of type 'I'. +!!! error TS2345: Object literal may only specify known properties, and '[Symbol.toPrimitive]' does not exist in type 'I'. \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty21.symbols b/tests/baselines/reference/symbolProperty21.symbols deleted file mode 100644 index 09997f687d5..00000000000 --- a/tests/baselines/reference/symbolProperty21.symbols +++ /dev/null @@ -1,51 +0,0 @@ -=== tests/cases/conformance/es6/Symbols/symbolProperty21.ts === -interface I { ->I : Symbol(I, Decl(symbolProperty21.ts, 0, 0)) ->T : Symbol(T, Decl(symbolProperty21.ts, 0, 12)) ->U : Symbol(U, Decl(symbolProperty21.ts, 0, 14)) - - [Symbol.unscopables]: T; ->Symbol.unscopables : Symbol(SymbolConstructor.unscopables, Decl(lib.d.ts, 1297, 24)) ->Symbol : Symbol(Symbol, Decl(lib.d.ts, 1199, 52), Decl(lib.d.ts, 1305, 11)) ->unscopables : Symbol(SymbolConstructor.unscopables, Decl(lib.d.ts, 1297, 24)) ->T : Symbol(T, Decl(symbolProperty21.ts, 0, 12)) - - [Symbol.isConcatSpreadable]: U; ->Symbol.isConcatSpreadable : Symbol(SymbolConstructor.isConcatSpreadable, Decl(lib.d.ts, 1243, 24)) ->Symbol : Symbol(Symbol, Decl(lib.d.ts, 1199, 52), Decl(lib.d.ts, 1305, 11)) ->isConcatSpreadable : Symbol(SymbolConstructor.isConcatSpreadable, Decl(lib.d.ts, 1243, 24)) ->U : Symbol(U, Decl(symbolProperty21.ts, 0, 14)) -} - -declare function foo(p: I): { t: T; u: U }; ->foo : Symbol(foo, Decl(symbolProperty21.ts, 3, 1)) ->T : Symbol(T, Decl(symbolProperty21.ts, 5, 21)) ->U : Symbol(U, Decl(symbolProperty21.ts, 5, 23)) ->p : Symbol(p, Decl(symbolProperty21.ts, 5, 27)) ->I : Symbol(I, Decl(symbolProperty21.ts, 0, 0)) ->T : Symbol(T, Decl(symbolProperty21.ts, 5, 21)) ->U : Symbol(U, Decl(symbolProperty21.ts, 5, 23)) ->t : Symbol(t, Decl(symbolProperty21.ts, 5, 41)) ->T : Symbol(T, Decl(symbolProperty21.ts, 5, 21)) ->u : Symbol(u, Decl(symbolProperty21.ts, 5, 47)) ->U : Symbol(U, Decl(symbolProperty21.ts, 5, 23)) - -foo({ ->foo : Symbol(foo, Decl(symbolProperty21.ts, 3, 1)) - - [Symbol.isConcatSpreadable]: "", ->Symbol.isConcatSpreadable : Symbol(SymbolConstructor.isConcatSpreadable, Decl(lib.d.ts, 1243, 24)) ->Symbol : Symbol(Symbol, Decl(lib.d.ts, 1199, 52), Decl(lib.d.ts, 1305, 11)) ->isConcatSpreadable : Symbol(SymbolConstructor.isConcatSpreadable, Decl(lib.d.ts, 1243, 24)) - - [Symbol.toPrimitive]: 0, ->Symbol.toPrimitive : Symbol(SymbolConstructor.toPrimitive, Decl(lib.d.ts, 1285, 18)) ->Symbol : Symbol(Symbol, Decl(lib.d.ts, 1199, 52), Decl(lib.d.ts, 1305, 11)) ->toPrimitive : Symbol(SymbolConstructor.toPrimitive, Decl(lib.d.ts, 1285, 18)) - - [Symbol.unscopables]: true ->Symbol.unscopables : Symbol(SymbolConstructor.unscopables, Decl(lib.d.ts, 1297, 24)) ->Symbol : Symbol(Symbol, Decl(lib.d.ts, 1199, 52), Decl(lib.d.ts, 1305, 11)) ->unscopables : Symbol(SymbolConstructor.unscopables, Decl(lib.d.ts, 1297, 24)) - -}); diff --git a/tests/baselines/reference/symbolProperty21.types b/tests/baselines/reference/symbolProperty21.types deleted file mode 100644 index e2cda0a896f..00000000000 --- a/tests/baselines/reference/symbolProperty21.types +++ /dev/null @@ -1,56 +0,0 @@ -=== tests/cases/conformance/es6/Symbols/symbolProperty21.ts === -interface I { ->I : I ->T : T ->U : U - - [Symbol.unscopables]: T; ->Symbol.unscopables : symbol ->Symbol : SymbolConstructor ->unscopables : symbol ->T : T - - [Symbol.isConcatSpreadable]: U; ->Symbol.isConcatSpreadable : symbol ->Symbol : SymbolConstructor ->isConcatSpreadable : symbol ->U : U -} - -declare function foo(p: I): { t: T; u: U }; ->foo : (p: I) => { t: T; u: U; } ->T : T ->U : U ->p : I ->I : I ->T : T ->U : U ->t : T ->T : T ->u : U ->U : U - -foo({ ->foo({ [Symbol.isConcatSpreadable]: "", [Symbol.toPrimitive]: 0, [Symbol.unscopables]: true}) : { t: boolean; u: string; } ->foo : (p: I) => { t: T; u: U; } ->{ [Symbol.isConcatSpreadable]: "", [Symbol.toPrimitive]: 0, [Symbol.unscopables]: true} : { [Symbol.isConcatSpreadable]: string; [Symbol.toPrimitive]: number; [Symbol.unscopables]: boolean; } - - [Symbol.isConcatSpreadable]: "", ->Symbol.isConcatSpreadable : symbol ->Symbol : SymbolConstructor ->isConcatSpreadable : symbol ->"" : string - - [Symbol.toPrimitive]: 0, ->Symbol.toPrimitive : symbol ->Symbol : SymbolConstructor ->toPrimitive : symbol ->0 : number - - [Symbol.unscopables]: true ->Symbol.unscopables : symbol ->Symbol : SymbolConstructor ->unscopables : symbol ->true : boolean - -}); diff --git a/tests/baselines/reference/symbolType11.types b/tests/baselines/reference/symbolType11.types index 903c4ec0ecc..a7de59a11b7 100644 --- a/tests/baselines/reference/symbolType11.types +++ b/tests/baselines/reference/symbolType11.types @@ -28,12 +28,12 @@ s || s; >s : symbol s || 1; ->s || 1 : number | symbol +>s || 1 : symbol | number >s : symbol >1 : number ({}) || s; ->({}) || s : {} +>({}) || s : {} | symbol >({}) : {} >{} : {} >s : symbol diff --git a/tests/baselines/reference/systemModule11.js b/tests/baselines/reference/systemModule11.js index 55011214042..34dd0d3df5f 100644 --- a/tests/baselines/reference/systemModule11.js +++ b/tests/baselines/reference/systemModule11.js @@ -51,9 +51,11 @@ System.register(['bar'], function(exports_1) { 'foo': true }; function exportStar_1(m) { + var exports = {}; for(var n in m) { - if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports_1(n, m[n]); + if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n]; } + exports_1(exports); } return { setters:[ @@ -72,9 +74,11 @@ System.register(['bar'], function(exports_1) { 'y1': true }; function exportStar_1(m) { + var exports = {}; for(var n in m) { - if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports_1(n, m[n]); + if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n]; } + exports_1(exports); } return { setters:[ @@ -96,15 +100,19 @@ System.register(['a', 'bar'], function(exports_1) { 'z': true }; function exportStar_1(m) { + var exports = {}; for(var n in m) { - if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports_1(n, m[n]); + if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n]; } + exports_1(exports); } return { setters:[ function (_a_1) { - exports_1("x", _a_1["x"]); - exports_1("z", _a_1["y"]); + var reexports_1 = {}; + reexports_1["x"] = _a_1["x"]; + reexports_1["z"] = _a_1["y"]; + exports_1(reexports_1); }, function (_bar_1) { exportStar_1(_bar_1); @@ -123,8 +131,10 @@ System.register(['a'], function(exports_1) { return { setters:[ function (_a_1) { - exports_1("s", _a_1["s"]); - exports_1("s2", _a_1["s1"]); + var reexports_1 = {}; + reexports_1["s"] = _a_1["s"]; + reexports_1["s2"] = _a_1["s1"]; + exports_1(reexports_1); }], execute: function() { exports_1("z", z); @@ -136,9 +146,11 @@ System.register(['a'], function(exports_1) { System.register(['a'], function(exports_1) { function foo() { } function exportStar_1(m) { + var exports = {}; for(var n in m) { - if (n !== "default") exports_1(n, m[n]); + if (n !== "default") exports[n] = m[n]; } + exports_1(exports); } return { setters:[ diff --git a/tests/baselines/reference/systemModule13.symbols b/tests/baselines/reference/systemModule13.symbols index d9e64335c2b..8245029e006 100644 --- a/tests/baselines/reference/systemModule13.symbols +++ b/tests/baselines/reference/systemModule13.symbols @@ -6,7 +6,10 @@ export let [x,y,z] = [1, 2, 3]; >z : Symbol(z, Decl(systemModule13.ts, 1, 16)) export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; +>a : Symbol(a, Decl(systemModule13.ts, 2, 36)) >z0 : Symbol(z0, Decl(systemModule13.ts, 2, 14)) +>b : Symbol(b, Decl(systemModule13.ts, 2, 44)) +>c : Symbol(c, Decl(systemModule13.ts, 2, 49)) >z1 : Symbol(z1, Decl(systemModule13.ts, 2, 25)) >a : Symbol(a, Decl(systemModule13.ts, 2, 36)) >b : Symbol(b, Decl(systemModule13.ts, 2, 44)) diff --git a/tests/baselines/reference/systemModule8.symbols b/tests/baselines/reference/systemModule8.symbols index 3365ce7e37d..719d48e4592 100644 --- a/tests/baselines/reference/systemModule8.symbols +++ b/tests/baselines/reference/systemModule8.symbols @@ -78,7 +78,10 @@ export let [y] = [1]; >y : Symbol(y, Decl(systemModule8.ts, 27, 12)) export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; +>a : Symbol(a, Decl(systemModule8.ts, 28, 36)) >z0 : Symbol(z0, Decl(systemModule8.ts, 28, 14)) +>b : Symbol(b, Decl(systemModule8.ts, 28, 44)) +>c : Symbol(c, Decl(systemModule8.ts, 28, 49)) >z1 : Symbol(z1, Decl(systemModule8.ts, 28, 25)) >a : Symbol(a, Decl(systemModule8.ts, 28, 36)) >b : Symbol(b, Decl(systemModule8.ts, 28, 44)) diff --git a/tests/baselines/reference/systemModule9.js b/tests/baselines/reference/systemModule9.js index af05948c351..c282a47b686 100644 --- a/tests/baselines/reference/systemModule9.js +++ b/tests/baselines/reference/systemModule9.js @@ -30,9 +30,11 @@ System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7'], 'z': true }; function exportStar_1(m) { + var exports = {}; for(var n in m) { - if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports_1(n, m[n]); + if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n]; } + exports_1(exports); } return { setters:[ diff --git a/tests/baselines/reference/systemModuleWithSuperClass.js b/tests/baselines/reference/systemModuleWithSuperClass.js new file mode 100644 index 00000000000..3484606ee0e --- /dev/null +++ b/tests/baselines/reference/systemModuleWithSuperClass.js @@ -0,0 +1,55 @@ +//// [tests/cases/compiler/systemModuleWithSuperClass.ts] //// + +//// [foo.ts] + +export class Foo { + a: string; +} + +//// [bar.ts] +import {Foo} from './foo'; +export class Bar extends Foo { + b: string; +} + +//// [foo.js] +System.register([], function(exports_1) { + var Foo; + return { + setters:[], + execute: function() { + Foo = (function () { + function Foo() { + } + return Foo; + })(); + exports_1("Foo", Foo); + } + } +}); +//// [bar.js] +System.register(['./foo'], function(exports_1) { + var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + var foo_1; + var Bar; + return { + setters:[ + function (_foo_1) { + foo_1 = _foo_1; + }], + execute: function() { + Bar = (function (_super) { + __extends(Bar, _super); + function Bar() { + _super.apply(this, arguments); + } + return Bar; + })(foo_1.Foo); + exports_1("Bar", Bar); + } + } +}); diff --git a/tests/baselines/reference/systemModuleWithSuperClass.symbols b/tests/baselines/reference/systemModuleWithSuperClass.symbols new file mode 100644 index 00000000000..46354333479 --- /dev/null +++ b/tests/baselines/reference/systemModuleWithSuperClass.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/foo.ts === + +export class Foo { +>Foo : Symbol(Foo, Decl(foo.ts, 0, 0)) + + a: string; +>a : Symbol(a, Decl(foo.ts, 1, 18)) +} + +=== tests/cases/compiler/bar.ts === +import {Foo} from './foo'; +>Foo : Symbol(Foo, Decl(bar.ts, 0, 8)) + +export class Bar extends Foo { +>Bar : Symbol(Bar, Decl(bar.ts, 0, 26)) +>Foo : Symbol(Foo, Decl(bar.ts, 0, 8)) + + b: string; +>b : Symbol(b, Decl(bar.ts, 1, 30)) +} diff --git a/tests/baselines/reference/systemModuleWithSuperClass.types b/tests/baselines/reference/systemModuleWithSuperClass.types new file mode 100644 index 00000000000..130f53f0ce3 --- /dev/null +++ b/tests/baselines/reference/systemModuleWithSuperClass.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/foo.ts === + +export class Foo { +>Foo : Foo + + a: string; +>a : string +} + +=== tests/cases/compiler/bar.ts === +import {Foo} from './foo'; +>Foo : typeof Foo + +export class Bar extends Foo { +>Bar : Bar +>Foo : Foo + + b: string; +>b : string +} diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt index f3706ae8f17..6464366d33d 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts(77,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; z: Date; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. - Property 'z' is missing in type '{ x: number; y: string; }'. + Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; z: Date; }'. ==== tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts (2 errors) ==== @@ -89,7 +89,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference ~~~~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; z: Date; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. -!!! error TS2453: Property 'z' is missing in type '{ x: number; y: string; }'. +!!! error TS2453: Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; z: Date; }'. var a9e: {}; // Generic tag with multiple parameters of generic type passed arguments with a single best common type diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt index 1a4a1dc5aac..be8c517d39c 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInferenceES6.ts(76,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; z: Date; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. - Property 'z' is missing in type '{ x: number; y: string; }'. + Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; z: Date; }'. ==== tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInferenceES6.ts (2 errors) ==== @@ -88,7 +88,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference ~~~~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; z: Date; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. -!!! error TS2453: Property 'z' is missing in type '{ x: number; y: string; }'. +!!! error TS2453: Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; z: Date; }'. var a9e: {}; // Generic tag with multiple parameters of generic type passed arguments with a single best common type diff --git a/tests/baselines/reference/targetTypeTest2.types b/tests/baselines/reference/targetTypeTest2.types index 25b36f948c6..53381b9de43 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"] : (string | number)[] +>[1,2,"3"] : (number | string)[] >1 : number >2 : number >"3" : string diff --git a/tests/baselines/reference/targetTypeTest3.errors.txt b/tests/baselines/reference/targetTypeTest3.errors.txt index f5dab732ed3..935a9b9e68e 100644 --- a/tests/baselines/reference/targetTypeTest3.errors.txt +++ b/tests/baselines/reference/targetTypeTest3.errors.txt @@ -1,5 +1,5 @@ -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'. +tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type '(number | string)[]' is not assignable to type 'string[]'. + Type 'number | string' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. @@ -9,8 +9,8 @@ tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type '(string | numb var a : string[] = [1,2,"3"]; // should produce an error ~ -!!! 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 | string)[]' is not assignable to type 'string[]'. +!!! error TS2322: Type 'number | string' is not assignable to type 'string'. !!! error TS2322: Type 'number' is not assignable to type 'string'. diff --git a/tests/baselines/reference/templateStringInArray.types b/tests/baselines/reference/templateStringInArray.types index 04cc09a1005..aec30c02e00 100644 --- a/tests/baselines/reference/templateStringInArray.types +++ b/tests/baselines/reference/templateStringInArray.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/templates/templateStringInArray.ts === var x = [1, 2, `abc${ 123 }def`]; ->x : (string | number)[] ->[1, 2, `abc${ 123 }def`] : (string | number)[] +>x : (number | string)[] +>[1, 2, `abc${ 123 }def`] : (number | string)[] >1 : number >2 : number >`abc${ 123 }def` : string diff --git a/tests/baselines/reference/templateStringWithEmbeddedConditional.types b/tests/baselines/reference/templateStringWithEmbeddedConditional.types index 7ec1ef97a30..2a741dc271b 100644 --- a/tests/baselines/reference/templateStringWithEmbeddedConditional.types +++ b/tests/baselines/reference/templateStringWithEmbeddedConditional.types @@ -2,7 +2,7 @@ var x = `abc${ true ? false : " " }def`; >x : string >`abc${ true ? false : " " }def` : string ->true ? false : " " : string | boolean +>true ? false : " " : boolean | string >true : boolean >false : boolean >" " : string diff --git a/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.types b/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.types index 5453880ce16..d0a228ee673 100644 --- a/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.types +++ b/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.types @@ -2,7 +2,7 @@ var x = `abc${ true ? false : " " }def`; >x : string >`abc${ true ? false : " " }def` : string ->true ? false : " " : string | boolean +>true ? false : " " : boolean | string >true : boolean >false : boolean >" " : string diff --git a/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt b/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt index b502eaad7e5..498e74ce350 100644 --- a/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt +++ b/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt @@ -1,8 +1,8 @@ -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'. +tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(5,19): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. + Type 'number | string' 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'. +tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. + Type 'number | string' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. @@ -13,13 +13,13 @@ 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 '(string | number)[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type 'string | number' is not assignable to type 'number'. +!!! error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'number | string' 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 '(string | number)[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type 'string | number' is not assignable to type 'number'. +!!! error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'number | string' is not assignable to type 'number'. !!! error TS2345: Type 'string' is not assignable to type 'number'. } } diff --git a/tests/baselines/reference/tsxAttributeResolution9.symbols b/tests/baselines/reference/tsxAttributeResolution9.symbols deleted file mode 100644 index 081482d5d47..00000000000 --- a/tests/baselines/reference/tsxAttributeResolution9.symbols +++ /dev/null @@ -1,47 +0,0 @@ -=== tests/cases/conformance/jsx/react.d.ts === - -declare module JSX { ->JSX : Symbol(JSX, Decl(react.d.ts, 0, 0)) - - interface Element { } ->Element : Symbol(Element, Decl(react.d.ts, 1, 20)) - - interface IntrinsicElements { ->IntrinsicElements : Symbol(IntrinsicElements, Decl(react.d.ts, 2, 22)) - } - interface ElementAttributesProperty { ->ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(react.d.ts, 4, 2)) - - props; ->props : Symbol(props, Decl(react.d.ts, 5, 38)) - } -} - -interface Props { ->Props : Symbol(Props, Decl(react.d.ts, 8, 1)) - - foo: string; ->foo : Symbol(foo, Decl(react.d.ts, 10, 17)) -} - -=== tests/cases/conformance/jsx/file.tsx === -export class MyComponent { ->MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) - - render() { ->render : Symbol(render, Decl(file.tsx, 0, 26)) - } - - props: { foo: string; } ->props : Symbol(props, Decl(file.tsx, 2, 3)) ->foo : Symbol(foo, Decl(file.tsx, 4, 10)) -} - -; // ok ->MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) ->foo : Symbol(unknown) - -; // should be an error ->MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) ->foo : Symbol(unknown) - diff --git a/tests/baselines/reference/tsxAttributeResolution9.types b/tests/baselines/reference/tsxAttributeResolution9.types deleted file mode 100644 index 1b2c6d42389..00000000000 --- a/tests/baselines/reference/tsxAttributeResolution9.types +++ /dev/null @@ -1,49 +0,0 @@ -=== tests/cases/conformance/jsx/react.d.ts === - -declare module JSX { ->JSX : any - - interface Element { } ->Element : Element - - interface IntrinsicElements { ->IntrinsicElements : IntrinsicElements - } - interface ElementAttributesProperty { ->ElementAttributesProperty : ElementAttributesProperty - - props; ->props : any - } -} - -interface Props { ->Props : Props - - foo: string; ->foo : string -} - -=== tests/cases/conformance/jsx/file.tsx === -export class MyComponent { ->MyComponent : MyComponent - - render() { ->render : () => void - } - - props: { foo: string; } ->props : { foo: string; } ->foo : string -} - -; // ok -> : JSX.Element ->MyComponent : typeof MyComponent ->foo : any - -; // should be an error -> : JSX.Element ->MyComponent : typeof MyComponent ->foo : any - diff --git a/tests/baselines/reference/tsxElementResolution8.errors.txt b/tests/baselines/reference/tsxElementResolution8.errors.txt index 5710c4e177d..92ff05d1aed 100644 --- a/tests/baselines/reference/tsxElementResolution8.errors.txt +++ b/tests/baselines/reference/tsxElementResolution8.errors.txt @@ -1,10 +1,8 @@ tests/cases/conformance/jsx/tsxElementResolution8.tsx(8,2): error TS2604: JSX element type 'Div' does not have any construct or call signatures. -tests/cases/conformance/jsx/tsxElementResolution8.tsx(16,2): error TS2601: The return type of a JSX element constructor must return an object type. -tests/cases/conformance/jsx/tsxElementResolution8.tsx(29,2): error TS2601: The return type of a JSX element constructor must return an object type. tests/cases/conformance/jsx/tsxElementResolution8.tsx(34,2): error TS2604: JSX element type 'Obj3' does not have any construct or call signatures. -==== tests/cases/conformance/jsx/tsxElementResolution8.tsx (4 errors) ==== +==== tests/cases/conformance/jsx/tsxElementResolution8.tsx (2 errors) ==== declare module JSX { interface Element { } interface IntrinsicElements { } @@ -23,8 +21,6 @@ tests/cases/conformance/jsx/tsxElementResolution8.tsx(34,2): error TS2604: JSX e // Error function Fnum(): number{ return 42; } - ~~~~ -!!! error TS2601: The return type of a JSX element constructor must return an object type. interface Obj1 { new(): {}; @@ -38,8 +34,6 @@ tests/cases/conformance/jsx/tsxElementResolution8.tsx(34,2): error TS2604: JSX e } var Obj2: Obj2; ; // Error - ~~~~ -!!! error TS2601: The return type of a JSX element constructor must return an object type. interface Obj3 { } diff --git a/tests/baselines/reference/tsxElementResolution9.errors.txt b/tests/baselines/reference/tsxElementResolution9.errors.txt deleted file mode 100644 index f4412719b33..00000000000 --- a/tests/baselines/reference/tsxElementResolution9.errors.txt +++ /dev/null @@ -1,35 +0,0 @@ -tests/cases/conformance/jsx/tsxElementResolution9.tsx(11,2): error TS2601: The return type of a JSX element constructor must return an object type. -tests/cases/conformance/jsx/tsxElementResolution9.tsx(18,2): error TS2601: The return type of a JSX element constructor must return an object type. - - -==== tests/cases/conformance/jsx/tsxElementResolution9.tsx (2 errors) ==== - declare module JSX { - interface Element { } - interface IntrinsicElements { } - } - - interface Obj1 { - new(n: string): { x: number }; - new(n: number): { y: string }; - } - var Obj1: Obj1; - ; // Error, return type is not an object type - ~~~~ -!!! error TS2601: The return type of a JSX element constructor must return an object type. - - interface Obj2 { - (n: string): { x: number }; - (n: number): { y: string }; - } - var Obj2: Obj2; - ; // Error, return type is not an object type - ~~~~ -!!! error TS2601: The return type of a JSX element constructor must return an object type. - - interface Obj3 { - (n: string): { x: number }; - (n: number): { x: number; y: string }; - } - var Obj3: Obj3; - ; // OK - \ No newline at end of file diff --git a/tests/baselines/reference/tsxElementResolution9.symbols b/tests/baselines/reference/tsxElementResolution9.symbols new file mode 100644 index 00000000000..bfa04219ef9 --- /dev/null +++ b/tests/baselines/reference/tsxElementResolution9.symbols @@ -0,0 +1,67 @@ +=== tests/cases/conformance/jsx/tsxElementResolution9.tsx === +declare module JSX { +>JSX : Symbol(JSX, Decl(tsxElementResolution9.tsx, 0, 0)) + + interface Element { } +>Element : Symbol(Element, Decl(tsxElementResolution9.tsx, 0, 20)) + + interface IntrinsicElements { } +>IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxElementResolution9.tsx, 1, 22)) +} + +interface Obj1 { +>Obj1 : Symbol(Obj1, Decl(tsxElementResolution9.tsx, 3, 1), Decl(tsxElementResolution9.tsx, 9, 3)) + + new(n: string): { x: number }; +>n : Symbol(n, Decl(tsxElementResolution9.tsx, 6, 5)) +>x : Symbol(x, Decl(tsxElementResolution9.tsx, 6, 18)) + + new(n: number): { y: string }; +>n : Symbol(n, Decl(tsxElementResolution9.tsx, 7, 5)) +>y : Symbol(y, Decl(tsxElementResolution9.tsx, 7, 18)) +} +var Obj1: Obj1; +>Obj1 : Symbol(Obj1, Decl(tsxElementResolution9.tsx, 3, 1), Decl(tsxElementResolution9.tsx, 9, 3)) +>Obj1 : Symbol(Obj1, Decl(tsxElementResolution9.tsx, 3, 1), Decl(tsxElementResolution9.tsx, 9, 3)) + +; // Error, return type is not an object type +>Obj1 : Symbol(Obj1, Decl(tsxElementResolution9.tsx, 3, 1), Decl(tsxElementResolution9.tsx, 9, 3)) + +interface Obj2 { +>Obj2 : Symbol(Obj2, Decl(tsxElementResolution9.tsx, 10, 9), Decl(tsxElementResolution9.tsx, 16, 3)) + + (n: string): { x: number }; +>n : Symbol(n, Decl(tsxElementResolution9.tsx, 13, 2)) +>x : Symbol(x, Decl(tsxElementResolution9.tsx, 13, 15)) + + (n: number): { y: string }; +>n : Symbol(n, Decl(tsxElementResolution9.tsx, 14, 2)) +>y : Symbol(y, Decl(tsxElementResolution9.tsx, 14, 15)) +} +var Obj2: Obj2; +>Obj2 : Symbol(Obj2, Decl(tsxElementResolution9.tsx, 10, 9), Decl(tsxElementResolution9.tsx, 16, 3)) +>Obj2 : Symbol(Obj2, Decl(tsxElementResolution9.tsx, 10, 9), Decl(tsxElementResolution9.tsx, 16, 3)) + +; // Error, return type is not an object type +>Obj2 : Symbol(Obj2, Decl(tsxElementResolution9.tsx, 10, 9), Decl(tsxElementResolution9.tsx, 16, 3)) + +interface Obj3 { +>Obj3 : Symbol(Obj3, Decl(tsxElementResolution9.tsx, 17, 9), Decl(tsxElementResolution9.tsx, 23, 3)) + + (n: string): { x: number }; +>n : Symbol(n, Decl(tsxElementResolution9.tsx, 20, 2)) +>x : Symbol(x, Decl(tsxElementResolution9.tsx, 20, 15)) + + (n: number): { x: number; y: string }; +>n : Symbol(n, Decl(tsxElementResolution9.tsx, 21, 2)) +>x : Symbol(x, Decl(tsxElementResolution9.tsx, 21, 15)) +>y : Symbol(y, Decl(tsxElementResolution9.tsx, 21, 26)) +} +var Obj3: Obj3; +>Obj3 : Symbol(Obj3, Decl(tsxElementResolution9.tsx, 17, 9), Decl(tsxElementResolution9.tsx, 23, 3)) +>Obj3 : Symbol(Obj3, Decl(tsxElementResolution9.tsx, 17, 9), Decl(tsxElementResolution9.tsx, 23, 3)) + +; // OK +>Obj3 : Symbol(Obj3, Decl(tsxElementResolution9.tsx, 17, 9), Decl(tsxElementResolution9.tsx, 23, 3)) +>x : Symbol(unknown) + diff --git a/tests/baselines/reference/tsxElementResolution9.types b/tests/baselines/reference/tsxElementResolution9.types new file mode 100644 index 00000000000..525e4600b2e --- /dev/null +++ b/tests/baselines/reference/tsxElementResolution9.types @@ -0,0 +1,70 @@ +=== tests/cases/conformance/jsx/tsxElementResolution9.tsx === +declare module JSX { +>JSX : any + + interface Element { } +>Element : Element + + interface IntrinsicElements { } +>IntrinsicElements : IntrinsicElements +} + +interface Obj1 { +>Obj1 : Obj1 + + new(n: string): { x: number }; +>n : string +>x : number + + new(n: number): { y: string }; +>n : number +>y : string +} +var Obj1: Obj1; +>Obj1 : Obj1 +>Obj1 : Obj1 + +; // Error, return type is not an object type +> : JSX.Element +>Obj1 : Obj1 + +interface Obj2 { +>Obj2 : Obj2 + + (n: string): { x: number }; +>n : string +>x : number + + (n: number): { y: string }; +>n : number +>y : string +} +var Obj2: Obj2; +>Obj2 : Obj2 +>Obj2 : Obj2 + +; // Error, return type is not an object type +> : JSX.Element +>Obj2 : Obj2 + +interface Obj3 { +>Obj3 : Obj3 + + (n: string): { x: number }; +>n : string +>x : number + + (n: number): { x: number; y: string }; +>n : number +>x : number +>y : string +} +var Obj3: Obj3; +>Obj3 : Obj3 +>Obj3 : Obj3 + +; // OK +> : JSX.Element +>Obj3 : Obj3 +>x : any + diff --git a/tests/baselines/reference/tsxEmit1.symbols b/tests/baselines/reference/tsxEmit1.symbols index 284f6cd9ce7..b7c8cde024a 100644 --- a/tests/baselines/reference/tsxEmit1.symbols +++ b/tests/baselines/reference/tsxEmit1.symbols @@ -57,16 +57,19 @@ var selfClosed7 =
; var openClosed1 =
; >openClosed1 : Symbol(openClosed1, Decl(tsxEmit1.tsx, 16, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) var openClosed2 =
foo
; >openClosed2 : Symbol(openClosed2, Decl(tsxEmit1.tsx, 17, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) >n : Symbol(unknown) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) var openClosed3 =
{p}
; >openClosed3 : Symbol(openClosed3, Decl(tsxEmit1.tsx, 18, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) >n : Symbol(unknown) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) var openClosed4 =
{p < p}
; >openClosed4 : Symbol(openClosed4, Decl(tsxEmit1.tsx, 19, 3)) @@ -74,6 +77,7 @@ var openClosed4 =
{p < p}
; >n : Symbol(unknown) >p : Symbol(p, Decl(tsxEmit1.tsx, 7, 3)) >p : Symbol(p, Decl(tsxEmit1.tsx, 7, 3)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) var openClosed5 =
{p > p}
; >openClosed5 : Symbol(openClosed5, Decl(tsxEmit1.tsx, 20, 3)) @@ -81,6 +85,7 @@ var openClosed5 =
{p > p}
; >n : Symbol(unknown) >p : Symbol(p, Decl(tsxEmit1.tsx, 7, 3)) >p : Symbol(p, Decl(tsxEmit1.tsx, 7, 3)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) class SomeClass { >SomeClass : Symbol(SomeClass, Decl(tsxEmit1.tsx, 20, 43)) @@ -92,6 +97,7 @@ class SomeClass { >rewrites1 : Symbol(rewrites1, Decl(tsxEmit1.tsx, 24, 5)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) >this : Symbol(SomeClass, Decl(tsxEmit1.tsx, 20, 43)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) var rewrites2 =
{[p, ...p, p]}
; >rewrites2 : Symbol(rewrites2, Decl(tsxEmit1.tsx, 25, 5)) @@ -99,17 +105,20 @@ class SomeClass { >p : Symbol(p, Decl(tsxEmit1.tsx, 7, 3)) >p : Symbol(p, Decl(tsxEmit1.tsx, 7, 3)) >p : Symbol(p, Decl(tsxEmit1.tsx, 7, 3)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) var rewrites3 =
{{p}}
; >rewrites3 : Symbol(rewrites3, Decl(tsxEmit1.tsx, 26, 5)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) >p : Symbol(p, Decl(tsxEmit1.tsx, 26, 25)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) var rewrites4 =
this}>
; >rewrites4 : Symbol(rewrites4, Decl(tsxEmit1.tsx, 28, 5)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) >a : Symbol(unknown) >this : Symbol(SomeClass, Decl(tsxEmit1.tsx, 20, 43)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) var rewrites5 =
; >rewrites5 : Symbol(rewrites5, Decl(tsxEmit1.tsx, 29, 5)) @@ -118,22 +127,26 @@ class SomeClass { >p : Symbol(p, Decl(tsxEmit1.tsx, 7, 3)) >p : Symbol(p, Decl(tsxEmit1.tsx, 7, 3)) >p : Symbol(p, Decl(tsxEmit1.tsx, 7, 3)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) var rewrites6 =
; >rewrites6 : Symbol(rewrites6, Decl(tsxEmit1.tsx, 30, 5)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) >a : Symbol(unknown) >p : Symbol(p, Decl(tsxEmit1.tsx, 30, 27)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) } } var whitespace1 =
; >whitespace1 : Symbol(whitespace1, Decl(tsxEmit1.tsx, 34, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) var whitespace2 =
{p}
; >whitespace2 : Symbol(whitespace2, Decl(tsxEmit1.tsx, 35, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) var whitespace3 =
>whitespace3 : Symbol(whitespace3, Decl(tsxEmit1.tsx, 36, 3)) @@ -141,4 +154,5 @@ var whitespace3 =
{p}
; +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit1.tsx, 1, 22)) diff --git a/tests/baselines/reference/tsxEmit2.symbols b/tests/baselines/reference/tsxEmit2.symbols index 28f6a9f5026..fd568953493 100644 --- a/tests/baselines/reference/tsxEmit2.symbols +++ b/tests/baselines/reference/tsxEmit2.symbols @@ -21,24 +21,29 @@ var p1, p2, p3; var spreads1 =
{p2}
; >spreads1 : Symbol(spreads1, Decl(tsxEmit2.tsx, 8, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit2.tsx, 1, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit2.tsx, 1, 22)) var spreads2 =
{p2}
; >spreads2 : Symbol(spreads2, Decl(tsxEmit2.tsx, 9, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit2.tsx, 1, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit2.tsx, 1, 22)) var spreads3 =
{p2}
; >spreads3 : Symbol(spreads3, Decl(tsxEmit2.tsx, 10, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit2.tsx, 1, 22)) >x : Symbol(unknown) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit2.tsx, 1, 22)) var spreads4 =
{p2}
; >spreads4 : Symbol(spreads4, Decl(tsxEmit2.tsx, 11, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit2.tsx, 1, 22)) >x : Symbol(unknown) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit2.tsx, 1, 22)) var spreads5 =
{p2}
; >spreads5 : Symbol(spreads5, Decl(tsxEmit2.tsx, 12, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit2.tsx, 1, 22)) >x : Symbol(unknown) >y : Symbol(unknown) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxEmit2.tsx, 1, 22)) diff --git a/tests/baselines/reference/tsxEmit3.js b/tests/baselines/reference/tsxEmit3.js index beae73e2bf1..aa958a0c79b 100644 --- a/tests/baselines/reference/tsxEmit3.js +++ b/tests/baselines/reference/tsxEmit3.js @@ -1,4 +1,5 @@ //// [tsxEmit3.tsx] + declare module JSX { interface Element { } interface IntrinsicElements { } @@ -82,3 +83,4 @@ var M; // Emit M_1.Foo M_1.Foo, ; })(M || (M = {})); +//# sourceMappingURL=tsxEmit3.jsx.map \ No newline at end of file diff --git a/tests/baselines/reference/tsxEmit3.js.map b/tests/baselines/reference/tsxEmit3.js.map new file mode 100644 index 00000000000..895a8283ba5 --- /dev/null +++ b/tests/baselines/reference/tsxEmit3.js.map @@ -0,0 +1,2 @@ +//// [tsxEmit3.jsx.map] +{"version":3,"file":"tsxEmit3.jsx","sourceRoot":"","sources":["tsxEmit3.tsx"],"names":["M","M.Foo","M.Foo.constructor","M.S","M.S.Bar","M.S.Bar.constructor"],"mappings":"AAMA,IAAO,CAAC,CAQP;AARD,WAAO,CAAC,EAAC,CAAC;IACTA;QAAmBC;QAAgBC,CAACA;QAACD,UAACA;IAADA,CAACA,AAAtCD,IAAsCA;IAAzBA,KAAGA,MAAsBA,CAAAA;IACtCA,IAAcA,CAACA,CAKdA;IALDA,WAAcA,CAACA,EAACA,CAACA;QAChBG;YAAAC;YAAmBC,CAACA;YAADD,UAACA;QAADA,CAACA,AAApBD,IAAoBA;QAAPA,KAAGA,MAAIA,CAAAA;IAIrBA,CAACA,EALaH,CAACA,GAADA,GAACA,KAADA,GAACA,QAKdA;AACFA,CAACA,EARM,CAAC,KAAD,CAAC,QAQP;AAED,IAAO,CAAC,CAYP;AAZD,WAAO,CAAC,EAAC,CAAC;IAETA,AADAA,aAAaA;IACbA,KAAGA,EAAEA,CAACA,KAAGA,GAAGA,CAACA;IAEbA,IAAcA,CAACA,CAMdA;IANDA,WAAcA,CAACA,EAACA,CAACA;QAEhBG,AADAA,aAAaA;QACbA,KAAGA,EAAEA,CAACA,KAAGA,GAAGA,CAACA;QAGbA,AADAA,aAAaA;QACbA,KAAGA,EAAEA,CAACA,KAAGA,GAAGA,CAACA;IACdA,CAACA,EANaH,CAACA,GAADA,GAACA,KAADA,GAACA,QAMdA;AAEFA,CAACA,EAZM,CAAC,KAAD,CAAC,QAYP;AAED,IAAO,CAAC,CAGP;AAHD,WAAO,CAAC,EAAC,CAAC;IAETA,AADAA,eAAeA;IACfA,GAACA,CAACA,GAAGA,EAAEA,CAACA,GAACA,CAACA,GAAGA,GAAGA,CAACA;AAClBA,CAACA,EAHM,CAAC,KAAD,CAAC,QAGP;AAED,IAAO,CAAC,CAIP;AAJD,WAAO,GAAC,EAAC,CAAC;IACTA,IAAIA,CAACA,GAAGA,GAAGA,CAACA;IAEZA,AADAA,eAAeA;IACfA,OAAGA,EAAEA,CAACA,OAAGA,GAAGA,CAACA;AACdA,CAACA,EAJM,CAAC,KAAD,CAAC,QAIP"} \ No newline at end of file diff --git a/tests/baselines/reference/tsxEmit3.sourcemap.txt b/tests/baselines/reference/tsxEmit3.sourcemap.txt new file mode 100644 index 00000000000..293e6480fb8 --- /dev/null +++ b/tests/baselines/reference/tsxEmit3.sourcemap.txt @@ -0,0 +1,805 @@ +=================================================================== +JsFile: tsxEmit3.jsx +mapUrl: tsxEmit3.jsx.map +sourceRoot: +sources: tsxEmit3.tsx +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/conformance/jsx/tsxEmit3.jsx +sourceFile:tsxEmit3.tsx +------------------------------------------------------------------- +>>>var M; +1 > +2 >^^^^ +3 > ^ +4 > ^ +5 > ^^^^^^^^^^-> +1 > + >declare module JSX { + > interface Element { } + > interface IntrinsicElements { } + >} + > + > +2 >module +3 > M +4 > { + > export class Foo { constructor() { } } + > export module S { + > export class Bar { } + > + > // Emit Foo + > // Foo, ; + > } + > } +1 >Emitted(1, 1) Source(7, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(7, 8) + SourceIndex(0) +3 >Emitted(1, 6) Source(7, 9) + SourceIndex(0) +4 >Emitted(1, 7) Source(15, 2) + SourceIndex(0) +--- +>>>(function (M) { +1-> +2 >^^^^^^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +6 > ^^^^^^^^^^^^^^-> +1-> +2 >module +3 > M +4 > +5 > { +1->Emitted(2, 1) Source(7, 1) + SourceIndex(0) +2 >Emitted(2, 12) Source(7, 8) + SourceIndex(0) +3 >Emitted(2, 13) Source(7, 9) + SourceIndex(0) +4 >Emitted(2, 15) Source(7, 10) + SourceIndex(0) +5 >Emitted(2, 16) Source(7, 11) + SourceIndex(0) +--- +>>> var Foo = (function () { +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^-> +1-> + > +1->Emitted(3, 5) Source(8, 2) + SourceIndex(0) name (M) +--- +>>> function Foo() { +1->^^^^^^^^ +2 > ^^-> +1->export class Foo { +1->Emitted(4, 9) Source(8, 21) + SourceIndex(0) name (M.Foo) +--- +>>> } +1->^^^^^^^^ +2 > ^ +3 > ^^^^^^^^^^^-> +1->constructor() { +2 > } +1->Emitted(5, 9) Source(8, 37) + SourceIndex(0) name (M.Foo.constructor) +2 >Emitted(5, 10) Source(8, 38) + SourceIndex(0) name (M.Foo.constructor) +--- +>>> return Foo; +1->^^^^^^^^ +2 > ^^^^^^^^^^ +1-> +2 > } +1->Emitted(6, 9) Source(8, 39) + SourceIndex(0) name (M.Foo) +2 >Emitted(6, 19) Source(8, 40) + SourceIndex(0) name (M.Foo) +--- +>>> })(); +1 >^^^^ +2 > ^ +3 > +4 > ^^^^ +5 > ^^^^^^^^-> +1 > +2 > } +3 > +4 > export class Foo { constructor() { } } +1 >Emitted(7, 5) Source(8, 39) + SourceIndex(0) name (M.Foo) +2 >Emitted(7, 6) Source(8, 40) + SourceIndex(0) name (M.Foo) +3 >Emitted(7, 6) Source(8, 2) + SourceIndex(0) name (M) +4 >Emitted(7, 10) Source(8, 40) + SourceIndex(0) name (M) +--- +>>> M.Foo = Foo; +1->^^^^ +2 > ^^^^^ +3 > ^^^^^^ +4 > ^ +1-> +2 > Foo +3 > { constructor() { } } +4 > +1->Emitted(8, 5) Source(8, 15) + SourceIndex(0) name (M) +2 >Emitted(8, 10) Source(8, 18) + SourceIndex(0) name (M) +3 >Emitted(8, 16) Source(8, 40) + SourceIndex(0) name (M) +4 >Emitted(8, 17) Source(8, 40) + SourceIndex(0) name (M) +--- +>>> var S; +1 >^^^^ +2 > ^^^^ +3 > ^ +4 > ^ +5 > ^^^^^^^^^^-> +1 > + > +2 > export module +3 > S +4 > { + > export class Bar { } + > + > // Emit Foo + > // Foo, ; + > } +1 >Emitted(9, 5) Source(9, 2) + SourceIndex(0) name (M) +2 >Emitted(9, 9) Source(9, 16) + SourceIndex(0) name (M) +3 >Emitted(9, 10) Source(9, 17) + SourceIndex(0) name (M) +4 >Emitted(9, 11) Source(14, 3) + SourceIndex(0) name (M) +--- +>>> (function (S) { +1->^^^^ +2 > ^^^^^^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +6 > ^^^^^^^^^^^^^^-> +1-> +2 > export module +3 > S +4 > +5 > { +1->Emitted(10, 5) Source(9, 2) + SourceIndex(0) name (M) +2 >Emitted(10, 16) Source(9, 16) + SourceIndex(0) name (M) +3 >Emitted(10, 17) Source(9, 17) + SourceIndex(0) name (M) +4 >Emitted(10, 19) Source(9, 18) + SourceIndex(0) name (M) +5 >Emitted(10, 20) Source(9, 19) + SourceIndex(0) name (M) +--- +>>> var Bar = (function () { +1->^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^-> +1-> + > +1->Emitted(11, 9) Source(10, 3) + SourceIndex(0) name (M.S) +--- +>>> function Bar() { +1->^^^^^^^^^^^^ +2 > ^^-> +1-> +1->Emitted(12, 13) Source(10, 3) + SourceIndex(0) name (M.S.Bar) +--- +>>> } +1->^^^^^^^^^^^^ +2 > ^ +3 > ^^^^^^^^^^^-> +1->export class Bar { +2 > } +1->Emitted(13, 13) Source(10, 22) + SourceIndex(0) name (M.S.Bar.constructor) +2 >Emitted(13, 14) Source(10, 23) + SourceIndex(0) name (M.S.Bar.constructor) +--- +>>> return Bar; +1->^^^^^^^^^^^^ +2 > ^^^^^^^^^^ +1-> +2 > } +1->Emitted(14, 13) Source(10, 22) + SourceIndex(0) name (M.S.Bar) +2 >Emitted(14, 23) Source(10, 23) + SourceIndex(0) name (M.S.Bar) +--- +>>> })(); +1 >^^^^^^^^ +2 > ^ +3 > +4 > ^^^^ +5 > ^^^^^^^^-> +1 > +2 > } +3 > +4 > export class Bar { } +1 >Emitted(15, 9) Source(10, 22) + SourceIndex(0) name (M.S.Bar) +2 >Emitted(15, 10) Source(10, 23) + SourceIndex(0) name (M.S.Bar) +3 >Emitted(15, 10) Source(10, 3) + SourceIndex(0) name (M.S) +4 >Emitted(15, 14) Source(10, 23) + SourceIndex(0) name (M.S) +--- +>>> S.Bar = Bar; +1->^^^^^^^^ +2 > ^^^^^ +3 > ^^^^^^ +4 > ^ +5 > ^^^^^^^^^^^-> +1-> +2 > Bar +3 > { } +4 > +1->Emitted(16, 9) Source(10, 16) + SourceIndex(0) name (M.S) +2 >Emitted(16, 14) Source(10, 19) + SourceIndex(0) name (M.S) +3 >Emitted(16, 20) Source(10, 23) + SourceIndex(0) name (M.S) +4 >Emitted(16, 21) Source(10, 23) + SourceIndex(0) name (M.S) +--- +>>> })(S = M.S || (M.S = {})); +1->^^^^ +2 > ^ +3 > ^^ +4 > ^ +5 > ^^^ +6 > ^^^ +7 > ^^^^^ +8 > ^^^ +9 > ^^^^^^^^ +1-> + > + > // Emit Foo + > // Foo, ; + > +2 > } +3 > +4 > S +5 > +6 > S +7 > +8 > S +9 > { + > export class Bar { } + > + > // Emit Foo + > // Foo, ; + > } +1->Emitted(17, 5) Source(14, 2) + SourceIndex(0) name (M.S) +2 >Emitted(17, 6) Source(14, 3) + SourceIndex(0) name (M.S) +3 >Emitted(17, 8) Source(9, 16) + SourceIndex(0) name (M) +4 >Emitted(17, 9) Source(9, 17) + SourceIndex(0) name (M) +5 >Emitted(17, 12) Source(9, 16) + SourceIndex(0) name (M) +6 >Emitted(17, 15) Source(9, 17) + SourceIndex(0) name (M) +7 >Emitted(17, 20) Source(9, 16) + SourceIndex(0) name (M) +8 >Emitted(17, 23) Source(9, 17) + SourceIndex(0) name (M) +9 >Emitted(17, 31) Source(14, 3) + SourceIndex(0) name (M) +--- +>>>})(M || (M = {})); +1 > +2 >^ +3 > ^^ +4 > ^ +5 > ^^^^^ +6 > ^ +7 > ^^^^^^^^ +1 > + > +2 >} +3 > +4 > M +5 > +6 > M +7 > { + > export class Foo { constructor() { } } + > export module S { + > export class Bar { } + > + > // Emit Foo + > // Foo, ; + > } + > } +1 >Emitted(18, 1) Source(15, 1) + SourceIndex(0) name (M) +2 >Emitted(18, 2) Source(15, 2) + SourceIndex(0) name (M) +3 >Emitted(18, 4) Source(7, 8) + SourceIndex(0) +4 >Emitted(18, 5) Source(7, 9) + SourceIndex(0) +5 >Emitted(18, 10) Source(7, 8) + SourceIndex(0) +6 >Emitted(18, 11) Source(7, 9) + SourceIndex(0) +7 >Emitted(18, 19) Source(15, 2) + SourceIndex(0) +--- +>>>var M; +1 > +2 >^^^^ +3 > ^ +4 > ^ +5 > ^^^^^^^^^^-> +1 > + > + > +2 >module +3 > M +4 > { + > // Emit M.Foo + > Foo, ; + > + > export module S { + > // Emit M.Foo + > Foo, ; + > + > // Emit S.Bar + > Bar, ; + > } + > + > } +1 >Emitted(19, 1) Source(17, 1) + SourceIndex(0) +2 >Emitted(19, 5) Source(17, 8) + SourceIndex(0) +3 >Emitted(19, 6) Source(17, 9) + SourceIndex(0) +4 >Emitted(19, 7) Source(29, 2) + SourceIndex(0) +--- +>>>(function (M) { +1-> +2 >^^^^^^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +6 > ^^^-> +1-> +2 >module +3 > M +4 > +5 > { +1->Emitted(20, 1) Source(17, 1) + SourceIndex(0) +2 >Emitted(20, 12) Source(17, 8) + SourceIndex(0) +3 >Emitted(20, 13) Source(17, 9) + SourceIndex(0) +4 >Emitted(20, 15) Source(17, 10) + SourceIndex(0) +5 >Emitted(20, 16) Source(17, 11) + SourceIndex(0) +--- +>>> // Emit M.Foo +1->^^^^ +2 > +3 > ^^^^^^^^^^^^^ +4 > ^^^^^-> +1-> + > // Emit M.Foo + > +2 > +3 > // Emit M.Foo +1->Emitted(21, 5) Source(19, 2) + SourceIndex(0) name (M) +2 >Emitted(21, 5) Source(18, 2) + SourceIndex(0) name (M) +3 >Emitted(21, 18) Source(18, 15) + SourceIndex(0) name (M) +--- +>>> M.Foo, ; +1->^^^^ +2 > ^^^^^ +3 > ^^ +4 > ^ +5 > ^^^^^ +6 > ^^^ +7 > ^ +1-> + > +2 > Foo +3 > , +4 > < +5 > Foo +6 > /> +7 > ; +1->Emitted(22, 5) Source(19, 2) + SourceIndex(0) name (M) +2 >Emitted(22, 10) Source(19, 5) + SourceIndex(0) name (M) +3 >Emitted(22, 12) Source(19, 7) + SourceIndex(0) name (M) +4 >Emitted(22, 13) Source(19, 8) + SourceIndex(0) name (M) +5 >Emitted(22, 18) Source(19, 11) + SourceIndex(0) name (M) +6 >Emitted(22, 21) Source(19, 14) + SourceIndex(0) name (M) +7 >Emitted(22, 22) Source(19, 15) + SourceIndex(0) name (M) +--- +>>> var S; +1 >^^^^ +2 > ^^^^ +3 > ^ +4 > ^ +5 > ^^^^^^^^^^-> +1 > + > + > +2 > export module +3 > S +4 > { + > // Emit M.Foo + > Foo, ; + > + > // Emit S.Bar + > Bar, ; + > } +1 >Emitted(23, 5) Source(21, 2) + SourceIndex(0) name (M) +2 >Emitted(23, 9) Source(21, 16) + SourceIndex(0) name (M) +3 >Emitted(23, 10) Source(21, 17) + SourceIndex(0) name (M) +4 >Emitted(23, 11) Source(27, 3) + SourceIndex(0) name (M) +--- +>>> (function (S) { +1->^^^^ +2 > ^^^^^^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +6 > ^^^-> +1-> +2 > export module +3 > S +4 > +5 > { +1->Emitted(24, 5) Source(21, 2) + SourceIndex(0) name (M) +2 >Emitted(24, 16) Source(21, 16) + SourceIndex(0) name (M) +3 >Emitted(24, 17) Source(21, 17) + SourceIndex(0) name (M) +4 >Emitted(24, 19) Source(21, 18) + SourceIndex(0) name (M) +5 >Emitted(24, 20) Source(21, 19) + SourceIndex(0) name (M) +--- +>>> // Emit M.Foo +1->^^^^^^^^ +2 > +3 > ^^^^^^^^^^^^^ +4 > ^^^^^-> +1-> + > // Emit M.Foo + > +2 > +3 > // Emit M.Foo +1->Emitted(25, 9) Source(23, 3) + SourceIndex(0) name (M.S) +2 >Emitted(25, 9) Source(22, 3) + SourceIndex(0) name (M.S) +3 >Emitted(25, 22) Source(22, 16) + SourceIndex(0) name (M.S) +--- +>>> M.Foo, ; +1->^^^^^^^^ +2 > ^^^^^ +3 > ^^ +4 > ^ +5 > ^^^^^ +6 > ^^^ +7 > ^ +1-> + > +2 > Foo +3 > , +4 > < +5 > Foo +6 > /> +7 > ; +1->Emitted(26, 9) Source(23, 3) + SourceIndex(0) name (M.S) +2 >Emitted(26, 14) Source(23, 6) + SourceIndex(0) name (M.S) +3 >Emitted(26, 16) Source(23, 8) + SourceIndex(0) name (M.S) +4 >Emitted(26, 17) Source(23, 9) + SourceIndex(0) name (M.S) +5 >Emitted(26, 22) Source(23, 12) + SourceIndex(0) name (M.S) +6 >Emitted(26, 25) Source(23, 15) + SourceIndex(0) name (M.S) +7 >Emitted(26, 26) Source(23, 16) + SourceIndex(0) name (M.S) +--- +>>> // Emit S.Bar +1 >^^^^^^^^ +2 > +3 > ^^^^^^^^^^^^^ +4 > ^^^^^-> +1 > + > + > // Emit S.Bar + > +2 > +3 > // Emit S.Bar +1 >Emitted(27, 9) Source(26, 3) + SourceIndex(0) name (M.S) +2 >Emitted(27, 9) Source(25, 3) + SourceIndex(0) name (M.S) +3 >Emitted(27, 22) Source(25, 16) + SourceIndex(0) name (M.S) +--- +>>> S.Bar, ; +1->^^^^^^^^ +2 > ^^^^^ +3 > ^^ +4 > ^ +5 > ^^^^^ +6 > ^^^ +7 > ^ +8 > ^^^^^^-> +1-> + > +2 > Bar +3 > , +4 > < +5 > Bar +6 > /> +7 > ; +1->Emitted(28, 9) Source(26, 3) + SourceIndex(0) name (M.S) +2 >Emitted(28, 14) Source(26, 6) + SourceIndex(0) name (M.S) +3 >Emitted(28, 16) Source(26, 8) + SourceIndex(0) name (M.S) +4 >Emitted(28, 17) Source(26, 9) + SourceIndex(0) name (M.S) +5 >Emitted(28, 22) Source(26, 12) + SourceIndex(0) name (M.S) +6 >Emitted(28, 25) Source(26, 15) + SourceIndex(0) name (M.S) +7 >Emitted(28, 26) Source(26, 16) + SourceIndex(0) name (M.S) +--- +>>> })(S = M.S || (M.S = {})); +1->^^^^ +2 > ^ +3 > ^^ +4 > ^ +5 > ^^^ +6 > ^^^ +7 > ^^^^^ +8 > ^^^ +9 > ^^^^^^^^ +1-> + > +2 > } +3 > +4 > S +5 > +6 > S +7 > +8 > S +9 > { + > // Emit M.Foo + > Foo, ; + > + > // Emit S.Bar + > Bar, ; + > } +1->Emitted(29, 5) Source(27, 2) + SourceIndex(0) name (M.S) +2 >Emitted(29, 6) Source(27, 3) + SourceIndex(0) name (M.S) +3 >Emitted(29, 8) Source(21, 16) + SourceIndex(0) name (M) +4 >Emitted(29, 9) Source(21, 17) + SourceIndex(0) name (M) +5 >Emitted(29, 12) Source(21, 16) + SourceIndex(0) name (M) +6 >Emitted(29, 15) Source(21, 17) + SourceIndex(0) name (M) +7 >Emitted(29, 20) Source(21, 16) + SourceIndex(0) name (M) +8 >Emitted(29, 23) Source(21, 17) + SourceIndex(0) name (M) +9 >Emitted(29, 31) Source(27, 3) + SourceIndex(0) name (M) +--- +>>>})(M || (M = {})); +1 > +2 >^ +3 > ^^ +4 > ^ +5 > ^^^^^ +6 > ^ +7 > ^^^^^^^^ +1 > + > + > +2 >} +3 > +4 > M +5 > +6 > M +7 > { + > // Emit M.Foo + > Foo, ; + > + > export module S { + > // Emit M.Foo + > Foo, ; + > + > // Emit S.Bar + > Bar, ; + > } + > + > } +1 >Emitted(30, 1) Source(29, 1) + SourceIndex(0) name (M) +2 >Emitted(30, 2) Source(29, 2) + SourceIndex(0) name (M) +3 >Emitted(30, 4) Source(17, 8) + SourceIndex(0) +4 >Emitted(30, 5) Source(17, 9) + SourceIndex(0) +5 >Emitted(30, 10) Source(17, 8) + SourceIndex(0) +6 >Emitted(30, 11) Source(17, 9) + SourceIndex(0) +7 >Emitted(30, 19) Source(29, 2) + SourceIndex(0) +--- +>>>var M; +1 > +2 >^^^^ +3 > ^ +4 > ^ +5 > ^^^^^^^^^^-> +1 > + > + > +2 >module +3 > M +4 > { + > // Emit M.S.Bar + > S.Bar, ; + > } +1 >Emitted(31, 1) Source(31, 1) + SourceIndex(0) +2 >Emitted(31, 5) Source(31, 8) + SourceIndex(0) +3 >Emitted(31, 6) Source(31, 9) + SourceIndex(0) +4 >Emitted(31, 7) Source(34, 2) + SourceIndex(0) +--- +>>>(function (M) { +1-> +2 >^^^^^^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +6 > ^^^^^-> +1-> +2 >module +3 > M +4 > +5 > { +1->Emitted(32, 1) Source(31, 1) + SourceIndex(0) +2 >Emitted(32, 12) Source(31, 8) + SourceIndex(0) +3 >Emitted(32, 13) Source(31, 9) + SourceIndex(0) +4 >Emitted(32, 15) Source(31, 10) + SourceIndex(0) +5 >Emitted(32, 16) Source(31, 11) + SourceIndex(0) +--- +>>> // Emit M.S.Bar +1->^^^^ +2 > +3 > ^^^^^^^^^^^^^^^ +4 > ^^^^^^^-> +1-> + > // Emit M.S.Bar + > +2 > +3 > // Emit M.S.Bar +1->Emitted(33, 5) Source(33, 2) + SourceIndex(0) name (M) +2 >Emitted(33, 5) Source(32, 2) + SourceIndex(0) name (M) +3 >Emitted(33, 20) Source(32, 17) + SourceIndex(0) name (M) +--- +>>> M.S.Bar, ; +1->^^^^ +2 > ^^^ +3 > ^ +4 > ^^^ +5 > ^^ +6 > ^ +7 > ^^^ +8 > ^ +9 > ^^^ +10> ^^^ +11> ^ +1-> + > +2 > S +3 > . +4 > Bar +5 > , +6 > < +7 > S +8 > . +9 > Bar +10> /> +11> ; +1->Emitted(34, 5) Source(33, 2) + SourceIndex(0) name (M) +2 >Emitted(34, 8) Source(33, 3) + SourceIndex(0) name (M) +3 >Emitted(34, 9) Source(33, 4) + SourceIndex(0) name (M) +4 >Emitted(34, 12) Source(33, 7) + SourceIndex(0) name (M) +5 >Emitted(34, 14) Source(33, 9) + SourceIndex(0) name (M) +6 >Emitted(34, 15) Source(33, 10) + SourceIndex(0) name (M) +7 >Emitted(34, 18) Source(33, 11) + SourceIndex(0) name (M) +8 >Emitted(34, 19) Source(33, 12) + SourceIndex(0) name (M) +9 >Emitted(34, 22) Source(33, 15) + SourceIndex(0) name (M) +10>Emitted(34, 25) Source(33, 18) + SourceIndex(0) name (M) +11>Emitted(34, 26) Source(33, 19) + SourceIndex(0) name (M) +--- +>>>})(M || (M = {})); +1 > +2 >^ +3 > ^^ +4 > ^ +5 > ^^^^^ +6 > ^ +7 > ^^^^^^^^ +1 > + > +2 >} +3 > +4 > M +5 > +6 > M +7 > { + > // Emit M.S.Bar + > S.Bar, ; + > } +1 >Emitted(35, 1) Source(34, 1) + SourceIndex(0) name (M) +2 >Emitted(35, 2) Source(34, 2) + SourceIndex(0) name (M) +3 >Emitted(35, 4) Source(31, 8) + SourceIndex(0) +4 >Emitted(35, 5) Source(31, 9) + SourceIndex(0) +5 >Emitted(35, 10) Source(31, 8) + SourceIndex(0) +6 >Emitted(35, 11) Source(31, 9) + SourceIndex(0) +7 >Emitted(35, 19) Source(34, 2) + SourceIndex(0) +--- +>>>var M; +1 > +2 >^^^^ +3 > ^ +4 > ^ +5 > ^^^^^^^^^^^^-> +1 > + > + > +2 >module +3 > M +4 > { + > var M = 100; + > // Emit M_1.Foo + > Foo, ; + > } +1 >Emitted(36, 1) Source(36, 1) + SourceIndex(0) +2 >Emitted(36, 5) Source(36, 8) + SourceIndex(0) +3 >Emitted(36, 6) Source(36, 9) + SourceIndex(0) +4 >Emitted(36, 7) Source(40, 2) + SourceIndex(0) +--- +>>>(function (M_1) { +1-> +2 >^^^^^^^^^^^ +3 > ^^^ +4 > ^^ +5 > ^ +1-> +2 >module +3 > M +4 > +5 > { +1->Emitted(37, 1) Source(36, 1) + SourceIndex(0) +2 >Emitted(37, 12) Source(36, 8) + SourceIndex(0) +3 >Emitted(37, 15) Source(36, 9) + SourceIndex(0) +4 >Emitted(37, 17) Source(36, 10) + SourceIndex(0) +5 >Emitted(37, 18) Source(36, 11) + SourceIndex(0) +--- +>>> var M = 100; +1 >^^^^ +2 > ^^^^ +3 > ^ +4 > ^^^ +5 > ^^^ +6 > ^ +7 > ^^^^-> +1 > + > +2 > var +3 > M +4 > = +5 > 100 +6 > ; +1 >Emitted(38, 5) Source(37, 2) + SourceIndex(0) name (M) +2 >Emitted(38, 9) Source(37, 6) + SourceIndex(0) name (M) +3 >Emitted(38, 10) Source(37, 7) + SourceIndex(0) name (M) +4 >Emitted(38, 13) Source(37, 10) + SourceIndex(0) name (M) +5 >Emitted(38, 16) Source(37, 13) + SourceIndex(0) name (M) +6 >Emitted(38, 17) Source(37, 14) + SourceIndex(0) name (M) +--- +>>> // Emit M_1.Foo +1->^^^^ +2 > +3 > ^^^^^^^^^^^^^^^ +4 > ^^^^^^^-> +1-> + > // Emit M_1.Foo + > +2 > +3 > // Emit M_1.Foo +1->Emitted(39, 5) Source(39, 2) + SourceIndex(0) name (M) +2 >Emitted(39, 5) Source(38, 2) + SourceIndex(0) name (M) +3 >Emitted(39, 20) Source(38, 17) + SourceIndex(0) name (M) +--- +>>> M_1.Foo, ; +1->^^^^ +2 > ^^^^^^^ +3 > ^^ +4 > ^ +5 > ^^^^^^^ +6 > ^^^ +7 > ^ +1-> + > +2 > Foo +3 > , +4 > < +5 > Foo +6 > /> +7 > ; +1->Emitted(40, 5) Source(39, 2) + SourceIndex(0) name (M) +2 >Emitted(40, 12) Source(39, 5) + SourceIndex(0) name (M) +3 >Emitted(40, 14) Source(39, 7) + SourceIndex(0) name (M) +4 >Emitted(40, 15) Source(39, 8) + SourceIndex(0) name (M) +5 >Emitted(40, 22) Source(39, 11) + SourceIndex(0) name (M) +6 >Emitted(40, 25) Source(39, 14) + SourceIndex(0) name (M) +7 >Emitted(40, 26) Source(39, 15) + SourceIndex(0) name (M) +--- +>>>})(M || (M = {})); +1 > +2 >^ +3 > ^^ +4 > ^ +5 > ^^^^^ +6 > ^ +7 > ^^^^^^^^ +8 > ^^^^^^^^^^^^^^^^^^-> +1 > + > +2 >} +3 > +4 > M +5 > +6 > M +7 > { + > var M = 100; + > // Emit M_1.Foo + > Foo, ; + > } +1 >Emitted(41, 1) Source(40, 1) + SourceIndex(0) name (M) +2 >Emitted(41, 2) Source(40, 2) + SourceIndex(0) name (M) +3 >Emitted(41, 4) Source(36, 8) + SourceIndex(0) +4 >Emitted(41, 5) Source(36, 9) + SourceIndex(0) +5 >Emitted(41, 10) Source(36, 8) + SourceIndex(0) +6 >Emitted(41, 11) Source(36, 9) + SourceIndex(0) +7 >Emitted(41, 19) Source(40, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=tsxEmit3.jsx.map \ No newline at end of file diff --git a/tests/baselines/reference/tsxEmit3.symbols b/tests/baselines/reference/tsxEmit3.symbols index 4ceed0b9b1e..64542d125b9 100644 --- a/tests/baselines/reference/tsxEmit3.symbols +++ b/tests/baselines/reference/tsxEmit3.symbols @@ -1,25 +1,26 @@ === tests/cases/conformance/jsx/tsxEmit3.tsx === + declare module JSX { >JSX : Symbol(JSX, Decl(tsxEmit3.tsx, 0, 0)) interface Element { } ->Element : Symbol(Element, Decl(tsxEmit3.tsx, 0, 20)) +>Element : Symbol(Element, Decl(tsxEmit3.tsx, 1, 20)) interface IntrinsicElements { } ->IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxEmit3.tsx, 1, 22)) +>IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxEmit3.tsx, 2, 22)) } module M { ->M : Symbol(M, Decl(tsxEmit3.tsx, 3, 1), Decl(tsxEmit3.tsx, 13, 1), Decl(tsxEmit3.tsx, 27, 1), Decl(tsxEmit3.tsx, 32, 1)) +>M : Symbol(M, Decl(tsxEmit3.tsx, 4, 1), Decl(tsxEmit3.tsx, 14, 1), Decl(tsxEmit3.tsx, 28, 1), Decl(tsxEmit3.tsx, 33, 1)) export class Foo { constructor() { } } ->Foo : Symbol(Foo, Decl(tsxEmit3.tsx, 5, 10)) +>Foo : Symbol(Foo, Decl(tsxEmit3.tsx, 6, 10)) export module S { ->S : Symbol(S, Decl(tsxEmit3.tsx, 6, 39), Decl(tsxEmit3.tsx, 17, 14)) +>S : Symbol(S, Decl(tsxEmit3.tsx, 7, 39), Decl(tsxEmit3.tsx, 18, 14)) export class Bar { } ->Bar : Symbol(Bar, Decl(tsxEmit3.tsx, 7, 18)) +>Bar : Symbol(Bar, Decl(tsxEmit3.tsx, 8, 18)) // Emit Foo // Foo, ; @@ -27,49 +28,49 @@ module M { } module M { ->M : Symbol(M, Decl(tsxEmit3.tsx, 3, 1), Decl(tsxEmit3.tsx, 13, 1), Decl(tsxEmit3.tsx, 27, 1), Decl(tsxEmit3.tsx, 32, 1)) +>M : Symbol(M, Decl(tsxEmit3.tsx, 4, 1), Decl(tsxEmit3.tsx, 14, 1), Decl(tsxEmit3.tsx, 28, 1), Decl(tsxEmit3.tsx, 33, 1)) // Emit M.Foo Foo, ; ->Foo : Symbol(Foo, Decl(tsxEmit3.tsx, 5, 10)) ->Foo : Symbol(Foo, Decl(tsxEmit3.tsx, 5, 10)) +>Foo : Symbol(Foo, Decl(tsxEmit3.tsx, 6, 10)) +>Foo : Symbol(Foo, Decl(tsxEmit3.tsx, 6, 10)) export module S { ->S : Symbol(S, Decl(tsxEmit3.tsx, 6, 39), Decl(tsxEmit3.tsx, 17, 14)) +>S : Symbol(S, Decl(tsxEmit3.tsx, 7, 39), Decl(tsxEmit3.tsx, 18, 14)) // Emit M.Foo Foo, ; ->Foo : Symbol(Foo, Decl(tsxEmit3.tsx, 5, 10)) ->Foo : Symbol(Foo, Decl(tsxEmit3.tsx, 5, 10)) +>Foo : Symbol(Foo, Decl(tsxEmit3.tsx, 6, 10)) +>Foo : Symbol(Foo, Decl(tsxEmit3.tsx, 6, 10)) // Emit S.Bar Bar, ; ->Bar : Symbol(Bar, Decl(tsxEmit3.tsx, 7, 18)) ->Bar : Symbol(Bar, Decl(tsxEmit3.tsx, 7, 18)) +>Bar : Symbol(Bar, Decl(tsxEmit3.tsx, 8, 18)) +>Bar : Symbol(Bar, Decl(tsxEmit3.tsx, 8, 18)) } } module M { ->M : Symbol(M, Decl(tsxEmit3.tsx, 3, 1), Decl(tsxEmit3.tsx, 13, 1), Decl(tsxEmit3.tsx, 27, 1), Decl(tsxEmit3.tsx, 32, 1)) +>M : Symbol(M, Decl(tsxEmit3.tsx, 4, 1), Decl(tsxEmit3.tsx, 14, 1), Decl(tsxEmit3.tsx, 28, 1), Decl(tsxEmit3.tsx, 33, 1)) // Emit M.S.Bar S.Bar, ; ->S.Bar : Symbol(S.Bar, Decl(tsxEmit3.tsx, 7, 18)) ->S : Symbol(S, Decl(tsxEmit3.tsx, 6, 39), Decl(tsxEmit3.tsx, 17, 14)) ->Bar : Symbol(S.Bar, Decl(tsxEmit3.tsx, 7, 18)) ->Bar : Symbol(S.Bar, Decl(tsxEmit3.tsx, 7, 18)) +>S.Bar : Symbol(S.Bar, Decl(tsxEmit3.tsx, 8, 18)) +>S : Symbol(S, Decl(tsxEmit3.tsx, 7, 39), Decl(tsxEmit3.tsx, 18, 14)) +>Bar : Symbol(S.Bar, Decl(tsxEmit3.tsx, 8, 18)) +>Bar : Symbol(S.Bar, Decl(tsxEmit3.tsx, 8, 18)) } module M { ->M : Symbol(M, Decl(tsxEmit3.tsx, 3, 1), Decl(tsxEmit3.tsx, 13, 1), Decl(tsxEmit3.tsx, 27, 1), Decl(tsxEmit3.tsx, 32, 1)) +>M : Symbol(M, Decl(tsxEmit3.tsx, 4, 1), Decl(tsxEmit3.tsx, 14, 1), Decl(tsxEmit3.tsx, 28, 1), Decl(tsxEmit3.tsx, 33, 1)) var M = 100; ->M : Symbol(M, Decl(tsxEmit3.tsx, 35, 4)) +>M : Symbol(M, Decl(tsxEmit3.tsx, 36, 4)) // Emit M_1.Foo Foo, ; ->Foo : Symbol(Foo, Decl(tsxEmit3.tsx, 5, 10)) ->Foo : Symbol(Foo, Decl(tsxEmit3.tsx, 5, 10)) +>Foo : Symbol(Foo, Decl(tsxEmit3.tsx, 6, 10)) +>Foo : Symbol(Foo, Decl(tsxEmit3.tsx, 6, 10)) } diff --git a/tests/baselines/reference/tsxEmit3.types b/tests/baselines/reference/tsxEmit3.types index 4bb92d9aea5..f4db9a3f36f 100644 --- a/tests/baselines/reference/tsxEmit3.types +++ b/tests/baselines/reference/tsxEmit3.types @@ -1,4 +1,5 @@ === tests/cases/conformance/jsx/tsxEmit3.tsx === + declare module JSX { >JSX : any diff --git a/tests/baselines/reference/tsxExternalModuleEmit2.js b/tests/baselines/reference/tsxExternalModuleEmit2.js new file mode 100644 index 00000000000..f8fe6096090 --- /dev/null +++ b/tests/baselines/reference/tsxExternalModuleEmit2.js @@ -0,0 +1,25 @@ +//// [tests/cases/conformance/jsx/tsxExternalModuleEmit2.tsx] //// + +//// [modules.d.ts] + +declare module 'mod' { + var y: any; + export default y; +} + +//// [app.tsx] +import Main from 'mod'; +declare var Foo, React; +// Should see mod_1['default'] in emit here +; +// Should see mod_1['default'] in emit here +; + + + +//// [app.js] +var mod_1 = require('mod'); +// Should see mod_1['default'] in emit here +React.createElement(Foo, {"handler": mod_1["default"]}); +// Should see mod_1['default'] in emit here +React.createElement(Foo, React.__spread({}, mod_1["default"])); diff --git a/tests/baselines/reference/tsxExternalModuleEmit2.symbols b/tests/baselines/reference/tsxExternalModuleEmit2.symbols new file mode 100644 index 00000000000..137e9befa56 --- /dev/null +++ b/tests/baselines/reference/tsxExternalModuleEmit2.symbols @@ -0,0 +1,30 @@ +=== tests/cases/conformance/jsx/modules.d.ts === + +declare module 'mod' { + var y: any; +>y : Symbol(y, Decl(modules.d.ts, 2, 5)) + + export default y; +>y : Symbol(y, Decl(modules.d.ts, 2, 5)) +} + +=== tests/cases/conformance/jsx/app.tsx === +import Main from 'mod'; +>Main : Symbol(Main, Decl(app.tsx, 0, 6)) + +declare var Foo, React; +>Foo : Symbol(Foo, Decl(app.tsx, 1, 11)) +>React : Symbol(React, Decl(app.tsx, 1, 16)) + +// Should see mod_1['default'] in emit here +; +>Foo : Symbol(Foo, Decl(app.tsx, 1, 11)) +>handler : Symbol(unknown) +>Foo : Symbol(Foo, Decl(app.tsx, 1, 11)) + +// Should see mod_1['default'] in emit here +; +>Foo : Symbol(Foo, Decl(app.tsx, 1, 11)) +>Foo : Symbol(Foo, Decl(app.tsx, 1, 11)) + + diff --git a/tests/baselines/reference/tsxExternalModuleEmit2.types b/tests/baselines/reference/tsxExternalModuleEmit2.types new file mode 100644 index 00000000000..b4746fe46c7 --- /dev/null +++ b/tests/baselines/reference/tsxExternalModuleEmit2.types @@ -0,0 +1,34 @@ +=== tests/cases/conformance/jsx/modules.d.ts === + +declare module 'mod' { + var y: any; +>y : any + + export default y; +>y : any +} + +=== tests/cases/conformance/jsx/app.tsx === +import Main from 'mod'; +>Main : any + +declare var Foo, React; +>Foo : any +>React : any + +// Should see mod_1['default'] in emit here +; +> : any +>Foo : any +>handler : any +>Main : any +>Foo : any + +// Should see mod_1['default'] in emit here +; +> : any +>Foo : any +>Main : any +>Foo : any + + diff --git a/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols b/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols index 8bd68b2e8e7..3bfd5505e76 100644 --- a/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols +++ b/tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols @@ -16,6 +16,7 @@ var T, T1, T2; var x1 = () => {}; >x1 : Symbol(x1, Decl(tsxGenericArrowFunctionParsing.tsx, 7, 3)) >T : Symbol(T, Decl(tsxGenericArrowFunctionParsing.tsx, 4, 3)) +>T : Symbol(T, Decl(tsxGenericArrowFunctionParsing.tsx, 4, 3)) x1.isElement; >x1.isElement : Symbol(JSX.Element.isElement, Decl(tsxGenericArrowFunctionParsing.tsx, 1, 20)) @@ -44,6 +45,7 @@ var x4 = () => {}; >x4 : Symbol(x4, Decl(tsxGenericArrowFunctionParsing.tsx, 19, 3)) >T : Symbol(T, Decl(tsxGenericArrowFunctionParsing.tsx, 4, 3)) >extends : Symbol(unknown) +>T : Symbol(T, Decl(tsxGenericArrowFunctionParsing.tsx, 4, 3)) x4.isElement; >x4.isElement : Symbol(JSX.Element.isElement, Decl(tsxGenericArrowFunctionParsing.tsx, 1, 20)) @@ -55,6 +57,7 @@ var x5 = () => {}; >x5 : Symbol(x5, Decl(tsxGenericArrowFunctionParsing.tsx, 23, 3)) >T : Symbol(T, Decl(tsxGenericArrowFunctionParsing.tsx, 4, 3)) >extends : Symbol(unknown) +>T : Symbol(T, Decl(tsxGenericArrowFunctionParsing.tsx, 4, 3)) x5.isElement; >x5.isElement : Symbol(JSX.Element.isElement, Decl(tsxGenericArrowFunctionParsing.tsx, 1, 20)) diff --git a/tests/baselines/reference/tsxInArrowFunction.symbols b/tests/baselines/reference/tsxInArrowFunction.symbols index 814f2577bf0..5896dfa1eef 100644 --- a/tests/baselines/reference/tsxInArrowFunction.symbols +++ b/tests/baselines/reference/tsxInArrowFunction.symbols @@ -24,6 +24,7 @@ declare namespace JSX { >div : Symbol(JSX.IntrinsicElements.div, Decl(tsxInArrowFunction.tsx, 3, 33)) >div : Symbol(JSX.IntrinsicElements.div, Decl(tsxInArrowFunction.tsx, 3, 33)) >text : Symbol(text, Decl(tsxInArrowFunction.tsx, 4, 14)) +>div : Symbol(JSX.IntrinsicElements.div, Decl(tsxInArrowFunction.tsx, 3, 33)) // didn't work
{x =>
}
; @@ -31,16 +32,20 @@ declare namespace JSX { >x : Symbol(x, Decl(tsxInArrowFunction.tsx, 15, 6)) >div : Symbol(JSX.IntrinsicElements.div, Decl(tsxInArrowFunction.tsx, 3, 33)) >text : Symbol(text, Decl(tsxInArrowFunction.tsx, 4, 14)) +>div : Symbol(JSX.IntrinsicElements.div, Decl(tsxInArrowFunction.tsx, 3, 33)) // worked
{() => (
)}
; >div : Symbol(JSX.IntrinsicElements.div, Decl(tsxInArrowFunction.tsx, 3, 33)) >div : Symbol(JSX.IntrinsicElements.div, Decl(tsxInArrowFunction.tsx, 3, 33)) >text : Symbol(text, Decl(tsxInArrowFunction.tsx, 4, 14)) +>div : Symbol(JSX.IntrinsicElements.div, Decl(tsxInArrowFunction.tsx, 3, 33)) // worked (!)
{() =>
}
; >div : Symbol(JSX.IntrinsicElements.div, Decl(tsxInArrowFunction.tsx, 3, 33)) >div : Symbol(JSX.IntrinsicElements.div, Decl(tsxInArrowFunction.tsx, 3, 33)) >text : Symbol(text, Decl(tsxInArrowFunction.tsx, 4, 14)) +>div : Symbol(JSX.IntrinsicElements.div, Decl(tsxInArrowFunction.tsx, 3, 33)) +>div : Symbol(JSX.IntrinsicElements.div, Decl(tsxInArrowFunction.tsx, 3, 33)) diff --git a/tests/baselines/reference/tsxOpeningClosingNames.symbols b/tests/baselines/reference/tsxOpeningClosingNames.symbols index 3ff2a3ff68d..e9734fb5ee1 100644 --- a/tests/baselines/reference/tsxOpeningClosingNames.symbols +++ b/tests/baselines/reference/tsxOpeningClosingNames.symbols @@ -17,4 +17,5 @@ declare module A.B.C { foo
>D : Symbol(unknown) +>D : Symbol(unknown) diff --git a/tests/baselines/reference/tsxParseTests1.symbols b/tests/baselines/reference/tsxParseTests1.symbols index dbe11dbcbba..f7b179f254f 100644 --- a/tests/baselines/reference/tsxParseTests1.symbols +++ b/tests/baselines/reference/tsxParseTests1.symbols @@ -17,4 +17,8 @@ var x =
; >div : Symbol(JSX.IntrinsicElements.div, Decl(tsxParseTests1.tsx, 2, 30)) >span : Symbol(JSX.IntrinsicElements.span, Decl(tsxParseTests1.tsx, 2, 35)) >div : Symbol(JSX.IntrinsicElements.div, Decl(tsxParseTests1.tsx, 2, 30)) +>div : Symbol(JSX.IntrinsicElements.div, Decl(tsxParseTests1.tsx, 2, 30)) +>span : Symbol(JSX.IntrinsicElements.span, Decl(tsxParseTests1.tsx, 2, 35)) +>div : Symbol(JSX.IntrinsicElements.div, Decl(tsxParseTests1.tsx, 2, 30)) +>div : Symbol(JSX.IntrinsicElements.div, Decl(tsxParseTests1.tsx, 2, 30)) diff --git a/tests/baselines/reference/tsxReactEmit1.symbols b/tests/baselines/reference/tsxReactEmit1.symbols index c9e819c82d3..665c6a0271f 100644 --- a/tests/baselines/reference/tsxReactEmit1.symbols +++ b/tests/baselines/reference/tsxReactEmit1.symbols @@ -60,16 +60,19 @@ var selfClosed7 =
; var openClosed1 =
; >openClosed1 : Symbol(openClosed1, Decl(tsxReactEmit1.tsx, 17, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var openClosed2 =
foo
; >openClosed2 : Symbol(openClosed2, Decl(tsxReactEmit1.tsx, 18, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >n : Symbol(unknown) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var openClosed3 =
{p}
; >openClosed3 : Symbol(openClosed3, Decl(tsxReactEmit1.tsx, 19, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >n : Symbol(unknown) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var openClosed4 =
{p < p}
; >openClosed4 : Symbol(openClosed4, Decl(tsxReactEmit1.tsx, 20, 3)) @@ -77,6 +80,7 @@ var openClosed4 =
{p < p}
; >n : Symbol(unknown) >p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) >p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var openClosed5 =
{p > p}
; >openClosed5 : Symbol(openClosed5, Decl(tsxReactEmit1.tsx, 21, 3)) @@ -85,6 +89,7 @@ var openClosed5 =
{p > p}
; >b : Symbol(unknown) >p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) >p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) class SomeClass { >SomeClass : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 21, 45)) @@ -96,6 +101,7 @@ class SomeClass { >rewrites1 : Symbol(rewrites1, Decl(tsxReactEmit1.tsx, 25, 5)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >this : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 21, 45)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var rewrites2 =
{[p, ...p, p]}
; >rewrites2 : Symbol(rewrites2, Decl(tsxReactEmit1.tsx, 26, 5)) @@ -103,17 +109,20 @@ class SomeClass { >p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) >p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) >p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var rewrites3 =
{{p}}
; >rewrites3 : Symbol(rewrites3, Decl(tsxReactEmit1.tsx, 27, 5)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >p : Symbol(p, Decl(tsxReactEmit1.tsx, 27, 25)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var rewrites4 =
this}>
; >rewrites4 : Symbol(rewrites4, Decl(tsxReactEmit1.tsx, 29, 5)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >a : Symbol(unknown) >this : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 21, 45)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var rewrites5 =
; >rewrites5 : Symbol(rewrites5, Decl(tsxReactEmit1.tsx, 30, 5)) @@ -122,22 +131,26 @@ class SomeClass { >p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) >p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) >p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var rewrites6 =
; >rewrites6 : Symbol(rewrites6, Decl(tsxReactEmit1.tsx, 31, 5)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >a : Symbol(unknown) >p : Symbol(p, Decl(tsxReactEmit1.tsx, 31, 27)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) } } var whitespace1 =
; >whitespace1 : Symbol(whitespace1, Decl(tsxReactEmit1.tsx, 35, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var whitespace2 =
{p}
; >whitespace2 : Symbol(whitespace2, Decl(tsxReactEmit1.tsx, 36, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var whitespace3 =
>whitespace3 : Symbol(whitespace3, Decl(tsxReactEmit1.tsx, 37, 3)) @@ -145,4 +158,5 @@ var whitespace3 =
{p}
; +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) diff --git a/tests/baselines/reference/tsxReactEmit2.symbols b/tests/baselines/reference/tsxReactEmit2.symbols index 9cf739c960c..7805a16363e 100644 --- a/tests/baselines/reference/tsxReactEmit2.symbols +++ b/tests/baselines/reference/tsxReactEmit2.symbols @@ -23,24 +23,29 @@ var p1, p2, p3; var spreads1 =
{p2}
; >spreads1 : Symbol(spreads1, Decl(tsxReactEmit2.tsx, 9, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) var spreads2 =
{p2}
; >spreads2 : Symbol(spreads2, Decl(tsxReactEmit2.tsx, 10, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) var spreads3 =
{p2}
; >spreads3 : Symbol(spreads3, Decl(tsxReactEmit2.tsx, 11, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) >x : Symbol(unknown) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) var spreads4 =
{p2}
; >spreads4 : Symbol(spreads4, Decl(tsxReactEmit2.tsx, 12, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) >x : Symbol(unknown) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) var spreads5 =
{p2}
; >spreads5 : Symbol(spreads5, Decl(tsxReactEmit2.tsx, 13, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) >x : Symbol(unknown) >y : Symbol(unknown) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) diff --git a/tests/baselines/reference/tsxReactEmit3.symbols b/tests/baselines/reference/tsxReactEmit3.symbols index 857647400a9..042488cf04c 100644 --- a/tests/baselines/reference/tsxReactEmit3.symbols +++ b/tests/baselines/reference/tsxReactEmit3.symbols @@ -18,4 +18,6 @@ declare var Foo, Bar, baz; >Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 4, 16)) >Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 4, 16)) >Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 4, 16)) +>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 4, 16)) +>Foo : Symbol(Foo, Decl(tsxReactEmit3.tsx, 4, 11)) diff --git a/tests/baselines/reference/tsxReactEmitWhitespace.symbols b/tests/baselines/reference/tsxReactEmitWhitespace.symbols index 06c8258a2c2..96b902372b7 100644 --- a/tests/baselines/reference/tsxReactEmitWhitespace.symbols +++ b/tests/baselines/reference/tsxReactEmitWhitespace.symbols @@ -24,10 +24,12 @@ var p = 0; // Emit " "
; >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmitWhitespace.tsx, 1, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmitWhitespace.tsx, 1, 22)) // Emit " ", p, " "
{p}
; >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmitWhitespace.tsx, 1, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmitWhitespace.tsx, 1, 22)) // Emit only p
@@ -35,6 +37,7 @@ var p = 0; {p}
; +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmitWhitespace.tsx, 1, 22)) // Emit only p
@@ -42,16 +45,19 @@ var p = 0; {p}
; +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmitWhitespace.tsx, 1, 22)) // Emit " 3"
3 >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmitWhitespace.tsx, 1, 22))
; +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmitWhitespace.tsx, 1, 22)) // Emit " 3 "
3
; >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmitWhitespace.tsx, 1, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmitWhitespace.tsx, 1, 22)) // Emit "3"
@@ -59,12 +65,14 @@ var p = 0; 3
; +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmitWhitespace.tsx, 1, 22)) // Emit no args
>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmitWhitespace.tsx, 1, 22))
; +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmitWhitespace.tsx, 1, 22)) // Emit "foo" + ' ' + "bar"
@@ -75,5 +83,6 @@ var p = 0; bar
; +>div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmitWhitespace.tsx, 1, 22)) diff --git a/tests/baselines/reference/tupleElementTypes1.js b/tests/baselines/reference/tupleElementTypes1.js new file mode 100644 index 00000000000..be220d5021c --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes1.js @@ -0,0 +1,5 @@ +//// [tupleElementTypes1.ts] +var [a, b]: [number, any] = [undefined, undefined]; + +//// [tupleElementTypes1.js] +var _a = [undefined, undefined], a = _a[0], b = _a[1]; diff --git a/tests/baselines/reference/tupleElementTypes1.symbols b/tests/baselines/reference/tupleElementTypes1.symbols new file mode 100644 index 00000000000..1d27232a2a5 --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes1.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes1.ts === +var [a, b]: [number, any] = [undefined, undefined]; +>a : Symbol(a, Decl(tupleElementTypes1.ts, 0, 5)) +>b : Symbol(b, Decl(tupleElementTypes1.ts, 0, 7)) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) + diff --git a/tests/baselines/reference/tupleElementTypes1.types b/tests/baselines/reference/tupleElementTypes1.types new file mode 100644 index 00000000000..3b0b8b6e854 --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes1.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes1.ts === +var [a, b]: [number, any] = [undefined, undefined]; +>a : number +>b : any +>[undefined, undefined] : [undefined, undefined] +>undefined : undefined +>undefined : undefined + diff --git a/tests/baselines/reference/tupleElementTypes2.js b/tests/baselines/reference/tupleElementTypes2.js new file mode 100644 index 00000000000..56a7b1c889e --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes2.js @@ -0,0 +1,7 @@ +//// [tupleElementTypes2.ts] +function f([a, b]: [number, any]) { } + +//// [tupleElementTypes2.js] +function f(_a) { + var a = _a[0], b = _a[1]; +} diff --git a/tests/baselines/reference/tupleElementTypes2.symbols b/tests/baselines/reference/tupleElementTypes2.symbols new file mode 100644 index 00000000000..0eae02320d4 --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes2.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes2.ts === +function f([a, b]: [number, any]) { } +>f : Symbol(f, Decl(tupleElementTypes2.ts, 0, 0)) +>a : Symbol(a, Decl(tupleElementTypes2.ts, 0, 12)) +>b : Symbol(b, Decl(tupleElementTypes2.ts, 0, 14)) + diff --git a/tests/baselines/reference/tupleElementTypes2.types b/tests/baselines/reference/tupleElementTypes2.types new file mode 100644 index 00000000000..978df27d6b6 --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes2.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes2.ts === +function f([a, b]: [number, any]) { } +>f : ([a, b]: [number, any]) => void +>a : number +>b : any + diff --git a/tests/baselines/reference/tupleElementTypes3.js b/tests/baselines/reference/tupleElementTypes3.js new file mode 100644 index 00000000000..a8db914137b --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes3.js @@ -0,0 +1,5 @@ +//// [tupleElementTypes3.ts] +var [a, b] = [0, undefined]; + +//// [tupleElementTypes3.js] +var _a = [0, undefined], a = _a[0], b = _a[1]; diff --git a/tests/baselines/reference/tupleElementTypes3.symbols b/tests/baselines/reference/tupleElementTypes3.symbols new file mode 100644 index 00000000000..bf4eb78a219 --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes3.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes3.ts === +var [a, b] = [0, undefined]; +>a : Symbol(a, Decl(tupleElementTypes3.ts, 0, 5)) +>b : Symbol(b, Decl(tupleElementTypes3.ts, 0, 7)) +>undefined : Symbol(undefined) + diff --git a/tests/baselines/reference/tupleElementTypes3.types b/tests/baselines/reference/tupleElementTypes3.types new file mode 100644 index 00000000000..6f29ba1371a --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes3.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes3.ts === +var [a, b] = [0, undefined]; +>a : number +>b : any +>[0, undefined] : [number, undefined] +>0 : number +>undefined : undefined + diff --git a/tests/baselines/reference/tupleElementTypes4.js b/tests/baselines/reference/tupleElementTypes4.js new file mode 100644 index 00000000000..58c5b3f31ae --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes4.js @@ -0,0 +1,7 @@ +//// [tupleElementTypes4.ts] +function f([a, b] = [0, undefined]) { } + +//// [tupleElementTypes4.js] +function f(_a) { + var _b = _a === void 0 ? [0, undefined] : _a, a = _b[0], b = _b[1]; +} diff --git a/tests/baselines/reference/tupleElementTypes4.symbols b/tests/baselines/reference/tupleElementTypes4.symbols new file mode 100644 index 00000000000..86b901e4d04 --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes4.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes4.ts === +function f([a, b] = [0, undefined]) { } +>f : Symbol(f, Decl(tupleElementTypes4.ts, 0, 0)) +>a : Symbol(a, Decl(tupleElementTypes4.ts, 0, 12)) +>b : Symbol(b, Decl(tupleElementTypes4.ts, 0, 14)) +>undefined : Symbol(undefined) + diff --git a/tests/baselines/reference/tupleElementTypes4.types b/tests/baselines/reference/tupleElementTypes4.types new file mode 100644 index 00000000000..06e19ef72bb --- /dev/null +++ b/tests/baselines/reference/tupleElementTypes4.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/types/tuple/tupleElementTypes4.ts === +function f([a, b] = [0, undefined]) { } +>f : ([a, b]?: [number, any]) => void +>a : number +>b : any +>[0, undefined] : [number, undefined] +>0 : number +>undefined : undefined + diff --git a/tests/baselines/reference/tupleTypeInference.js b/tests/baselines/reference/tupleTypeInference.js new file mode 100644 index 00000000000..dfc0de83022 --- /dev/null +++ b/tests/baselines/reference/tupleTypeInference.js @@ -0,0 +1,31 @@ +//// [tupleTypeInference.ts] +declare var $q: IQService; + +interface IQService { + all(x: [IPromise, IPromise, IPromise]): IPromise<[T1, T2, T3]>; + all(x: [IPromise, IPromise]): IPromise<[T1, T2]>; + all(x: [IPromise]): IPromise<[T1]>; + when(t?: T): IPromise; +} + +interface IPromise { + then(callback: (t: T) => TResult): IPromise; +} + +// Implicit different types +var a = $q.all([$q.when(), $q.when()]); + +// Explicit different types +var b = $q.all([$q.when(), $q.when()]); + +// Implicit identical types +var c = $q.all([$q.when(), $q.when()]); + + +//// [tupleTypeInference.js] +// Implicit different types +var a = $q.all([$q.when(), $q.when()]); +// Explicit different types +var b = $q.all([$q.when(), $q.when()]); +// Implicit identical types +var c = $q.all([$q.when(), $q.when()]); diff --git a/tests/baselines/reference/tupleTypeInference.symbols b/tests/baselines/reference/tupleTypeInference.symbols new file mode 100644 index 00000000000..4dbed73e395 --- /dev/null +++ b/tests/baselines/reference/tupleTypeInference.symbols @@ -0,0 +1,110 @@ +=== tests/cases/compiler/tupleTypeInference.ts === +declare var $q: IQService; +>$q : Symbol($q, Decl(tupleTypeInference.ts, 0, 11)) +>IQService : Symbol(IQService, Decl(tupleTypeInference.ts, 0, 26)) + +interface IQService { +>IQService : Symbol(IQService, Decl(tupleTypeInference.ts, 0, 26)) + + all(x: [IPromise, IPromise, IPromise]): IPromise<[T1, T2, T3]>; +>all : Symbol(all, Decl(tupleTypeInference.ts, 2, 21), Decl(tupleTypeInference.ts, 3, 91), Decl(tupleTypeInference.ts, 4, 69)) +>T1 : Symbol(T1, Decl(tupleTypeInference.ts, 3, 8)) +>T2 : Symbol(T2, Decl(tupleTypeInference.ts, 3, 11)) +>T3 : Symbol(T3, Decl(tupleTypeInference.ts, 3, 15)) +>x : Symbol(x, Decl(tupleTypeInference.ts, 3, 20)) +>IPromise : Symbol(IPromise, Decl(tupleTypeInference.ts, 7, 1)) +>T1 : Symbol(T1, Decl(tupleTypeInference.ts, 3, 8)) +>IPromise : Symbol(IPromise, Decl(tupleTypeInference.ts, 7, 1)) +>T2 : Symbol(T2, Decl(tupleTypeInference.ts, 3, 11)) +>IPromise : Symbol(IPromise, Decl(tupleTypeInference.ts, 7, 1)) +>T3 : Symbol(T3, Decl(tupleTypeInference.ts, 3, 15)) +>IPromise : Symbol(IPromise, Decl(tupleTypeInference.ts, 7, 1)) +>T1 : Symbol(T1, Decl(tupleTypeInference.ts, 3, 8)) +>T2 : Symbol(T2, Decl(tupleTypeInference.ts, 3, 11)) +>T3 : Symbol(T3, Decl(tupleTypeInference.ts, 3, 15)) + + all(x: [IPromise, IPromise]): IPromise<[T1, T2]>; +>all : Symbol(all, Decl(tupleTypeInference.ts, 2, 21), Decl(tupleTypeInference.ts, 3, 91), Decl(tupleTypeInference.ts, 4, 69)) +>T1 : Symbol(T1, Decl(tupleTypeInference.ts, 4, 8)) +>T2 : Symbol(T2, Decl(tupleTypeInference.ts, 4, 11)) +>x : Symbol(x, Decl(tupleTypeInference.ts, 4, 16)) +>IPromise : Symbol(IPromise, Decl(tupleTypeInference.ts, 7, 1)) +>T1 : Symbol(T1, Decl(tupleTypeInference.ts, 4, 8)) +>IPromise : Symbol(IPromise, Decl(tupleTypeInference.ts, 7, 1)) +>T2 : Symbol(T2, Decl(tupleTypeInference.ts, 4, 11)) +>IPromise : Symbol(IPromise, Decl(tupleTypeInference.ts, 7, 1)) +>T1 : Symbol(T1, Decl(tupleTypeInference.ts, 4, 8)) +>T2 : Symbol(T2, Decl(tupleTypeInference.ts, 4, 11)) + + all(x: [IPromise]): IPromise<[T1]>; +>all : Symbol(all, Decl(tupleTypeInference.ts, 2, 21), Decl(tupleTypeInference.ts, 3, 91), Decl(tupleTypeInference.ts, 4, 69)) +>T1 : Symbol(T1, Decl(tupleTypeInference.ts, 5, 8)) +>x : Symbol(x, Decl(tupleTypeInference.ts, 5, 12)) +>IPromise : Symbol(IPromise, Decl(tupleTypeInference.ts, 7, 1)) +>T1 : Symbol(T1, Decl(tupleTypeInference.ts, 5, 8)) +>IPromise : Symbol(IPromise, Decl(tupleTypeInference.ts, 7, 1)) +>T1 : Symbol(T1, Decl(tupleTypeInference.ts, 5, 8)) + + when(t?: T): IPromise; +>when : Symbol(when, Decl(tupleTypeInference.ts, 5, 47)) +>T : Symbol(T, Decl(tupleTypeInference.ts, 6, 9)) +>t : Symbol(t, Decl(tupleTypeInference.ts, 6, 12)) +>T : Symbol(T, Decl(tupleTypeInference.ts, 6, 9)) +>IPromise : Symbol(IPromise, Decl(tupleTypeInference.ts, 7, 1)) +>T : Symbol(T, Decl(tupleTypeInference.ts, 6, 9)) +} + +interface IPromise { +>IPromise : Symbol(IPromise, Decl(tupleTypeInference.ts, 7, 1)) +>T : Symbol(T, Decl(tupleTypeInference.ts, 9, 19)) + + then(callback: (t: T) => TResult): IPromise; +>then : Symbol(then, Decl(tupleTypeInference.ts, 9, 23)) +>TResult : Symbol(TResult, Decl(tupleTypeInference.ts, 10, 9)) +>callback : Symbol(callback, Decl(tupleTypeInference.ts, 10, 18)) +>t : Symbol(t, Decl(tupleTypeInference.ts, 10, 29)) +>T : Symbol(T, Decl(tupleTypeInference.ts, 9, 19)) +>TResult : Symbol(TResult, Decl(tupleTypeInference.ts, 10, 9)) +>IPromise : Symbol(IPromise, Decl(tupleTypeInference.ts, 7, 1)) +>TResult : Symbol(TResult, Decl(tupleTypeInference.ts, 10, 9)) +} + +// Implicit different types +var a = $q.all([$q.when(), $q.when()]); +>a : Symbol(a, Decl(tupleTypeInference.ts, 14, 3)) +>$q.all : Symbol(IQService.all, Decl(tupleTypeInference.ts, 2, 21), Decl(tupleTypeInference.ts, 3, 91), Decl(tupleTypeInference.ts, 4, 69)) +>$q : Symbol($q, Decl(tupleTypeInference.ts, 0, 11)) +>all : Symbol(IQService.all, Decl(tupleTypeInference.ts, 2, 21), Decl(tupleTypeInference.ts, 3, 91), Decl(tupleTypeInference.ts, 4, 69)) +>$q.when : Symbol(IQService.when, Decl(tupleTypeInference.ts, 5, 47)) +>$q : Symbol($q, Decl(tupleTypeInference.ts, 0, 11)) +>when : Symbol(IQService.when, Decl(tupleTypeInference.ts, 5, 47)) +>$q.when : Symbol(IQService.when, Decl(tupleTypeInference.ts, 5, 47)) +>$q : Symbol($q, Decl(tupleTypeInference.ts, 0, 11)) +>when : Symbol(IQService.when, Decl(tupleTypeInference.ts, 5, 47)) + +// Explicit different types +var b = $q.all([$q.when(), $q.when()]); +>b : Symbol(b, Decl(tupleTypeInference.ts, 17, 3)) +>$q.all : Symbol(IQService.all, Decl(tupleTypeInference.ts, 2, 21), Decl(tupleTypeInference.ts, 3, 91), Decl(tupleTypeInference.ts, 4, 69)) +>$q : Symbol($q, Decl(tupleTypeInference.ts, 0, 11)) +>all : Symbol(IQService.all, Decl(tupleTypeInference.ts, 2, 21), Decl(tupleTypeInference.ts, 3, 91), Decl(tupleTypeInference.ts, 4, 69)) +>$q.when : Symbol(IQService.when, Decl(tupleTypeInference.ts, 5, 47)) +>$q : Symbol($q, Decl(tupleTypeInference.ts, 0, 11)) +>when : Symbol(IQService.when, Decl(tupleTypeInference.ts, 5, 47)) +>$q.when : Symbol(IQService.when, Decl(tupleTypeInference.ts, 5, 47)) +>$q : Symbol($q, Decl(tupleTypeInference.ts, 0, 11)) +>when : Symbol(IQService.when, Decl(tupleTypeInference.ts, 5, 47)) + +// Implicit identical types +var c = $q.all([$q.when(), $q.when()]); +>c : Symbol(c, Decl(tupleTypeInference.ts, 20, 3)) +>$q.all : Symbol(IQService.all, Decl(tupleTypeInference.ts, 2, 21), Decl(tupleTypeInference.ts, 3, 91), Decl(tupleTypeInference.ts, 4, 69)) +>$q : Symbol($q, Decl(tupleTypeInference.ts, 0, 11)) +>all : Symbol(IQService.all, Decl(tupleTypeInference.ts, 2, 21), Decl(tupleTypeInference.ts, 3, 91), Decl(tupleTypeInference.ts, 4, 69)) +>$q.when : Symbol(IQService.when, Decl(tupleTypeInference.ts, 5, 47)) +>$q : Symbol($q, Decl(tupleTypeInference.ts, 0, 11)) +>when : Symbol(IQService.when, Decl(tupleTypeInference.ts, 5, 47)) +>$q.when : Symbol(IQService.when, Decl(tupleTypeInference.ts, 5, 47)) +>$q : Symbol($q, Decl(tupleTypeInference.ts, 0, 11)) +>when : Symbol(IQService.when, Decl(tupleTypeInference.ts, 5, 47)) + diff --git a/tests/baselines/reference/tupleTypeInference.types b/tests/baselines/reference/tupleTypeInference.types new file mode 100644 index 00000000000..999574a78e1 --- /dev/null +++ b/tests/baselines/reference/tupleTypeInference.types @@ -0,0 +1,122 @@ +=== tests/cases/compiler/tupleTypeInference.ts === +declare var $q: IQService; +>$q : IQService +>IQService : IQService + +interface IQService { +>IQService : IQService + + all(x: [IPromise, IPromise, IPromise]): IPromise<[T1, T2, T3]>; +>all : { (x: [IPromise, IPromise, IPromise]): IPromise<[T1, T2, T3]>; (x: [IPromise, IPromise]): IPromise<[T1, T2]>; (x: [IPromise]): IPromise<[T1]>; } +>T1 : T1 +>T2 : T2 +>T3 : T3 +>x : [IPromise, IPromise, IPromise] +>IPromise : IPromise +>T1 : T1 +>IPromise : IPromise +>T2 : T2 +>IPromise : IPromise +>T3 : T3 +>IPromise : IPromise +>T1 : T1 +>T2 : T2 +>T3 : T3 + + all(x: [IPromise, IPromise]): IPromise<[T1, T2]>; +>all : { (x: [IPromise, IPromise, IPromise]): IPromise<[T1, T2, T3]>; (x: [IPromise, IPromise]): IPromise<[T1, T2]>; (x: [IPromise]): IPromise<[T1]>; } +>T1 : T1 +>T2 : T2 +>x : [IPromise, IPromise] +>IPromise : IPromise +>T1 : T1 +>IPromise : IPromise +>T2 : T2 +>IPromise : IPromise +>T1 : T1 +>T2 : T2 + + all(x: [IPromise]): IPromise<[T1]>; +>all : { (x: [IPromise, IPromise, IPromise]): IPromise<[T1, T2, T3]>; (x: [IPromise, IPromise]): IPromise<[T1, T2]>; (x: [IPromise]): IPromise<[T1]>; } +>T1 : T1 +>x : [IPromise] +>IPromise : IPromise +>T1 : T1 +>IPromise : IPromise +>T1 : T1 + + when(t?: T): IPromise; +>when : (t?: T) => IPromise +>T : T +>t : T +>T : T +>IPromise : IPromise +>T : T +} + +interface IPromise { +>IPromise : IPromise +>T : T + + then(callback: (t: T) => TResult): IPromise; +>then : (callback: (t: T) => TResult) => IPromise +>TResult : TResult +>callback : (t: T) => TResult +>t : T +>T : T +>TResult : TResult +>IPromise : IPromise +>TResult : TResult +} + +// Implicit different types +var a = $q.all([$q.when(), $q.when()]); +>a : IPromise<[string, number]> +>$q.all([$q.when(), $q.when()]) : IPromise<[string, number]> +>$q.all : { (x: [IPromise, IPromise, IPromise]): IPromise<[T1, T2, T3]>; (x: [IPromise, IPromise]): IPromise<[T1, T2]>; (x: [IPromise]): IPromise<[T1]>; } +>$q : IQService +>all : { (x: [IPromise, IPromise, IPromise]): IPromise<[T1, T2, T3]>; (x: [IPromise, IPromise]): IPromise<[T1, T2]>; (x: [IPromise]): IPromise<[T1]>; } +>[$q.when(), $q.when()] : [IPromise, IPromise] +>$q.when() : IPromise +>$q.when : (t?: T) => IPromise +>$q : IQService +>when : (t?: T) => IPromise +>$q.when() : IPromise +>$q.when : (t?: T) => IPromise +>$q : IQService +>when : (t?: T) => IPromise + +// Explicit different types +var b = $q.all([$q.when(), $q.when()]); +>b : IPromise<[string, number]> +>$q.all([$q.when(), $q.when()]) : IPromise<[string, number]> +>$q.all : { (x: [IPromise, IPromise, IPromise]): IPromise<[T1, T2, T3]>; (x: [IPromise, IPromise]): IPromise<[T1, T2]>; (x: [IPromise]): IPromise<[T1]>; } +>$q : IQService +>all : { (x: [IPromise, IPromise, IPromise]): IPromise<[T1, T2, T3]>; (x: [IPromise, IPromise]): IPromise<[T1, T2]>; (x: [IPromise]): IPromise<[T1]>; } +>[$q.when(), $q.when()] : [IPromise, IPromise] +>$q.when() : IPromise +>$q.when : (t?: T) => IPromise +>$q : IQService +>when : (t?: T) => IPromise +>$q.when() : IPromise +>$q.when : (t?: T) => IPromise +>$q : IQService +>when : (t?: T) => IPromise + +// Implicit identical types +var c = $q.all([$q.when(), $q.when()]); +>c : IPromise<[string, string]> +>$q.all([$q.when(), $q.when()]) : IPromise<[string, string]> +>$q.all : { (x: [IPromise, IPromise, IPromise]): IPromise<[T1, T2, T3]>; (x: [IPromise, IPromise]): IPromise<[T1, T2]>; (x: [IPromise]): IPromise<[T1]>; } +>$q : IQService +>all : { (x: [IPromise, IPromise, IPromise]): IPromise<[T1, T2, T3]>; (x: [IPromise, IPromise]): IPromise<[T1, T2]>; (x: [IPromise]): IPromise<[T1]>; } +>[$q.when(), $q.when()] : [IPromise, IPromise] +>$q.when() : IPromise +>$q.when : (t?: T) => IPromise +>$q : IQService +>when : (t?: T) => IPromise +>$q.when() : IPromise +>$q.when : (t?: T) => IPromise +>$q : IQService +>when : (t?: T) => IPromise + diff --git a/tests/baselines/reference/tupleTypes.errors.txt b/tests/baselines/reference/tupleTypes.errors.txt index d1257be13ef..8f418f98157 100644 --- a/tests/baselines/reference/tupleTypes.errors.txt +++ b/tests/baselines/reference/tupleTypes.errors.txt @@ -9,13 +9,14 @@ tests/cases/compiler/tupleTypes.ts(17,1): error TS2322: Type '[string, number]' tests/cases/compiler/tupleTypes.ts(41,1): error TS2322: 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 '() => string | number' is not assignable to type '() => number'. - Type 'string | number' is not assignable to type 'number'. + Type '() => number | string' is not assignable to type '() => number'. + Type 'number | string' 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'. - Type '{}' is not assignable to type 'number'. + Type '() => number | {}' is not assignable to type '() => number'. + Type 'number | {}' is not assignable to type 'number'. + Type '{}' is not assignable to type 'number'. tests/cases/compiler/tupleTypes.ts(50,1): error TS2322: Type '[number, number]' is not assignable to type '[number, string]'. Types of property '1' are incompatible. Type 'number' is not assignable to type 'string'. @@ -89,16 +90,17 @@ 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 '() => string | number' is not assignable to type '() => number'. -!!! error TS2322: Type 'string | number' is not assignable to type 'number'. +!!! error TS2322: Type '() => number | string' is not assignable to type '() => number'. +!!! error TS2322: Type 'number | string' is not assignable to type 'number'. !!! error TS2322: Type 'string' is not assignable to type 'number'. a = a2; a = a3; // Error ~ !!! error TS2322: Type '[number, {}]' 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 '() => number | {}' is not assignable to type '() => number'. +!!! error TS2322: Type 'number | {}' is not assignable to type 'number'. +!!! error TS2322: Type '{}' is not assignable to type 'number'. a1 = a2; // Error ~~ !!! error TS2322: Type '[number, number]' is not assignable to type '[number, string]'. diff --git a/tests/baselines/reference/typeAliasDoesntMakeModuleInstantiated.types b/tests/baselines/reference/typeAliasDoesntMakeModuleInstantiated.types index 45ddf8cd949..eb0fcdcbbca 100644 --- a/tests/baselines/reference/typeAliasDoesntMakeModuleInstantiated.types +++ b/tests/baselines/reference/typeAliasDoesntMakeModuleInstantiated.types @@ -4,7 +4,7 @@ declare module m { // type alias declaration here shouldnt make the module declaration instantiated type Selector = string| string[] |Function; ->Selector : string | Function | string[] +>Selector : string | string[] | Function >Function : Function export interface IStatic { diff --git a/tests/baselines/reference/typeArgInference2.errors.txt b/tests/baselines/reference/typeArgInference2.errors.txt index dd2e227f2ff..71d2a13f4a1 100644 --- a/tests/baselines/reference/typeArgInference2.errors.txt +++ b/tests/baselines/reference/typeArgInference2.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/typeArgInference2.ts(12,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ name: string; a: number; }' is not a valid type argument because it is not a supertype of candidate '{ name: string; b: number; }'. - Property 'a' is missing in type '{ name: string; b: number; }'. + Object literal may only specify known properties, and 'b' does not exist in type '{ name: string; a: number; }'. ==== tests/cases/compiler/typeArgInference2.ts (1 errors) ==== @@ -19,4 +19,4 @@ tests/cases/compiler/typeArgInference2.ts(12,10): error TS2453: The type argumen ~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ name: string; a: number; }' is not a valid type argument because it is not a supertype of candidate '{ name: string; b: number; }'. -!!! error TS2453: Property 'a' is missing in type '{ name: string; b: number; }'. \ No newline at end of file +!!! error TS2453: Object literal may only specify known properties, and 'b' does not exist in type '{ name: string; a: number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInference.errors.txt b/tests/baselines/reference/typeArgumentInference.errors.txt index 126fe3d772f..669ebadd28a 100644 --- a/tests/baselines/reference/typeArgumentInference.errors.txt +++ b/tests/baselines/reference/typeArgumentInference.errors.txt @@ -2,10 +2,12 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts(68,11 Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts(82,11): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; z: Date; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. - Property 'z' is missing in type '{ x: number; y: string; }'. + Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; z: Date; }'. +tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts(84,66): error TS2345: Argument of type '{ x: number; y: string; }' is not assignable to parameter of type 'A92'. + Object literal may only specify known properties, and 'y' does not exist in type 'A92'. -==== tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts (2 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts (3 errors) ==== // Generic call with no parameters function noParams() { } noParams(); @@ -94,9 +96,12 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts(82,11 ~~~~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; z: Date; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. -!!! error TS2453: Property 'z' is missing in type '{ x: number; y: string; }'. +!!! error TS2453: Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; z: Date; }'. var a9e: {}; var a9f = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ x: number; y: string; }' is not assignable to parameter of type 'A92'. +!!! error TS2345: Object literal may only specify known properties, and 'y' does not exist in type 'A92'. var a9f: A92; // Generic call with multiple parameters of generic type passed arguments with a single best common type diff --git a/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt b/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt index c82dab89e94..305eee1c941 100644 --- a/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt @@ -14,12 +14,14 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(118,9): error TS2304: Cannot find name 'Window'. tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts(120,15): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; z: any; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. - Property 'z' is missing in type '{ x: number; y: string; }'. + Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; z: any; }'. 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(122,66): error TS2345: Argument of type '{ x: number; y: string; }' is not assignable to parameter of type 'A92'. + Object literal may only specify known properties, and 'y' does not exist in type 'A92'. -==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts (10 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts (11 errors) ==== // Generic call with no parameters interface NoParams { new (); @@ -164,13 +166,16 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct ~~~~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; z: any; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. -!!! error TS2453: Property 'z' is missing in type '{ x: number; y: string; }'. +!!! error TS2453: Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; z: any; }'. ~~~~~~ !!! error TS2304: Cannot find name 'window'. var a9e: {}; var a9f = new someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' }); ~~~~~~ !!! error TS2304: Cannot find name 'window'. + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ x: number; y: string; }' is not assignable to parameter of type 'A92'. +!!! error TS2345: Object literal may only specify known properties, and 'y' does not exist in type 'A92'. var a9f: A92; // Generic call with multiple parameters of generic type passed arguments with a single best common type diff --git a/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt b/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt index 56370ac03d5..6b81cd6f232 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt @@ -19,12 +19,14 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst 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 TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate '{ x: number; z: any; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. - Property 'z' is missing in type '{ x: number; y: string; }'. + Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; z: any; }'. 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(89,62): error TS2345: Argument of type '{ x: number; y: string; }' is not assignable to parameter of type 'A92'. + Object literal may only specify known properties, and 'y' does not exist in type 'A92'. -==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts (15 errors) ==== +==== tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts (16 errors) ==== // Generic call with no parameters function noParams() { } noParams(); @@ -146,13 +148,16 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst ~~~~~~~~~~~~~ !!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. !!! error TS2453: Type argument candidate '{ x: number; z: any; }' is not a valid type argument because it is not a supertype of candidate '{ x: number; y: string; }'. -!!! error TS2453: Property 'z' is missing in type '{ x: number; y: string; }'. +!!! error TS2453: Object literal may only specify known properties, and 'y' does not exist in type '{ x: number; z: any; }'. ~~~~~~ !!! error TS2304: Cannot find name 'window'. var a9e: {}; var a9f = someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' }); ~~~~~~ !!! error TS2304: Cannot find name 'window'. + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ x: number; y: string; }' is not assignable to parameter of type 'A92'. +!!! error TS2345: Object literal may only specify known properties, and 'y' does not exist in type 'A92'. var a9f: A92; // Generic call with multiple parameters of generic type passed arguments with a single best common type diff --git a/tests/baselines/reference/typeGuardFunction.types b/tests/baselines/reference/typeGuardFunction.types index 6cc278f122f..50a5fcaf324 100644 --- a/tests/baselines/reference/typeGuardFunction.types +++ b/tests/baselines/reference/typeGuardFunction.types @@ -216,7 +216,7 @@ acceptingTypeGuardFunction(isA); // Binary expressions let union2: C | B; ->union2 : B | C +>union2 : C | B >C : C >B : B @@ -226,6 +226,6 @@ let union3: boolean | B = isA(union2) || union2; >isA(union2) || union2 : boolean | B >isA(union2) : boolean >isA : (p1: any) => p1 is A ->union2 : B | C +>union2 : C | B >union2 : B diff --git a/tests/baselines/reference/typeGuardOfFormExpr1AndExpr2.types b/tests/baselines/reference/typeGuardOfFormExpr1AndExpr2.types index 6714ecf5570..10f50bed52e 100644 --- a/tests/baselines/reference/typeGuardOfFormExpr1AndExpr2.types +++ b/tests/baselines/reference/typeGuardOfFormExpr1AndExpr2.types @@ -26,7 +26,7 @@ var c: C; >C : C var cOrBool: C| boolean; ->cOrBool : boolean | C +>cOrBool : C | boolean >C : C var strOrNumOrBoolOrC: string | number | boolean | C; @@ -108,7 +108,7 @@ if (typeof strOrNumOrBoolOrC !== "string" && typeof strOrNumOrBoolOrC !== "numbe cOrBool = strOrNumOrBoolOrC; // C | boolean >cOrBool = strOrNumOrBoolOrC : boolean | C ->cOrBool : boolean | C +>cOrBool : C | boolean >strOrNumOrBoolOrC : boolean | C bool = strOrNumOrBool; // boolean diff --git a/tests/baselines/reference/typeGuardOfFormExpr1OrExpr2.types b/tests/baselines/reference/typeGuardOfFormExpr1OrExpr2.types index 2cad437ddeb..acd929a7ca1 100644 --- a/tests/baselines/reference/typeGuardOfFormExpr1OrExpr2.types +++ b/tests/baselines/reference/typeGuardOfFormExpr1OrExpr2.types @@ -26,7 +26,7 @@ var c: C; >C : C var cOrBool: C| boolean; ->cOrBool : boolean | C +>cOrBool : C | boolean >C : C var strOrNumOrBoolOrC: string | number | boolean | C; @@ -118,7 +118,7 @@ if (typeof strOrNumOrBoolOrC === "string" || typeof strOrNumOrBoolOrC === "numbe else { cOrBool = strOrNumOrBoolOrC; // C | boolean >cOrBool = strOrNumOrBoolOrC : boolean | C ->cOrBool : boolean | C +>cOrBool : C | boolean >strOrNumOrBoolOrC : boolean | C bool = strOrNumOrBool; // boolean diff --git a/tests/baselines/reference/typeGuardOfFormInstanceOf.types b/tests/baselines/reference/typeGuardOfFormInstanceOf.types index 891e8c1bea2..c824e907733 100644 --- a/tests/baselines/reference/typeGuardOfFormInstanceOf.types +++ b/tests/baselines/reference/typeGuardOfFormInstanceOf.types @@ -121,7 +121,7 @@ str = c2Ord1 instanceof D1 && c2Ord1.p1; // D1 >p1 : string var r2: D1 | C2 = c2Ord1 instanceof C1 && c2Ord1; // C2 | D1 ->r2 : C2 | D1 +>r2 : D1 | C2 >D1 : D1 >C2 : C2 >c2Ord1 instanceof C1 && c2Ord1 : D1 diff --git a/tests/baselines/reference/typeGuardOfFormInstanceOfOnInterface.types b/tests/baselines/reference/typeGuardOfFormInstanceOfOnInterface.types index fe23d6d303e..20d1c1644fc 100644 --- a/tests/baselines/reference/typeGuardOfFormInstanceOfOnInterface.types +++ b/tests/baselines/reference/typeGuardOfFormInstanceOfOnInterface.types @@ -151,7 +151,7 @@ str = c2Ord1 instanceof d1 && c2Ord1.p1; // D1 >p1 : string var r2: D1 | C2 = c2Ord1 instanceof c1 && c2Ord1; // C2 | D1 ->r2 : C2 | D1 +>r2 : D1 | C2 >D1 : D1 >C2 : C2 >c2Ord1 instanceof c1 && c2Ord1 : D1 diff --git a/tests/baselines/reference/typeGuardsDefeat.types b/tests/baselines/reference/typeGuardsDefeat.types index d3a017bd913..cc655d3ce0f 100644 --- a/tests/baselines/reference/typeGuardsDefeat.types +++ b/tests/baselines/reference/typeGuardsDefeat.types @@ -2,21 +2,21 @@ // Also note that it is possible to defeat a type guard by calling a function that changes the // type of the guarded variable. function foo(x: number | string) { ->foo : (x: string | number) => number ->x : string | number +>foo : (x: number | string) => number +>x : number | string function f() { >f : () => void x = 10; >x = 10 : number ->x : string | number +>x : number | string >10 : number } if (typeof x === "string") { >typeof x === "string" : boolean >typeof x : string ->x : string | number +>x : number | string >"string" : string f(); @@ -35,13 +35,13 @@ function foo(x: number | string) { } } function foo2(x: number | string) { ->foo2 : (x: string | number) => number ->x : string | number +>foo2 : (x: number | string) => number +>x : number | string if (typeof x === "string") { >typeof x === "string" : boolean >typeof x : string ->x : string | number +>x : number | string >"string" : string return x.length; // string @@ -63,7 +63,7 @@ function foo2(x: number | string) { } x = "hello"; >x = "hello" : string ->x : string | number +>x : number | string >"hello" : string f(); @@ -71,13 +71,13 @@ function foo2(x: number | string) { >f : () => number } function foo3(x: number | string) { ->foo3 : (x: string | number) => number ->x : string | number +>foo3 : (x: number | string) => number +>x : number | string if (typeof x === "string") { >typeof x === "string" : boolean >typeof x : string ->x : string | number +>x : number | string >"string" : string return x.length; // string @@ -95,7 +95,7 @@ function foo3(x: number | string) { } x = "hello"; >x = "hello" : string ->x : string | number +>x : number | string >"hello" : string f(); diff --git a/tests/baselines/reference/typeGuardsInConditionalExpression.errors.txt b/tests/baselines/reference/typeGuardsInConditionalExpression.errors.txt new file mode 100644 index 00000000000..37a662e007c --- /dev/null +++ b/tests/baselines/reference/typeGuardsInConditionalExpression.errors.txt @@ -0,0 +1,103 @@ +tests/cases/conformance/expressions/typeGuards/typeGuardsInConditionalExpression.ts(93,22): error TS2349: Cannot invoke an expression whose type lacks a call signature. + + +==== tests/cases/conformance/expressions/typeGuards/typeGuardsInConditionalExpression.ts (1 errors) ==== + // 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. + + function foo(x: number | string) { + return typeof x === "string" + ? x.length // string + : x++; // number + } + function foo2(x: number | string) { + // x is assigned in the if true branch, the type is not narrowed + return typeof x === "string" + ? (x = 10 && x)// string | number + : x; // string | number + } + function foo3(x: number | string) { + // x is assigned in the if false branch, the type is not narrowed + // even though assigned using same type as narrowed expression + return typeof x === "string" + ? (x = "Hello" && x) // string | number + : x; // string | number + } + function foo4(x: number | string) { + // false branch updates the variable - so here it is not number + // even though assigned using same type as narrowed expression + return typeof x === "string" + ? x // string | number + : (x = 10 && x); // string | number + } + function foo5(x: number | string) { + // false branch updates the variable - so here it is not number + return typeof x === "string" + ? x // string | number + : (x = "hello" && x); // string | number + } + function foo6(x: number | string) { + // Modify in both branches + return typeof x === "string" + ? (x = 10 && x) // string | number + : (x = "hello" && x); // string | number + } + function foo7(x: number | string | boolean) { + return typeof x === "string" + ? x === "hello" // string + : typeof x === "boolean" + ? x // boolean + : x == 10; // number + } + function foo8(x: number | string | boolean) { + var b: number | boolean; + return typeof x === "string" + ? x === "hello" + : ((b = x) && // number | boolean + (typeof x === "boolean" + ? x // boolean + : x == 10)); // number + } + function foo9(x: number | string) { + var y = 10; + // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop + return typeof x === "string" + ? ((y = x.length) && x === "hello") // string + : x === 10; // number + } + function foo10(x: number | string | boolean) { + // Mixing typeguards + var b: boolean | number; + return typeof x === "string" + ? x // string + : ((b = x) // x is number | boolean + && typeof x === "number" + && x.toString()); // x is number + } + function foo11(x: number | string | boolean) { + // Mixing typeguards + // Assigning value to x deep inside another guard stops narrowing of type too + var b: number | boolean | string; + return typeof x === "string" + ? x // number | boolean | string - changed in the false branch + : ((b = x) // x is number | boolean | string - because the assignment changed it + && typeof x === "number" + && (x = 10) // assignment to x + && x); // x is number | boolean | string + } + function foo12(x: number | string | boolean) { + // Mixing typeguards + // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression + var b: number | boolean | string; + return typeof x === "string" + ? (x = 10 && x.toString().length) // number | boolean | string - changed here + ~~~~~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. + : ((b = x) // x is number | boolean | string - changed in true branch + && typeof x === "number" + && x); // x is number + } \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsInConditionalExpression.symbols b/tests/baselines/reference/typeGuardsInConditionalExpression.symbols deleted file mode 100644 index 2a7eb47523f..00000000000 --- a/tests/baselines/reference/typeGuardsInConditionalExpression.symbols +++ /dev/null @@ -1,251 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardsInConditionalExpression.ts === -// 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. - -function foo(x: number | string) { ->foo : Symbol(foo, Decl(typeGuardsInConditionalExpression.ts, 0, 0)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 7, 13)) - - return typeof x === "string" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 7, 13)) - - ? x.length // string ->x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 7, 13)) ->length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) - - : x++; // number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 7, 13)) -} -function foo2(x: number | string) { ->foo2 : Symbol(foo2, Decl(typeGuardsInConditionalExpression.ts, 11, 1)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14)) - - // x is assigned in the if true branch, the type is not narrowed - return typeof x === "string" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14)) - - ? (x = 10 && x)// string | number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14)) - - : x; // string | number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14)) -} -function foo3(x: number | string) { ->foo3 : Symbol(foo3, Decl(typeGuardsInConditionalExpression.ts, 17, 1)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14)) - - // x is assigned in the if false branch, the type is not narrowed - // even though assigned using same type as narrowed expression - return typeof x === "string" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14)) - - ? (x = "Hello" && x) // string | number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14)) - - : x; // string | number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14)) -} -function foo4(x: number | string) { ->foo4 : Symbol(foo4, Decl(typeGuardsInConditionalExpression.ts, 24, 1)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14)) - - // false branch updates the variable - so here it is not number - // even though assigned using same type as narrowed expression - return typeof x === "string" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14)) - - ? x // string | number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14)) - - : (x = 10 && x); // string | number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14)) -} -function foo5(x: number | string) { ->foo5 : Symbol(foo5, Decl(typeGuardsInConditionalExpression.ts, 31, 1)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14)) - - // false branch updates the variable - so here it is not number - return typeof x === "string" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14)) - - ? x // string | number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14)) - - : (x = "hello" && x); // string | number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14)) -} -function foo6(x: number | string) { ->foo6 : Symbol(foo6, Decl(typeGuardsInConditionalExpression.ts, 37, 1)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14)) - - // Modify in both branches - return typeof x === "string" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14)) - - ? (x = 10 && x) // string | number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14)) - - : (x = "hello" && x); // string | number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14)) -} -function foo7(x: number | string | boolean) { ->foo7 : Symbol(foo7, Decl(typeGuardsInConditionalExpression.ts, 43, 1)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14)) - - return typeof x === "string" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14)) - - ? x === "hello" // string ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14)) - - : typeof x === "boolean" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14)) - - ? x // boolean ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14)) - - : x == 10; // number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14)) -} -function foo8(x: number | string | boolean) { ->foo8 : Symbol(foo8, Decl(typeGuardsInConditionalExpression.ts, 50, 1)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14)) - - var b: number | boolean; ->b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 52, 7)) - - return typeof x === "string" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14)) - - ? x === "hello" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14)) - - : ((b = x) && // number | boolean ->b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 52, 7)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14)) - - (typeof x === "boolean" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14)) - - ? x // boolean ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14)) - - : x == 10)); // number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14)) -} -function foo9(x: number | string) { ->foo9 : Symbol(foo9, Decl(typeGuardsInConditionalExpression.ts, 59, 1)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14)) - - var y = 10; ->y : Symbol(y, Decl(typeGuardsInConditionalExpression.ts, 61, 7)) - - // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop - return typeof x === "string" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14)) - - ? ((y = x.length) && x === "hello") // string ->y : Symbol(y, Decl(typeGuardsInConditionalExpression.ts, 61, 7)) ->x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14)) ->length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14)) - - : x === 10; // number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14)) -} -function foo10(x: number | string | boolean) { ->foo10 : Symbol(foo10, Decl(typeGuardsInConditionalExpression.ts, 66, 1)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15)) - - // Mixing typeguards - var b: boolean | number; ->b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 69, 7)) - - return typeof x === "string" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15)) - - ? x // string ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15)) - - : ((b = x) // x is number | boolean ->b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 69, 7)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15)) - - && typeof x === "number" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15)) - - && x.toString()); // x is number ->x.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15)) ->toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) -} -function foo11(x: number | string | boolean) { ->foo11 : Symbol(foo11, Decl(typeGuardsInConditionalExpression.ts, 75, 1)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15)) - - // Mixing typeguards - // Assigning value to x deep inside another guard stops narrowing of type too - var b: number | boolean | string; ->b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 79, 7)) - - return typeof x === "string" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15)) - - ? x // number | boolean | string - changed in the false branch ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15)) - - : ((b = x) // x is number | boolean | string - because the assignment changed it ->b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 79, 7)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15)) - - && typeof x === "number" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15)) - - && (x = 10) // assignment to x ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15)) - - && x); // x is number | boolean | string ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15)) -} -function foo12(x: number | string | boolean) { ->foo12 : Symbol(foo12, Decl(typeGuardsInConditionalExpression.ts, 86, 1)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15)) - - // Mixing typeguards - // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression - var b: number | boolean | string; ->b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 90, 7)) - - return typeof x === "string" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15)) - - ? (x = 10 && x.toString().length) // number | boolean | string - changed here ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15)) ->x.toString().length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) ->x.toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15)) ->toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) ->length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) - - : ((b = x) // x is number | boolean | string - changed in true branch ->b : Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 90, 7)) ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15)) - - && typeof x === "number" ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15)) - - && x); // x is number ->x : Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15)) -} diff --git a/tests/baselines/reference/typeGuardsInConditionalExpression.types b/tests/baselines/reference/typeGuardsInConditionalExpression.types deleted file mode 100644 index 3965abfe962..00000000000 --- a/tests/baselines/reference/typeGuardsInConditionalExpression.types +++ /dev/null @@ -1,388 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardsInConditionalExpression.ts === -// 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. - -function foo(x: number | string) { ->foo : (x: string | number) => number ->x : string | number - - return typeof x === "string" ->typeof x === "string" ? x.length // string : x++ : number ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - ? x.length // string ->x.length : number ->x : string ->length : number - - : x++; // number ->x++ : number ->x : number -} -function foo2(x: number | string) { ->foo2 : (x: string | number) => string | number ->x : string | number - - // x is assigned in the if true branch, the type is not narrowed - return typeof x === "string" ->typeof x === "string" ? (x = 10 && x)// string | number : x : string | number ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - ? (x = 10 && x)// string | number ->(x = 10 && x) : string | number ->x = 10 && x : string | number ->x : string | number ->10 && x : string | number ->10 : number ->x : string | number - - : x; // string | number ->x : string | number -} -function foo3(x: number | string) { ->foo3 : (x: string | number) => string | number ->x : string | number - - // x is assigned in the if false branch, the type is not narrowed - // even though assigned using same type as narrowed expression - return typeof x === "string" ->typeof x === "string" ? (x = "Hello" && x) // string | number : x : string | number ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - ? (x = "Hello" && x) // string | number ->(x = "Hello" && x) : string | number ->x = "Hello" && x : string | number ->x : string | number ->"Hello" && x : string | number ->"Hello" : string ->x : string | number - - : x; // string | number ->x : string | number -} -function foo4(x: number | string) { ->foo4 : (x: string | number) => string | number ->x : string | number - - // false branch updates the variable - so here it is not number - // even though assigned using same type as narrowed expression - return typeof x === "string" ->typeof x === "string" ? x // string | number : (x = 10 && x) : string | number ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - ? x // string | number ->x : string | number - - : (x = 10 && x); // string | number ->(x = 10 && x) : string | number ->x = 10 && x : string | number ->x : string | number ->10 && x : string | number ->10 : number ->x : string | number -} -function foo5(x: number | string) { ->foo5 : (x: string | number) => string | number ->x : string | number - - // false branch updates the variable - so here it is not number - return typeof x === "string" ->typeof x === "string" ? x // string | number : (x = "hello" && x) : string | number ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - ? x // string | number ->x : string | number - - : (x = "hello" && x); // string | number ->(x = "hello" && x) : string | number ->x = "hello" && x : string | number ->x : string | number ->"hello" && x : string | number ->"hello" : string ->x : string | number -} -function foo6(x: number | string) { ->foo6 : (x: string | number) => string | number ->x : string | number - - // Modify in both branches - return typeof x === "string" ->typeof x === "string" ? (x = 10 && x) // string | number : (x = "hello" && x) : string | number ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - ? (x = 10 && x) // string | number ->(x = 10 && x) : string | number ->x = 10 && x : string | number ->x : string | number ->10 && x : string | number ->10 : number ->x : string | number - - : (x = "hello" && x); // string | number ->(x = "hello" && x) : string | number ->x = "hello" && x : string | number ->x : string | number ->"hello" && x : string | number ->"hello" : string ->x : string | number -} -function foo7(x: number | string | boolean) { ->foo7 : (x: string | number | boolean) => boolean ->x : string | number | boolean - - return typeof x === "string" ->typeof x === "string" ? x === "hello" // string : typeof x === "boolean" ? x // boolean : x == 10 : boolean ->typeof x === "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - ? x === "hello" // string ->x === "hello" : boolean ->x : string ->"hello" : string - - : typeof x === "boolean" ->typeof x === "boolean" ? x // boolean : x == 10 : boolean ->typeof x === "boolean" : boolean ->typeof x : string ->x : number | boolean ->"boolean" : string - - ? x // boolean ->x : boolean - - : x == 10; // number ->x == 10 : boolean ->x : number ->10 : number -} -function foo8(x: number | string | boolean) { ->foo8 : (x: string | number | boolean) => boolean ->x : string | number | boolean - - var b: number | boolean; ->b : number | boolean - - return typeof x === "string" ->typeof x === "string" ? x === "hello" : ((b = x) && // number | boolean (typeof x === "boolean" ? x // boolean : x == 10)) : boolean ->typeof x === "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - ? x === "hello" ->x === "hello" : boolean ->x : string ->"hello" : string - - : ((b = x) && // number | boolean ->((b = x) && // number | boolean (typeof x === "boolean" ? x // boolean : x == 10)) : boolean ->(b = x) && // number | boolean (typeof x === "boolean" ? x // boolean : x == 10) : boolean ->(b = x) : number | boolean ->b = x : number | boolean ->b : number | boolean ->x : number | boolean - - (typeof x === "boolean" ->(typeof x === "boolean" ? x // boolean : x == 10) : boolean ->typeof x === "boolean" ? x // boolean : x == 10 : boolean ->typeof x === "boolean" : boolean ->typeof x : string ->x : number | boolean ->"boolean" : string - - ? x // boolean ->x : boolean - - : x == 10)); // number ->x == 10 : boolean ->x : number ->10 : number -} -function foo9(x: number | string) { ->foo9 : (x: string | number) => boolean ->x : string | number - - var y = 10; ->y : number ->10 : number - - // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop - return typeof x === "string" ->typeof x === "string" ? ((y = x.length) && x === "hello") // string : x === 10 : boolean ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - ? ((y = x.length) && x === "hello") // string ->((y = x.length) && x === "hello") : boolean ->(y = x.length) && x === "hello" : boolean ->(y = x.length) : number ->y = x.length : number ->y : number ->x.length : number ->x : string ->length : number ->x === "hello" : boolean ->x : string ->"hello" : string - - : x === 10; // number ->x === 10 : boolean ->x : number ->10 : number -} -function foo10(x: number | string | boolean) { ->foo10 : (x: string | number | boolean) => string ->x : string | number | boolean - - // Mixing typeguards - var b: boolean | number; ->b : number | boolean - - return typeof x === "string" ->typeof x === "string" ? x // string : ((b = x) // x is number | boolean && typeof x === "number" && x.toString()) : string ->typeof x === "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - ? x // string ->x : string - - : ((b = x) // x is number | boolean ->((b = x) // x is number | boolean && typeof x === "number" && x.toString()) : string ->(b = x) // x is number | boolean && typeof x === "number" && x.toString() : string ->(b = x) // x is number | boolean && typeof x === "number" : boolean ->(b = x) : number | boolean ->b = x : number | boolean ->b : number | boolean ->x : number | boolean - - && typeof x === "number" ->typeof x === "number" : boolean ->typeof x : string ->x : number | boolean ->"number" : string - - && x.toString()); // x is number ->x.toString() : string ->x.toString : (radix?: number) => string ->x : number ->toString : (radix?: number) => string -} -function foo11(x: number | string | boolean) { ->foo11 : (x: string | number | boolean) => string | number | boolean ->x : string | number | boolean - - // Mixing typeguards - // Assigning value to x deep inside another guard stops narrowing of type too - var b: number | boolean | string; ->b : string | number | boolean - - return typeof x === "string" ->typeof x === "string" ? x // number | boolean | string - changed in the false branch : ((b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) // assignment to x && x) : string | number | boolean ->typeof x === "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - ? x // number | boolean | string - changed in the false branch ->x : string | number | boolean - - : ((b = x) // x is number | boolean | string - because the assignment changed it ->((b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) // assignment to x && x) : string | number | boolean ->(b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) // assignment to x && x : string | number | boolean ->(b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) : number ->(b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" : boolean ->(b = x) : string | number | boolean ->b = x : string | number | boolean ->b : string | number | boolean ->x : string | number | boolean - - && typeof x === "number" ->typeof x === "number" : boolean ->typeof x : string ->x : string | number | boolean ->"number" : string - - && (x = 10) // assignment to x ->(x = 10) : number ->x = 10 : number ->x : string | number | boolean ->10 : number - - && x); // x is number | boolean | string ->x : string | number | boolean -} -function foo12(x: number | string | boolean) { ->foo12 : (x: string | number | boolean) => number ->x : string | number | boolean - - // Mixing typeguards - // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression - var b: number | boolean | string; ->b : string | number | boolean - - return typeof x === "string" ->typeof x === "string" ? (x = 10 && x.toString().length) // number | boolean | string - changed here : ((b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" && x) : number ->typeof x === "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - ? (x = 10 && x.toString().length) // number | boolean | string - changed here ->(x = 10 && x.toString().length) : number ->x = 10 && x.toString().length : number ->x : string | number | boolean ->10 && x.toString().length : number ->10 : number ->x.toString().length : number ->x.toString() : string ->x.toString : (radix?: number) => string ->x : string | number | boolean ->toString : (radix?: number) => string ->length : number - - : ((b = x) // x is number | boolean | string - changed in true branch ->((b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" && x) : number ->(b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" && x : number ->(b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" : boolean ->(b = x) : string | number | boolean ->b = x : string | number | boolean ->b : string | number | boolean ->x : string | number | boolean - - && typeof x === "number" ->typeof x === "number" : boolean ->typeof x : string ->x : string | number | boolean ->"number" : string - - && x); // x is number ->x : number -} diff --git a/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types b/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types index 600b2720404..0a084d6eb54 100644 --- a/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types +++ b/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types @@ -2,14 +2,14 @@ // typeguards are scoped in function/module block function foo(x: number | string | boolean) { ->foo : (x: string | number | boolean) => string ->x : string | number | boolean +>foo : (x: number | string | boolean) => string +>x : number | string | boolean return typeof x === "string" >typeof x === "string" ? x : function f() { var b = x; // number | boolean return typeof x === "boolean" ? x.toString() // boolean : x.toString(); // number } () : string >typeof x === "string" : boolean >typeof x : string ->x : string | number | boolean +>x : number | string | boolean >"string" : string ? x @@ -46,14 +46,14 @@ function foo(x: number | string | boolean) { } (); } function foo2(x: number | string | boolean) { ->foo2 : (x: string | number | boolean) => string ->x : string | number | boolean +>foo2 : (x: number | string | boolean) => string +>x : number | string | boolean return typeof x === "string" >typeof x === "string" ? x : function f(a: number | boolean) { var b = x; // new scope - number | boolean return typeof x === "boolean" ? x.toString() // boolean : x.toString(); // number } (x) : string >typeof x === "string" : boolean >typeof x : string ->x : string | number | boolean +>x : number | string | boolean >"string" : string ? x @@ -92,14 +92,14 @@ function foo2(x: number | string | boolean) { >x : number | boolean } function foo3(x: number | string | boolean) { ->foo3 : (x: string | number | boolean) => string ->x : string | number | boolean +>foo3 : (x: number | string | boolean) => string +>x : number | string | boolean return typeof x === "string" >typeof x === "string" ? x : (() => { var b = x; // new scope - number | boolean return typeof x === "boolean" ? x.toString() // boolean : x.toString(); // number })() : string >typeof x === "string" : boolean >typeof x : string ->x : string | number | boolean +>x : number | string | boolean >"string" : string ? x @@ -136,14 +136,14 @@ function foo3(x: number | string | boolean) { })(); } function foo4(x: number | string | boolean) { ->foo4 : (x: string | number | boolean) => string ->x : string | number | boolean +>foo4 : (x: number | string | boolean) => string +>x : number | string | boolean return typeof x === "string" >typeof x === "string" ? x : ((a: number | boolean) => { var b = x; // new scope - number | boolean return typeof x === "boolean" ? x.toString() // boolean : x.toString(); // number })(x) : string >typeof x === "string" : boolean >typeof x : string ->x : string | number | boolean +>x : number | string | boolean >"string" : string ? x @@ -183,13 +183,13 @@ function foo4(x: number | string | boolean) { } // Type guards affect nested function expressions, but not nested function declarations function foo5(x: number | string | boolean) { ->foo5 : (x: string | number | boolean) => void ->x : string | number | boolean +>foo5 : (x: number | string | boolean) => void +>x : number | string | boolean if (typeof x === "string") { >typeof x === "string" : boolean >typeof x : string ->x : string | number | boolean +>x : number | string | boolean >"string" : string var y = x; // string; @@ -200,8 +200,8 @@ function foo5(x: number | string | boolean) { >foo : () => void var z = x; // number | string | boolean, type guard has no effect ->z : string | number | boolean ->x : string | number | boolean +>z : number | string | boolean +>x : number | string | boolean } } } @@ -209,14 +209,14 @@ module m { >m : typeof m var x: number | string | boolean; ->x : string | number | boolean +>x : number | string | boolean module m2 { >m2 : typeof m2 var b = x; // new scope - number | boolean | string ->b : string | number | boolean ->x : string | number | boolean +>b : number | string | boolean +>x : number | string | boolean var y: string; >y : string @@ -224,7 +224,7 @@ module m { if (typeof x === "string") { >typeof x === "string" : boolean >typeof x : string ->x : string | number | boolean +>x : number | string | boolean >"string" : string y = x // string; @@ -260,15 +260,15 @@ module m1 { >m1 : typeof m1 var x: number | string | boolean; ->x : string | number | boolean +>x : number | string | boolean module m2.m3 { >m2 : typeof m2 >m3 : typeof m3 var b = x; // new scope - number | boolean | string ->b : string | number | boolean ->x : string | number | boolean +>b : number | string | boolean +>x : number | string | boolean var y: string; >y : string @@ -276,7 +276,7 @@ module m1 { if (typeof x === "string") { >typeof x === "string" : boolean >typeof x : string ->x : string | number | boolean +>x : number | string | boolean >"string" : string y = x // string; diff --git a/tests/baselines/reference/typeGuardsInIfStatement.errors.txt b/tests/baselines/reference/typeGuardsInIfStatement.errors.txt new file mode 100644 index 00000000000..e675daffd6e --- /dev/null +++ b/tests/baselines/reference/typeGuardsInIfStatement.errors.txt @@ -0,0 +1,160 @@ +tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(127,23): error TS2349: Cannot invoke an expression whose type lacks a call signature. +tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(131,22): error TS2349: Cannot invoke an expression whose type lacks a call signature. +tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts(139,16): error TS2349: Cannot invoke an expression whose type lacks a call signature. + + +==== tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts (3 errors) ==== + // 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 + function foo(x: number | string) { + if (typeof x === "string") { + return x.length; // string + } + else { + return x++; // number + } + } + function foo2(x: number | string) { + // x is assigned in the if true branch, the type is not narrowed + if (typeof x === "string") { + x = 10; + return x; // string | number + } + else { + return x; // string | number + } + } + function foo3(x: number | string) { + // x is assigned in the if true branch, the type is not narrowed + if (typeof x === "string") { + x = "Hello"; // even though assigned using same type as narrowed expression + return x; // string | number + } + else { + return x; // string | number + } + } + function foo4(x: number | string) { + // false branch updates the variable - so here it is not number + if (typeof x === "string") { + return x; // string | number + } + else { + x = 10; // even though assigned number - this should result in x to be string | number + return x; // string | number + } + } + function foo5(x: number | string) { + // false branch updates the variable - so here it is not number + if (typeof x === "string") { + return x; // string | number + } + else { + x = "hello"; + return x; // string | number + } + } + function foo6(x: number | string) { + // Modify in both branches + if (typeof x === "string") { + x = 10; + return x; // string | number + } + else { + x = "hello"; + return x; // string | number + } + } + function foo7(x: number | string | boolean) { + if (typeof x === "string") { + return x === "hello"; // string + } + else if (typeof x === "boolean") { + return x; // boolean + } + else { + return x == 10; // number + } + } + function foo8(x: number | string | boolean) { + if (typeof x === "string") { + return x === "hello"; // string + } + else { + var b: number | boolean = x; // number | boolean + if (typeof x === "boolean") { + return x; // boolean + } + else { + return x == 10; // number + } + } + } + function foo9(x: number | string) { + var y = 10; + if (typeof x === "string") { + // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop + y = x.length; + return x === "hello"; // string + } + else { + return x == 10; // number + } + } + function foo10(x: number | string | boolean) { + // Mixing typeguard narrowing in if statement with conditional expression typeguard + if (typeof x === "string") { + return x === "hello"; // string + } + else { + var y: boolean | string; + var b = x; // number | boolean + return typeof x === "number" + ? x === 10 // number + : x; // x should be boolean + } + } + function foo11(x: number | string | boolean) { + // Mixing typeguard narrowing in if statement with conditional expression typeguard + // Assigning value to x deep inside another guard stops narrowing of type too + if (typeof x === "string") { + return x; // string | number | boolean - x changed in else branch + } + else { + var y: number| boolean | string; + var b = x; // number | boolean | string - because below we are changing value of x in if statement + return typeof x === "number" + ? ( + // change value of x + x = 10 && x.toString() // number | boolean | string + ~~~~~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. + ) + : ( + // do not change value + y = x && x.toString() // number | boolean | string + ~~~~~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. + ); + } + } + function foo12(x: number | string | boolean) { + // Mixing typeguard narrowing in if statement with conditional expression typeguard + // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression + if (typeof x === "string") { + return x.toString(); // string | number | boolean - x changed in else branch + ~~~~~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. + } + else { + x = 10; + var b = x; // number | boolean | string + return typeof x === "number" + ? x.toString() // number + : x.toString(); // boolean | string + } + } \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsInIfStatement.symbols b/tests/baselines/reference/typeGuardsInIfStatement.symbols deleted file mode 100644 index d81be08d1a0..00000000000 --- a/tests/baselines/reference/typeGuardsInIfStatement.symbols +++ /dev/null @@ -1,304 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts === -// 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 -function foo(x: number | string) { ->foo : Symbol(foo, Decl(typeGuardsInIfStatement.ts, 0, 0)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 6, 13)) - - if (typeof x === "string") { ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 6, 13)) - - return x.length; // string ->x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 6, 13)) ->length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) - } - else { - return x++; // number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 6, 13)) - } -} -function foo2(x: number | string) { ->foo2 : Symbol(foo2, Decl(typeGuardsInIfStatement.ts, 13, 1)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 14, 14)) - - // x is assigned in the if true branch, the type is not narrowed - if (typeof x === "string") { ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 14, 14)) - - x = 10; ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 14, 14)) - - return x; // string | number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 14, 14)) - } - else { - return x; // string | number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 14, 14)) - } -} -function foo3(x: number | string) { ->foo3 : Symbol(foo3, Decl(typeGuardsInIfStatement.ts, 23, 1)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 24, 14)) - - // x is assigned in the if true branch, the type is not narrowed - if (typeof x === "string") { ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 24, 14)) - - x = "Hello"; // even though assigned using same type as narrowed expression ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 24, 14)) - - return x; // string | number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 24, 14)) - } - else { - return x; // string | number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 24, 14)) - } -} -function foo4(x: number | string) { ->foo4 : Symbol(foo4, Decl(typeGuardsInIfStatement.ts, 33, 1)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 34, 14)) - - // false branch updates the variable - so here it is not number - if (typeof x === "string") { ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 34, 14)) - - return x; // string | number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 34, 14)) - } - else { - x = 10; // even though assigned number - this should result in x to be string | number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 34, 14)) - - return x; // string | number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 34, 14)) - } -} -function foo5(x: number | string) { ->foo5 : Symbol(foo5, Decl(typeGuardsInIfStatement.ts, 43, 1)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 44, 14)) - - // false branch updates the variable - so here it is not number - if (typeof x === "string") { ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 44, 14)) - - return x; // string | number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 44, 14)) - } - else { - x = "hello"; ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 44, 14)) - - return x; // string | number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 44, 14)) - } -} -function foo6(x: number | string) { ->foo6 : Symbol(foo6, Decl(typeGuardsInIfStatement.ts, 53, 1)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 54, 14)) - - // Modify in both branches - if (typeof x === "string") { ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 54, 14)) - - x = 10; ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 54, 14)) - - return x; // string | number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 54, 14)) - } - else { - x = "hello"; ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 54, 14)) - - return x; // string | number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 54, 14)) - } -} -function foo7(x: number | string | boolean) { ->foo7 : Symbol(foo7, Decl(typeGuardsInIfStatement.ts, 64, 1)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 65, 14)) - - if (typeof x === "string") { ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 65, 14)) - - return x === "hello"; // string ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 65, 14)) - } - else if (typeof x === "boolean") { ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 65, 14)) - - return x; // boolean ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 65, 14)) - } - else { - return x == 10; // number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 65, 14)) - } -} -function foo8(x: number | string | boolean) { ->foo8 : Symbol(foo8, Decl(typeGuardsInIfStatement.ts, 75, 1)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 76, 14)) - - if (typeof x === "string") { ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 76, 14)) - - return x === "hello"; // string ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 76, 14)) - } - else { - var b: number | boolean = x; // number | boolean ->b : Symbol(b, Decl(typeGuardsInIfStatement.ts, 81, 11)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 76, 14)) - - if (typeof x === "boolean") { ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 76, 14)) - - return x; // boolean ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 76, 14)) - } - else { - return x == 10; // number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 76, 14)) - } - } -} -function foo9(x: number | string) { ->foo9 : Symbol(foo9, Decl(typeGuardsInIfStatement.ts, 89, 1)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 90, 14)) - - var y = 10; ->y : Symbol(y, Decl(typeGuardsInIfStatement.ts, 91, 7)) - - if (typeof x === "string") { ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 90, 14)) - - // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop - y = x.length; ->y : Symbol(y, Decl(typeGuardsInIfStatement.ts, 91, 7)) ->x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 90, 14)) ->length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) - - return x === "hello"; // string ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 90, 14)) - } - else { - return x == 10; // number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 90, 14)) - } -} -function foo10(x: number | string | boolean) { ->foo10 : Symbol(foo10, Decl(typeGuardsInIfStatement.ts, 100, 1)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 101, 15)) - - // Mixing typeguard narrowing in if statement with conditional expression typeguard - if (typeof x === "string") { ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 101, 15)) - - return x === "hello"; // string ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 101, 15)) - } - else { - var y: boolean | string; ->y : Symbol(y, Decl(typeGuardsInIfStatement.ts, 107, 11)) - - var b = x; // number | boolean ->b : Symbol(b, Decl(typeGuardsInIfStatement.ts, 108, 11)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 101, 15)) - - return typeof x === "number" ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 101, 15)) - - ? x === 10 // number ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 101, 15)) - - : x; // x should be boolean ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 101, 15)) - } -} -function foo11(x: number | string | boolean) { ->foo11 : Symbol(foo11, Decl(typeGuardsInIfStatement.ts, 113, 1)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15)) - - // Mixing typeguard narrowing in if statement with conditional expression typeguard - // Assigning value to x deep inside another guard stops narrowing of type too - if (typeof x === "string") { ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15)) - - return x; // string | number | boolean - x changed in else branch ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15)) - } - else { - var y: number| boolean | string; ->y : Symbol(y, Decl(typeGuardsInIfStatement.ts, 121, 11)) - - var b = x; // number | boolean | string - because below we are changing value of x in if statement ->b : Symbol(b, Decl(typeGuardsInIfStatement.ts, 122, 11)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15)) - - return typeof x === "number" ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15)) - - ? ( - // change value of x - x = 10 && x.toString() // number | boolean | string ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15)) ->x.toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15)) ->toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) - - ) - : ( - // do not change value - y = x && x.toString() // number | boolean | string ->y : Symbol(y, Decl(typeGuardsInIfStatement.ts, 121, 11)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15)) ->x.toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 114, 15)) ->toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) - - ); - } -} -function foo12(x: number | string | boolean) { ->foo12 : Symbol(foo12, Decl(typeGuardsInIfStatement.ts, 133, 1)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15)) - - // Mixing typeguard narrowing in if statement with conditional expression typeguard - // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression - if (typeof x === "string") { ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15)) - - return x.toString(); // string | number | boolean - x changed in else branch ->x.toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15)) ->toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) - } - else { - x = 10; ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15)) - - var b = x; // number | boolean | string ->b : Symbol(b, Decl(typeGuardsInIfStatement.ts, 142, 11)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15)) - - return typeof x === "number" ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15)) - - ? x.toString() // number ->x.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15)) ->toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) - - : x.toString(); // boolean | string ->x.toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26)) ->x : Symbol(x, Decl(typeGuardsInIfStatement.ts, 134, 15)) ->toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 96, 26)) - } -} diff --git a/tests/baselines/reference/typeGuardsInIfStatement.types b/tests/baselines/reference/typeGuardsInIfStatement.types deleted file mode 100644 index 59a9ff512af..00000000000 --- a/tests/baselines/reference/typeGuardsInIfStatement.types +++ /dev/null @@ -1,405 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardsInIfStatement.ts === -// 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 -function foo(x: number | string) { ->foo : (x: string | number) => number ->x : string | number - - if (typeof x === "string") { ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - return x.length; // string ->x.length : number ->x : string ->length : number - } - else { - return x++; // number ->x++ : number ->x : number - } -} -function foo2(x: number | string) { ->foo2 : (x: string | number) => string | number ->x : string | number - - // x is assigned in the if true branch, the type is not narrowed - if (typeof x === "string") { ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - x = 10; ->x = 10 : number ->x : string | number ->10 : number - - return x; // string | number ->x : string | number - } - else { - return x; // string | number ->x : string | number - } -} -function foo3(x: number | string) { ->foo3 : (x: string | number) => string | number ->x : string | number - - // x is assigned in the if true branch, the type is not narrowed - if (typeof x === "string") { ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - x = "Hello"; // even though assigned using same type as narrowed expression ->x = "Hello" : string ->x : string | number ->"Hello" : string - - return x; // string | number ->x : string | number - } - else { - return x; // string | number ->x : string | number - } -} -function foo4(x: number | string) { ->foo4 : (x: string | number) => string | number ->x : string | number - - // false branch updates the variable - so here it is not number - if (typeof x === "string") { ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - return x; // string | number ->x : string | number - } - else { - x = 10; // even though assigned number - this should result in x to be string | number ->x = 10 : number ->x : string | number ->10 : number - - return x; // string | number ->x : string | number - } -} -function foo5(x: number | string) { ->foo5 : (x: string | number) => string | number ->x : string | number - - // false branch updates the variable - so here it is not number - if (typeof x === "string") { ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - return x; // string | number ->x : string | number - } - else { - x = "hello"; ->x = "hello" : string ->x : string | number ->"hello" : string - - return x; // string | number ->x : string | number - } -} -function foo6(x: number | string) { ->foo6 : (x: string | number) => string | number ->x : string | number - - // Modify in both branches - if (typeof x === "string") { ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - x = 10; ->x = 10 : number ->x : string | number ->10 : number - - return x; // string | number ->x : string | number - } - else { - x = "hello"; ->x = "hello" : string ->x : string | number ->"hello" : string - - return x; // string | number ->x : string | number - } -} -function foo7(x: number | string | boolean) { ->foo7 : (x: string | number | boolean) => boolean ->x : string | number | boolean - - if (typeof x === "string") { ->typeof x === "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - return x === "hello"; // string ->x === "hello" : boolean ->x : string ->"hello" : string - } - else if (typeof x === "boolean") { ->typeof x === "boolean" : boolean ->typeof x : string ->x : number | boolean ->"boolean" : string - - return x; // boolean ->x : boolean - } - else { - return x == 10; // number ->x == 10 : boolean ->x : number ->10 : number - } -} -function foo8(x: number | string | boolean) { ->foo8 : (x: string | number | boolean) => boolean ->x : string | number | boolean - - if (typeof x === "string") { ->typeof x === "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - return x === "hello"; // string ->x === "hello" : boolean ->x : string ->"hello" : string - } - else { - var b: number | boolean = x; // number | boolean ->b : number | boolean ->x : number | boolean - - if (typeof x === "boolean") { ->typeof x === "boolean" : boolean ->typeof x : string ->x : number | boolean ->"boolean" : string - - return x; // boolean ->x : boolean - } - else { - return x == 10; // number ->x == 10 : boolean ->x : number ->10 : number - } - } -} -function foo9(x: number | string) { ->foo9 : (x: string | number) => boolean ->x : string | number - - var y = 10; ->y : number ->10 : number - - if (typeof x === "string") { ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop - y = x.length; ->y = x.length : number ->y : number ->x.length : number ->x : string ->length : number - - return x === "hello"; // string ->x === "hello" : boolean ->x : string ->"hello" : string - } - else { - return x == 10; // number ->x == 10 : boolean ->x : number ->10 : number - } -} -function foo10(x: number | string | boolean) { ->foo10 : (x: string | number | boolean) => boolean ->x : string | number | boolean - - // Mixing typeguard narrowing in if statement with conditional expression typeguard - if (typeof x === "string") { ->typeof x === "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - return x === "hello"; // string ->x === "hello" : boolean ->x : string ->"hello" : string - } - else { - var y: boolean | string; ->y : string | boolean - - var b = x; // number | boolean ->b : number | boolean ->x : number | boolean - - return typeof x === "number" ->typeof x === "number" ? x === 10 // number : x : boolean ->typeof x === "number" : boolean ->typeof x : string ->x : number | boolean ->"number" : string - - ? x === 10 // number ->x === 10 : boolean ->x : number ->10 : number - - : x; // x should be boolean ->x : boolean - } -} -function foo11(x: number | string | boolean) { ->foo11 : (x: string | number | boolean) => string | number | boolean ->x : string | number | boolean - - // Mixing typeguard narrowing in if statement with conditional expression typeguard - // Assigning value to x deep inside another guard stops narrowing of type too - if (typeof x === "string") { ->typeof x === "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - return x; // string | number | boolean - x changed in else branch ->x : string | number | boolean - } - else { - var y: number| boolean | string; ->y : string | number | boolean - - var b = x; // number | boolean | string - because below we are changing value of x in if statement ->b : string | number | boolean ->x : string | number | boolean - - return typeof x === "number" ->typeof x === "number" ? ( // change value of x x = 10 && x.toString() // number | boolean | string ) : ( // do not change value y = x && x.toString() // number | boolean | string ) : string ->typeof x === "number" : boolean ->typeof x : string ->x : string | number | boolean ->"number" : string - - ? ( ->( // change value of x x = 10 && x.toString() // number | boolean | string ) : string - - // change value of x - x = 10 && x.toString() // number | boolean | string ->x = 10 && x.toString() : string ->x : string | number | boolean ->10 && x.toString() : string ->10 : number ->x.toString() : string ->x.toString : () => string ->x : string | number | boolean ->toString : () => string - - ) - : ( ->( // do not change value y = x && x.toString() // number | boolean | string ) : string - - // do not change value - y = x && x.toString() // number | boolean | string ->y = x && x.toString() : string ->y : string | number | boolean ->x && x.toString() : string ->x : string | number | boolean ->x.toString() : string ->x.toString : () => string ->x : string | number | boolean ->toString : () => string - - ); - } -} -function foo12(x: number | string | boolean) { ->foo12 : (x: string | number | boolean) => string ->x : string | number | boolean - - // Mixing typeguard narrowing in if statement with conditional expression typeguard - // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression - if (typeof x === "string") { ->typeof x === "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - return x.toString(); // string | number | boolean - x changed in else branch ->x.toString() : string ->x.toString : () => string ->x : string | number | boolean ->toString : () => string - } - else { - x = 10; ->x = 10 : number ->x : string | number | boolean ->10 : number - - var b = x; // number | boolean | string ->b : string | number | boolean ->x : string | number | boolean - - return typeof x === "number" ->typeof x === "number" ? x.toString() // number : x.toString() : string ->typeof x === "number" : boolean ->typeof x : string ->x : string | number | boolean ->"number" : string - - ? x.toString() // number ->x.toString() : string ->x.toString : (radix?: number) => string ->x : number ->toString : (radix?: number) => string - - : x.toString(); // boolean | string ->x.toString() : string ->x.toString : () => string ->x : string | boolean ->toString : () => string - } -} diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.errors.txt b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.errors.txt new file mode 100644 index 00000000000..f44e433a2c8 --- /dev/null +++ b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.errors.txt @@ -0,0 +1,64 @@ +tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfAndAndOperator.ts(43,22): error TS2349: Cannot invoke an expression whose type lacks a call signature. +tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfAndAndOperator.ts(45,21): error TS2349: Cannot invoke an expression whose type lacks a call signature. + + +==== tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfAndAndOperator.ts (2 errors) ==== + // 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. + function foo(x: number | string) { + return typeof x === "string" && x.length === 10; // string + } + function foo2(x: number | string) { + // modify x in right hand operand + return typeof x === "string" && ((x = 10) && x); // string | number + } + function foo3(x: number | string) { + // modify x in right hand operand with string type itself + return typeof x === "string" && ((x = "hello") && x); // string | number + } + function foo4(x: number | string | boolean) { + return typeof x !== "string" // string | number | boolean + && typeof x !== "number" // number | boolean + && x; // boolean + } + function foo5(x: number | string | boolean) { + // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop + var b: number | boolean; + return typeof x !== "string" // string | number | boolean + && ((b = x) && (typeof x !== "number" // number | boolean + && x)); // boolean + } + function foo6(x: number | string | boolean) { + // Mixing typeguard narrowing in if statement with conditional expression typeguard + return typeof x !== "string" // string | number | boolean + && (typeof x !== "number" // number | boolean + ? x // boolean + : x === 10) // number + } + function foo7(x: number | string | boolean) { + var y: number| boolean | string; + var z: number| boolean | string; + // Mixing typeguard narrowing + // Assigning value to x deep inside another guard stops narrowing of type too + return typeof x !== "string" + && ((z = x) // string | number | boolean - x changed deeper in conditional expression + && (typeof x === "number" + // change value of x + ? (x = 10 && x.toString()) // number | boolean | string + ~~~~~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. + // do not change value + : (y = x && x.toString()))); // number | boolean | string + ~~~~~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. + } + function foo8(x: number | string) { + // Mixing typeguard + // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression + return typeof x !== "string" + && (x = 10) // change x - number| string + && (typeof x === "number" + ? x // number + : x.length); // string + } \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.symbols b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.symbols deleted file mode 100644 index 2a757460234..00000000000 --- a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.symbols +++ /dev/null @@ -1,143 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfAndAndOperator.ts === -// 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. -function foo(x: number | string) { ->foo : Symbol(foo, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 0, 0)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 3, 13)) - - return typeof x === "string" && x.length === 10; // string ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 3, 13)) ->x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 3, 13)) ->length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) -} -function foo2(x: number | string) { ->foo2 : Symbol(foo2, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 5, 1)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 6, 14)) - - // modify x in right hand operand - return typeof x === "string" && ((x = 10) && x); // string | number ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 6, 14)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 6, 14)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 6, 14)) -} -function foo3(x: number | string) { ->foo3 : Symbol(foo3, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 9, 1)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 10, 14)) - - // modify x in right hand operand with string type itself - return typeof x === "string" && ((x = "hello") && x); // string | number ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 10, 14)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 10, 14)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 10, 14)) -} -function foo4(x: number | string | boolean) { ->foo4 : Symbol(foo4, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 13, 1)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 14, 14)) - - return typeof x !== "string" // string | number | boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 14, 14)) - - && typeof x !== "number" // number | boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 14, 14)) - - && x; // boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 14, 14)) -} -function foo5(x: number | string | boolean) { ->foo5 : Symbol(foo5, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 18, 1)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 19, 14)) - - // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop - var b: number | boolean; ->b : Symbol(b, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 21, 7)) - - return typeof x !== "string" // string | number | boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 19, 14)) - - && ((b = x) && (typeof x !== "number" // number | boolean ->b : Symbol(b, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 21, 7)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 19, 14)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 19, 14)) - - && x)); // boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 19, 14)) -} -function foo6(x: number | string | boolean) { ->foo6 : Symbol(foo6, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 25, 1)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 26, 14)) - - // Mixing typeguard narrowing in if statement with conditional expression typeguard - return typeof x !== "string" // string | number | boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 26, 14)) - - && (typeof x !== "number" // number | boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 26, 14)) - - ? x // boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 26, 14)) - - : x === 10) // number ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 26, 14)) -} -function foo7(x: number | string | boolean) { ->foo7 : Symbol(foo7, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 32, 1)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14)) - - var y: number| boolean | string; ->y : Symbol(y, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 34, 7)) - - var z: number| boolean | string; ->z : Symbol(z, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 35, 7)) - - // Mixing typeguard narrowing - // Assigning value to x deep inside another guard stops narrowing of type too - return typeof x !== "string" ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14)) - - && ((z = x) // string | number | boolean - x changed deeper in conditional expression ->z : Symbol(z, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 35, 7)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14)) - - && (typeof x === "number" ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14)) - - // change value of x - ? (x = 10 && x.toString()) // number | boolean | string ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14)) ->x.toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14)) ->toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) - - // do not change value - : (y = x && x.toString()))); // number | boolean | string ->y : Symbol(y, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 34, 7)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14)) ->x.toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 33, 14)) ->toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) -} -function foo8(x: number | string) { ->foo8 : Symbol(foo8, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 45, 1)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 46, 14)) - - // Mixing typeguard - // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression - return typeof x !== "string" ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 46, 14)) - - && (x = 10) // change x - number| string ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 46, 14)) - - && (typeof x === "number" ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 46, 14)) - - ? x // number ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 46, 14)) - - : x.length); // string ->x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfAndAndOperator.ts, 46, 14)) ->length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) -} diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types deleted file mode 100644 index 10b72e3fbd1..00000000000 --- a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types +++ /dev/null @@ -1,234 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfAndAndOperator.ts === -// 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. -function foo(x: number | string) { ->foo : (x: string | number) => boolean ->x : string | number - - return typeof x === "string" && x.length === 10; // string ->typeof x === "string" && x.length === 10 : boolean ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string ->x.length === 10 : boolean ->x.length : number ->x : string ->length : number ->10 : number -} -function foo2(x: number | string) { ->foo2 : (x: string | number) => string | number ->x : string | number - - // modify x in right hand operand - return typeof x === "string" && ((x = 10) && x); // string | number ->typeof x === "string" && ((x = 10) && x) : string | number ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string ->((x = 10) && x) : string | number ->(x = 10) && x : string | number ->(x = 10) : number ->x = 10 : number ->x : string | number ->10 : number ->x : string | number -} -function foo3(x: number | string) { ->foo3 : (x: string | number) => string | number ->x : string | number - - // modify x in right hand operand with string type itself - return typeof x === "string" && ((x = "hello") && x); // string | number ->typeof x === "string" && ((x = "hello") && x) : string | number ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string ->((x = "hello") && x) : string | number ->(x = "hello") && x : string | number ->(x = "hello") : string ->x = "hello" : string ->x : string | number ->"hello" : string ->x : string | number -} -function foo4(x: number | string | boolean) { ->foo4 : (x: string | number | boolean) => boolean ->x : string | number | boolean - - return typeof x !== "string" // string | number | boolean ->typeof x !== "string" // string | number | boolean && typeof x !== "number" // number | boolean && x : boolean ->typeof x !== "string" // string | number | boolean && typeof x !== "number" : boolean ->typeof x !== "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - && typeof x !== "number" // number | boolean ->typeof x !== "number" : boolean ->typeof x : string ->x : number | boolean ->"number" : string - - && x; // boolean ->x : boolean -} -function foo5(x: number | string | boolean) { ->foo5 : (x: string | number | boolean) => boolean ->x : string | number | boolean - - // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop - var b: number | boolean; ->b : number | boolean - - return typeof x !== "string" // string | number | boolean ->typeof x !== "string" // string | number | boolean && ((b = x) && (typeof x !== "number" // number | boolean && x)) : boolean ->typeof x !== "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - && ((b = x) && (typeof x !== "number" // number | boolean ->((b = x) && (typeof x !== "number" // number | boolean && x)) : boolean ->(b = x) && (typeof x !== "number" // number | boolean && x) : boolean ->(b = x) : number | boolean ->b = x : number | boolean ->b : number | boolean ->x : number | boolean ->(typeof x !== "number" // number | boolean && x) : boolean ->typeof x !== "number" // number | boolean && x : boolean ->typeof x !== "number" : boolean ->typeof x : string ->x : number | boolean ->"number" : string - - && x)); // boolean ->x : boolean -} -function foo6(x: number | string | boolean) { ->foo6 : (x: string | number | boolean) => boolean ->x : string | number | boolean - - // Mixing typeguard narrowing in if statement with conditional expression typeguard - return typeof x !== "string" // string | number | boolean ->typeof x !== "string" // string | number | boolean && (typeof x !== "number" // number | boolean ? x // boolean : x === 10) : boolean ->typeof x !== "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - && (typeof x !== "number" // number | boolean ->(typeof x !== "number" // number | boolean ? x // boolean : x === 10) : boolean ->typeof x !== "number" // number | boolean ? x // boolean : x === 10 : boolean ->typeof x !== "number" : boolean ->typeof x : string ->x : number | boolean ->"number" : string - - ? x // boolean ->x : boolean - - : x === 10) // number ->x === 10 : boolean ->x : number ->10 : number -} -function foo7(x: number | string | boolean) { ->foo7 : (x: string | number | boolean) => string ->x : string | number | boolean - - var y: number| boolean | string; ->y : string | number | boolean - - var z: number| boolean | string; ->z : string | number | boolean - - // Mixing typeguard narrowing - // Assigning value to x deep inside another guard stops narrowing of type too - return typeof x !== "string" ->typeof x !== "string" && ((z = x) // string | number | boolean - x changed deeper in conditional expression && (typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString()))) : string ->typeof x !== "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - && ((z = x) // string | number | boolean - x changed deeper in conditional expression ->((z = x) // string | number | boolean - x changed deeper in conditional expression && (typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString()))) : string ->(z = x) // string | number | boolean - x changed deeper in conditional expression && (typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString())) : string ->(z = x) : string | number | boolean ->z = x : string | number | boolean ->z : string | number | boolean ->x : string | number | boolean - - && (typeof x === "number" ->(typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString())) : string ->typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString()) : string ->typeof x === "number" : boolean ->typeof x : string ->x : string | number | boolean ->"number" : string - - // change value of x - ? (x = 10 && x.toString()) // number | boolean | string ->(x = 10 && x.toString()) : string ->x = 10 && x.toString() : string ->x : string | number | boolean ->10 && x.toString() : string ->10 : number ->x.toString() : string ->x.toString : () => string ->x : string | number | boolean ->toString : () => string - - // do not change value - : (y = x && x.toString()))); // number | boolean | string ->(y = x && x.toString()) : string ->y = x && x.toString() : string ->y : string | number | boolean ->x && x.toString() : string ->x : string | number | boolean ->x.toString() : string ->x.toString : () => string ->x : string | number | boolean ->toString : () => string -} -function foo8(x: number | string) { ->foo8 : (x: string | number) => number ->x : string | number - - // Mixing typeguard - // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression - return typeof x !== "string" ->typeof x !== "string" && (x = 10) // change x - number| string && (typeof x === "number" ? x // number : x.length) : number ->typeof x !== "string" && (x = 10) : number ->typeof x !== "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - && (x = 10) // change x - number| string ->(x = 10) : number ->x = 10 : number ->x : string | number ->10 : number - - && (typeof x === "number" ->(typeof x === "number" ? x // number : x.length) : number ->typeof x === "number" ? x // number : x.length : number ->typeof x === "number" : boolean ->typeof x : string ->x : string | number ->"number" : string - - ? x // number ->x : number - - : x.length); // string ->x.length : number ->x : string ->length : number -} diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.errors.txt b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.errors.txt new file mode 100644 index 00000000000..f34d035fa40 --- /dev/null +++ b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.errors.txt @@ -0,0 +1,64 @@ +tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfOrOrOperator.ts(43,22): error TS2349: Cannot invoke an expression whose type lacks a call signature. +tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfOrOrOperator.ts(45,21): error TS2349: Cannot invoke an expression whose type lacks a call signature. + + +==== tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfOrOrOperator.ts (2 errors) ==== + // 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. + function foo(x: number | string) { + return typeof x !== "string" || x.length === 10; // string + } + function foo2(x: number | string) { + // modify x in right hand operand + return typeof x !== "string" || ((x = 10) || x); // string | number + } + function foo3(x: number | string) { + // modify x in right hand operand with string type itself + return typeof x !== "string" || ((x = "hello") || x); // string | number + } + function foo4(x: number | string | boolean) { + return typeof x === "string" // string | number | boolean + || typeof x === "number" // number | boolean + || x; // boolean + } + function foo5(x: number | string | boolean) { + // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop + var b: number | boolean; + return typeof x === "string" // string | number | boolean + || ((b = x) || (typeof x === "number" // number | boolean + || x)); // boolean + } + function foo6(x: number | string | boolean) { + // Mixing typeguard + return typeof x === "string" // string | number | boolean + || (typeof x !== "number" // number | boolean + ? x // boolean + : x === 10) // number + } + function foo7(x: number | string | boolean) { + var y: number| boolean | string; + var z: number| boolean | string; + // Mixing typeguard narrowing + // Assigning value to x deep inside another guard stops narrowing of type too + return typeof x === "string" + || ((z = x) // string | number | boolean - x changed deeper in conditional expression + || (typeof x === "number" + // change value of x + ? (x = 10 && x.toString()) // number | boolean | string + ~~~~~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. + // do not change value + : (y = x && x.toString()))); // number | boolean | string + ~~~~~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. + } + function foo8(x: number | string) { + // Mixing typeguard + // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression + return typeof x === "string" + || (x = 10) // change x - number| string + || (typeof x === "number" + ? x // number + : x.length); // string + } \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.symbols b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.symbols deleted file mode 100644 index dd751b7d8dd..00000000000 --- a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.symbols +++ /dev/null @@ -1,143 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfOrOrOperator.ts === -// 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. -function foo(x: number | string) { ->foo : Symbol(foo, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 0, 0)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 3, 13)) - - return typeof x !== "string" || x.length === 10; // string ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 3, 13)) ->x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 3, 13)) ->length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) -} -function foo2(x: number | string) { ->foo2 : Symbol(foo2, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 5, 1)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 6, 14)) - - // modify x in right hand operand - return typeof x !== "string" || ((x = 10) || x); // string | number ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 6, 14)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 6, 14)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 6, 14)) -} -function foo3(x: number | string) { ->foo3 : Symbol(foo3, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 9, 1)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 10, 14)) - - // modify x in right hand operand with string type itself - return typeof x !== "string" || ((x = "hello") || x); // string | number ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 10, 14)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 10, 14)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 10, 14)) -} -function foo4(x: number | string | boolean) { ->foo4 : Symbol(foo4, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 13, 1)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 14, 14)) - - return typeof x === "string" // string | number | boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 14, 14)) - - || typeof x === "number" // number | boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 14, 14)) - - || x; // boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 14, 14)) -} -function foo5(x: number | string | boolean) { ->foo5 : Symbol(foo5, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 18, 1)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 19, 14)) - - // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop - var b: number | boolean; ->b : Symbol(b, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 21, 7)) - - return typeof x === "string" // string | number | boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 19, 14)) - - || ((b = x) || (typeof x === "number" // number | boolean ->b : Symbol(b, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 21, 7)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 19, 14)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 19, 14)) - - || x)); // boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 19, 14)) -} -function foo6(x: number | string | boolean) { ->foo6 : Symbol(foo6, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 25, 1)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 26, 14)) - - // Mixing typeguard - return typeof x === "string" // string | number | boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 26, 14)) - - || (typeof x !== "number" // number | boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 26, 14)) - - ? x // boolean ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 26, 14)) - - : x === 10) // number ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 26, 14)) -} -function foo7(x: number | string | boolean) { ->foo7 : Symbol(foo7, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 32, 1)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14)) - - var y: number| boolean | string; ->y : Symbol(y, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 34, 7)) - - var z: number| boolean | string; ->z : Symbol(z, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 35, 7)) - - // Mixing typeguard narrowing - // Assigning value to x deep inside another guard stops narrowing of type too - return typeof x === "string" ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14)) - - || ((z = x) // string | number | boolean - x changed deeper in conditional expression ->z : Symbol(z, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 35, 7)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14)) - - || (typeof x === "number" ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14)) - - // change value of x - ? (x = 10 && x.toString()) // number | boolean | string ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14)) ->x.toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14)) ->toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) - - // do not change value - : (y = x && x.toString()))); // number | boolean | string ->y : Symbol(y, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 34, 7)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14)) ->x.toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 33, 14)) ->toString : Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26)) -} -function foo8(x: number | string) { ->foo8 : Symbol(foo8, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 45, 1)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 46, 14)) - - // Mixing typeguard - // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression - return typeof x === "string" ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 46, 14)) - - || (x = 10) // change x - number| string ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 46, 14)) - - || (typeof x === "number" ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 46, 14)) - - ? x // number ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 46, 14)) - - : x.length); // string ->x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) ->x : Symbol(x, Decl(typeGuardsInRightOperandOfOrOrOperator.ts, 46, 14)) ->length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) -} diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types deleted file mode 100644 index 81160323429..00000000000 --- a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types +++ /dev/null @@ -1,234 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardsInRightOperandOfOrOrOperator.ts === -// 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. -function foo(x: number | string) { ->foo : (x: string | number) => boolean ->x : string | number - - return typeof x !== "string" || x.length === 10; // string ->typeof x !== "string" || x.length === 10 : boolean ->typeof x !== "string" : boolean ->typeof x : string ->x : string | number ->"string" : string ->x.length === 10 : boolean ->x.length : number ->x : string ->length : number ->10 : number -} -function foo2(x: number | string) { ->foo2 : (x: string | number) => string | number | boolean ->x : string | number - - // modify x in right hand operand - return typeof x !== "string" || ((x = 10) || x); // string | number ->typeof x !== "string" || ((x = 10) || x) : string | number | boolean ->typeof x !== "string" : boolean ->typeof x : string ->x : string | number ->"string" : string ->((x = 10) || x) : string | number ->(x = 10) || x : string | number ->(x = 10) : number ->x = 10 : number ->x : string | number ->10 : number ->x : string | number -} -function foo3(x: number | string) { ->foo3 : (x: string | number) => string | number | boolean ->x : string | number - - // modify x in right hand operand with string type itself - return typeof x !== "string" || ((x = "hello") || x); // string | number ->typeof x !== "string" || ((x = "hello") || x) : string | number | boolean ->typeof x !== "string" : boolean ->typeof x : string ->x : string | number ->"string" : string ->((x = "hello") || x) : string | number ->(x = "hello") || x : string | number ->(x = "hello") : string ->x = "hello" : string ->x : string | number ->"hello" : string ->x : string | number -} -function foo4(x: number | string | boolean) { ->foo4 : (x: string | number | boolean) => boolean ->x : string | number | boolean - - return typeof x === "string" // string | number | boolean ->typeof x === "string" // string | number | boolean || typeof x === "number" // number | boolean || x : boolean ->typeof x === "string" // string | number | boolean || typeof x === "number" : boolean ->typeof x === "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - || typeof x === "number" // number | boolean ->typeof x === "number" : boolean ->typeof x : string ->x : number | boolean ->"number" : string - - || x; // boolean ->x : boolean -} -function foo5(x: number | string | boolean) { ->foo5 : (x: string | number | boolean) => number | boolean ->x : string | number | boolean - - // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop - var b: number | boolean; ->b : number | boolean - - return typeof x === "string" // string | number | boolean ->typeof x === "string" // string | number | boolean || ((b = x) || (typeof x === "number" // number | boolean || x)) : number | boolean ->typeof x === "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - || ((b = x) || (typeof x === "number" // number | boolean ->((b = x) || (typeof x === "number" // number | boolean || x)) : number | boolean ->(b = x) || (typeof x === "number" // number | boolean || x) : number | boolean ->(b = x) : number | boolean ->b = x : number | boolean ->b : number | boolean ->x : number | boolean ->(typeof x === "number" // number | boolean || x) : boolean ->typeof x === "number" // number | boolean || x : boolean ->typeof x === "number" : boolean ->typeof x : string ->x : number | boolean ->"number" : string - - || x)); // boolean ->x : boolean -} -function foo6(x: number | string | boolean) { ->foo6 : (x: string | number | boolean) => boolean ->x : string | number | boolean - - // Mixing typeguard - return typeof x === "string" // string | number | boolean ->typeof x === "string" // string | number | boolean || (typeof x !== "number" // number | boolean ? x // boolean : x === 10) : boolean ->typeof x === "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - || (typeof x !== "number" // number | boolean ->(typeof x !== "number" // number | boolean ? x // boolean : x === 10) : boolean ->typeof x !== "number" // number | boolean ? x // boolean : x === 10 : boolean ->typeof x !== "number" : boolean ->typeof x : string ->x : number | boolean ->"number" : string - - ? x // boolean ->x : boolean - - : x === 10) // number ->x === 10 : boolean ->x : number ->10 : number -} -function foo7(x: number | string | boolean) { ->foo7 : (x: string | number | boolean) => string | number | boolean ->x : string | number | boolean - - var y: number| boolean | string; ->y : string | number | boolean - - var z: number| boolean | string; ->z : string | number | boolean - - // Mixing typeguard narrowing - // Assigning value to x deep inside another guard stops narrowing of type too - return typeof x === "string" ->typeof x === "string" || ((z = x) // string | number | boolean - x changed deeper in conditional expression || (typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString()))) : string | number | boolean ->typeof x === "string" : boolean ->typeof x : string ->x : string | number | boolean ->"string" : string - - || ((z = x) // string | number | boolean - x changed deeper in conditional expression ->((z = x) // string | number | boolean - x changed deeper in conditional expression || (typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString()))) : string | number | boolean ->(z = x) // string | number | boolean - x changed deeper in conditional expression || (typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString())) : string | number | boolean ->(z = x) : string | number | boolean ->z = x : string | number | boolean ->z : string | number | boolean ->x : string | number | boolean - - || (typeof x === "number" ->(typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString())) : string ->typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString()) : string ->typeof x === "number" : boolean ->typeof x : string ->x : string | number | boolean ->"number" : string - - // change value of x - ? (x = 10 && x.toString()) // number | boolean | string ->(x = 10 && x.toString()) : string ->x = 10 && x.toString() : string ->x : string | number | boolean ->10 && x.toString() : string ->10 : number ->x.toString() : string ->x.toString : () => string ->x : string | number | boolean ->toString : () => string - - // do not change value - : (y = x && x.toString()))); // number | boolean | string ->(y = x && x.toString()) : string ->y = x && x.toString() : string ->y : string | number | boolean ->x && x.toString() : string ->x : string | number | boolean ->x.toString() : string ->x.toString : () => string ->x : string | number | boolean ->toString : () => string -} -function foo8(x: number | string) { ->foo8 : (x: string | number) => number | boolean ->x : string | number - - // Mixing typeguard - // Assigning value to x in outer guard shouldn't stop narrowing in the inner expression - return typeof x === "string" ->typeof x === "string" || (x = 10) // change x - number| string || (typeof x === "number" ? x // number : x.length) : number | boolean ->typeof x === "string" || (x = 10) : number | boolean ->typeof x === "string" : boolean ->typeof x : string ->x : string | number ->"string" : string - - || (x = 10) // change x - number| string ->(x = 10) : number ->x = 10 : number ->x : string | number ->10 : number - - || (typeof x === "number" ->(typeof x === "number" ? x // number : x.length) : number ->typeof x === "number" ? x // number : x.length : number ->typeof x === "number" : boolean ->typeof x : string ->x : string | number ->"number" : string - - ? x // number ->x : number - - : x.length); // string ->x.length : number ->x : string ->length : number -} diff --git a/tests/baselines/reference/typeGuardsOnClassProperty.errors.txt b/tests/baselines/reference/typeGuardsOnClassProperty.errors.txt index 4e6a8b83ae3..91d6d6998bc 100644 --- a/tests/baselines/reference/typeGuardsOnClassProperty.errors.txt +++ b/tests/baselines/reference/typeGuardsOnClassProperty.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts(14,70): error TS2339: Property 'join' does not exist on type 'string | string[]'. -tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts(26,44): error TS2339: Property 'toLowerCase' does not exist on type 'string | number'. +tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts(26,44): error TS2339: Property 'toLowerCase' does not exist on type 'number | string'. ==== tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts (2 errors) ==== @@ -32,6 +32,6 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts(26,4 if (typeof o.prop1 === "string" && o.prop1.toLowerCase()) {} ~~~~~~~~~~~ -!!! error TS2339: Property 'toLowerCase' does not exist on type 'string | number'. +!!! error TS2339: Property 'toLowerCase' does not exist on type 'number | string'. var prop1 = o.prop1; if (typeof prop1 === "string" && prop1.toLocaleLowerCase()) { } \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt index 4960940d3ab..63b9de2aeda 100644 --- a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt @@ -1,18 +1,16 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(12,10): error TS2339: Property 'bar' does not exist on type 'A'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(33,5): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(34,10): error TS2339: Property 'bar' does not exist on type 'B'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(65,10): error TS2339: Property 'bar1' does not exist on type 'C1 | C2'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(66,10): error TS2339: Property 'bar2' does not exist on type 'C1 | C2'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(66,10): error TS2339: Property 'bar2' does not exist on type 'C1'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(85,10): error TS2339: Property 'bar' does not exist on type 'D'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(111,10): error TS2339: Property 'bar1' does not exist on type 'E1 | E2'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(112,10): error TS2339: Property 'bar2' does not exist on type 'E1 | E2'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(134,11): error TS2339: Property 'foo' does not exist on type 'string | F'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(135,11): error TS2339: Property 'bar' does not exist on type 'string | F'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(112,10): error TS2339: Property 'bar2' does not exist on type 'E1'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(134,11): error TS2339: Property 'foo' does not exist on type 'F | string'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(135,11): error TS2339: Property 'bar' does not exist on type 'F | string'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(160,11): error TS2339: Property 'foo2' does not exist on type 'G1'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(182,11): error TS2339: Property 'bar' does not exist on type 'H'. -==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts (12 errors) ==== +==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts (10 errors) ==== interface AConstructor { new (): A; } @@ -84,11 +82,9 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru obj5.foo; obj5.c; obj5.bar1; - ~~~~ -!!! error TS2339: Property 'bar1' does not exist on type 'C1 | C2'. obj5.bar2; ~~~~ -!!! error TS2339: Property 'bar2' does not exist on type 'C1 | C2'. +!!! error TS2339: Property 'bar2' does not exist on type 'C1'. } var obj6: any; @@ -136,11 +132,9 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru if (obj9 instanceof E) { // narrowed to E1 | E2 obj9.foo; obj9.bar1; - ~~~~ -!!! error TS2339: Property 'bar1' does not exist on type 'E1 | E2'. obj9.bar2; ~~~~ -!!! error TS2339: Property 'bar2' does not exist on type 'E1 | E2'. +!!! error TS2339: Property 'bar2' does not exist on type 'E1'. } var obj10: any; @@ -164,10 +158,10 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru if (obj11 instanceof F) { // can't type narrowing, construct signature returns any. obj11.foo; ~~~ -!!! error TS2339: Property 'foo' does not exist on type 'string | F'. +!!! error TS2339: Property 'foo' does not exist on type 'F | string'. obj11.bar; ~~~ -!!! error TS2339: Property 'bar' does not exist on type 'string | F'. +!!! error TS2339: Property 'bar' does not exist on type 'F | string'. } var obj12: any; diff --git a/tests/baselines/reference/typeInfer1.errors.txt b/tests/baselines/reference/typeInfer1.errors.txt index cce736e2531..2550bb1fe8d 100644 --- a/tests/baselines/reference/typeInfer1.errors.txt +++ b/tests/baselines/reference/typeInfer1.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/typeInfer1.ts(11,5): error TS2322: Type '{ Moo: () => string; }' is not assignable to type 'ITextWriter2'. - Property 'Write' is missing in type '{ Moo: () => string; }'. + Object literal may only specify known properties, and 'Moo' does not exist in type 'ITextWriter2'. ==== tests/cases/compiler/typeInfer1.ts (1 errors) ==== @@ -16,6 +16,6 @@ tests/cases/compiler/typeInfer1.ts(11,5): error TS2322: Type '{ Moo: () => strin var yyyyyyyy: ITextWriter2 = { ~~~~~~~~ !!! error TS2322: Type '{ Moo: () => string; }' is not assignable to type 'ITextWriter2'. -!!! error TS2322: Property 'Write' is missing in type '{ Moo: () => string; }'. +!!! error TS2322: Object literal may only specify known properties, and 'Moo' does not exist in type 'ITextWriter2'. Moo: function() { return "cow"; } } \ No newline at end of file diff --git a/tests/baselines/reference/typeMatch2.errors.txt b/tests/baselines/reference/typeMatch2.errors.txt index 4db4828064e..a497551c953 100644 --- a/tests/baselines/reference/typeMatch2.errors.txt +++ b/tests/baselines/reference/typeMatch2.errors.txt @@ -2,8 +2,10 @@ tests/cases/compiler/typeMatch2.ts(3,2): error TS2322: Type '{}' is not assignab Property 'x' is missing in type '{}'. tests/cases/compiler/typeMatch2.ts(4,5): error TS2322: Type '{ x: number; }' is not assignable to type '{ x: number; y: number; }'. Property 'y' is missing in type '{ x: number; }'. +tests/cases/compiler/typeMatch2.ts(5,2): error TS2322: Type '{ x: number; y: number; z: number; }' is not assignable to type '{ x: number; y: number; }'. + Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: number; }'. tests/cases/compiler/typeMatch2.ts(6,5): error TS2322: Type '{ x: number; z: number; }' is not assignable to type '{ x: number; y: number; }'. - Property 'y' is missing in type '{ x: number; z: number; }'. + Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: number; }'. tests/cases/compiler/typeMatch2.ts(18,5): error TS2322: Type 'Animal[]' is not assignable to type 'Giraffe[]'. Type 'Animal' is not assignable to type 'Giraffe'. Property 'g' is missing in type 'Animal'. @@ -11,11 +13,13 @@ tests/cases/compiler/typeMatch2.ts(22,5): error TS2322: Type '{ f1: number; f2: Types of property 'f2' are incompatible. Type 'Animal[]' is not assignable to type 'Giraffe[]'. Type 'Animal' is not assignable to type 'Giraffe'. +tests/cases/compiler/typeMatch2.ts(34,5): error TS2322: Type '{ x: number; y: any; z: number; }' is not assignable to type '{ x: number; y: number; }'. + Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: number; }'. tests/cases/compiler/typeMatch2.ts(35,5): error TS2322: Type '{ x: number; }' is not assignable to type '{ x: number; y: number; }'. Property 'y' is missing in type '{ x: number; }'. -==== tests/cases/compiler/typeMatch2.ts (6 errors) ==== +==== tests/cases/compiler/typeMatch2.ts (8 errors) ==== function f1() { var a = { x: 1, y: 2 }; a = {}; // error @@ -27,10 +31,13 @@ tests/cases/compiler/typeMatch2.ts(35,5): error TS2322: Type '{ x: number; }' is !!! error TS2322: Type '{ x: number; }' is not assignable to type '{ x: number; y: number; }'. !!! error TS2322: Property 'y' is missing in type '{ x: number; }'. a = { x: 1, y: 2, z: 3 }; + ~ +!!! error TS2322: Type '{ x: number; y: number; z: number; }' is not assignable to type '{ x: number; y: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: number; }'. a = { x: 1, z: 3 }; // error ~ !!! error TS2322: Type '{ x: number; z: number; }' is not assignable to type '{ x: number; y: number; }'. -!!! error TS2322: Property 'y' is missing in type '{ x: number; z: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: number; }'. } class Animal { private a; } @@ -68,6 +75,9 @@ tests/cases/compiler/typeMatch2.ts(35,5): error TS2322: Type '{ x: number; }' is a = { x: 1, y: undefined }; a = { x: 1, y: _any }; a = { x: 1, y: _any, z:1 }; + ~ +!!! error TS2322: Type '{ x: number; y: any; z: number; }' is not assignable to type '{ x: number; y: number; }'. +!!! error TS2322: Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: number; }'. a = { x: 1 }; // error ~ !!! error TS2322: Type '{ x: number; }' is not assignable to type '{ x: number; y: number; }'. diff --git a/tests/baselines/reference/typeParameterAsElementType.types b/tests/baselines/reference/typeParameterAsElementType.types index 10e6787ae31..3b145b7f3cf 100644 --- a/tests/baselines/reference/typeParameterAsElementType.types +++ b/tests/baselines/reference/typeParameterAsElementType.types @@ -8,8 +8,8 @@ function fee() { >T : T var arr = [t, ""]; ->arr : (string | T)[] ->[t, ""] : (string | T)[] +>arr : (T | string)[] +>[t, ""] : (T | string)[] >t : T >"" : string } diff --git a/tests/baselines/reference/typeParameterAssignability2.errors.txt b/tests/baselines/reference/typeParameterAssignability2.errors.txt index b3cc924d419..ab8803e0478 100644 --- a/tests/baselines/reference/typeParameterAssignability2.errors.txt +++ b/tests/baselines/reference/typeParameterAssignability2.errors.txt @@ -16,9 +16,11 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typePara tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(24,28): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(25,5): error TS2322: Type 'U' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(26,5): error TS2322: Type 'V' is not assignable to type 'T'. + Type 'Date' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(27,5): error TS2322: Type 'Date' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(29,5): error TS2322: Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(30,5): error TS2322: Type 'V' is not assignable to type 'U'. + Type 'Date' is not assignable to type 'U'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(31,5): error TS2322: Type 'Date' is not assignable to type 'U'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(33,5): error TS2322: Type 'T' is not assignable to type 'V'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(34,5): error TS2322: Type 'U' is not assignable to type 'V'. @@ -29,9 +31,11 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typePara tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(44,44): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(45,5): error TS2322: Type 'U' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(46,5): error TS2322: Type 'V' is not assignable to type 'T'. + Type 'Date' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(47,5): error TS2322: Type 'Date' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(49,5): error TS2322: Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(50,5): error TS2322: Type 'V' is not assignable to type 'U'. + Type 'Date' is not assignable to type 'U'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(51,5): error TS2322: Type 'Date' is not assignable to type 'U'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(53,5): error TS2322: Type 'T' is not assignable to type 'V'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(54,5): error TS2322: Type 'U' is not assignable to type 'V'. @@ -110,6 +114,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typePara t = v; // error ~ !!! error TS2322: Type 'V' is not assignable to type 'T'. +!!! error TS2322: Type 'Date' is not assignable to type 'T'. t = new Date(); // error ~ !!! error TS2322: Type 'Date' is not assignable to type 'T'. @@ -120,6 +125,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typePara u = v; // error ~ !!! error TS2322: Type 'V' is not assignable to type 'U'. +!!! error TS2322: Type 'Date' is not assignable to type 'U'. u = new Date(); // error ~ !!! error TS2322: Type 'Date' is not assignable to type 'U'. @@ -156,6 +162,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typePara t = v; // error ~ !!! error TS2322: Type 'V' is not assignable to type 'T'. +!!! error TS2322: Type 'Date' is not assignable to type 'T'. t = new Date(); // error ~ !!! error TS2322: Type 'Date' is not assignable to type 'T'. @@ -166,6 +173,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typePara u = v; // error ~ !!! error TS2322: Type 'V' is not assignable to type 'U'. +!!! error TS2322: Type 'Date' is not assignable to type 'U'. u = new Date(); // error ~ !!! error TS2322: Type 'Date' is not assignable to type 'U'. diff --git a/tests/baselines/reference/typeParameterAssignability3.errors.txt b/tests/baselines/reference/typeParameterAssignability3.errors.txt index 7dbb24ef643..ca7850d747e 100644 --- a/tests/baselines/reference/typeParameterAssignability3.errors.txt +++ b/tests/baselines/reference/typeParameterAssignability3.errors.txt @@ -1,7 +1,11 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability3.ts(14,5): error TS2322: Type 'U' is not assignable to type 'T'. + Type 'Foo' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability3.ts(15,5): error TS2322: Type 'T' is not assignable to type 'U'. + Type 'Foo' is not assignable to type 'U'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability3.ts(22,9): error TS2322: Type 'U' is not assignable to type 'T'. + Type 'Foo' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability3.ts(23,9): error TS2322: Type 'T' is not assignable to type 'U'. + Type 'Foo' is not assignable to type 'U'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability3.ts (4 errors) ==== @@ -21,9 +25,11 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typePara t = u; // error ~ !!! error TS2322: Type 'U' is not assignable to type 'T'. +!!! error TS2322: Type 'Foo' is not assignable to type 'T'. u = t; // error ~ !!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'Foo' is not assignable to type 'U'. } class C { @@ -33,8 +39,10 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typePara this.t = this.u; // error ~~~~~~ !!! error TS2322: Type 'U' is not assignable to type 'T'. +!!! error TS2322: Type 'Foo' is not assignable to type 'T'. this.u = this.t; // error ~~~~~~ !!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'Foo' is not assignable to type 'U'. } } \ No newline at end of file diff --git a/tests/baselines/reference/typeParameterDiamond3.errors.txt b/tests/baselines/reference/typeParameterDiamond3.errors.txt index abefeb2a2d9..14d5e4a313a 100644 --- a/tests/baselines/reference/typeParameterDiamond3.errors.txt +++ b/tests/baselines/reference/typeParameterDiamond3.errors.txt @@ -4,6 +4,9 @@ tests/cases/compiler/typeParameterDiamond3.ts(9,13): error TS2322: Type 'Bottom' Type 'Top | T | U' is not assignable to type 'T | U'. Type 'Top' is not assignable to type 'T | U'. Type 'Top' is not assignable to type 'U'. + Type 'Bottom' is not assignable to type 'U'. + Type 'Top | T | U' is not assignable to type 'U'. + Type 'Top' is not assignable to type 'U'. tests/cases/compiler/typeParameterDiamond3.ts(10,13): error TS2322: Type 'Bottom' is not assignable to type 'Top'. Type 'Top | T | U' is not assignable to type 'Top'. Type 'T' is not assignable to type 'Top'. @@ -27,6 +30,9 @@ tests/cases/compiler/typeParameterDiamond3.ts(10,13): error TS2322: Type 'Bottom !!! error TS2322: Type 'Top | T | U' is not assignable to type 'T | U'. !!! error TS2322: Type 'Top' is not assignable to type 'T | U'. !!! error TS2322: Type 'Top' is not assignable to type 'U'. +!!! error TS2322: Type 'Bottom' is not assignable to type 'U'. +!!! error TS2322: Type 'Top | T | U' is not assignable to type 'U'. +!!! error TS2322: Type 'Top' is not assignable to type 'U'. top = bottom; ~~~ !!! error TS2322: Type 'Bottom' is not assignable to type 'Top'. diff --git a/tests/baselines/reference/typeParameterUsedAsTypeParameterConstraint4.errors.txt b/tests/baselines/reference/typeParameterUsedAsTypeParameterConstraint4.errors.txt index d86b63d2ce3..d78faf74fab 100644 --- a/tests/baselines/reference/typeParameterUsedAsTypeParameterConstraint4.errors.txt +++ b/tests/baselines/reference/typeParameterUsedAsTypeParameterConstraint4.errors.txt @@ -2,6 +2,7 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsed tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(4,25): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(5,8): error TS2304: Cannot find name 'W'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(8,16): error TS2322: Type 'W' is not assignable to type 'T'. + Type 'V' is not assignable to type 'T'. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(12,16): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(12,29): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsedAsTypeParameterConstraint4.ts(15,8): error TS2304: Cannot find name 'W'. @@ -42,6 +43,7 @@ tests/cases/conformance/types/objectTypeLiteral/callSignatures/typeParameterUsed return x; ~ !!! error TS2322: Type 'W' is not assignable to type 'T'. +!!! error TS2322: Type 'V' is not assignable to type 'T'. } } diff --git a/tests/baselines/reference/typeParametersShouldNotBeEqual2.errors.txt b/tests/baselines/reference/typeParametersShouldNotBeEqual2.errors.txt index 0d9375140ab..27ac1e07eab 100644 --- a/tests/baselines/reference/typeParametersShouldNotBeEqual2.errors.txt +++ b/tests/baselines/reference/typeParametersShouldNotBeEqual2.errors.txt @@ -1,8 +1,11 @@ tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(4,5): error TS2322: Type 'U' is not assignable to type 'T'. + Type 'Date' is not assignable to type 'T'. tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(5,5): error TS2322: Type 'V' is not assignable to type 'T'. tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(6,5): error TS2322: Type 'T' is not assignable to type 'V'. + Type 'Date' is not assignable to type 'V'. tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(7,5): error TS2322: Type 'V' is not assignable to type 'U'. tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(8,5): error TS2322: Type 'U' is not assignable to type 'V'. + Type 'Date' is not assignable to type 'V'. tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(9,5): error TS2322: Type 'Object' is not assignable to type 'T'. @@ -13,18 +16,21 @@ tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(9,5): error TS2322: Type x = y; // Ok ~ !!! error TS2322: Type 'U' is not assignable to type 'T'. +!!! error TS2322: Type 'Date' is not assignable to type 'T'. x = z; // Error ~ !!! error TS2322: Type 'V' is not assignable to type 'T'. z = x; // Error ~ !!! error TS2322: Type 'T' is not assignable to type 'V'. +!!! error TS2322: Type 'Date' is not assignable to type 'V'. y = z; // Error ~ !!! error TS2322: Type 'V' is not assignable to type 'U'. z = y; // Error ~ !!! error TS2322: Type 'U' is not assignable to type 'V'. +!!! error TS2322: Type 'Date' is not assignable to type 'V'. x = zz; // Error ~ !!! error TS2322: Type 'Object' is not assignable to type 'T'. diff --git a/tests/baselines/reference/typeParametersShouldNotBeEqual3.errors.txt b/tests/baselines/reference/typeParametersShouldNotBeEqual3.errors.txt index 5b1a8e9ae7e..0169f57c06f 100644 --- a/tests/baselines/reference/typeParametersShouldNotBeEqual3.errors.txt +++ b/tests/baselines/reference/typeParametersShouldNotBeEqual3.errors.txt @@ -1,4 +1,5 @@ tests/cases/compiler/typeParametersShouldNotBeEqual3.ts(4,5): error TS2322: Type 'U' is not assignable to type 'T'. + Type 'Object' is not assignable to type 'T'. tests/cases/compiler/typeParametersShouldNotBeEqual3.ts(5,5): error TS2322: Type 'Object' is not assignable to type 'T'. @@ -9,6 +10,7 @@ tests/cases/compiler/typeParametersShouldNotBeEqual3.ts(5,5): error TS2322: Type x = y; // Ok ~ !!! error TS2322: Type 'U' is not assignable to type 'T'. +!!! error TS2322: Type 'Object' is not assignable to type 'T'. x = z; // Ok ~ !!! error TS2322: Type 'Object' is not assignable to type 'T'. diff --git a/tests/baselines/reference/underscoreTest1.js b/tests/baselines/reference/underscoreTest1.js index ddd5201b858..687a210e670 100644 --- a/tests/baselines/reference/underscoreTest1.js +++ b/tests/baselines/reference/underscoreTest1.js @@ -385,6 +385,7 @@ module Underscore { evaluate?: RegExp; interpolate?: RegExp; escape?: RegExp; + variable?: string; } export interface Static { diff --git a/tests/baselines/reference/underscoreTest1.symbols b/tests/baselines/reference/underscoreTest1.symbols index 128ce83051a..1ba7c97d331 100644 --- a/tests/baselines/reference/underscoreTest1.symbols +++ b/tests/baselines/reference/underscoreTest1.symbols @@ -9,9 +9,9 @@ declare function alert(x: string): void; >x : Symbol(x, Decl(underscoreTest1_underscoreTests.ts, 3, 23)) _.each([1, 2, 3], (num) => alert(num.toString())); ->_.each : Symbol(Underscore.Static.each, Decl(underscoreTest1_underscore.ts, 394, 43), Decl(underscoreTest1_underscore.ts, 396, 77)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->each : Symbol(Underscore.Static.each, Decl(underscoreTest1_underscore.ts, 394, 43), Decl(underscoreTest1_underscore.ts, 396, 77)) +>_.each : Symbol(Underscore.Static.each, Decl(underscoreTest1_underscore.ts, 395, 43), Decl(underscoreTest1_underscore.ts, 397, 77)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>each : Symbol(Underscore.Static.each, Decl(underscoreTest1_underscore.ts, 395, 43), Decl(underscoreTest1_underscore.ts, 397, 77)) >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 5, 19)) >alert : Symbol(alert, Decl(underscoreTest1_underscoreTests.ts, 2, 14)) >num.toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) @@ -19,9 +19,9 @@ _.each([1, 2, 3], (num) => alert(num.toString())); >toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) _.each({ one: 1, two: 2, three: 3 }, (value: number, key?: string) => alert(value.toString())); ->_.each : Symbol(Underscore.Static.each, Decl(underscoreTest1_underscore.ts, 394, 43), Decl(underscoreTest1_underscore.ts, 396, 77)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->each : Symbol(Underscore.Static.each, Decl(underscoreTest1_underscore.ts, 394, 43), Decl(underscoreTest1_underscore.ts, 396, 77)) +>_.each : Symbol(Underscore.Static.each, Decl(underscoreTest1_underscore.ts, 395, 43), Decl(underscoreTest1_underscore.ts, 397, 77)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>each : Symbol(Underscore.Static.each, Decl(underscoreTest1_underscore.ts, 395, 43), Decl(underscoreTest1_underscore.ts, 397, 77)) >one : Symbol(one, Decl(underscoreTest1_underscoreTests.ts, 6, 8)) >two : Symbol(two, Decl(underscoreTest1_underscoreTests.ts, 6, 16)) >three : Symbol(three, Decl(underscoreTest1_underscoreTests.ts, 6, 24)) @@ -33,16 +33,16 @@ _.each({ one: 1, two: 2, three: 3 }, (value: number, key?: string) => alert(valu >toString : Symbol(Number.toString, Decl(lib.d.ts, 458, 18)) _.map([1, 2, 3], (num) => num * 3); ->_.map : Symbol(Underscore.Static.map, Decl(underscoreTest1_underscore.ts, 399, 90), Decl(underscoreTest1_underscore.ts, 401, 75)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->map : Symbol(Underscore.Static.map, Decl(underscoreTest1_underscore.ts, 399, 90), Decl(underscoreTest1_underscore.ts, 401, 75)) +>_.map : Symbol(Underscore.Static.map, Decl(underscoreTest1_underscore.ts, 400, 90), Decl(underscoreTest1_underscore.ts, 402, 75)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>map : Symbol(Underscore.Static.map, Decl(underscoreTest1_underscore.ts, 400, 90), Decl(underscoreTest1_underscore.ts, 402, 75)) >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 8, 18)) >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 8, 18)) _.map({ one: 1, two: 2, three: 3 }, (value: number, key?: string) => value * 3); ->_.map : Symbol(Underscore.Static.map, Decl(underscoreTest1_underscore.ts, 399, 90), Decl(underscoreTest1_underscore.ts, 401, 75)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->map : Symbol(Underscore.Static.map, Decl(underscoreTest1_underscore.ts, 399, 90), Decl(underscoreTest1_underscore.ts, 401, 75)) +>_.map : Symbol(Underscore.Static.map, Decl(underscoreTest1_underscore.ts, 400, 90), Decl(underscoreTest1_underscore.ts, 402, 75)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>map : Symbol(Underscore.Static.map, Decl(underscoreTest1_underscore.ts, 400, 90), Decl(underscoreTest1_underscore.ts, 402, 75)) >one : Symbol(one, Decl(underscoreTest1_underscoreTests.ts, 9, 7)) >two : Symbol(two, Decl(underscoreTest1_underscoreTests.ts, 9, 15)) >three : Symbol(three, Decl(underscoreTest1_underscoreTests.ts, 9, 23)) @@ -52,9 +52,9 @@ _.map({ one: 1, two: 2, three: 3 }, (value: number, key?: string) => value * 3); var sum = _.reduce([1, 2, 3], (memo, num) => memo + num, 0); >sum : Symbol(sum, Decl(underscoreTest1_underscoreTests.ts, 11, 3)) ->_.reduce : Symbol(Underscore.Static.reduce, Decl(underscoreTest1_underscore.ts, 404, 89), Decl(underscoreTest1_underscore.ts, 406, 90), Decl(underscoreTest1_underscore.ts, 407, 92), Decl(underscoreTest1_underscore.ts, 408, 100)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->reduce : Symbol(Underscore.Static.reduce, Decl(underscoreTest1_underscore.ts, 404, 89), Decl(underscoreTest1_underscore.ts, 406, 90), Decl(underscoreTest1_underscore.ts, 407, 92), Decl(underscoreTest1_underscore.ts, 408, 100)) +>_.reduce : Symbol(Underscore.Static.reduce, Decl(underscoreTest1_underscore.ts, 405, 89), Decl(underscoreTest1_underscore.ts, 407, 90), Decl(underscoreTest1_underscore.ts, 408, 92), Decl(underscoreTest1_underscore.ts, 409, 100)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>reduce : Symbol(Underscore.Static.reduce, Decl(underscoreTest1_underscore.ts, 405, 89), Decl(underscoreTest1_underscore.ts, 407, 90), Decl(underscoreTest1_underscore.ts, 408, 92), Decl(underscoreTest1_underscore.ts, 409, 100)) >memo : Symbol(memo, Decl(underscoreTest1_underscoreTests.ts, 11, 31)) >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 11, 36)) >memo : Symbol(memo, Decl(underscoreTest1_underscoreTests.ts, 11, 31)) @@ -65,9 +65,9 @@ var list = [[0, 1], [2, 3], [4, 5]]; var flat = _.reduceRight(list, (a, b) => a.concat(b), []); >flat : Symbol(flat, Decl(underscoreTest1_underscoreTests.ts, 14, 3)) ->_.reduceRight : Symbol(Underscore.Static.reduceRight, Decl(underscoreTest1_underscore.ts, 417, 102), Decl(underscoreTest1_underscore.ts, 419, 95), Decl(underscoreTest1_underscore.ts, 420, 97), Decl(underscoreTest1_underscore.ts, 421, 105)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->reduceRight : Symbol(Underscore.Static.reduceRight, Decl(underscoreTest1_underscore.ts, 417, 102), Decl(underscoreTest1_underscore.ts, 419, 95), Decl(underscoreTest1_underscore.ts, 420, 97), Decl(underscoreTest1_underscore.ts, 421, 105)) +>_.reduceRight : Symbol(Underscore.Static.reduceRight, Decl(underscoreTest1_underscore.ts, 418, 102), Decl(underscoreTest1_underscore.ts, 420, 95), Decl(underscoreTest1_underscore.ts, 421, 97), Decl(underscoreTest1_underscore.ts, 422, 105)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>reduceRight : Symbol(Underscore.Static.reduceRight, Decl(underscoreTest1_underscore.ts, 418, 102), Decl(underscoreTest1_underscore.ts, 420, 95), Decl(underscoreTest1_underscore.ts, 421, 97), Decl(underscoreTest1_underscore.ts, 422, 105)) >list : Symbol(list, Decl(underscoreTest1_underscoreTests.ts, 13, 3)) >a : Symbol(a, Decl(underscoreTest1_underscoreTests.ts, 14, 32)) >b : Symbol(b, Decl(underscoreTest1_underscoreTests.ts, 14, 34)) @@ -78,17 +78,17 @@ var flat = _.reduceRight(list, (a, b) => a.concat(b), []); var even = _.find([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0); >even : Symbol(even, Decl(underscoreTest1_underscoreTests.ts, 16, 3)) ->_.find : Symbol(Underscore.Static.find, Decl(underscoreTest1_underscore.ts, 426, 101), Decl(underscoreTest1_underscore.ts, 428, 77)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->find : Symbol(Underscore.Static.find, Decl(underscoreTest1_underscore.ts, 426, 101), Decl(underscoreTest1_underscore.ts, 428, 77)) +>_.find : Symbol(Underscore.Static.find, Decl(underscoreTest1_underscore.ts, 427, 101), Decl(underscoreTest1_underscore.ts, 429, 77)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>find : Symbol(Underscore.Static.find, Decl(underscoreTest1_underscore.ts, 427, 101), Decl(underscoreTest1_underscore.ts, 429, 77)) >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 16, 39)) >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 16, 39)) var evens = _.filter([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0); >evens : Symbol(evens, Decl(underscoreTest1_underscoreTests.ts, 18, 3)) ->_.filter : Symbol(Underscore.Static.filter, Decl(underscoreTest1_underscore.ts, 431, 89), Decl(underscoreTest1_underscore.ts, 433, 81)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->filter : Symbol(Underscore.Static.filter, Decl(underscoreTest1_underscore.ts, 431, 89), Decl(underscoreTest1_underscore.ts, 433, 81)) +>_.filter : Symbol(Underscore.Static.filter, Decl(underscoreTest1_underscore.ts, 432, 89), Decl(underscoreTest1_underscore.ts, 434, 81)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>filter : Symbol(Underscore.Static.filter, Decl(underscoreTest1_underscore.ts, 432, 89), Decl(underscoreTest1_underscore.ts, 434, 81)) >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 18, 42)) >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 18, 42)) @@ -105,43 +105,43 @@ var listOfPlays = [{ title: "Cymbeline", author: "Shakespeare", year: 1611 }, { >year : Symbol(year, Decl(underscoreTest1_underscoreTests.ts, 20, 183)) _.where(listOfPlays, { author: "Shakespeare", year: 1611 }); ->_.where : Symbol(Underscore.Static.where, Decl(underscoreTest1_underscore.ts, 436, 91), Decl(underscoreTest1_underscore.ts, 438, 53)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->where : Symbol(Underscore.Static.where, Decl(underscoreTest1_underscore.ts, 436, 91), Decl(underscoreTest1_underscore.ts, 438, 53)) +>_.where : Symbol(Underscore.Static.where, Decl(underscoreTest1_underscore.ts, 437, 91), Decl(underscoreTest1_underscore.ts, 439, 53)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>where : Symbol(Underscore.Static.where, Decl(underscoreTest1_underscore.ts, 437, 91), Decl(underscoreTest1_underscore.ts, 439, 53)) >listOfPlays : Symbol(listOfPlays, Decl(underscoreTest1_underscoreTests.ts, 20, 3)) >author : Symbol(author, Decl(underscoreTest1_underscoreTests.ts, 21, 22)) >year : Symbol(year, Decl(underscoreTest1_underscoreTests.ts, 21, 45)) var odds = _.reject([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0); >odds : Symbol(odds, Decl(underscoreTest1_underscoreTests.ts, 23, 3)) ->_.reject : Symbol(Underscore.Static.reject, Decl(underscoreTest1_underscore.ts, 442, 65), Decl(underscoreTest1_underscore.ts, 444, 81)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->reject : Symbol(Underscore.Static.reject, Decl(underscoreTest1_underscore.ts, 442, 65), Decl(underscoreTest1_underscore.ts, 444, 81)) +>_.reject : Symbol(Underscore.Static.reject, Decl(underscoreTest1_underscore.ts, 443, 65), Decl(underscoreTest1_underscore.ts, 445, 81)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>reject : Symbol(Underscore.Static.reject, Decl(underscoreTest1_underscore.ts, 443, 65), Decl(underscoreTest1_underscore.ts, 445, 81)) >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 23, 41)) >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 23, 41)) _.all([true, 1, null, 'yes'], _.identity); ->_.all : Symbol(Underscore.Static.all, Decl(underscoreTest1_underscore.ts, 448, 95), Decl(underscoreTest1_underscore.ts, 449, 83)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->all : Symbol(Underscore.Static.all, Decl(underscoreTest1_underscore.ts, 448, 95), Decl(underscoreTest1_underscore.ts, 449, 83)) ->_.identity : Symbol(Underscore.Static.identity, Decl(underscoreTest1_underscore.ts, 617, 29)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->identity : Symbol(Underscore.Static.identity, Decl(underscoreTest1_underscore.ts, 617, 29)) +>_.all : Symbol(Underscore.Static.all, Decl(underscoreTest1_underscore.ts, 449, 95), Decl(underscoreTest1_underscore.ts, 450, 83)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>all : Symbol(Underscore.Static.all, Decl(underscoreTest1_underscore.ts, 449, 95), Decl(underscoreTest1_underscore.ts, 450, 83)) +>_.identity : Symbol(Underscore.Static.identity, Decl(underscoreTest1_underscore.ts, 618, 29)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>identity : Symbol(Underscore.Static.identity, Decl(underscoreTest1_underscore.ts, 618, 29)) _.any([null, 0, 'yes', false]); ->_.any : Symbol(Underscore.Static.any, Decl(underscoreTest1_underscore.ts, 453, 94), Decl(underscoreTest1_underscore.ts, 454, 83)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->any : Symbol(Underscore.Static.any, Decl(underscoreTest1_underscore.ts, 453, 94), Decl(underscoreTest1_underscore.ts, 454, 83)) +>_.any : Symbol(Underscore.Static.any, Decl(underscoreTest1_underscore.ts, 454, 94), Decl(underscoreTest1_underscore.ts, 455, 83)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>any : Symbol(Underscore.Static.any, Decl(underscoreTest1_underscore.ts, 454, 94), Decl(underscoreTest1_underscore.ts, 455, 83)) _.contains([1, 2, 3], 3); ->_.contains : Symbol(Underscore.Static.contains, Decl(underscoreTest1_underscore.ts, 455, 93), Decl(underscoreTest1_underscore.ts, 457, 50)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->contains : Symbol(Underscore.Static.contains, Decl(underscoreTest1_underscore.ts, 455, 93), Decl(underscoreTest1_underscore.ts, 457, 50)) +>_.contains : Symbol(Underscore.Static.contains, Decl(underscoreTest1_underscore.ts, 456, 93), Decl(underscoreTest1_underscore.ts, 458, 50)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>contains : Symbol(Underscore.Static.contains, Decl(underscoreTest1_underscore.ts, 456, 93), Decl(underscoreTest1_underscore.ts, 458, 50)) _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); ->_.invoke : Symbol(Underscore.Static.invoke, Decl(underscoreTest1_underscore.ts, 460, 59), Decl(underscoreTest1_underscore.ts, 462, 71)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->invoke : Symbol(Underscore.Static.invoke, Decl(underscoreTest1_underscore.ts, 460, 59), Decl(underscoreTest1_underscore.ts, 462, 71)) +>_.invoke : Symbol(Underscore.Static.invoke, Decl(underscoreTest1_underscore.ts, 461, 59), Decl(underscoreTest1_underscore.ts, 463, 71)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>invoke : Symbol(Underscore.Static.invoke, Decl(underscoreTest1_underscore.ts, 461, 59), Decl(underscoreTest1_underscore.ts, 463, 71)) var stooges = [{ name: 'moe', age: 40 }, { name: 'larry', age: 50 }, { name: 'curly', age: 60 }]; >stooges : Symbol(stooges, Decl(underscoreTest1_underscoreTests.ts, 33, 3)) @@ -153,15 +153,15 @@ var stooges = [{ name: 'moe', age: 40 }, { name: 'larry', age: 50 }, { name: 'cu >age : Symbol(age, Decl(underscoreTest1_underscoreTests.ts, 33, 85)) _.pluck(stooges, 'name'); ->_.pluck : Symbol(Underscore.Static.pluck, Decl(underscoreTest1_underscore.ts, 463, 81), Decl(underscoreTest1_underscore.ts, 465, 56)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->pluck : Symbol(Underscore.Static.pluck, Decl(underscoreTest1_underscore.ts, 463, 81), Decl(underscoreTest1_underscore.ts, 465, 56)) +>_.pluck : Symbol(Underscore.Static.pluck, Decl(underscoreTest1_underscore.ts, 464, 81), Decl(underscoreTest1_underscore.ts, 466, 56)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>pluck : Symbol(Underscore.Static.pluck, Decl(underscoreTest1_underscore.ts, 464, 81), Decl(underscoreTest1_underscore.ts, 466, 56)) >stooges : Symbol(stooges, Decl(underscoreTest1_underscoreTests.ts, 33, 3)) _.max(stooges, (stooge) => stooge.age); ->_.max : Symbol(Underscore.Static.max, Decl(underscoreTest1_underscore.ts, 466, 66), Decl(underscoreTest1_underscore.ts, 468, 73)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->max : Symbol(Underscore.Static.max, Decl(underscoreTest1_underscore.ts, 466, 66), Decl(underscoreTest1_underscore.ts, 468, 73)) +>_.max : Symbol(Underscore.Static.max, Decl(underscoreTest1_underscore.ts, 467, 66), Decl(underscoreTest1_underscore.ts, 469, 73)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>max : Symbol(Underscore.Static.max, Decl(underscoreTest1_underscore.ts, 467, 66), Decl(underscoreTest1_underscore.ts, 469, 73)) >stooges : Symbol(stooges, Decl(underscoreTest1_underscoreTests.ts, 33, 3)) >stooge : Symbol(stooge, Decl(underscoreTest1_underscoreTests.ts, 36, 16)) >stooge.age : Symbol(age, Decl(underscoreTest1_underscoreTests.ts, 33, 29)) @@ -172,15 +172,15 @@ var numbers = [10, 5, 100, 2, 1000]; >numbers : Symbol(numbers, Decl(underscoreTest1_underscoreTests.ts, 38, 3)) _.min(numbers); ->_.min : Symbol(Underscore.Static.min, Decl(underscoreTest1_underscore.ts, 469, 83), Decl(underscoreTest1_underscore.ts, 471, 73)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->min : Symbol(Underscore.Static.min, Decl(underscoreTest1_underscore.ts, 469, 83), Decl(underscoreTest1_underscore.ts, 471, 73)) +>_.min : Symbol(Underscore.Static.min, Decl(underscoreTest1_underscore.ts, 470, 83), Decl(underscoreTest1_underscore.ts, 472, 73)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>min : Symbol(Underscore.Static.min, Decl(underscoreTest1_underscore.ts, 470, 83), Decl(underscoreTest1_underscore.ts, 472, 73)) >numbers : Symbol(numbers, Decl(underscoreTest1_underscoreTests.ts, 38, 3)) _.sortBy([1, 2, 3, 4, 5, 6], (num) => Math.sin(num)); ->_.sortBy : Symbol(Underscore.Static.sortBy, Decl(underscoreTest1_underscore.ts, 472, 83), Decl(underscoreTest1_underscore.ts, 474, 77), Decl(underscoreTest1_underscore.ts, 475, 87), Decl(underscoreTest1_underscore.ts, 476, 56)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->sortBy : Symbol(Underscore.Static.sortBy, Decl(underscoreTest1_underscore.ts, 472, 83), Decl(underscoreTest1_underscore.ts, 474, 77), Decl(underscoreTest1_underscore.ts, 475, 87), Decl(underscoreTest1_underscore.ts, 476, 56)) +>_.sortBy : Symbol(Underscore.Static.sortBy, Decl(underscoreTest1_underscore.ts, 473, 83), Decl(underscoreTest1_underscore.ts, 475, 77), Decl(underscoreTest1_underscore.ts, 476, 87), Decl(underscoreTest1_underscore.ts, 477, 56)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>sortBy : Symbol(Underscore.Static.sortBy, Decl(underscoreTest1_underscore.ts, 473, 83), Decl(underscoreTest1_underscore.ts, 475, 77), Decl(underscoreTest1_underscore.ts, 476, 87), Decl(underscoreTest1_underscore.ts, 477, 56)) >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 41, 30)) >Math.sin : Symbol(Math.sin, Decl(lib.d.ts, 615, 29)) >Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11)) @@ -191,7 +191,7 @@ _.sortBy([1, 2, 3, 4, 5, 6], (num) => Math.sin(num)); // not sure how this is typechecking at all.. Math.floor(e) is number not string..? _([1.3, 2.1, 2.4]).groupBy((e: number, i?: number, list?: number[]) => Math.floor(e)); >_([1.3, 2.1, 2.4]).groupBy : Symbol(Underscore.WrappedArray.groupBy, Decl(underscoreTest1_underscore.ts, 112, 42), Decl(underscoreTest1_underscore.ts, 113, 77)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) >groupBy : Symbol(Underscore.WrappedArray.groupBy, Decl(underscoreTest1_underscore.ts, 112, 42), Decl(underscoreTest1_underscore.ts, 113, 77)) >e : Symbol(e, Decl(underscoreTest1_underscoreTests.ts, 45, 28)) >i : Symbol(i, Decl(underscoreTest1_underscoreTests.ts, 45, 38)) @@ -202,9 +202,9 @@ _([1.3, 2.1, 2.4]).groupBy((e: number, i?: number, list?: number[]) => Math.floo >e : Symbol(e, Decl(underscoreTest1_underscoreTests.ts, 45, 28)) _.groupBy([1.3, 2.1, 2.4], (num: number) => Math.floor(num)); ->_.groupBy : Symbol(Underscore.Static.groupBy, Decl(underscoreTest1_underscore.ts, 477, 66), Decl(underscoreTest1_underscore.ts, 479, 91), Decl(underscoreTest1_underscore.ts, 480, 101), Decl(underscoreTest1_underscore.ts, 481, 69)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->groupBy : Symbol(Underscore.Static.groupBy, Decl(underscoreTest1_underscore.ts, 477, 66), Decl(underscoreTest1_underscore.ts, 479, 91), Decl(underscoreTest1_underscore.ts, 480, 101), Decl(underscoreTest1_underscore.ts, 481, 69)) +>_.groupBy : Symbol(Underscore.Static.groupBy, Decl(underscoreTest1_underscore.ts, 478, 66), Decl(underscoreTest1_underscore.ts, 480, 91), Decl(underscoreTest1_underscore.ts, 481, 101), Decl(underscoreTest1_underscore.ts, 482, 69)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>groupBy : Symbol(Underscore.Static.groupBy, Decl(underscoreTest1_underscore.ts, 478, 66), Decl(underscoreTest1_underscore.ts, 480, 91), Decl(underscoreTest1_underscore.ts, 481, 101), Decl(underscoreTest1_underscore.ts, 482, 69)) >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 46, 28)) >Math.floor : Symbol(Math.floor, Decl(lib.d.ts, 582, 27)) >Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11)) @@ -212,28 +212,28 @@ _.groupBy([1.3, 2.1, 2.4], (num: number) => Math.floor(num)); >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 46, 28)) _.groupBy(['one', 'two', 'three'], 'length'); ->_.groupBy : Symbol(Underscore.Static.groupBy, Decl(underscoreTest1_underscore.ts, 477, 66), Decl(underscoreTest1_underscore.ts, 479, 91), Decl(underscoreTest1_underscore.ts, 480, 101), Decl(underscoreTest1_underscore.ts, 481, 69)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->groupBy : Symbol(Underscore.Static.groupBy, Decl(underscoreTest1_underscore.ts, 477, 66), Decl(underscoreTest1_underscore.ts, 479, 91), Decl(underscoreTest1_underscore.ts, 480, 101), Decl(underscoreTest1_underscore.ts, 481, 69)) +>_.groupBy : Symbol(Underscore.Static.groupBy, Decl(underscoreTest1_underscore.ts, 478, 66), Decl(underscoreTest1_underscore.ts, 480, 91), Decl(underscoreTest1_underscore.ts, 481, 101), Decl(underscoreTest1_underscore.ts, 482, 69)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>groupBy : Symbol(Underscore.Static.groupBy, Decl(underscoreTest1_underscore.ts, 478, 66), Decl(underscoreTest1_underscore.ts, 480, 91), Decl(underscoreTest1_underscore.ts, 481, 101), Decl(underscoreTest1_underscore.ts, 482, 69)) _.countBy([1, 2, 3, 4, 5], (num) => num % 2 == 0 ? 'even' : 'odd'); ->_.countBy : Symbol(Underscore.Static.countBy, Decl(underscoreTest1_underscore.ts, 482, 79), Decl(underscoreTest1_underscore.ts, 484, 94), Decl(underscoreTest1_underscore.ts, 485, 104), Decl(underscoreTest1_underscore.ts, 486, 72)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->countBy : Symbol(Underscore.Static.countBy, Decl(underscoreTest1_underscore.ts, 482, 79), Decl(underscoreTest1_underscore.ts, 484, 94), Decl(underscoreTest1_underscore.ts, 485, 104), Decl(underscoreTest1_underscore.ts, 486, 72)) +>_.countBy : Symbol(Underscore.Static.countBy, Decl(underscoreTest1_underscore.ts, 483, 79), Decl(underscoreTest1_underscore.ts, 485, 94), Decl(underscoreTest1_underscore.ts, 486, 104), Decl(underscoreTest1_underscore.ts, 487, 72)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>countBy : Symbol(Underscore.Static.countBy, Decl(underscoreTest1_underscore.ts, 483, 79), Decl(underscoreTest1_underscore.ts, 485, 94), Decl(underscoreTest1_underscore.ts, 486, 104), Decl(underscoreTest1_underscore.ts, 487, 72)) >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 49, 28)) >num : Symbol(num, Decl(underscoreTest1_underscoreTests.ts, 49, 28)) _.shuffle([1, 2, 3, 4, 5, 6]); ->_.shuffle : Symbol(Underscore.Static.shuffle, Decl(underscoreTest1_underscore.ts, 487, 82), Decl(underscoreTest1_underscore.ts, 489, 35)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->shuffle : Symbol(Underscore.Static.shuffle, Decl(underscoreTest1_underscore.ts, 487, 82), Decl(underscoreTest1_underscore.ts, 489, 35)) +>_.shuffle : Symbol(Underscore.Static.shuffle, Decl(underscoreTest1_underscore.ts, 488, 82), Decl(underscoreTest1_underscore.ts, 490, 35)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>shuffle : Symbol(Underscore.Static.shuffle, Decl(underscoreTest1_underscore.ts, 488, 82), Decl(underscoreTest1_underscore.ts, 490, 35)) // (function(){ return _.toArray(arguments).slice(1); })(1, 2, 3, 4); _.size({ one: 1, two: 2, three: 3 }); ->_.size : Symbol(Underscore.Static.size, Decl(underscoreTest1_underscore.ts, 493, 45), Decl(underscoreTest1_underscore.ts, 495, 35)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->size : Symbol(Underscore.Static.size, Decl(underscoreTest1_underscore.ts, 493, 45), Decl(underscoreTest1_underscore.ts, 495, 35)) +>_.size : Symbol(Underscore.Static.size, Decl(underscoreTest1_underscore.ts, 494, 45), Decl(underscoreTest1_underscore.ts, 496, 35)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>size : Symbol(Underscore.Static.size, Decl(underscoreTest1_underscore.ts, 494, 45), Decl(underscoreTest1_underscore.ts, 496, 35)) >one : Symbol(one, Decl(underscoreTest1_underscoreTests.ts, 55, 8)) >two : Symbol(two, Decl(underscoreTest1_underscoreTests.ts, 55, 16)) >three : Symbol(three, Decl(underscoreTest1_underscoreTests.ts, 55, 24)) @@ -241,130 +241,130 @@ _.size({ one: 1, two: 2, three: 3 }); /////////////////////////////////////////////////////////////////////////////////////// _.first([5, 4, 3, 2, 1]); ->_.first : Symbol(Underscore.Static.first, Decl(underscoreTest1_underscore.ts, 496, 45), Decl(underscoreTest1_underscore.ts, 498, 31)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->first : Symbol(Underscore.Static.first, Decl(underscoreTest1_underscore.ts, 496, 45), Decl(underscoreTest1_underscore.ts, 498, 31)) +>_.first : Symbol(Underscore.Static.first, Decl(underscoreTest1_underscore.ts, 497, 45), Decl(underscoreTest1_underscore.ts, 499, 31)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>first : Symbol(Underscore.Static.first, Decl(underscoreTest1_underscore.ts, 497, 45), Decl(underscoreTest1_underscore.ts, 499, 31)) _.initial([5, 4, 3, 2, 1]); ->_.initial : Symbol(Underscore.Static.initial, Decl(underscoreTest1_underscore.ts, 503, 47), Decl(underscoreTest1_underscore.ts, 505, 33)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->initial : Symbol(Underscore.Static.initial, Decl(underscoreTest1_underscore.ts, 503, 47), Decl(underscoreTest1_underscore.ts, 505, 33)) +>_.initial : Symbol(Underscore.Static.initial, Decl(underscoreTest1_underscore.ts, 504, 47), Decl(underscoreTest1_underscore.ts, 506, 33)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>initial : Symbol(Underscore.Static.initial, Decl(underscoreTest1_underscore.ts, 504, 47), Decl(underscoreTest1_underscore.ts, 506, 33)) _.last([5, 4, 3, 2, 1]); ->_.last : Symbol(Underscore.Static.last, Decl(underscoreTest1_underscore.ts, 506, 50), Decl(underscoreTest1_underscore.ts, 508, 30)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->last : Symbol(Underscore.Static.last, Decl(underscoreTest1_underscore.ts, 506, 50), Decl(underscoreTest1_underscore.ts, 508, 30)) +>_.last : Symbol(Underscore.Static.last, Decl(underscoreTest1_underscore.ts, 507, 50), Decl(underscoreTest1_underscore.ts, 509, 30)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>last : Symbol(Underscore.Static.last, Decl(underscoreTest1_underscore.ts, 507, 50), Decl(underscoreTest1_underscore.ts, 509, 30)) _.rest([5, 4, 3, 2, 1]); ->_.rest : Symbol(Underscore.Static.rest, Decl(underscoreTest1_underscore.ts, 509, 47)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->rest : Symbol(Underscore.Static.rest, Decl(underscoreTest1_underscore.ts, 509, 47)) +>_.rest : Symbol(Underscore.Static.rest, Decl(underscoreTest1_underscore.ts, 510, 47)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>rest : Symbol(Underscore.Static.rest, Decl(underscoreTest1_underscore.ts, 510, 47)) _.compact([0, 1, false, 2, '', 3]); ->_.compact : Symbol(Underscore.Static.compact, Decl(underscoreTest1_underscore.ts, 511, 48)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->compact : Symbol(Underscore.Static.compact, Decl(underscoreTest1_underscore.ts, 511, 48)) +>_.compact : Symbol(Underscore.Static.compact, Decl(underscoreTest1_underscore.ts, 512, 48)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>compact : Symbol(Underscore.Static.compact, Decl(underscoreTest1_underscore.ts, 512, 48)) _.flatten([1, 2, 3, 4]); ->_.flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 513, 35), Decl(underscoreTest1_underscore.ts, 515, 37)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 513, 35), Decl(underscoreTest1_underscore.ts, 515, 37)) +>_.flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 514, 35), Decl(underscoreTest1_underscore.ts, 516, 37)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 514, 35), Decl(underscoreTest1_underscore.ts, 516, 37)) _.flatten([1, [2]]); ->_.flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 513, 35), Decl(underscoreTest1_underscore.ts, 515, 37)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 513, 35), Decl(underscoreTest1_underscore.ts, 515, 37)) +>_.flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 514, 35), Decl(underscoreTest1_underscore.ts, 516, 37)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 514, 35), Decl(underscoreTest1_underscore.ts, 516, 37)) // typescript doesn't like the elements being different _.flatten([1, [2], [3, [[4]]]]); ->_.flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 513, 35), Decl(underscoreTest1_underscore.ts, 515, 37)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 513, 35), Decl(underscoreTest1_underscore.ts, 515, 37)) +>_.flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 514, 35), Decl(underscoreTest1_underscore.ts, 516, 37)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 514, 35), Decl(underscoreTest1_underscore.ts, 516, 37)) _.flatten([1, [2], [3, [[4]]]], true); ->_.flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 513, 35), Decl(underscoreTest1_underscore.ts, 515, 37)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 513, 35), Decl(underscoreTest1_underscore.ts, 515, 37)) +>_.flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 514, 35), Decl(underscoreTest1_underscore.ts, 516, 37)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>flatten : Symbol(Underscore.Static.flatten, Decl(underscoreTest1_underscore.ts, 514, 35), Decl(underscoreTest1_underscore.ts, 516, 37)) _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ->_.without : Symbol(Underscore.Static.without, Decl(underscoreTest1_underscore.ts, 516, 57)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->without : Symbol(Underscore.Static.without, Decl(underscoreTest1_underscore.ts, 516, 57)) +>_.without : Symbol(Underscore.Static.without, Decl(underscoreTest1_underscore.ts, 517, 57)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>without : Symbol(Underscore.Static.without, Decl(underscoreTest1_underscore.ts, 517, 57)) _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ->_.union : Symbol(Underscore.Static.union, Decl(underscoreTest1_underscore.ts, 518, 51)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->union : Symbol(Underscore.Static.union, Decl(underscoreTest1_underscore.ts, 518, 51)) +>_.union : Symbol(Underscore.Static.union, Decl(underscoreTest1_underscore.ts, 519, 51)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>union : Symbol(Underscore.Static.union, Decl(underscoreTest1_underscore.ts, 519, 51)) _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ->_.intersection : Symbol(Underscore.Static.intersection, Decl(underscoreTest1_underscore.ts, 520, 40)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->intersection : Symbol(Underscore.Static.intersection, Decl(underscoreTest1_underscore.ts, 520, 40)) +>_.intersection : Symbol(Underscore.Static.intersection, Decl(underscoreTest1_underscore.ts, 521, 40)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>intersection : Symbol(Underscore.Static.intersection, Decl(underscoreTest1_underscore.ts, 521, 40)) _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ->_.difference : Symbol(Underscore.Static.difference, Decl(underscoreTest1_underscore.ts, 522, 47)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->difference : Symbol(Underscore.Static.difference, Decl(underscoreTest1_underscore.ts, 522, 47)) +>_.difference : Symbol(Underscore.Static.difference, Decl(underscoreTest1_underscore.ts, 523, 47)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>difference : Symbol(Underscore.Static.difference, Decl(underscoreTest1_underscore.ts, 523, 47)) _.uniq([1, 2, 1, 3, 1, 4]); ->_.uniq : Symbol(Underscore.Static.uniq, Decl(underscoreTest1_underscore.ts, 524, 56), Decl(underscoreTest1_underscore.ts, 526, 52)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->uniq : Symbol(Underscore.Static.uniq, Decl(underscoreTest1_underscore.ts, 524, 56), Decl(underscoreTest1_underscore.ts, 526, 52)) +>_.uniq : Symbol(Underscore.Static.uniq, Decl(underscoreTest1_underscore.ts, 525, 56), Decl(underscoreTest1_underscore.ts, 527, 52)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>uniq : Symbol(Underscore.Static.uniq, Decl(underscoreTest1_underscore.ts, 525, 56), Decl(underscoreTest1_underscore.ts, 527, 52)) _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ->_.zip : Symbol(Underscore.Static.zip, Decl(underscoreTest1_underscore.ts, 529, 97), Decl(underscoreTest1_underscore.ts, 531, 58), Decl(underscoreTest1_underscore.ts, 532, 76), Decl(underscoreTest1_underscore.ts, 533, 94)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->zip : Symbol(Underscore.Static.zip, Decl(underscoreTest1_underscore.ts, 529, 97), Decl(underscoreTest1_underscore.ts, 531, 58), Decl(underscoreTest1_underscore.ts, 532, 76), Decl(underscoreTest1_underscore.ts, 533, 94)) +>_.zip : Symbol(Underscore.Static.zip, Decl(underscoreTest1_underscore.ts, 530, 97), Decl(underscoreTest1_underscore.ts, 532, 58), Decl(underscoreTest1_underscore.ts, 533, 76), Decl(underscoreTest1_underscore.ts, 534, 94)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>zip : Symbol(Underscore.Static.zip, Decl(underscoreTest1_underscore.ts, 530, 97), Decl(underscoreTest1_underscore.ts, 532, 58), Decl(underscoreTest1_underscore.ts, 533, 76), Decl(underscoreTest1_underscore.ts, 534, 94)) _.object(['moe', 'larry', 'curly'], [30, 40, 50]); ->_.object : Symbol(Underscore.Static.object, Decl(underscoreTest1_underscore.ts, 534, 41), Decl(underscoreTest1_underscore.ts, 536, 35)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->object : Symbol(Underscore.Static.object, Decl(underscoreTest1_underscore.ts, 534, 41), Decl(underscoreTest1_underscore.ts, 536, 35)) +>_.object : Symbol(Underscore.Static.object, Decl(underscoreTest1_underscore.ts, 535, 41), Decl(underscoreTest1_underscore.ts, 537, 35)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>object : Symbol(Underscore.Static.object, Decl(underscoreTest1_underscore.ts, 535, 41), Decl(underscoreTest1_underscore.ts, 537, 35)) _.object([['moe', 30], ['larry', 40], ['curly', 50]]); ->_.object : Symbol(Underscore.Static.object, Decl(underscoreTest1_underscore.ts, 534, 41), Decl(underscoreTest1_underscore.ts, 536, 35)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->object : Symbol(Underscore.Static.object, Decl(underscoreTest1_underscore.ts, 534, 41), Decl(underscoreTest1_underscore.ts, 536, 35)) +>_.object : Symbol(Underscore.Static.object, Decl(underscoreTest1_underscore.ts, 535, 41), Decl(underscoreTest1_underscore.ts, 537, 35)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>object : Symbol(Underscore.Static.object, Decl(underscoreTest1_underscore.ts, 535, 41), Decl(underscoreTest1_underscore.ts, 537, 35)) _.indexOf([1, 2, 3], 2); ->_.indexOf : Symbol(Underscore.Static.indexOf, Decl(underscoreTest1_underscore.ts, 537, 51)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->indexOf : Symbol(Underscore.Static.indexOf, Decl(underscoreTest1_underscore.ts, 537, 51)) +>_.indexOf : Symbol(Underscore.Static.indexOf, Decl(underscoreTest1_underscore.ts, 538, 51)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>indexOf : Symbol(Underscore.Static.indexOf, Decl(underscoreTest1_underscore.ts, 538, 51)) _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); ->_.lastIndexOf : Symbol(Underscore.Static.lastIndexOf, Decl(underscoreTest1_underscore.ts, 539, 68)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->lastIndexOf : Symbol(Underscore.Static.lastIndexOf, Decl(underscoreTest1_underscore.ts, 539, 68)) +>_.lastIndexOf : Symbol(Underscore.Static.lastIndexOf, Decl(underscoreTest1_underscore.ts, 540, 68)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>lastIndexOf : Symbol(Underscore.Static.lastIndexOf, Decl(underscoreTest1_underscore.ts, 540, 68)) _.sortedIndex([10, 20, 30, 40, 50], 35); ->_.sortedIndex : Symbol(Underscore.Static.sortedIndex, Decl(underscoreTest1_underscore.ts, 541, 72), Decl(underscoreTest1_underscore.ts, 543, 72)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->sortedIndex : Symbol(Underscore.Static.sortedIndex, Decl(underscoreTest1_underscore.ts, 541, 72), Decl(underscoreTest1_underscore.ts, 543, 72)) +>_.sortedIndex : Symbol(Underscore.Static.sortedIndex, Decl(underscoreTest1_underscore.ts, 542, 72), Decl(underscoreTest1_underscore.ts, 544, 72)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>sortedIndex : Symbol(Underscore.Static.sortedIndex, Decl(underscoreTest1_underscore.ts, 542, 72), Decl(underscoreTest1_underscore.ts, 544, 72)) _.range(10); ->_.range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 544, 94), Decl(underscoreTest1_underscore.ts, 546, 38)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 544, 94), Decl(underscoreTest1_underscore.ts, 546, 38)) +>_.range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 545, 94), Decl(underscoreTest1_underscore.ts, 547, 38)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 545, 94), Decl(underscoreTest1_underscore.ts, 547, 38)) _.range(1, 11); ->_.range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 544, 94), Decl(underscoreTest1_underscore.ts, 546, 38)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 544, 94), Decl(underscoreTest1_underscore.ts, 546, 38)) +>_.range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 545, 94), Decl(underscoreTest1_underscore.ts, 547, 38)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 545, 94), Decl(underscoreTest1_underscore.ts, 547, 38)) _.range(0, 30, 5); ->_.range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 544, 94), Decl(underscoreTest1_underscore.ts, 546, 38)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 544, 94), Decl(underscoreTest1_underscore.ts, 546, 38)) +>_.range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 545, 94), Decl(underscoreTest1_underscore.ts, 547, 38)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 545, 94), Decl(underscoreTest1_underscore.ts, 547, 38)) _.range(0, 30, 5); ->_.range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 544, 94), Decl(underscoreTest1_underscore.ts, 546, 38)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 544, 94), Decl(underscoreTest1_underscore.ts, 546, 38)) +>_.range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 545, 94), Decl(underscoreTest1_underscore.ts, 547, 38)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 545, 94), Decl(underscoreTest1_underscore.ts, 547, 38)) _.range(0); ->_.range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 544, 94), Decl(underscoreTest1_underscore.ts, 546, 38)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 544, 94), Decl(underscoreTest1_underscore.ts, 546, 38)) +>_.range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 545, 94), Decl(underscoreTest1_underscore.ts, 547, 38)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>range : Symbol(Underscore.Static.range, Decl(underscoreTest1_underscore.ts, 545, 94), Decl(underscoreTest1_underscore.ts, 547, 38)) /////////////////////////////////////////////////////////////////////////////////////// @@ -377,9 +377,9 @@ var func = function (greeting) { return greeting + ': ' + this.name }; // instead of the newly returned _bind => func type. var func2 = _.bind(func, { name: 'moe' }, 'hi'); >func2 : Symbol(func2, Decl(underscoreTest1_underscoreTests.ts, 93, 3)) ->_.bind : Symbol(Underscore.Static.bind, Decl(underscoreTest1_underscore.ts, 547, 68), Decl(underscoreTest1_underscore.ts, 549, 58)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->bind : Symbol(Underscore.Static.bind, Decl(underscoreTest1_underscore.ts, 547, 68), Decl(underscoreTest1_underscore.ts, 549, 58)) +>_.bind : Symbol(Underscore.Static.bind, Decl(underscoreTest1_underscore.ts, 548, 68), Decl(underscoreTest1_underscore.ts, 550, 58)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>bind : Symbol(Underscore.Static.bind, Decl(underscoreTest1_underscore.ts, 548, 68), Decl(underscoreTest1_underscore.ts, 550, 58)) >func : Symbol(func, Decl(underscoreTest1_underscoreTests.ts, 90, 3)) >name : Symbol(name, Decl(underscoreTest1_underscoreTests.ts, 93, 26)) @@ -402,9 +402,9 @@ var buttonView = { }; _.bindAll(buttonView); ->_.bindAll : Symbol(Underscore.Static.bindAll, Decl(underscoreTest1_underscore.ts, 550, 68)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->bindAll : Symbol(Underscore.Static.bindAll, Decl(underscoreTest1_underscore.ts, 550, 68)) +>_.bindAll : Symbol(Underscore.Static.bindAll, Decl(underscoreTest1_underscore.ts, 551, 68)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>bindAll : Symbol(Underscore.Static.bindAll, Decl(underscoreTest1_underscore.ts, 551, 68)) >buttonView : Symbol(buttonView, Decl(underscoreTest1_underscoreTests.ts, 96, 3)) $('#underscore_button').bind('click', buttonView.onClick); @@ -415,9 +415,9 @@ $('#underscore_button').bind('click', buttonView.onClick); var fibonacci = _.memoize(function (n) { >fibonacci : Symbol(fibonacci, Decl(underscoreTest1_underscoreTests.ts, 104, 3)) ->_.memoize : Symbol(Underscore.Static.memoize, Decl(underscoreTest1_underscore.ts, 554, 58)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->memoize : Symbol(Underscore.Static.memoize, Decl(underscoreTest1_underscore.ts, 554, 58)) +>_.memoize : Symbol(Underscore.Static.memoize, Decl(underscoreTest1_underscore.ts, 555, 58)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>memoize : Symbol(Underscore.Static.memoize, Decl(underscoreTest1_underscore.ts, 555, 58)) >n : Symbol(n, Decl(underscoreTest1_underscoreTests.ts, 104, 36)) return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); @@ -432,23 +432,23 @@ var fibonacci = _.memoize(function (n) { var log = _.bind((message?: string, ...rest: string[]) => { }, Date); >log : Symbol(log, Decl(underscoreTest1_underscoreTests.ts, 108, 3)) ->_.bind : Symbol(Underscore.Static.bind, Decl(underscoreTest1_underscore.ts, 547, 68), Decl(underscoreTest1_underscore.ts, 549, 58)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->bind : Symbol(Underscore.Static.bind, Decl(underscoreTest1_underscore.ts, 547, 68), Decl(underscoreTest1_underscore.ts, 549, 58)) +>_.bind : Symbol(Underscore.Static.bind, Decl(underscoreTest1_underscore.ts, 548, 68), Decl(underscoreTest1_underscore.ts, 550, 58)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>bind : Symbol(Underscore.Static.bind, Decl(underscoreTest1_underscore.ts, 548, 68), Decl(underscoreTest1_underscore.ts, 550, 58)) >message : Symbol(message, Decl(underscoreTest1_underscoreTests.ts, 108, 18)) >rest : Symbol(rest, Decl(underscoreTest1_underscoreTests.ts, 108, 35)) >Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11)) _.delay(log, 1000, 'logged later'); ->_.delay : Symbol(Underscore.Static.delay, Decl(underscoreTest1_underscore.ts, 556, 73)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->delay : Symbol(Underscore.Static.delay, Decl(underscoreTest1_underscore.ts, 556, 73)) +>_.delay : Symbol(Underscore.Static.delay, Decl(underscoreTest1_underscore.ts, 557, 73)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>delay : Symbol(Underscore.Static.delay, Decl(underscoreTest1_underscore.ts, 557, 73)) >log : Symbol(log, Decl(underscoreTest1_underscoreTests.ts, 108, 3)) _.defer(function () { alert('deferred'); }); ->_.defer : Symbol(Underscore.Static.defer, Decl(underscoreTest1_underscore.ts, 558, 68)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->defer : Symbol(Underscore.Static.defer, Decl(underscoreTest1_underscore.ts, 558, 68)) +>_.defer : Symbol(Underscore.Static.defer, Decl(underscoreTest1_underscore.ts, 559, 68)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>defer : Symbol(Underscore.Static.defer, Decl(underscoreTest1_underscore.ts, 559, 68)) >alert : Symbol(alert, Decl(underscoreTest1_underscoreTests.ts, 2, 14)) var updatePosition = () => alert('updating position...'); @@ -457,9 +457,9 @@ var updatePosition = () => alert('updating position...'); var throttled = _.throttle(updatePosition, 100); >throttled : Symbol(throttled, Decl(underscoreTest1_underscoreTests.ts, 114, 3)) ->_.throttle : Symbol(Underscore.Static.throttle, Decl(underscoreTest1_underscore.ts, 560, 54)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->throttle : Symbol(Underscore.Static.throttle, Decl(underscoreTest1_underscore.ts, 560, 54)) +>_.throttle : Symbol(Underscore.Static.throttle, Decl(underscoreTest1_underscore.ts, 561, 54)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>throttle : Symbol(Underscore.Static.throttle, Decl(underscoreTest1_underscore.ts, 561, 54)) >updatePosition : Symbol(updatePosition, Decl(underscoreTest1_underscoreTests.ts, 113, 3)) $(null).scroll(throttled); @@ -472,9 +472,9 @@ var calculateLayout = () => alert('calculating layout...'); var lazyLayout = _.debounce(calculateLayout, 300); >lazyLayout : Symbol(lazyLayout, Decl(underscoreTest1_underscoreTests.ts, 118, 3)) ->_.debounce : Symbol(Underscore.Static.debounce, Decl(underscoreTest1_underscore.ts, 562, 63)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->debounce : Symbol(Underscore.Static.debounce, Decl(underscoreTest1_underscore.ts, 562, 63)) +>_.debounce : Symbol(Underscore.Static.debounce, Decl(underscoreTest1_underscore.ts, 563, 63)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>debounce : Symbol(Underscore.Static.debounce, Decl(underscoreTest1_underscore.ts, 563, 63)) >calculateLayout : Symbol(calculateLayout, Decl(underscoreTest1_underscoreTests.ts, 117, 3)) $(null).resize(lazyLayout); @@ -487,9 +487,9 @@ var createApplication = () => alert('creating application...'); var initialize = _.once(createApplication); >initialize : Symbol(initialize, Decl(underscoreTest1_underscoreTests.ts, 122, 3)) ->_.once : Symbol(Underscore.Static.once, Decl(underscoreTest1_underscore.ts, 564, 84)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->once : Symbol(Underscore.Static.once, Decl(underscoreTest1_underscore.ts, 564, 84)) +>_.once : Symbol(Underscore.Static.once, Decl(underscoreTest1_underscore.ts, 565, 84)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>once : Symbol(Underscore.Static.once, Decl(underscoreTest1_underscore.ts, 565, 84)) >createApplication : Symbol(createApplication, Decl(underscoreTest1_underscoreTests.ts, 121, 3)) initialize(); @@ -507,18 +507,18 @@ var render = () => alert("rendering..."); var renderNotes = _.after(notes.length, render); >renderNotes : Symbol(renderNotes, Decl(underscoreTest1_underscoreTests.ts, 128, 3)) ->_.after : Symbol(Underscore.Static.after, Decl(underscoreTest1_underscore.ts, 566, 45)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->after : Symbol(Underscore.Static.after, Decl(underscoreTest1_underscore.ts, 566, 45)) +>_.after : Symbol(Underscore.Static.after, Decl(underscoreTest1_underscore.ts, 567, 45)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>after : Symbol(Underscore.Static.after, Decl(underscoreTest1_underscore.ts, 567, 45)) >notes.length : Symbol(Array.length, Decl(lib.d.ts, 1007, 20)) >notes : Symbol(notes, Decl(underscoreTest1_underscoreTests.ts, 126, 3)) >length : Symbol(Array.length, Decl(lib.d.ts, 1007, 20)) >render : Symbol(render, Decl(underscoreTest1_underscoreTests.ts, 127, 3)) _.each(notes, (note) => note.asyncSave({ success: renderNotes })); ->_.each : Symbol(Underscore.Static.each, Decl(underscoreTest1_underscore.ts, 394, 43), Decl(underscoreTest1_underscore.ts, 396, 77)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->each : Symbol(Underscore.Static.each, Decl(underscoreTest1_underscore.ts, 394, 43), Decl(underscoreTest1_underscore.ts, 396, 77)) +>_.each : Symbol(Underscore.Static.each, Decl(underscoreTest1_underscore.ts, 395, 43), Decl(underscoreTest1_underscore.ts, 397, 77)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>each : Symbol(Underscore.Static.each, Decl(underscoreTest1_underscore.ts, 395, 43), Decl(underscoreTest1_underscore.ts, 397, 77)) >notes : Symbol(notes, Decl(underscoreTest1_underscoreTests.ts, 126, 3)) >note : Symbol(note, Decl(underscoreTest1_underscoreTests.ts, 129, 15)) >note : Symbol(note, Decl(underscoreTest1_underscoreTests.ts, 129, 15)) @@ -532,9 +532,9 @@ var hello = function (name) { return "hello: " + name; }; hello = _.wrap(hello, (func, arg) => { return "before, " + func(arg) + ", after"; }); >hello : Symbol(hello, Decl(underscoreTest1_underscoreTests.ts, 131, 3)) ->_.wrap : Symbol(Underscore.Static.wrap, Decl(underscoreTest1_underscore.ts, 568, 61)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->wrap : Symbol(Underscore.Static.wrap, Decl(underscoreTest1_underscore.ts, 568, 61)) +>_.wrap : Symbol(Underscore.Static.wrap, Decl(underscoreTest1_underscore.ts, 569, 61)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>wrap : Symbol(Underscore.Static.wrap, Decl(underscoreTest1_underscore.ts, 569, 61)) >hello : Symbol(hello, Decl(underscoreTest1_underscoreTests.ts, 131, 3)) >func : Symbol(func, Decl(underscoreTest1_underscoreTests.ts, 132, 23)) >arg : Symbol(arg, Decl(underscoreTest1_underscoreTests.ts, 132, 28)) @@ -556,9 +556,9 @@ var exclaim = function (statement) { return statement + "!"; }; var welcome = _.compose(exclaim, greet); >welcome : Symbol(welcome, Decl(underscoreTest1_underscoreTests.ts, 137, 3)) ->_.compose : Symbol(Underscore.Static.compose, Decl(underscoreTest1_underscore.ts, 570, 88)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->compose : Symbol(Underscore.Static.compose, Decl(underscoreTest1_underscore.ts, 570, 88)) +>_.compose : Symbol(Underscore.Static.compose, Decl(underscoreTest1_underscore.ts, 571, 88)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>compose : Symbol(Underscore.Static.compose, Decl(underscoreTest1_underscore.ts, 571, 88)) >exclaim : Symbol(exclaim, Decl(underscoreTest1_underscoreTests.ts, 136, 3)) >greet : Symbol(greet, Decl(underscoreTest1_underscoreTests.ts, 135, 3)) @@ -568,62 +568,62 @@ welcome('moe'); /////////////////////////////////////////////////////////////////////////////////////// _.keys({ one: 1, two: 2, three: 3 }); ->_.keys : Symbol(Underscore.Static.keys, Decl(underscoreTest1_underscore.ts, 572, 48)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->keys : Symbol(Underscore.Static.keys, Decl(underscoreTest1_underscore.ts, 572, 48)) +>_.keys : Symbol(Underscore.Static.keys, Decl(underscoreTest1_underscore.ts, 573, 48)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>keys : Symbol(Underscore.Static.keys, Decl(underscoreTest1_underscore.ts, 573, 48)) >one : Symbol(one, Decl(underscoreTest1_underscoreTests.ts, 142, 8)) >two : Symbol(two, Decl(underscoreTest1_underscoreTests.ts, 142, 16)) >three : Symbol(three, Decl(underscoreTest1_underscoreTests.ts, 142, 24)) _.values({ one: 1, two: 2, three: 3 }); ->_.values : Symbol(Underscore.Static.values, Decl(underscoreTest1_underscore.ts, 574, 36)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->values : Symbol(Underscore.Static.values, Decl(underscoreTest1_underscore.ts, 574, 36)) +>_.values : Symbol(Underscore.Static.values, Decl(underscoreTest1_underscore.ts, 575, 36)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>values : Symbol(Underscore.Static.values, Decl(underscoreTest1_underscore.ts, 575, 36)) >one : Symbol(one, Decl(underscoreTest1_underscoreTests.ts, 143, 10)) >two : Symbol(two, Decl(underscoreTest1_underscoreTests.ts, 143, 18)) >three : Symbol(three, Decl(underscoreTest1_underscoreTests.ts, 143, 26)) _.pairs({ one: 1, two: 2, three: 3 }); ->_.pairs : Symbol(Underscore.Static.pairs, Decl(underscoreTest1_underscore.ts, 576, 35)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->pairs : Symbol(Underscore.Static.pairs, Decl(underscoreTest1_underscore.ts, 576, 35)) +>_.pairs : Symbol(Underscore.Static.pairs, Decl(underscoreTest1_underscore.ts, 577, 35)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>pairs : Symbol(Underscore.Static.pairs, Decl(underscoreTest1_underscore.ts, 577, 35)) >one : Symbol(one, Decl(underscoreTest1_underscoreTests.ts, 144, 9)) >two : Symbol(two, Decl(underscoreTest1_underscoreTests.ts, 144, 17)) >three : Symbol(three, Decl(underscoreTest1_underscoreTests.ts, 144, 25)) _.invert({ Moe: "Moses", Larry: "Louis", Curly: "Jerome" }); ->_.invert : Symbol(Underscore.Static.invert, Decl(underscoreTest1_underscore.ts, 578, 36)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->invert : Symbol(Underscore.Static.invert, Decl(underscoreTest1_underscore.ts, 578, 36)) +>_.invert : Symbol(Underscore.Static.invert, Decl(underscoreTest1_underscore.ts, 579, 36)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>invert : Symbol(Underscore.Static.invert, Decl(underscoreTest1_underscore.ts, 579, 36)) >Moe : Symbol(Moe, Decl(underscoreTest1_underscoreTests.ts, 145, 10)) >Larry : Symbol(Larry, Decl(underscoreTest1_underscoreTests.ts, 145, 24)) >Curly : Symbol(Curly, Decl(underscoreTest1_underscoreTests.ts, 145, 40)) _.functions(_); ->_.functions : Symbol(Underscore.Static.functions, Decl(underscoreTest1_underscore.ts, 580, 33)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->functions : Symbol(Underscore.Static.functions, Decl(underscoreTest1_underscore.ts, 580, 33)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) +>_.functions : Symbol(Underscore.Static.functions, Decl(underscoreTest1_underscore.ts, 581, 33)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>functions : Symbol(Underscore.Static.functions, Decl(underscoreTest1_underscore.ts, 581, 33)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) _.extend({ name: 'moe' }, { age: 50 }); ->_.extend : Symbol(Underscore.Static.extend, Decl(underscoreTest1_underscore.ts, 583, 39)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->extend : Symbol(Underscore.Static.extend, Decl(underscoreTest1_underscore.ts, 583, 39)) +>_.extend : Symbol(Underscore.Static.extend, Decl(underscoreTest1_underscore.ts, 584, 39)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>extend : Symbol(Underscore.Static.extend, Decl(underscoreTest1_underscore.ts, 584, 39)) >name : Symbol(name, Decl(underscoreTest1_underscoreTests.ts, 147, 10)) >age : Symbol(age, Decl(underscoreTest1_underscoreTests.ts, 147, 27)) _.pick({ name: 'moe', age: 50, userid: 'moe1' }, 'name', 'age'); ->_.pick : Symbol(Underscore.Static.pick, Decl(underscoreTest1_underscore.ts, 585, 56)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->pick : Symbol(Underscore.Static.pick, Decl(underscoreTest1_underscore.ts, 585, 56)) +>_.pick : Symbol(Underscore.Static.pick, Decl(underscoreTest1_underscore.ts, 586, 56)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>pick : Symbol(Underscore.Static.pick, Decl(underscoreTest1_underscore.ts, 586, 56)) >name : Symbol(name, Decl(underscoreTest1_underscoreTests.ts, 148, 8)) >age : Symbol(age, Decl(underscoreTest1_underscoreTests.ts, 148, 21)) >userid : Symbol(userid, Decl(underscoreTest1_underscoreTests.ts, 148, 30)) _.omit({ name: 'moe', age: 50, userid: 'moe1' }, 'userid'); ->_.omit : Symbol(Underscore.Static.omit, Decl(underscoreTest1_underscore.ts, 587, 49)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->omit : Symbol(Underscore.Static.omit, Decl(underscoreTest1_underscore.ts, 587, 49)) +>_.omit : Symbol(Underscore.Static.omit, Decl(underscoreTest1_underscore.ts, 588, 49)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>omit : Symbol(Underscore.Static.omit, Decl(underscoreTest1_underscore.ts, 588, 49)) >name : Symbol(name, Decl(underscoreTest1_underscoreTests.ts, 149, 8)) >age : Symbol(age, Decl(underscoreTest1_underscoreTests.ts, 149, 21)) >userid : Symbol(userid, Decl(underscoreTest1_underscoreTests.ts, 149, 30)) @@ -633,17 +633,17 @@ var iceCream = { flavor: "chocolate" }; >flavor : Symbol(flavor, Decl(underscoreTest1_underscoreTests.ts, 151, 16)) _.defaults(iceCream, { flavor: "vanilla", sprinkles: "lots" }); ->_.defaults : Symbol(Underscore.Static.defaults, Decl(underscoreTest1_underscore.ts, 589, 49)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->defaults : Symbol(Underscore.Static.defaults, Decl(underscoreTest1_underscore.ts, 589, 49)) +>_.defaults : Symbol(Underscore.Static.defaults, Decl(underscoreTest1_underscore.ts, 590, 49)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>defaults : Symbol(Underscore.Static.defaults, Decl(underscoreTest1_underscore.ts, 590, 49)) >iceCream : Symbol(iceCream, Decl(underscoreTest1_underscoreTests.ts, 151, 3)) >flavor : Symbol(flavor, Decl(underscoreTest1_underscoreTests.ts, 152, 22)) >sprinkles : Symbol(sprinkles, Decl(underscoreTest1_underscoreTests.ts, 152, 41)) _.clone({ name: 'moe' }); ->_.clone : Symbol(Underscore.Static.clone, Decl(underscoreTest1_underscore.ts, 591, 54)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->clone : Symbol(Underscore.Static.clone, Decl(underscoreTest1_underscore.ts, 591, 54)) +>_.clone : Symbol(Underscore.Static.clone, Decl(underscoreTest1_underscore.ts, 592, 54)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>clone : Symbol(Underscore.Static.clone, Decl(underscoreTest1_underscore.ts, 592, 54)) >name : Symbol(name, Decl(underscoreTest1_underscoreTests.ts, 154, 9)) _.chain([1, 2, 3, 200]) @@ -651,9 +651,9 @@ _.chain([1, 2, 3, 200]) >_.chain([1, 2, 3, 200]) .filter(function (num) { return num % 2 == 0; }) .tap(alert) .map : Symbol(Underscore.ChainedArray.map, Decl(underscoreTest1_underscore.ts, 240, 81)) >_.chain([1, 2, 3, 200]) .filter(function (num) { return num % 2 == 0; }) .tap : Symbol(Underscore.ChainedArray.tap, Decl(underscoreTest1_underscore.ts, 325, 33)) >_.chain([1, 2, 3, 200]) .filter : Symbol(Underscore.ChainedArray.filter, Decl(underscoreTest1_underscore.ts, 254, 80)) ->_.chain : Symbol(Underscore.Static.chain, Decl(underscoreTest1_underscore.ts, 390, 38), Decl(underscoreTest1_underscore.ts, 392, 45), Decl(underscoreTest1_underscore.ts, 393, 60)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->chain : Symbol(Underscore.Static.chain, Decl(underscoreTest1_underscore.ts, 390, 38), Decl(underscoreTest1_underscore.ts, 392, 45), Decl(underscoreTest1_underscore.ts, 393, 60)) +>_.chain : Symbol(Underscore.Static.chain, Decl(underscoreTest1_underscore.ts, 391, 38), Decl(underscoreTest1_underscore.ts, 393, 45), Decl(underscoreTest1_underscore.ts, 394, 60)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>chain : Symbol(Underscore.Static.chain, Decl(underscoreTest1_underscore.ts, 391, 38), Decl(underscoreTest1_underscore.ts, 393, 45), Decl(underscoreTest1_underscore.ts, 394, 60)) .filter(function (num) { return num % 2 == 0; }) >filter : Symbol(Underscore.ChainedArray.filter, Decl(underscoreTest1_underscore.ts, 254, 80)) @@ -674,9 +674,9 @@ _.chain([1, 2, 3, 200]) >value : Symbol(Underscore.ChainedObject.value, Decl(underscoreTest1_underscore.ts, 234, 46)) _.has({ a: 1, b: 2, c: 3 }, "b"); ->_.has : Symbol(Underscore.Static.has, Decl(underscoreTest1_underscore.ts, 595, 63)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->has : Symbol(Underscore.Static.has, Decl(underscoreTest1_underscore.ts, 595, 63)) +>_.has : Symbol(Underscore.Static.has, Decl(underscoreTest1_underscore.ts, 596, 63)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>has : Symbol(Underscore.Static.has, Decl(underscoreTest1_underscore.ts, 596, 63)) >a : Symbol(a, Decl(underscoreTest1_underscoreTests.ts, 162, 7)) >b : Symbol(b, Decl(underscoreTest1_underscoreTests.ts, 162, 13)) >c : Symbol(c, Decl(underscoreTest1_underscoreTests.ts, 162, 19)) @@ -696,103 +696,103 @@ moe == clone; >clone : Symbol(clone, Decl(underscoreTest1_underscoreTests.ts, 165, 3)) _.isEqual(moe, clone); ->_.isEqual : Symbol(Underscore.Static.isEqual, Decl(underscoreTest1_underscore.ts, 597, 47)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isEqual : Symbol(Underscore.Static.isEqual, Decl(underscoreTest1_underscore.ts, 597, 47)) +>_.isEqual : Symbol(Underscore.Static.isEqual, Decl(underscoreTest1_underscore.ts, 598, 47)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isEqual : Symbol(Underscore.Static.isEqual, Decl(underscoreTest1_underscore.ts, 598, 47)) >moe : Symbol(moe, Decl(underscoreTest1_underscoreTests.ts, 164, 3)) >clone : Symbol(clone, Decl(underscoreTest1_underscoreTests.ts, 165, 3)) _.isEmpty([1, 2, 3]); ->_.isEmpty : Symbol(Underscore.Static.isEmpty, Decl(underscoreTest1_underscore.ts, 599, 49)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isEmpty : Symbol(Underscore.Static.isEmpty, Decl(underscoreTest1_underscore.ts, 599, 49)) +>_.isEmpty : Symbol(Underscore.Static.isEmpty, Decl(underscoreTest1_underscore.ts, 600, 49)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isEmpty : Symbol(Underscore.Static.isEmpty, Decl(underscoreTest1_underscore.ts, 600, 49)) _.isEmpty({}); ->_.isEmpty : Symbol(Underscore.Static.isEmpty, Decl(underscoreTest1_underscore.ts, 599, 49)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isEmpty : Symbol(Underscore.Static.isEmpty, Decl(underscoreTest1_underscore.ts, 599, 49)) +>_.isEmpty : Symbol(Underscore.Static.isEmpty, Decl(underscoreTest1_underscore.ts, 600, 49)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isEmpty : Symbol(Underscore.Static.isEmpty, Decl(underscoreTest1_underscore.ts, 600, 49)) _.isElement($('body')[0]); ->_.isElement : Symbol(Underscore.Static.isElement, Decl(underscoreTest1_underscore.ts, 601, 38)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isElement : Symbol(Underscore.Static.isElement, Decl(underscoreTest1_underscore.ts, 601, 38)) +>_.isElement : Symbol(Underscore.Static.isElement, Decl(underscoreTest1_underscore.ts, 602, 38)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isElement : Symbol(Underscore.Static.isElement, Decl(underscoreTest1_underscore.ts, 602, 38)) >$ : Symbol($, Decl(underscoreTest1_underscoreTests.ts, 2, 11)) (function () { return _.isArray(arguments); })(); ->_.isArray : Symbol(Underscore.Static.isArray, Decl(underscoreTest1_underscore.ts, 602, 40)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isArray : Symbol(Underscore.Static.isArray, Decl(underscoreTest1_underscore.ts, 602, 40)) +>_.isArray : Symbol(Underscore.Static.isArray, Decl(underscoreTest1_underscore.ts, 603, 40)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isArray : Symbol(Underscore.Static.isArray, Decl(underscoreTest1_underscore.ts, 603, 40)) >arguments : Symbol(arguments) _.isArray([1, 2, 3]); ->_.isArray : Symbol(Underscore.Static.isArray, Decl(underscoreTest1_underscore.ts, 602, 40)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isArray : Symbol(Underscore.Static.isArray, Decl(underscoreTest1_underscore.ts, 602, 40)) +>_.isArray : Symbol(Underscore.Static.isArray, Decl(underscoreTest1_underscore.ts, 603, 40)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isArray : Symbol(Underscore.Static.isArray, Decl(underscoreTest1_underscore.ts, 603, 40)) _.isObject({}); ->_.isObject : Symbol(Underscore.Static.isObject, Decl(underscoreTest1_underscore.ts, 603, 38)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isObject : Symbol(Underscore.Static.isObject, Decl(underscoreTest1_underscore.ts, 603, 38)) +>_.isObject : Symbol(Underscore.Static.isObject, Decl(underscoreTest1_underscore.ts, 604, 38)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isObject : Symbol(Underscore.Static.isObject, Decl(underscoreTest1_underscore.ts, 604, 38)) _.isObject(1); ->_.isObject : Symbol(Underscore.Static.isObject, Decl(underscoreTest1_underscore.ts, 603, 38)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isObject : Symbol(Underscore.Static.isObject, Decl(underscoreTest1_underscore.ts, 603, 38)) +>_.isObject : Symbol(Underscore.Static.isObject, Decl(underscoreTest1_underscore.ts, 604, 38)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isObject : Symbol(Underscore.Static.isObject, Decl(underscoreTest1_underscore.ts, 604, 38)) // (() => { return _.isArguments(arguments); })(1, 2, 3); _.isArguments([1, 2, 3]); ->_.isArguments : Symbol(Underscore.Static.isArguments, Decl(underscoreTest1_underscore.ts, 604, 38)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isArguments : Symbol(Underscore.Static.isArguments, Decl(underscoreTest1_underscore.ts, 604, 38)) +>_.isArguments : Symbol(Underscore.Static.isArguments, Decl(underscoreTest1_underscore.ts, 605, 38)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isArguments : Symbol(Underscore.Static.isArguments, Decl(underscoreTest1_underscore.ts, 605, 38)) _.isFunction(alert); ->_.isFunction : Symbol(Underscore.Static.isFunction, Decl(underscoreTest1_underscore.ts, 605, 42)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isFunction : Symbol(Underscore.Static.isFunction, Decl(underscoreTest1_underscore.ts, 605, 42)) +>_.isFunction : Symbol(Underscore.Static.isFunction, Decl(underscoreTest1_underscore.ts, 606, 42)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isFunction : Symbol(Underscore.Static.isFunction, Decl(underscoreTest1_underscore.ts, 606, 42)) >alert : Symbol(alert, Decl(underscoreTest1_underscoreTests.ts, 2, 14)) _.isString("moe"); ->_.isString : Symbol(Underscore.Static.isString, Decl(underscoreTest1_underscore.ts, 606, 41)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isString : Symbol(Underscore.Static.isString, Decl(underscoreTest1_underscore.ts, 606, 41)) +>_.isString : Symbol(Underscore.Static.isString, Decl(underscoreTest1_underscore.ts, 607, 41)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isString : Symbol(Underscore.Static.isString, Decl(underscoreTest1_underscore.ts, 607, 41)) _.isNumber(8.4 * 5); ->_.isNumber : Symbol(Underscore.Static.isNumber, Decl(underscoreTest1_underscore.ts, 607, 39)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isNumber : Symbol(Underscore.Static.isNumber, Decl(underscoreTest1_underscore.ts, 607, 39)) +>_.isNumber : Symbol(Underscore.Static.isNumber, Decl(underscoreTest1_underscore.ts, 608, 39)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isNumber : Symbol(Underscore.Static.isNumber, Decl(underscoreTest1_underscore.ts, 608, 39)) _.isFinite(-101); ->_.isFinite : Symbol(Underscore.Static.isFinite, Decl(underscoreTest1_underscore.ts, 608, 39)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isFinite : Symbol(Underscore.Static.isFinite, Decl(underscoreTest1_underscore.ts, 608, 39)) +>_.isFinite : Symbol(Underscore.Static.isFinite, Decl(underscoreTest1_underscore.ts, 609, 39)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isFinite : Symbol(Underscore.Static.isFinite, Decl(underscoreTest1_underscore.ts, 609, 39)) _.isFinite(-Infinity); ->_.isFinite : Symbol(Underscore.Static.isFinite, Decl(underscoreTest1_underscore.ts, 608, 39)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isFinite : Symbol(Underscore.Static.isFinite, Decl(underscoreTest1_underscore.ts, 608, 39)) +>_.isFinite : Symbol(Underscore.Static.isFinite, Decl(underscoreTest1_underscore.ts, 609, 39)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isFinite : Symbol(Underscore.Static.isFinite, Decl(underscoreTest1_underscore.ts, 609, 39)) >Infinity : Symbol(Infinity, Decl(lib.d.ts, 22, 11)) _.isBoolean(null); ->_.isBoolean : Symbol(Underscore.Static.isBoolean, Decl(underscoreTest1_underscore.ts, 609, 39)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isBoolean : Symbol(Underscore.Static.isBoolean, Decl(underscoreTest1_underscore.ts, 609, 39)) +>_.isBoolean : Symbol(Underscore.Static.isBoolean, Decl(underscoreTest1_underscore.ts, 610, 39)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isBoolean : Symbol(Underscore.Static.isBoolean, Decl(underscoreTest1_underscore.ts, 610, 39)) _.isDate(new Date()); ->_.isDate : Symbol(Underscore.Static.isDate, Decl(underscoreTest1_underscore.ts, 610, 40)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isDate : Symbol(Underscore.Static.isDate, Decl(underscoreTest1_underscore.ts, 610, 40)) +>_.isDate : Symbol(Underscore.Static.isDate, Decl(underscoreTest1_underscore.ts, 611, 40)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isDate : Symbol(Underscore.Static.isDate, Decl(underscoreTest1_underscore.ts, 611, 40)) >Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11)) _.isRegExp(/moe/); ->_.isRegExp : Symbol(Underscore.Static.isRegExp, Decl(underscoreTest1_underscore.ts, 611, 37)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isRegExp : Symbol(Underscore.Static.isRegExp, Decl(underscoreTest1_underscore.ts, 611, 37)) +>_.isRegExp : Symbol(Underscore.Static.isRegExp, Decl(underscoreTest1_underscore.ts, 612, 37)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isRegExp : Symbol(Underscore.Static.isRegExp, Decl(underscoreTest1_underscore.ts, 612, 37)) _.isNaN(NaN); ->_.isNaN : Symbol(Underscore.Static.isNaN, Decl(underscoreTest1_underscore.ts, 612, 39)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isNaN : Symbol(Underscore.Static.isNaN, Decl(underscoreTest1_underscore.ts, 612, 39)) +>_.isNaN : Symbol(Underscore.Static.isNaN, Decl(underscoreTest1_underscore.ts, 613, 39)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isNaN : Symbol(Underscore.Static.isNaN, Decl(underscoreTest1_underscore.ts, 613, 39)) >NaN : Symbol(NaN, Decl(lib.d.ts, 21, 11)) isNaN(undefined); @@ -800,34 +800,34 @@ isNaN(undefined); >undefined : Symbol(undefined) _.isNaN(undefined); ->_.isNaN : Symbol(Underscore.Static.isNaN, Decl(underscoreTest1_underscore.ts, 612, 39)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isNaN : Symbol(Underscore.Static.isNaN, Decl(underscoreTest1_underscore.ts, 612, 39)) +>_.isNaN : Symbol(Underscore.Static.isNaN, Decl(underscoreTest1_underscore.ts, 613, 39)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isNaN : Symbol(Underscore.Static.isNaN, Decl(underscoreTest1_underscore.ts, 613, 39)) >undefined : Symbol(undefined) _.isNull(null); ->_.isNull : Symbol(Underscore.Static.isNull, Decl(underscoreTest1_underscore.ts, 613, 36)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isNull : Symbol(Underscore.Static.isNull, Decl(underscoreTest1_underscore.ts, 613, 36)) +>_.isNull : Symbol(Underscore.Static.isNull, Decl(underscoreTest1_underscore.ts, 614, 36)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isNull : Symbol(Underscore.Static.isNull, Decl(underscoreTest1_underscore.ts, 614, 36)) _.isNull(undefined); ->_.isNull : Symbol(Underscore.Static.isNull, Decl(underscoreTest1_underscore.ts, 613, 36)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isNull : Symbol(Underscore.Static.isNull, Decl(underscoreTest1_underscore.ts, 613, 36)) +>_.isNull : Symbol(Underscore.Static.isNull, Decl(underscoreTest1_underscore.ts, 614, 36)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isNull : Symbol(Underscore.Static.isNull, Decl(underscoreTest1_underscore.ts, 614, 36)) >undefined : Symbol(undefined) _.isUndefined((null).missingVariable); ->_.isUndefined : Symbol(Underscore.Static.isUndefined, Decl(underscoreTest1_underscore.ts, 614, 37)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->isUndefined : Symbol(Underscore.Static.isUndefined, Decl(underscoreTest1_underscore.ts, 614, 37)) +>_.isUndefined : Symbol(Underscore.Static.isUndefined, Decl(underscoreTest1_underscore.ts, 615, 37)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>isUndefined : Symbol(Underscore.Static.isUndefined, Decl(underscoreTest1_underscore.ts, 615, 37)) /////////////////////////////////////////////////////////////////////////////////////// var underscore = _.noConflict(); >underscore : Symbol(underscore, Decl(underscoreTest1_underscoreTests.ts, 211, 3)) ->_.noConflict : Symbol(Underscore.Static.noConflict, Decl(underscoreTest1_underscore.ts, 615, 41)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->noConflict : Symbol(Underscore.Static.noConflict, Decl(underscoreTest1_underscore.ts, 615, 41)) +>_.noConflict : Symbol(Underscore.Static.noConflict, Decl(underscoreTest1_underscore.ts, 616, 41)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>noConflict : Symbol(Underscore.Static.noConflict, Decl(underscoreTest1_underscore.ts, 616, 41)) var moe2 = { name: 'moe' }; >moe2 : Symbol(moe2, Decl(underscoreTest1_underscoreTests.ts, 213, 3)) @@ -835,31 +835,31 @@ var moe2 = { name: 'moe' }; moe2 === _.identity(moe); >moe2 : Symbol(moe2, Decl(underscoreTest1_underscoreTests.ts, 213, 3)) ->_.identity : Symbol(Underscore.Static.identity, Decl(underscoreTest1_underscore.ts, 617, 29)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->identity : Symbol(Underscore.Static.identity, Decl(underscoreTest1_underscore.ts, 617, 29)) +>_.identity : Symbol(Underscore.Static.identity, Decl(underscoreTest1_underscore.ts, 618, 29)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>identity : Symbol(Underscore.Static.identity, Decl(underscoreTest1_underscore.ts, 618, 29)) >moe : Symbol(moe, Decl(underscoreTest1_underscoreTests.ts, 164, 3)) var genie; >genie : Symbol(genie, Decl(underscoreTest1_underscoreTests.ts, 216, 3)) _.times(3, function (n) { genie.grantWishNumber(n); }); ->_.times : Symbol(Underscore.Static.times, Decl(underscoreTest1_underscore.ts, 619, 33)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->times : Symbol(Underscore.Static.times, Decl(underscoreTest1_underscore.ts, 619, 33)) +>_.times : Symbol(Underscore.Static.times, Decl(underscoreTest1_underscore.ts, 620, 33)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>times : Symbol(Underscore.Static.times, Decl(underscoreTest1_underscore.ts, 620, 33)) >n : Symbol(n, Decl(underscoreTest1_underscoreTests.ts, 218, 21)) >genie : Symbol(genie, Decl(underscoreTest1_underscoreTests.ts, 216, 3)) >n : Symbol(n, Decl(underscoreTest1_underscoreTests.ts, 218, 21)) _.random(0, 100); ->_.random : Symbol(Underscore.Static.random, Decl(underscoreTest1_underscore.ts, 621, 79), Decl(underscoreTest1_underscore.ts, 623, 36)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->random : Symbol(Underscore.Static.random, Decl(underscoreTest1_underscore.ts, 621, 79), Decl(underscoreTest1_underscore.ts, 623, 36)) +>_.random : Symbol(Underscore.Static.random, Decl(underscoreTest1_underscore.ts, 622, 79), Decl(underscoreTest1_underscore.ts, 624, 36)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>random : Symbol(Underscore.Static.random, Decl(underscoreTest1_underscore.ts, 622, 79), Decl(underscoreTest1_underscore.ts, 624, 36)) _.mixin({ ->_.mixin : Symbol(Underscore.Static.mixin, Decl(underscoreTest1_underscore.ts, 624, 49)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->mixin : Symbol(Underscore.Static.mixin, Decl(underscoreTest1_underscore.ts, 624, 49)) +>_.mixin : Symbol(Underscore.Static.mixin, Decl(underscoreTest1_underscore.ts, 625, 49)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>mixin : Symbol(Underscore.Static.mixin, Decl(underscoreTest1_underscore.ts, 625, 49)) capitalize: function (string) { >capitalize : Symbol(capitalize, Decl(underscoreTest1_underscoreTests.ts, 222, 9)) @@ -871,17 +871,17 @@ _.mixin({ } }); (_("fabio")).capitalize(); ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) _.uniqueId('contact_'); ->_.uniqueId : Symbol(Underscore.Static.uniqueId, Decl(underscoreTest1_underscore.ts, 626, 33), Decl(underscoreTest1_underscore.ts, 628, 27)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->uniqueId : Symbol(Underscore.Static.uniqueId, Decl(underscoreTest1_underscore.ts, 626, 33), Decl(underscoreTest1_underscore.ts, 628, 27)) +>_.uniqueId : Symbol(Underscore.Static.uniqueId, Decl(underscoreTest1_underscore.ts, 627, 33), Decl(underscoreTest1_underscore.ts, 629, 27)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>uniqueId : Symbol(Underscore.Static.uniqueId, Decl(underscoreTest1_underscore.ts, 627, 33), Decl(underscoreTest1_underscore.ts, 629, 27)) _.escape('Curly, Larry & Moe'); ->_.escape : Symbol(Underscore.Static.escape, Decl(underscoreTest1_underscore.ts, 629, 41)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->escape : Symbol(Underscore.Static.escape, Decl(underscoreTest1_underscore.ts, 629, 41)) +>_.escape : Symbol(Underscore.Static.escape, Decl(underscoreTest1_underscore.ts, 630, 41)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>escape : Symbol(Underscore.Static.escape, Decl(underscoreTest1_underscore.ts, 630, 41)) var object = { cheese: 'crumpets', stuff: function () { return 'nonsense'; } }; >object : Symbol(object, Decl(underscoreTest1_underscoreTests.ts, 233, 3)) @@ -889,22 +889,22 @@ var object = { cheese: 'crumpets', stuff: function () { return 'nonsense'; } }; >stuff : Symbol(stuff, Decl(underscoreTest1_underscoreTests.ts, 233, 34)) _.result(object, 'cheese'); ->_.result : Symbol(Underscore.Static.result, Decl(underscoreTest1_underscore.ts, 633, 36)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->result : Symbol(Underscore.Static.result, Decl(underscoreTest1_underscore.ts, 633, 36)) +>_.result : Symbol(Underscore.Static.result, Decl(underscoreTest1_underscore.ts, 634, 36)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>result : Symbol(Underscore.Static.result, Decl(underscoreTest1_underscore.ts, 634, 36)) >object : Symbol(object, Decl(underscoreTest1_underscoreTests.ts, 233, 3)) _.result(object, 'stuff'); ->_.result : Symbol(Underscore.Static.result, Decl(underscoreTest1_underscore.ts, 633, 36)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->result : Symbol(Underscore.Static.result, Decl(underscoreTest1_underscore.ts, 633, 36)) +>_.result : Symbol(Underscore.Static.result, Decl(underscoreTest1_underscore.ts, 634, 36)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>result : Symbol(Underscore.Static.result, Decl(underscoreTest1_underscore.ts, 634, 36)) >object : Symbol(object, Decl(underscoreTest1_underscoreTests.ts, 233, 3)) var compiled = _.template("hello: <%= name %>"); >compiled : Symbol(compiled, Decl(underscoreTest1_underscoreTests.ts, 238, 3)) ->_.template : Symbol(Underscore.Static.template, Decl(underscoreTest1_underscore.ts, 637, 43), Decl(underscoreTest1_underscore.ts, 639, 64)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->template : Symbol(Underscore.Static.template, Decl(underscoreTest1_underscore.ts, 637, 43), Decl(underscoreTest1_underscore.ts, 639, 64)) +>_.template : Symbol(Underscore.Static.template, Decl(underscoreTest1_underscore.ts, 638, 43), Decl(underscoreTest1_underscore.ts, 640, 64)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>template : Symbol(Underscore.Static.template, Decl(underscoreTest1_underscore.ts, 638, 43), Decl(underscoreTest1_underscore.ts, 640, 64)) compiled({ name: 'moe' }); >compiled : Symbol(compiled, Decl(underscoreTest1_underscoreTests.ts, 238, 3)) @@ -914,17 +914,17 @@ var list2 = "<% _.each(people, function(name) { %>
  • <%= name %>
  • <% }); % >list2 : Symbol(list2, Decl(underscoreTest1_underscoreTests.ts, 240, 3)) _.template(list2, { people: ['moe', 'curly', 'larry'] }); ->_.template : Symbol(Underscore.Static.template, Decl(underscoreTest1_underscore.ts, 637, 43), Decl(underscoreTest1_underscore.ts, 639, 64)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->template : Symbol(Underscore.Static.template, Decl(underscoreTest1_underscore.ts, 637, 43), Decl(underscoreTest1_underscore.ts, 639, 64)) +>_.template : Symbol(Underscore.Static.template, Decl(underscoreTest1_underscore.ts, 638, 43), Decl(underscoreTest1_underscore.ts, 640, 64)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>template : Symbol(Underscore.Static.template, Decl(underscoreTest1_underscore.ts, 638, 43), Decl(underscoreTest1_underscore.ts, 640, 64)) >list2 : Symbol(list2, Decl(underscoreTest1_underscoreTests.ts, 240, 3)) >people : Symbol(people, Decl(underscoreTest1_underscoreTests.ts, 241, 19)) var template = _.template("<%- value %>"); >template : Symbol(template, Decl(underscoreTest1_underscoreTests.ts, 242, 3)) ->_.template : Symbol(Underscore.Static.template, Decl(underscoreTest1_underscore.ts, 637, 43), Decl(underscoreTest1_underscore.ts, 639, 64)) ->_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 644, 11)) ->template : Symbol(Underscore.Static.template, Decl(underscoreTest1_underscore.ts, 637, 43), Decl(underscoreTest1_underscore.ts, 639, 64)) +>_.template : Symbol(Underscore.Static.template, Decl(underscoreTest1_underscore.ts, 638, 43), Decl(underscoreTest1_underscore.ts, 640, 64)) +>_ : Symbol(_, Decl(underscoreTest1_underscore.ts, 645, 11)) +>template : Symbol(Underscore.Static.template, Decl(underscoreTest1_underscore.ts, 638, 43), Decl(underscoreTest1_underscore.ts, 640, 64)) template({ value: '