From 57546393ff0a3d1e643870bf835119f37d07bdb3 Mon Sep 17 00:00:00 2001 From: ispedals Date: Sun, 28 Oct 2018 12:38:16 -0400 Subject: [PATCH 01/22] Support synthesized SourceFile parent in getOrCreateEmitNode (#24709) getOrCreateEmitNode() assumes that the SourceFile of node that is part of a parse tree will also be a parse tree node. This assumption is not valid for a transformed SourceFile. disposeEmitNodes() already handles this case by getting the original SourceFile node if the provided node is synthesized, so do the same in getOrCreateEmitNode(). This results in the test case in #24709 to run without error. --- src/compiler/factory.ts | 2 +- src/testRunner/unittests/transform.ts | 40 +++++++++++++++++++ .../transformsCorrectly.issue24709.js | 6 +++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/transformApi/transformsCorrectly.issue24709.js diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 01de5850471..a5e38943072 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -2819,7 +2819,7 @@ namespace ts { return node.emitNode = { annotatedNodes: [node] } as EmitNode; } - const sourceFile = getSourceFileOfNode(node); + const sourceFile = getSourceFileOfNode(getParseTreeNode(getSourceFileOfNode(node))); getOrCreateEmitNode(sourceFile).annotatedNodes!.push(node); } diff --git a/src/testRunner/unittests/transform.ts b/src/testRunner/unittests/transform.ts index f219fb6c683..2fc4d117e99 100644 --- a/src/testRunner/unittests/transform.ts +++ b/src/testRunner/unittests/transform.ts @@ -400,6 +400,46 @@ namespace Foo { } }).outputText; }); + + // https://github.com/Microsoft/TypeScript/issues/24709 + testBaseline("issue24709", () => { + const fs = vfs.createFromFileSystem(Harness.IO, /*caseSensitive*/ true); + const transformed = transform(createSourceFile("source.ts", "class X { echo(x: string) { return x; } }", ScriptTarget.ES3), [transformSourceFile]); + const transformedSourceFile = transformed.transformed[0]; + transformed.dispose(); + const host = new fakes.CompilerHost(fs); + host.getSourceFile = () => transformedSourceFile; + const program = createProgram(["source.ts"], { + target: ScriptTarget.ES3, + module: ModuleKind.None, + noLib: true + }, host); + program.emit(transformedSourceFile, (_p, s, b) => host.writeFile("source.js", s, b)); + return host.readFile("source.js")!.toString(); + + function transformSourceFile(context: TransformationContext) { + const visitor: Visitor = (node) => { + if (isMethodDeclaration(node)) { + return updateMethod( + node, + node.decorators, + node.modifiers, + node.asteriskToken, + createIdentifier("foobar"), + node.questionToken, + node.typeParameters, + node.parameters, + node.type, + node.body, + ); + } + return visitEachChild(node, visitor, context); + }; + return (node: SourceFile) => visitNode(node, visitor); + } + + }); + }); } diff --git a/tests/baselines/reference/transformApi/transformsCorrectly.issue24709.js b/tests/baselines/reference/transformApi/transformsCorrectly.issue24709.js new file mode 100644 index 00000000000..9d1d48ca96d --- /dev/null +++ b/tests/baselines/reference/transformApi/transformsCorrectly.issue24709.js @@ -0,0 +1,6 @@ +var X = /** @class */ (function () { + function X() { + } + X.prototype.foobar = function (x) { return x; }; + return X; +}()); From 1397fed2ad5befcbb19d22580ffa739f633df10e Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Tue, 30 Oct 2018 21:31:22 +0100 Subject: [PATCH 02/22] Only suggest adding to types if present in compilerOptions Fixes: https://github.com/Microsoft/TypeScript/pull/28211#issuecomment-434438407 --- src/compiler/checker.ts | 12 +++++-- src/compiler/diagnosticMessages.json | 18 ++++++++-- .../reference/anonymousModules.errors.txt | 12 +++---- ...onflictingCommonJSES2015Exports.errors.txt | 4 +-- ...torWithIncompleteTypeAnnotation.errors.txt | 4 +-- .../didYouMeanSuggestionErrors.errors.txt | 36 +++++++++---------- .../exportAsNamespace_augment.errors.txt | 2 +- .../reference/externModule.errors.txt | 4 +-- .../reference/fixSignatureCaching.errors.txt | 12 +++---- .../reference/innerModExport1.errors.txt | 4 +-- .../reference/innerModExport2.errors.txt | 4 +-- .../reference/jsxAndTypeAssertion.errors.txt | 4 +-- .../reference/metadataImportType.errors.txt | 4 +-- .../reference/moduleExports1.errors.txt | 8 ++--- .../moduleKeywordRepeatError.errors.txt | 4 +-- .../noAssertForUnparseableTypedefs.errors.txt | 4 +-- ...adingStaticFunctionsInFunctions.errors.txt | 12 +++---- .../reference/parser509534.errors.txt | 8 ++--- .../reference/parser509693.errors.txt | 8 ++--- .../reference/parser519458.errors.txt | 4 +-- .../reference/parser521128.errors.txt | 4 +-- .../parserCommaInTypeMemberList2.errors.txt | 4 +-- .../reference/parserharness.errors.txt | 8 ++--- .../reference/reservedWords2.errors.txt | 8 ++--- .../reference/staticsInAFunction.errors.txt | 12 +++---- .../templateStringInModuleName.errors.txt | 8 ++--- .../templateStringInModuleNameES6.errors.txt | 8 ++--- .../reference/typecheckIfCondition.errors.txt | 8 ++--- .../reference/typingsSuggestion1.errors.txt | 11 ++++++ .../baselines/reference/typingsSuggestion1.js | 6 ++++ .../reference/typingsSuggestion1.symbols | 4 +++ .../reference/typingsSuggestion1.types | 8 +++++ .../reference/typingsSuggestion2.errors.txt | 11 ++++++ .../baselines/reference/typingsSuggestion2.js | 6 ++++ .../reference/typingsSuggestion2.symbols | 4 +++ .../reference/typingsSuggestion2.types | 8 +++++ .../conformance/typings/typingsSuggestion1.ts | 5 +++ .../conformance/typings/typingsSuggestion2.ts | 5 +++ 38 files changed, 191 insertions(+), 105 deletions(-) create mode 100644 tests/baselines/reference/typingsSuggestion1.errors.txt create mode 100644 tests/baselines/reference/typingsSuggestion1.js create mode 100644 tests/baselines/reference/typingsSuggestion1.symbols create mode 100644 tests/baselines/reference/typingsSuggestion1.types create mode 100644 tests/baselines/reference/typingsSuggestion2.errors.txt create mode 100644 tests/baselines/reference/typingsSuggestion2.js create mode 100644 tests/baselines/reference/typingsSuggestion2.symbols create mode 100644 tests/baselines/reference/typingsSuggestion2.types create mode 100644 tests/cases/conformance/typings/typingsSuggestion1.ts create mode 100644 tests/cases/conformance/typings/typingsSuggestion2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f23e26f51fc..ec241d75775 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14172,17 +14172,23 @@ namespace ts { case "console": return Diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_include_dom; case "$": - return Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig; + return compilerOptions.types + ? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig + : Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_types_Slashjquery; case "describe": case "suite": case "it": case "test": - return Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_types_Slashjest_or_npm_i_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig; + return compilerOptions.types + ? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_types_Slashjest_or_npm_i_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig + : Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_types_Slashjest_or_npm_i_types_Slashmocha; case "process": case "require": case "Buffer": case "module": - return Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig; + return compilerOptions.types + ? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig + : Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_types_Slashnode; case "Map": case "Set": case "Promise": diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 1f1ee7a6948..e793e8846f4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2088,15 +2088,15 @@ "category": "Error", "code": 2577 }, - "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.": { + "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i @types/node`.": { "category": "Error", "code": 2580 }, - "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i @types/jquery` and then add `jquery` to the types field in your tsconfig.": { + "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i @types/jquery`.": { "category": "Error", "code": 2581 }, - "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.": { + "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.": { "category": "Error", "code": 2582 }, @@ -2120,6 +2120,18 @@ "category": "Error", "code": 2587 }, + "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.": { + "category": "Error", + "code": 2588 + }, + "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i @types/jquery` and then add `jquery` to the types field in your tsconfig.": { + "category": "Error", + "code": 2589 + }, + "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.": { + "category": "Error", + "code": 2590 + }, "JSX element attributes type '{0}' may not be a union type.": { "category": "Error", "code": 2600 diff --git a/tests/baselines/reference/anonymousModules.errors.txt b/tests/baselines/reference/anonymousModules.errors.txt index 24468352d03..b81513cfbbd 100644 --- a/tests/baselines/reference/anonymousModules.errors.txt +++ b/tests/baselines/reference/anonymousModules.errors.txt @@ -1,22 +1,22 @@ -tests/cases/compiler/anonymousModules.ts(1,1): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/compiler/anonymousModules.ts(1,1): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/compiler/anonymousModules.ts(1,8): error TS1005: ';' expected. -tests/cases/compiler/anonymousModules.ts(4,2): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/compiler/anonymousModules.ts(4,2): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/compiler/anonymousModules.ts(4,9): error TS1005: ';' expected. -tests/cases/compiler/anonymousModules.ts(10,2): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/compiler/anonymousModules.ts(10,2): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/compiler/anonymousModules.ts(10,9): error TS1005: ';' expected. ==== tests/cases/compiler/anonymousModules.ts (6 errors) ==== module { ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ~ !!! error TS1005: ';' expected. export var foo = 1; module { ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ~ !!! error TS1005: ';' expected. export var bar = 1; @@ -26,7 +26,7 @@ tests/cases/compiler/anonymousModules.ts(10,9): error TS1005: ';' expected. module { ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ~ !!! error TS1005: ';' expected. var x = bar; diff --git a/tests/baselines/reference/conflictingCommonJSES2015Exports.errors.txt b/tests/baselines/reference/conflictingCommonJSES2015Exports.errors.txt index 717ed95a505..2f47712c9db 100644 --- a/tests/baselines/reference/conflictingCommonJSES2015Exports.errors.txt +++ b/tests/baselines/reference/conflictingCommonJSES2015Exports.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/salsa/bug24934.js(2,1): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/conformance/salsa/bug24934.js(2,1): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ==== tests/cases/conformance/salsa/bug24934.js (1 errors) ==== export function abc(a, b, c) { return 5; } module.exports = { abc }; ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ==== tests/cases/conformance/salsa/use.js (0 errors) ==== import { abc } from './bug24934'; abc(1, 2, 3); diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt index d683899f41d..1b0034a3063 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(11,13): error TS2503: Cannot find namespace 'module'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(11,13): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(11,13): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(11,19): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(22,35): error TS1005: ')' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(22,39): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. @@ -105,7 +105,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(261,1): error TS ~~~~~~ !!! error TS2503: Cannot find namespace 'module'. ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ~ !!! error TS1005: ';' expected. diff --git a/tests/baselines/reference/didYouMeanSuggestionErrors.errors.txt b/tests/baselines/reference/didYouMeanSuggestionErrors.errors.txt index 9bf043562d9..a41b19ecd9d 100644 --- a/tests/baselines/reference/didYouMeanSuggestionErrors.errors.txt +++ b/tests/baselines/reference/didYouMeanSuggestionErrors.errors.txt @@ -1,14 +1,14 @@ -tests/cases/compiler/didYouMeanSuggestionErrors.ts(1,1): error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. -tests/cases/compiler/didYouMeanSuggestionErrors.ts(2,5): error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. -tests/cases/compiler/didYouMeanSuggestionErrors.ts(3,19): error TS2581: Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i @types/jquery` and then add `jquery` to the types field in your tsconfig. -tests/cases/compiler/didYouMeanSuggestionErrors.ts(7,1): error TS2582: Cannot find name 'suite'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. -tests/cases/compiler/didYouMeanSuggestionErrors.ts(8,5): error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. +tests/cases/compiler/didYouMeanSuggestionErrors.ts(1,1): error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. +tests/cases/compiler/didYouMeanSuggestionErrors.ts(2,5): error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. +tests/cases/compiler/didYouMeanSuggestionErrors.ts(3,19): error TS2581: Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i @types/jquery`. +tests/cases/compiler/didYouMeanSuggestionErrors.ts(7,1): error TS2582: Cannot find name 'suite'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. +tests/cases/compiler/didYouMeanSuggestionErrors.ts(8,5): error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. tests/cases/compiler/didYouMeanSuggestionErrors.ts(9,9): error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the `lib` compiler option to include 'dom'. -tests/cases/compiler/didYouMeanSuggestionErrors.ts(9,21): error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/compiler/didYouMeanSuggestionErrors.ts(9,21): error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/compiler/didYouMeanSuggestionErrors.ts(10,9): error TS2584: Cannot find name 'document'. Do you need to change your target library? Try changing the `lib` compiler option to include 'dom'. -tests/cases/compiler/didYouMeanSuggestionErrors.ts(12,19): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. -tests/cases/compiler/didYouMeanSuggestionErrors.ts(13,19): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. -tests/cases/compiler/didYouMeanSuggestionErrors.ts(14,19): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/compiler/didYouMeanSuggestionErrors.ts(12,19): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node`. +tests/cases/compiler/didYouMeanSuggestionErrors.ts(13,19): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node`. +tests/cases/compiler/didYouMeanSuggestionErrors.ts(14,19): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/compiler/didYouMeanSuggestionErrors.ts(16,23): error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later. tests/cases/compiler/didYouMeanSuggestionErrors.ts(17,23): error TS2583: Cannot find name 'Set'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later. tests/cases/compiler/didYouMeanSuggestionErrors.ts(18,23): error TS2583: Cannot find name 'WeakMap'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later. @@ -22,40 +22,40 @@ tests/cases/compiler/didYouMeanSuggestionErrors.ts(24,18): error TS2583: Cannot ==== tests/cases/compiler/didYouMeanSuggestionErrors.ts (19 errors) ==== describe("my test suite", () => { ~~~~~~~~ -!!! error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. +!!! error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. it("should run", () => { ~~ -!!! error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. +!!! error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. const a = $(".thing"); ~ -!!! error TS2581: Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i @types/jquery` and then add `jquery` to the types field in your tsconfig. +!!! error TS2581: Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i @types/jquery`. }); }); suite("another suite", () => { ~~~~~ -!!! error TS2582: Cannot find name 'suite'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. +!!! error TS2582: Cannot find name 'suite'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. test("everything else", () => { ~~~~ -!!! error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. +!!! error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. console.log(process.env); ~~~~~~~ !!! error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the `lib` compiler option to include 'dom'. ~~~~~~~ -!!! error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i @types/node`. document.createElement("div"); ~~~~~~~~ !!! error TS2584: Cannot find name 'document'. Do you need to change your target library? Try changing the `lib` compiler option to include 'dom'. const x = require("fs"); ~~~~~~~ -!!! error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node`. const y = Buffer.from([]); ~~~~~~ -!!! error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node`. const z = module.exports; ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. const a = new Map(); ~~~ diff --git a/tests/baselines/reference/exportAsNamespace_augment.errors.txt b/tests/baselines/reference/exportAsNamespace_augment.errors.txt index 76cb643d62a..ba1b4d80c6d 100644 --- a/tests/baselines/reference/exportAsNamespace_augment.errors.txt +++ b/tests/baselines/reference/exportAsNamespace_augment.errors.txt @@ -14,7 +14,7 @@ ~~~~~~~~ !!! error TS2451: Cannot redeclare block-scoped variable 'conflict'. !!! related TS6203 /b.ts:6:22: 'conflict' was also declared here. -!!! related TS6204 /b.ts:6:22: and here. +!!! related TS6204 /b.ts:12:18: and here. ==== /b.ts (6 errors) ==== import * as a2 from "./a"; diff --git a/tests/baselines/reference/externModule.errors.txt b/tests/baselines/reference/externModule.errors.txt index 377fe025cc6..e1077550985 100644 --- a/tests/baselines/reference/externModule.errors.txt +++ b/tests/baselines/reference/externModule.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/externModule.ts(1,1): error TS2304: Cannot find name 'declare'. tests/cases/compiler/externModule.ts(1,9): error TS1005: ';' expected. -tests/cases/compiler/externModule.ts(1,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/compiler/externModule.ts(1,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/compiler/externModule.ts(1,16): error TS1005: ';' expected. tests/cases/compiler/externModule.ts(3,10): error TS2391: Function implementation is missing or not immediately following the declaration. tests/cases/compiler/externModule.ts(4,10): error TS2391: Function implementation is missing or not immediately following the declaration. @@ -21,7 +21,7 @@ tests/cases/compiler/externModule.ts(37,3): error TS2552: Cannot find name 'XDat ~~~~~~ !!! error TS1005: ';' expected. ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ~ !!! error TS1005: ';' expected. export class XDate { diff --git a/tests/baselines/reference/fixSignatureCaching.errors.txt b/tests/baselines/reference/fixSignatureCaching.errors.txt index ad992cae7db..bf4400313b2 100644 --- a/tests/baselines/reference/fixSignatureCaching.errors.txt +++ b/tests/baselines/reference/fixSignatureCaching.errors.txt @@ -50,9 +50,9 @@ tests/cases/conformance/fixSignatureCaching.ts(915,36): error TS2339: Property ' tests/cases/conformance/fixSignatureCaching.ts(915,53): error TS2339: Property 'mobileDetectRules' does not exist on type '{}'. tests/cases/conformance/fixSignatureCaching.ts(955,42): error TS2339: Property 'mobileGrade' does not exist on type '{}'. tests/cases/conformance/fixSignatureCaching.ts(964,57): error TS2339: Property 'getDeviceSmallerSide' does not exist on type '{}'. -tests/cases/conformance/fixSignatureCaching.ts(978,16): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. -tests/cases/conformance/fixSignatureCaching.ts(978,42): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. -tests/cases/conformance/fixSignatureCaching.ts(979,37): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/conformance/fixSignatureCaching.ts(978,16): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. +tests/cases/conformance/fixSignatureCaching.ts(978,42): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. +tests/cases/conformance/fixSignatureCaching.ts(979,37): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/conformance/fixSignatureCaching.ts(980,23): error TS2304: Cannot find name 'define'. tests/cases/conformance/fixSignatureCaching.ts(980,48): error TS2304: Cannot find name 'define'. tests/cases/conformance/fixSignatureCaching.ts(981,16): error TS2304: Cannot find name 'define'. @@ -1143,12 +1143,12 @@ tests/cases/conformance/fixSignatureCaching.ts(983,44): error TS2339: Property ' })((function (undefined) { if (typeof module !== 'undefined' && module.exports) { ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. return function (factory) { module.exports = factory(); }; ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. } else if (typeof define === 'function' && define.amd) { ~~~~~~ !!! error TS2304: Cannot find name 'define'. diff --git a/tests/baselines/reference/innerModExport1.errors.txt b/tests/baselines/reference/innerModExport1.errors.txt index 1278afcb4d3..29ce225dfa2 100644 --- a/tests/baselines/reference/innerModExport1.errors.txt +++ b/tests/baselines/reference/innerModExport1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/innerModExport1.ts(5,5): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/compiler/innerModExport1.ts(5,5): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/compiler/innerModExport1.ts(5,12): error TS1005: ';' expected. @@ -9,7 +9,7 @@ tests/cases/compiler/innerModExport1.ts(5,12): error TS1005: ';' expected. var non_export_var: number; module { ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ~ !!! error TS1005: ';' expected. var non_export_var = 0; diff --git a/tests/baselines/reference/innerModExport2.errors.txt b/tests/baselines/reference/innerModExport2.errors.txt index ffd136f1a65..21cc583c5d3 100644 --- a/tests/baselines/reference/innerModExport2.errors.txt +++ b/tests/baselines/reference/innerModExport2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/innerModExport2.ts(5,5): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/compiler/innerModExport2.ts(5,5): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. 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. @@ -12,7 +12,7 @@ tests/cases/compiler/innerModExport2.ts(20,7): error TS2339: Property 'NonExport var non_export_var: number; module { ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ~ !!! error TS1005: ';' expected. var non_export_var = 0; diff --git a/tests/baselines/reference/jsxAndTypeAssertion.errors.txt b/tests/baselines/reference/jsxAndTypeAssertion.errors.txt index c67e9c70dfd..6d3f6874a88 100644 --- a/tests/baselines/reference/jsxAndTypeAssertion.errors.txt +++ b/tests/baselines/reference/jsxAndTypeAssertion.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(6,6): error TS17008: JSX element 'any' has no corresponding closing tag. -tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(6,13): error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. +tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(6,13): error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(6,17): error TS1005: '}' expected. tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(8,6): error TS17008: JSX element 'any' has no corresponding closing tag. tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(10,6): error TS17008: JSX element 'foo' has no corresponding closing tag. @@ -24,7 +24,7 @@ tests/cases/conformance/jsx/jsxAndTypeAssertion.tsx(21,1): error TS1005: '({ workItem: this._workItem }, {}); ~ -!!! error TS2581: Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i @types/jquery` and then add `jquery` to the types field in your tsconfig. +!!! error TS2581: Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i @types/jquery`. \ No newline at end of file diff --git a/tests/baselines/reference/parserharness.errors.txt b/tests/baselines/reference/parserharness.errors.txt index 568eb370e0d..990fa5816c7 100644 --- a/tests/baselines/reference/parserharness.errors.txt +++ b/tests/baselines/reference/parserharness.errors.txt @@ -5,8 +5,8 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(19,21): er tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(21,29): error TS2694: Namespace 'Harness' has no exported member 'Assert'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(25,17): error TS2304: Cannot find name 'IIO'. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(41,12): error TS2304: Cannot find name 'ActiveXObject'. -tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(43,19): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. -tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(44,14): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(43,19): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node`. +tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(44,14): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(341,13): error TS2662: Cannot find name 'errorHandlerStack'. Did you mean the static member 'Runnable.errorHandlerStack'? tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(347,13): error TS2662: Cannot find name 'errorHandlerStack'. Did you mean the static member 'Runnable.errorHandlerStack'? tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(351,17): error TS2662: Cannot find name 'errorHandlerStack'. Did you mean the static member 'Runnable.errorHandlerStack'? @@ -169,10 +169,10 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): eval(typescriptServiceFile); } else if (typeof require === "function") { ~~~~~~~ -!!! error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node`. var vm = require('vm'); ~~~~~~~ -!!! error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node`. vm.runInThisContext(typescriptServiceFile, 'typescriptServices.js'); } else { throw new Error('Unknown context'); diff --git a/tests/baselines/reference/reservedWords2.errors.txt b/tests/baselines/reference/reservedWords2.errors.txt index b4af3c52916..437b414a69d 100644 --- a/tests/baselines/reference/reservedWords2.errors.txt +++ b/tests/baselines/reference/reservedWords2.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/reservedWords2.ts(1,8): error TS1109: Expression expected. tests/cases/compiler/reservedWords2.ts(1,14): error TS1005: '(' expected. -tests/cases/compiler/reservedWords2.ts(1,16): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/compiler/reservedWords2.ts(1,16): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/compiler/reservedWords2.ts(1,31): error TS1005: ')' expected. tests/cases/compiler/reservedWords2.ts(2,12): error TS2300: Duplicate identifier '(Missing)'. tests/cases/compiler/reservedWords2.ts(2,12): error TS2567: Enum declarations can only merge with namespace or other enum declarations. @@ -14,7 +14,7 @@ tests/cases/compiler/reservedWords2.ts(5,9): error TS2300: Duplicate identifier tests/cases/compiler/reservedWords2.ts(5,9): error TS2567: Enum declarations can only merge with namespace or other enum declarations. tests/cases/compiler/reservedWords2.ts(5,10): error TS1003: Identifier expected. tests/cases/compiler/reservedWords2.ts(5,18): error TS1005: '=>' expected. -tests/cases/compiler/reservedWords2.ts(6,1): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/compiler/reservedWords2.ts(6,1): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/compiler/reservedWords2.ts(6,8): error TS1005: ';' expected. tests/cases/compiler/reservedWords2.ts(7,11): error TS2300: Duplicate identifier '(Missing)'. tests/cases/compiler/reservedWords2.ts(7,11): error TS1005: ':' expected. @@ -39,7 +39,7 @@ tests/cases/compiler/reservedWords2.ts(10,6): error TS1003: Identifier expected. ~ !!! error TS1005: '(' expected. ~~~~~~~ -!!! error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node`. ~ !!! error TS1005: ')' expected. import * as while from "foo" @@ -72,7 +72,7 @@ tests/cases/compiler/reservedWords2.ts(10,6): error TS1003: Identifier expected. !!! error TS1005: '=>' expected. module void {} ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ~~~~ !!! error TS1005: ';' expected. var {while, return} = { while: 1, return: 2 }; diff --git a/tests/baselines/reference/staticsInAFunction.errors.txt b/tests/baselines/reference/staticsInAFunction.errors.txt index 33ca824de99..499ab91e93f 100644 --- a/tests/baselines/reference/staticsInAFunction.errors.txt +++ b/tests/baselines/reference/staticsInAFunction.errors.txt @@ -1,13 +1,13 @@ tests/cases/compiler/staticsInAFunction.ts(1,13): error TS1005: '(' expected. tests/cases/compiler/staticsInAFunction.ts(2,4): error TS1128: Declaration or statement expected. -tests/cases/compiler/staticsInAFunction.ts(2,11): error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. +tests/cases/compiler/staticsInAFunction.ts(2,11): error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. tests/cases/compiler/staticsInAFunction.ts(3,4): error TS1128: Declaration or statement expected. -tests/cases/compiler/staticsInAFunction.ts(3,11): error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. +tests/cases/compiler/staticsInAFunction.ts(3,11): error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. tests/cases/compiler/staticsInAFunction.ts(3,16): error TS2304: Cannot find name 'name'. tests/cases/compiler/staticsInAFunction.ts(3,20): error TS1005: ',' expected. tests/cases/compiler/staticsInAFunction.ts(3,21): error TS2693: 'string' only refers to a type, but is being used as a value here. tests/cases/compiler/staticsInAFunction.ts(4,4): error TS1128: Declaration or statement expected. -tests/cases/compiler/staticsInAFunction.ts(4,11): error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. +tests/cases/compiler/staticsInAFunction.ts(4,11): error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. tests/cases/compiler/staticsInAFunction.ts(4,16): error TS2304: Cannot find name 'name'. tests/cases/compiler/staticsInAFunction.ts(4,21): error TS1109: Expression expected. tests/cases/compiler/staticsInAFunction.ts(4,22): error TS2693: 'any' only refers to a type, but is being used as a value here. @@ -22,12 +22,12 @@ tests/cases/compiler/staticsInAFunction.ts(4,26): error TS1005: ';' expected. ~~~~~~ !!! error TS1128: Declaration or statement expected. ~~~~ -!!! error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. +!!! error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. static test(name:string) ~~~~~~ !!! error TS1128: Declaration or statement expected. ~~~~ -!!! error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. +!!! error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. ~~~~ !!! error TS2304: Cannot find name 'name'. ~ @@ -38,7 +38,7 @@ tests/cases/compiler/staticsInAFunction.ts(4,26): error TS1005: ';' expected. ~~~~~~ !!! error TS1128: Declaration or statement expected. ~~~~ -!!! error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig. +!!! error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`. ~~~~ !!! error TS2304: Cannot find name 'name'. ~ diff --git a/tests/baselines/reference/templateStringInModuleName.errors.txt b/tests/baselines/reference/templateStringInModuleName.errors.txt index 3236b6da81c..f684b305c52 100644 --- a/tests/baselines/reference/templateStringInModuleName.errors.txt +++ b/tests/baselines/reference/templateStringInModuleName.errors.txt @@ -1,10 +1,10 @@ tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,1): error TS2304: Cannot find name 'declare'. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,9): error TS1005: ';' expected. -tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(1,21): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,1): error TS2304: Cannot find name 'declare'. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,9): error TS1005: ';' expected. -tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,24): error TS1005: ';' expected. @@ -15,7 +15,7 @@ tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,24): error ~~~~~~ !!! error TS1005: ';' expected. ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ~ !!! error TS1005: ';' expected. } @@ -26,7 +26,7 @@ tests/cases/conformance/es6/templates/templateStringInModuleName.ts(4,24): error ~~~~~~ !!! error TS1005: ';' expected. ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ~ !!! error TS1005: ';' expected. } \ No newline at end of file diff --git a/tests/baselines/reference/templateStringInModuleNameES6.errors.txt b/tests/baselines/reference/templateStringInModuleNameES6.errors.txt index 4526bb0d792..ecd072a7579 100644 --- a/tests/baselines/reference/templateStringInModuleNameES6.errors.txt +++ b/tests/baselines/reference/templateStringInModuleNameES6.errors.txt @@ -1,10 +1,10 @@ tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,1): error TS2304: Cannot find name 'declare'. tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,9): error TS1005: ';' expected. -tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(1,21): error TS1005: ';' expected. tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,1): error TS2304: Cannot find name 'declare'. tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,9): error TS1005: ';' expected. -tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,24): error TS1005: ';' expected. @@ -15,7 +15,7 @@ tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,24): er ~~~~~~ !!! error TS1005: ';' expected. ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ~ !!! error TS1005: ';' expected. } @@ -26,7 +26,7 @@ tests/cases/conformance/es6/templates/templateStringInModuleNameES6.ts(4,24): er ~~~~~~ !!! error TS1005: ';' expected. ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ~ !!! error TS1005: ';' expected. } \ No newline at end of file diff --git a/tests/baselines/reference/typecheckIfCondition.errors.txt b/tests/baselines/reference/typecheckIfCondition.errors.txt index 5a9255f7f85..e9c3707583e 100644 --- a/tests/baselines/reference/typecheckIfCondition.errors.txt +++ b/tests/baselines/reference/typecheckIfCondition.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/typecheckIfCondition.ts(4,10): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. -tests/cases/compiler/typecheckIfCondition.ts(4,26): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/compiler/typecheckIfCondition.ts(4,10): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. +tests/cases/compiler/typecheckIfCondition.ts(4,26): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ==== tests/cases/compiler/typecheckIfCondition.ts (2 errors) ==== @@ -8,9 +8,9 @@ tests/cases/compiler/typecheckIfCondition.ts(4,26): error TS2580: Cannot find na { if (!module.exports) module.exports = ""; ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. ~~~~~~ -!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. var x = null; // don't want to baseline output } \ No newline at end of file diff --git a/tests/baselines/reference/typingsSuggestion1.errors.txt b/tests/baselines/reference/typingsSuggestion1.errors.txt new file mode 100644 index 00000000000..a9fa0a8a5e9 --- /dev/null +++ b/tests/baselines/reference/typingsSuggestion1.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/typings/a.ts(1,1): error TS2588: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. + + +==== tests/cases/conformance/typings/tsconfig.json (0 errors) ==== + { "compilerOptions": {"types": []} } + +==== tests/cases/conformance/typings/a.ts (1 errors) ==== + module.exports = 1; + ~~~~~~ +!!! error TS2588: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. + \ No newline at end of file diff --git a/tests/baselines/reference/typingsSuggestion1.js b/tests/baselines/reference/typingsSuggestion1.js new file mode 100644 index 00000000000..b3ba53b1134 --- /dev/null +++ b/tests/baselines/reference/typingsSuggestion1.js @@ -0,0 +1,6 @@ +//// [a.ts] +module.exports = 1; + + +//// [a.js] +module.exports = 1; diff --git a/tests/baselines/reference/typingsSuggestion1.symbols b/tests/baselines/reference/typingsSuggestion1.symbols new file mode 100644 index 00000000000..f2f77a4389f --- /dev/null +++ b/tests/baselines/reference/typingsSuggestion1.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/typings/a.ts === +module.exports = 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/typingsSuggestion1.types b/tests/baselines/reference/typingsSuggestion1.types new file mode 100644 index 00000000000..3dfbb761101 --- /dev/null +++ b/tests/baselines/reference/typingsSuggestion1.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/typings/a.ts === +module.exports = 1; +>module.exports = 1 : 1 +>module.exports : any +>module : any +>exports : any +>1 : 1 + diff --git a/tests/baselines/reference/typingsSuggestion2.errors.txt b/tests/baselines/reference/typingsSuggestion2.errors.txt new file mode 100644 index 00000000000..de196446d3d --- /dev/null +++ b/tests/baselines/reference/typingsSuggestion2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/typings/a.ts(1,1): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. + + +==== tests/cases/conformance/typings/tsconfig.json (0 errors) ==== + { "compilerOptions": {} } + +==== tests/cases/conformance/typings/a.ts (1 errors) ==== + module.exports = 1; + ~~~~~~ +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. + \ No newline at end of file diff --git a/tests/baselines/reference/typingsSuggestion2.js b/tests/baselines/reference/typingsSuggestion2.js new file mode 100644 index 00000000000..b3ba53b1134 --- /dev/null +++ b/tests/baselines/reference/typingsSuggestion2.js @@ -0,0 +1,6 @@ +//// [a.ts] +module.exports = 1; + + +//// [a.js] +module.exports = 1; diff --git a/tests/baselines/reference/typingsSuggestion2.symbols b/tests/baselines/reference/typingsSuggestion2.symbols new file mode 100644 index 00000000000..f2f77a4389f --- /dev/null +++ b/tests/baselines/reference/typingsSuggestion2.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/typings/a.ts === +module.exports = 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/typingsSuggestion2.types b/tests/baselines/reference/typingsSuggestion2.types new file mode 100644 index 00000000000..3dfbb761101 --- /dev/null +++ b/tests/baselines/reference/typingsSuggestion2.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/typings/a.ts === +module.exports = 1; +>module.exports = 1 : 1 +>module.exports : any +>module : any +>exports : any +>1 : 1 + diff --git a/tests/cases/conformance/typings/typingsSuggestion1.ts b/tests/cases/conformance/typings/typingsSuggestion1.ts new file mode 100644 index 00000000000..68efd308b6d --- /dev/null +++ b/tests/cases/conformance/typings/typingsSuggestion1.ts @@ -0,0 +1,5 @@ +// @filename: tsconfig.json +{ "compilerOptions": {"types": []} } + +// @filename: a.ts +module.exports = 1; diff --git a/tests/cases/conformance/typings/typingsSuggestion2.ts b/tests/cases/conformance/typings/typingsSuggestion2.ts new file mode 100644 index 00000000000..013155dedd7 --- /dev/null +++ b/tests/cases/conformance/typings/typingsSuggestion2.ts @@ -0,0 +1,5 @@ +// @filename: tsconfig.json +{ "compilerOptions": {} } + +// @filename: a.ts +module.exports = 1; From 490f69f984361710b64d59843be378d287c923ba Mon Sep 17 00:00:00 2001 From: Daniel Krom Date: Fri, 21 Dec 2018 10:41:24 +0200 Subject: [PATCH 03/22] duplicate `wait` instead of `wait` and `notify` original was ``` notify(typedArray: Int32Array, index: number, count: number): number; ``` it seems to be a mistake, the real method is `notify` (the first wait is fine) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify --- src/lib/es2017.sharedmemory.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/es2017.sharedmemory.d.ts b/src/lib/es2017.sharedmemory.d.ts index 018a2f162a5..1d052d6a988 100644 --- a/src/lib/es2017.sharedmemory.d.ts +++ b/src/lib/es2017.sharedmemory.d.ts @@ -103,7 +103,7 @@ interface Atomics { * Wakes up sleeping agents that are waiting on the given index of the array, returning the * number of agents that were awoken. */ - wake(typedArray: Int32Array, index: number, count: number): number; + notify(typedArray: Int32Array, index: number, count: number): number; /** * Stores the bitwise XOR of a value with the value at the given position in the array, @@ -115,4 +115,4 @@ interface Atomics { readonly [Symbol.toStringTag]: "Atomics"; } -declare var Atomics: Atomics; \ No newline at end of file +declare var Atomics: Atomics; From 4cd859aa8532f530e034eb0f219b3d781b7744ed Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Mon, 7 Jan 2019 22:09:27 +0100 Subject: [PATCH 04/22] Allow referencing 'this' in parameters of functions in the constructor Fixes: #29286 --- src/compiler/checker.ts | 2 +- .../reference/superAccess2.errors.txt | 5 +--- .../baselines/reference/superAccess2.symbols | 1 + tests/baselines/reference/superAccess2.types | 2 +- .../thisInConstructorParameter2.errors.txt | 4 ++- .../reference/thisInConstructorParameter2.js | 15 +++++++++-- .../thisInConstructorParameter2.symbols | 25 +++++++++++++------ .../thisInConstructorParameter2.types | 16 +++++++++++- .../compiler/thisInConstructorParameter2.ts | 4 ++- 9 files changed, 56 insertions(+), 18 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index de44e8bb37c..a5147715bb1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16831,7 +16831,7 @@ namespace ts { } function isInConstructorArgumentInitializer(node: Node, constructorDecl: Node): boolean { - return !!findAncestor(node, n => n === constructorDecl ? "quit" : n.kind === SyntaxKind.Parameter); + return !!findAncestor(node, n => isFunctionLikeDeclaration(n) ? "quit" : n.kind === SyntaxKind.Parameter && n.parent === constructorDecl); } function checkSuperExpression(node: Node): Type { diff --git a/tests/baselines/reference/superAccess2.errors.txt b/tests/baselines/reference/superAccess2.errors.txt index 3ba682b3145..65d4c10794d 100644 --- a/tests/baselines/reference/superAccess2.errors.txt +++ b/tests/baselines/reference/superAccess2.errors.txt @@ -7,7 +7,6 @@ tests/cases/compiler/superAccess2.ts(11,33): error TS1034: 'super' must be follo tests/cases/compiler/superAccess2.ts(11,40): error TS2336: 'super' cannot be referenced in constructor arguments. tests/cases/compiler/superAccess2.ts(11,40): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. tests/cases/compiler/superAccess2.ts(11,45): error TS1034: 'super' must be followed by an argument list or member access. -tests/cases/compiler/superAccess2.ts(11,59): error TS2336: 'super' cannot be referenced in constructor arguments. tests/cases/compiler/superAccess2.ts(11,59): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. tests/cases/compiler/superAccess2.ts(11,64): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/compiler/superAccess2.ts(15,19): error TS1034: 'super' must be followed by an argument list or member access. @@ -16,7 +15,7 @@ tests/cases/compiler/superAccess2.ts(20,26): error TS1034: 'super' must be follo tests/cases/compiler/superAccess2.ts(21,15): error TS2339: Property 'x' does not exist on type 'typeof P'. -==== tests/cases/compiler/superAccess2.ts (16 errors) ==== +==== tests/cases/compiler/superAccess2.ts (15 errors) ==== class P { x() { } static y() { } @@ -47,8 +46,6 @@ tests/cases/compiler/superAccess2.ts(21,15): error TS2339: Property 'x' does not ~ !!! error TS1034: 'super' must be followed by an argument list or member access. ~~~~~ -!!! error TS2336: 'super' cannot be referenced in constructor arguments. - ~~~~~ !!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. ~ !!! error TS1034: 'super' must be followed by an argument list or member access. diff --git a/tests/baselines/reference/superAccess2.symbols b/tests/baselines/reference/superAccess2.symbols index 7a9fcb236d6..abb3385b970 100644 --- a/tests/baselines/reference/superAccess2.symbols +++ b/tests/baselines/reference/superAccess2.symbols @@ -25,6 +25,7 @@ class Q extends P { >z : Symbol(Q.z, Decl(superAccess2.ts, 10, 16)) >zz : Symbol(zz, Decl(superAccess2.ts, 10, 33)) >zzz : Symbol(zzz, Decl(superAccess2.ts, 10, 45)) +>super : Symbol(P, Decl(superAccess2.ts, 0, 0)) super(); >super : Symbol(P, Decl(superAccess2.ts, 0, 0)) diff --git a/tests/baselines/reference/superAccess2.types b/tests/baselines/reference/superAccess2.types index 06fcd380480..00ae91bf4c3 100644 --- a/tests/baselines/reference/superAccess2.types +++ b/tests/baselines/reference/superAccess2.types @@ -38,7 +38,7 @@ class Q extends P { >zzz : () => any >() => super : () => any >super : any ->super : any +>super : P > : any super(); diff --git a/tests/baselines/reference/thisInConstructorParameter2.errors.txt b/tests/baselines/reference/thisInConstructorParameter2.errors.txt index 35818b8f379..2b6ed8017c2 100644 --- a/tests/baselines/reference/thisInConstructorParameter2.errors.txt +++ b/tests/baselines/reference/thisInConstructorParameter2.errors.txt @@ -10,11 +10,13 @@ tests/cases/compiler/thisInConstructorParameter2.ts(5,39): error TS2333: 'this' ~~~~ !!! error TS2334: 'this' cannot be referenced in a static property initializer. - constructor(public z = this, zz = this) { } + constructor(public z = this, zz = this, zzz = (p = this) => this) { ~~~~ !!! error TS2333: 'this' cannot be referenced in constructor arguments. ~~~~ !!! error TS2333: 'this' cannot be referenced in constructor arguments. + zzz = (p = this) => this; + } foo(zz = this) { zz.x; } static bar(zz = this) { zz.y; } diff --git a/tests/baselines/reference/thisInConstructorParameter2.js b/tests/baselines/reference/thisInConstructorParameter2.js index a5e4f4d8b57..fc1525f03cf 100644 --- a/tests/baselines/reference/thisInConstructorParameter2.js +++ b/tests/baselines/reference/thisInConstructorParameter2.js @@ -3,7 +3,9 @@ class P { x = this; static y = this; - constructor(public z = this, zz = this) { } + constructor(public z = this, zz = this, zzz = (p = this) => this) { + zzz = (p = this) => this; + } foo(zz = this) { zz.x; } static bar(zz = this) { zz.y; } @@ -12,11 +14,20 @@ class P { //// [thisInConstructorParameter2.js] var _this = this; var P = /** @class */ (function () { - function P(z, zz) { + function P(z, zz, zzz) { if (z === void 0) { z = this; } if (zz === void 0) { zz = this; } + if (zzz === void 0) { zzz = function (p) { + if (p === void 0) { p = _this; } + return _this; + }; } + var _this = this; this.z = z; this.x = this; + zzz = function (p) { + if (p === void 0) { p = _this; } + return _this; + }; } P.prototype.foo = function (zz) { if (zz === void 0) { zz = this; } diff --git a/tests/baselines/reference/thisInConstructorParameter2.symbols b/tests/baselines/reference/thisInConstructorParameter2.symbols index 8991e64f66a..96bdfb159be 100644 --- a/tests/baselines/reference/thisInConstructorParameter2.symbols +++ b/tests/baselines/reference/thisInConstructorParameter2.symbols @@ -10,25 +10,36 @@ class P { >y : Symbol(P.y, Decl(thisInConstructorParameter2.ts, 1, 13)) >this : Symbol(P, Decl(thisInConstructorParameter2.ts, 0, 0)) - constructor(public z = this, zz = this) { } + constructor(public z = this, zz = this, zzz = (p = this) => this) { >z : Symbol(P.z, Decl(thisInConstructorParameter2.ts, 4, 16)) >this : Symbol(P, Decl(thisInConstructorParameter2.ts, 0, 0)) >zz : Symbol(zz, Decl(thisInConstructorParameter2.ts, 4, 32)) >this : Symbol(P, Decl(thisInConstructorParameter2.ts, 0, 0)) +>zzz : Symbol(zzz, Decl(thisInConstructorParameter2.ts, 4, 43)) +>p : Symbol(p, Decl(thisInConstructorParameter2.ts, 4, 51)) +>this : Symbol(P, Decl(thisInConstructorParameter2.ts, 0, 0)) +>this : Symbol(P, Decl(thisInConstructorParameter2.ts, 0, 0)) + + zzz = (p = this) => this; +>zzz : Symbol(zzz, Decl(thisInConstructorParameter2.ts, 4, 43)) +>p : Symbol(p, Decl(thisInConstructorParameter2.ts, 5, 15)) +>this : Symbol(P, Decl(thisInConstructorParameter2.ts, 0, 0)) +>this : Symbol(P, Decl(thisInConstructorParameter2.ts, 0, 0)) + } foo(zz = this) { zz.x; } ->foo : Symbol(P.foo, Decl(thisInConstructorParameter2.ts, 4, 47)) ->zz : Symbol(zz, Decl(thisInConstructorParameter2.ts, 6, 8)) +>foo : Symbol(P.foo, Decl(thisInConstructorParameter2.ts, 6, 5)) +>zz : Symbol(zz, Decl(thisInConstructorParameter2.ts, 8, 8)) >this : Symbol(P, Decl(thisInConstructorParameter2.ts, 0, 0)) >zz.x : Symbol(P.x, Decl(thisInConstructorParameter2.ts, 0, 9)) ->zz : Symbol(zz, Decl(thisInConstructorParameter2.ts, 6, 8)) +>zz : Symbol(zz, Decl(thisInConstructorParameter2.ts, 8, 8)) >x : Symbol(P.x, Decl(thisInConstructorParameter2.ts, 0, 9)) static bar(zz = this) { zz.y; } ->bar : Symbol(P.bar, Decl(thisInConstructorParameter2.ts, 6, 28)) ->zz : Symbol(zz, Decl(thisInConstructorParameter2.ts, 7, 15)) +>bar : Symbol(P.bar, Decl(thisInConstructorParameter2.ts, 8, 28)) +>zz : Symbol(zz, Decl(thisInConstructorParameter2.ts, 9, 15)) >this : Symbol(P, Decl(thisInConstructorParameter2.ts, 0, 0)) >zz.y : Symbol(P.y, Decl(thisInConstructorParameter2.ts, 1, 13)) ->zz : Symbol(zz, Decl(thisInConstructorParameter2.ts, 7, 15)) +>zz : Symbol(zz, Decl(thisInConstructorParameter2.ts, 9, 15)) >y : Symbol(P.y, Decl(thisInConstructorParameter2.ts, 1, 13)) } diff --git a/tests/baselines/reference/thisInConstructorParameter2.types b/tests/baselines/reference/thisInConstructorParameter2.types index 73c5f4d7362..69198bafa5f 100644 --- a/tests/baselines/reference/thisInConstructorParameter2.types +++ b/tests/baselines/reference/thisInConstructorParameter2.types @@ -10,11 +10,25 @@ class P { >y : typeof P >this : typeof P - constructor(public z = this, zz = this) { } + constructor(public z = this, zz = this, zzz = (p = this) => this) { >z : this >this : this >zz : this >this : this +>zzz : (p?: this) => this +>(p = this) => this : (p?: this) => this +>p : this +>this : this +>this : this + + zzz = (p = this) => this; +>zzz = (p = this) => this : (p?: this) => this +>zzz : (p?: this) => this +>(p = this) => this : (p?: this) => this +>p : this +>this : this +>this : this + } foo(zz = this) { zz.x; } >foo : (zz?: this) => void diff --git a/tests/cases/compiler/thisInConstructorParameter2.ts b/tests/cases/compiler/thisInConstructorParameter2.ts index 2b09d2bb7e7..18d35bea341 100644 --- a/tests/cases/compiler/thisInConstructorParameter2.ts +++ b/tests/cases/compiler/thisInConstructorParameter2.ts @@ -2,7 +2,9 @@ class P { x = this; static y = this; - constructor(public z = this, zz = this) { } + constructor(public z = this, zz = this, zzz = (p = this) => this) { + zzz = (p = this) => this; + } foo(zz = this) { zz.x; } static bar(zz = this) { zz.y; } From beb02703b818857ebc1db9f02f3b69e6a2c3d493 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 18 Jan 2019 16:16:45 -0800 Subject: [PATCH 05/22] Support ' xxx' and 'xxx as const' --- src/compiler/checker.ts | 101 +++++++++++++++++++++----------------- src/compiler/utilities.ts | 5 ++ 2 files changed, 60 insertions(+), 46 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c126b5458f1..57f8d037762 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3788,7 +3788,7 @@ namespace ts { context.approximateLength += (symbolName(propertySymbol).length + 1); context.enclosingDeclaration = saveEnclosingDeclaration; const optionalToken = propertySymbol.flags & SymbolFlags.Optional ? createToken(SyntaxKind.QuestionToken) : undefined; - if (propertySymbol.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(propertyType).length) { + if (propertySymbol.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(propertyType).length && !isReadonlySymbol(propertySymbol)) { const signatures = getSignaturesOfType(propertyType, SignatureKind.Call); for (const signature of signatures) { const methodDeclaration = signatureToSignatureDeclarationHelper(signature, SyntaxKind.MethodSignature, context); @@ -4790,7 +4790,7 @@ namespace ts { if (!isTypeAssignableTo(getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique), omitKeyType) && !(getDeclarationModifierFlagsFromSymbol(prop) & (ModifierFlags.Private | ModifierFlags.Protected)) && isSpreadableProperty(prop)) { - members.set(prop.escapedName, getSpreadSymbol(prop)); + members.set(prop.escapedName, getSpreadSymbol(prop, /*readonly*/ false)); } } const stringIndexInfo = getIndexInfoOfType(source, IndexKind.String); @@ -10223,7 +10223,7 @@ namespace ts { * this function should be called in a left folding style, with left = previous result of getSpreadType * and right = the new element to be spread. */ - function getSpreadType(left: Type, right: Type, symbol: Symbol | undefined, typeFlags: TypeFlags, objectFlags: ObjectFlags): Type { + function getSpreadType(left: Type, right: Type, symbol: Symbol | undefined, typeFlags: TypeFlags, objectFlags: ObjectFlags, readonly: boolean): Type { if (left.flags & TypeFlags.Any || right.flags & TypeFlags.Any) { return anyType; } @@ -10237,10 +10237,10 @@ namespace ts { return left; } if (left.flags & TypeFlags.Union) { - return mapType(left, t => getSpreadType(t, right, symbol, typeFlags, objectFlags)); + return mapType(left, t => getSpreadType(t, right, symbol, typeFlags, objectFlags, readonly)); } if (right.flags & TypeFlags.Union) { - return mapType(right, t => getSpreadType(left, t, symbol, typeFlags, objectFlags)); + return mapType(right, t => getSpreadType(left, t, symbol, typeFlags, objectFlags, readonly)); } if (right.flags & (TypeFlags.BooleanLike | TypeFlags.NumberLike | TypeFlags.BigIntLike | TypeFlags.StringLike | TypeFlags.EnumLike | TypeFlags.NonPrimitive | TypeFlags.Index)) { return left; @@ -10257,7 +10257,7 @@ namespace ts { const types = (left).types; const lastLeft = types[types.length - 1]; if (isNonGenericObjectType(lastLeft) && isNonGenericObjectType(right)) { - return getIntersectionType(concatenate(types.slice(0, types.length - 1), [getSpreadType(lastLeft, right, symbol, typeFlags, objectFlags)])); + return getIntersectionType(concatenate(types.slice(0, types.length - 1), [getSpreadType(lastLeft, right, symbol, typeFlags, objectFlags, readonly)])); } } return getIntersectionType([left, right]); @@ -10282,7 +10282,7 @@ namespace ts { skippedPrivateMembers.set(rightProp.escapedName, true); } else if (isSpreadableProperty(rightProp)) { - members.set(rightProp.escapedName, getSpreadSymbol(rightProp)); + members.set(rightProp.escapedName, getSpreadSymbol(rightProp, readonly)); } } @@ -10306,7 +10306,7 @@ namespace ts { } } else { - members.set(leftProp.escapedName, getSpreadSymbol(leftProp)); + members.set(leftProp.escapedName, getSpreadSymbol(leftProp, readonly)); } } @@ -10315,8 +10315,8 @@ namespace ts { members, emptyArray, emptyArray, - getNonReadonlyIndexSignature(stringIndexInfo), - getNonReadonlyIndexSignature(numberIndexInfo)); + getIndexInfoWithReadonly(stringIndexInfo, readonly), + getIndexInfoWithReadonly(numberIndexInfo, readonly)); spread.flags |= TypeFlags.ContainsObjectLiteral | typeFlags; spread.objectFlags |= ObjectFlags.ObjectLiteral | ObjectFlags.ContainsSpread | objectFlags; return spread; @@ -10328,14 +10328,13 @@ namespace ts { !prop.declarations.some(decl => isClassLike(decl.parent)); } - function getSpreadSymbol(prop: Symbol) { - const isReadonly = isReadonlySymbol(prop); + function getSpreadSymbol(prop: Symbol, readonly: boolean) { const isSetonlyAccessor = prop.flags & SymbolFlags.SetAccessor && !(prop.flags & SymbolFlags.GetAccessor); - if (!isReadonly && !isSetonlyAccessor) { + if (!isSetonlyAccessor && readonly === isReadonlySymbol(prop)) { return prop; } const flags = SymbolFlags.Property | (prop.flags & SymbolFlags.Optional); - const result = createSymbol(flags, prop.escapedName); + const result = createSymbol(flags, prop.escapedName, readonly ? CheckFlags.Readonly : 0); result.type = isSetonlyAccessor ? undefinedType : getTypeOfSymbol(prop); result.declarations = prop.declarations; result.nameType = prop.nameType; @@ -10343,11 +10342,8 @@ namespace ts { return result; } - function getNonReadonlyIndexSignature(index: IndexInfo | undefined) { - if (index && index.isReadonly) { - return createIndexInfo(index.type, /*isReadonly*/ false, index.declaration); - } - return index; + function getIndexInfoWithReadonly(info: IndexInfo | undefined, readonly: boolean) { + return info && info.isReadonly !== readonly ? createIndexInfo(info.type, readonly, info.declaration) : info; } function createLiteralType(flags: TypeFlags, value: string | number | PseudoBigInt, symbol: Symbol | undefined) { @@ -17623,7 +17619,7 @@ namespace ts { return getContextualTypeForArgument(parent, node); case SyntaxKind.TypeAssertionExpression: case SyntaxKind.AsExpression: - return getTypeFromTypeNode((parent).type); + return isConstTypeReference((parent).type) ? undefined : getTypeFromTypeNode((parent).type); case SyntaxKind.BinaryExpression: return getContextualTypeForBinaryOperand(node); case SyntaxKind.PropertyAssignment: @@ -17909,6 +17905,7 @@ namespace ts { const elementTypes: Type[] = []; const inDestructuringPattern = isAssignmentTarget(node); const contextualType = getApparentTypeOfContextualType(node); + const inConstContext = isConstContext(node); for (let index = 0; index < elementCount; index++) { const e = elements[index]; if (inDestructuringPattern && e.kind === SyntaxKind.SpreadElement) { @@ -17951,7 +17948,7 @@ namespace ts { type.pattern = node; return type; } - else if (tupleResult = getArrayLiteralTupleTypeIfApplicable(elementTypes, contextualType, hasRestElement, elementCount)) { + else if (tupleResult = getArrayLiteralTupleTypeIfApplicable(elementTypes, contextualType, hasRestElement, elementCount, inConstContext)) { return tupleResult; } else if (forceTuple) { @@ -17960,14 +17957,14 @@ namespace ts { } return createArrayType(elementTypes.length ? getUnionType(elementTypes, UnionReduction.Subtype) : - strictNullChecks ? implicitNeverType : undefinedWideningType); + strictNullChecks ? implicitNeverType : undefinedWideningType, inConstContext); } - function getArrayLiteralTupleTypeIfApplicable(elementTypes: Type[], contextualType: Type | undefined, hasRestElement: boolean, elementCount = elementTypes.length) { + function getArrayLiteralTupleTypeIfApplicable(elementTypes: Type[], contextualType: Type | undefined, hasRestElement: boolean, elementCount = elementTypes.length, readonly = false) { // Infer a tuple type when the contextual type is or contains a tuple-like type - if (contextualType && forEachType(contextualType, isTupleLikeType)) { + if (readonly || (contextualType && forEachType(contextualType, isTupleLikeType))) { const minLength = elementCount - (hasRestElement ? 1 : 0); - const pattern = contextualType.pattern; + const pattern = contextualType && contextualType.pattern; // If array literal is contextually typed by a binding pattern or an assignment pattern, pad the resulting // tuple type with the corresponding binding or assignment element types to make the lengths equal. if (!hasRestElement && pattern && (pattern.kind === SyntaxKind.ArrayBindingPattern || pattern.kind === SyntaxKind.ArrayLiteralExpression)) { @@ -17985,7 +17982,7 @@ namespace ts { } } } - return createTupleType(elementTypes, minLength, hasRestElement); + return createTupleType(elementTypes, minLength, hasRestElement, readonly); } } @@ -18057,15 +18054,15 @@ namespace ts { return links.resolvedType; } - function getObjectLiteralIndexInfo(propertyNodes: NodeArray, offset: number, properties: Symbol[], kind: IndexKind): IndexInfo { + function getObjectLiteralIndexInfo(node: ObjectLiteralExpression, offset: number, properties: Symbol[], kind: IndexKind): IndexInfo { const propTypes: Type[] = []; for (let i = 0; i < properties.length; i++) { - if (kind === IndexKind.String || isNumericName(propertyNodes[i + offset].name!)) { + if (kind === IndexKind.String || isNumericName(node.properties[i + offset].name!)) { propTypes.push(getTypeOfSymbol(properties[i])); } } const unionType = propTypes.length ? getUnionType(propTypes, UnionReduction.Subtype) : undefinedType; - return createIndexInfo(unionType, /*isReadonly*/ false); + return createIndexInfo(unionType, isConstContext(node)); } function getImmediateAliasedSymbol(symbol: Symbol): Symbol | undefined { @@ -18093,6 +18090,8 @@ namespace ts { const contextualType = getApparentTypeOfContextualType(node); const contextualTypeHasPattern = contextualType && contextualType.pattern && (contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern || contextualType.pattern.kind === SyntaxKind.ObjectLiteralExpression); + const inConstContext = isConstContext(node); + const checkFlags = inConstContext ? CheckFlags.Readonly : 0; const isInJavascript = isInJSFile(node) && !isInJsonFile(node); const enumTag = getJSDocEnumTag(node); const isJSObjectLiteral = !contextualType && isInJavascript && !enumTag; @@ -18128,8 +18127,8 @@ namespace ts { const nameType = computedNameType && computedNameType.flags & TypeFlags.StringOrNumberLiteralOrUnique ? computedNameType : undefined; const prop = nameType ? - createSymbol(SymbolFlags.Property | member.flags, getLateBoundNameFromType(nameType), CheckFlags.Late) : - createSymbol(SymbolFlags.Property | member.flags, member.escapedName); + createSymbol(SymbolFlags.Property | member.flags, getLateBoundNameFromType(nameType), checkFlags | CheckFlags.Late) : + createSymbol(SymbolFlags.Property | member.flags, member.escapedName, checkFlags); if (nameType) { prop.nameType = nameType; } @@ -18173,7 +18172,7 @@ namespace ts { checkExternalEmitHelpers(memberDecl, ExternalEmitHelpers.Assign); } if (propertiesArray.length > 0) { - spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags, ObjectFlags.FreshLiteral); + spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags, ObjectFlags.FreshLiteral, inConstContext); propertiesArray = []; propertiesTable = createSymbolTable(); hasComputedStringProperty = false; @@ -18185,7 +18184,7 @@ namespace ts { error(memberDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types); return errorType; } - spread = getSpreadType(spread, type, node.symbol, propagatedFlags, ObjectFlags.FreshLiteral); + spread = getSpreadType(spread, type, node.symbol, propagatedFlags, ObjectFlags.FreshLiteral, inConstContext); offset = i + 1; continue; } @@ -18235,7 +18234,7 @@ namespace ts { if (spread !== emptyObjectType) { if (propertiesArray.length > 0) { - spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags, ObjectFlags.FreshLiteral); + spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags, ObjectFlags.FreshLiteral, inConstContext); } return spread; } @@ -18243,8 +18242,8 @@ namespace ts { return createObjectLiteralType(); function createObjectLiteralType() { - const stringIndexInfo = hasComputedStringProperty ? getObjectLiteralIndexInfo(node.properties, offset, propertiesArray, IndexKind.String) : undefined; - const numberIndexInfo = hasComputedNumberProperty ? getObjectLiteralIndexInfo(node.properties, offset, propertiesArray, IndexKind.Number) : undefined; + const stringIndexInfo = hasComputedStringProperty ? getObjectLiteralIndexInfo(node, offset, propertiesArray, IndexKind.String) : undefined; + const numberIndexInfo = hasComputedNumberProperty ? getObjectLiteralIndexInfo(node, offset, propertiesArray, IndexKind.Number) : undefined; const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); result.flags |= TypeFlags.ContainsObjectLiteral | typeFlags & TypeFlags.PropagatingFlags; result.objectFlags |= ObjectFlags.ObjectLiteral | freshObjectLiteralFlag; @@ -18374,7 +18373,7 @@ namespace ts { else { Debug.assert(attributeDecl.kind === SyntaxKind.JsxSpreadAttribute); if (attributesTable.size > 0) { - spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, typeFlags, objectFlags); + spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, typeFlags, objectFlags, /*readonly*/ false); attributesTable = createSymbolTable(); } const exprType = checkExpressionCached(attributeDecl.expression, checkMode); @@ -18382,7 +18381,7 @@ namespace ts { hasSpreadAnyType = true; } if (isValidSpreadType(exprType)) { - spread = getSpreadType(spread, exprType, attributes.symbol, typeFlags, objectFlags); + spread = getSpreadType(spread, exprType, attributes.symbol, typeFlags, objectFlags, /*readonly*/ false); } else { typeToIntersect = typeToIntersect ? getIntersectionType([typeToIntersect, exprType]) : exprType; @@ -18392,7 +18391,7 @@ namespace ts { if (!hasSpreadAnyType) { if (attributesTable.size > 0) { - spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, typeFlags, objectFlags); + spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, typeFlags, objectFlags, /*readonly*/ false); } } @@ -18420,7 +18419,7 @@ namespace ts { const childPropMap = createSymbolTable(); childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol); spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined), - attributes.symbol, typeFlags, objectFlags); + attributes.symbol, typeFlags, objectFlags, /*readonly*/ false); } } @@ -21107,7 +21106,7 @@ namespace ts { const anonymousSymbol = createSymbol(SymbolFlags.TypeLiteral, InternalSymbolName.Type); const defaultContainingObject = createAnonymousType(anonymousSymbol, memberTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined); anonymousSymbol.type = defaultContainingObject; - synthType.syntheticType = isValidSpreadType(type) ? getSpreadType(type, defaultContainingObject, anonymousSymbol, /*typeFLags*/ 0, /*objectFlags*/ 0) : defaultContainingObject; + synthType.syntheticType = isValidSpreadType(type) ? getSpreadType(type, defaultContainingObject, anonymousSymbol, /*typeFLags*/ 0, /*objectFlags*/ 0, /*readonly*/ false) : defaultContainingObject; } else { synthType.syntheticType = type; @@ -21160,11 +21159,13 @@ namespace ts { } function checkAssertionWorker(errNode: Node, type: TypeNode, expression: UnaryExpression | Expression, checkMode?: CheckMode) { - const exprType = getRegularTypeOfObjectLiteral(getBaseTypeOfLiteralType(checkExpression(expression, checkMode))); - + let exprType = checkExpression(expression, checkMode); + if (isConstTypeReference(type)) { + return getRegularTypeOfLiteralType(exprType); + } checkSourceElement(type); + exprType = getRegularTypeOfObjectLiteral(getBaseTypeOfLiteralType(exprType)); const targetType = getTypeFromTypeNode(type); - if (produceDiagnostics && targetType !== errorType) { const widenedType = getWidenedType(exprType); if (!isTypeComparableTo(targetType, widenedType)) { @@ -22884,12 +22885,20 @@ namespace ts { return false; } + function isConstContext(node: Expression): boolean { + const parent = node.parent; + return isAssertionExpression(parent) && isConstTypeReference(parent.type) || + (isParenthesizedExpression(parent) || isArrayLiteralExpression(parent) || isSpreadElement(parent)) && isConstContext(parent) || + (isPropertyAssignment(parent) || isShorthandPropertyAssignment(parent)) && isConstContext(parent.parent); + } + function checkExpressionForMutableLocation(node: Expression, checkMode: CheckMode | undefined, contextualType?: Type, forceTuple?: boolean): Type { if (arguments.length === 2) { contextualType = getContextualType(node); } const type = checkExpression(node, checkMode, forceTuple); - return isTypeAssertion(node) ? type : + return isConstContext(node) ? getRegularTypeOfLiteralType(type) : + isTypeAssertion(node) ? type : getWidenedLiteralLikeTypeForContextualType(type, contextualType); } @@ -22953,7 +22962,7 @@ namespace ts { return getReturnTypeOfSignature(signature); } } - else if (expr.kind === SyntaxKind.TypeAssertionExpression || expr.kind === SyntaxKind.AsExpression) { + else if (isAssertionExpression(expr) && !isConstTypeReference(expr.type)) { return getTypeFromTypeNode((expr).type); } // Otherwise simply call checkExpression. Ideally, the entire family of checkXXX functions diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 9c6b27de13c..1a352175cb8 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -5606,6 +5606,11 @@ namespace ts { return node.kind === SyntaxKind.TypeAssertionExpression; } + export function isConstTypeReference(node: Node) { + return isTypeReferenceNode(node) && isIdentifier(node.typeName) && + node.typeName.escapedText === "const" && !node.typeArguments; + } + export function isParenthesizedExpression(node: Node): node is ParenthesizedExpression { return node.kind === SyntaxKind.ParenthesizedExpression; } From ec30c20ec975675fc4941c3a1236edff1f36bf5c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 19 Jan 2019 10:25:41 -0800 Subject: [PATCH 06/22] Validate const assertion operand --- src/compiler/checker.ts | 27 ++++++++++++++++++++++++++- src/compiler/diagnosticMessages.json | 4 ++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 57f8d037762..bc4375413d7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9104,7 +9104,7 @@ namespace ts { function createTupleType(elementTypes: ReadonlyArray, minLength = elementTypes.length, hasRestElement = false, readonly = false, associatedNames?: __String[]) { const arity = elementTypes.length; if (arity === 1 && hasRestElement) { - return createArrayType(elementTypes[0]); + return createArrayType(elementTypes[0], readonly); } const tupleType = getTupleTypeOfArity(arity, minLength, arity > 0 && hasRestElement, readonly, associatedNames); return elementTypes.length ? createTypeReference(tupleType, elementTypes) : tupleType; @@ -21158,9 +21158,34 @@ namespace ts { return checkAssertionWorker(node, node.type, node.expression); } + function isValidConstAssertionArgument(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.StringLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.NumericLiteral: + case SyntaxKind.BigIntLiteral: + case SyntaxKind.TrueKeyword: + case SyntaxKind.FalseKeyword: + case SyntaxKind.ArrayLiteralExpression: + case SyntaxKind.ObjectLiteralExpression: + return true; + case SyntaxKind.ParenthesizedExpression: + return isValidConstAssertionArgument((node).expression); + case SyntaxKind.PrefixUnaryExpression: + const op = (node).operator; + const arg = (node).operand; + return op === SyntaxKind.MinusToken && (arg.kind === SyntaxKind.NumericLiteral || arg.kind === SyntaxKind.BigIntLiteral) || + op === SyntaxKind.PlusToken && arg.kind === SyntaxKind.NumericLiteral; + } + return false; + } + function checkAssertionWorker(errNode: Node, type: TypeNode, expression: UnaryExpression | Expression, checkMode?: CheckMode) { let exprType = checkExpression(expression, checkMode); if (isConstTypeReference(type)) { + if (!isValidConstAssertionArgument(expression)) { + error(expression, Diagnostics.A_const_assertion_can_only_be_applied_to_a_string_number_boolean_array_or_object_literal); + } return getRegularTypeOfLiteralType(exprType); } checkSourceElement(type); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9d2f251e100..96c8854bff3 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1027,6 +1027,10 @@ "category": "Error", "code": 1354 }, + "A 'const' assertion can only be applied to a string, number, boolean, array, or object literal.": { + "category": "Error", + "code": 1355 + }, "Duplicate identifier '{0}'.": { "category": "Error", From 980a6817b3cd31594f0b08cf0e4d16cc3c80f075 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 19 Jan 2019 10:34:29 -0800 Subject: [PATCH 07/22] Accept baseline API changes --- tests/baselines/reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 380e43c2409..137e05303a7 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3355,6 +3355,7 @@ declare namespace ts { function isNewExpression(node: Node): node is NewExpression; function isTaggedTemplateExpression(node: Node): node is TaggedTemplateExpression; function isTypeAssertion(node: Node): node is TypeAssertion; + function isConstTypeReference(node: Node): boolean; function isParenthesizedExpression(node: Node): node is ParenthesizedExpression; function skipPartiallyEmittedExpressions(node: Expression): Expression; function skipPartiallyEmittedExpressions(node: Node): Node; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 1234144ac4a..1debe817254 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3355,6 +3355,7 @@ declare namespace ts { function isNewExpression(node: Node): node is NewExpression; function isTaggedTemplateExpression(node: Node): node is TaggedTemplateExpression; function isTypeAssertion(node: Node): node is TypeAssertion; + function isConstTypeReference(node: Node): boolean; function isParenthesizedExpression(node: Node): node is ParenthesizedExpression; function skipPartiallyEmittedExpressions(node: Expression): Expression; function skipPartiallyEmittedExpressions(node: Node): Node; From 2e94f47602d970a60e78737f52cb0f9e21a13300 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 19 Jan 2019 10:34:38 -0800 Subject: [PATCH 08/22] Add tests --- .../typeAssertions/constAssertions.ts | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/cases/conformance/expressions/typeAssertions/constAssertions.ts diff --git a/tests/cases/conformance/expressions/typeAssertions/constAssertions.ts b/tests/cases/conformance/expressions/typeAssertions/constAssertions.ts new file mode 100644 index 00000000000..e2ce7aba993 --- /dev/null +++ b/tests/cases/conformance/expressions/typeAssertions/constAssertions.ts @@ -0,0 +1,67 @@ +// @strict: true +// @declaration: true +// @target: esnext + +let v1 = 'abc' as const; +let v2 = `abc` as const; +let v3 = 10 as const; +let v4 = -10 as const; +let v5 = +10 as const; +let v6 = 10n as const; +let v7 = -10n as const; +let v8 = true as const; +let v9 = false as const; + +let c1 = 'abc' as const; +let c2 = `abc` as const; +let c3 = 10 as const; +let c4 = -10 as const; +let c5 = +10 as const; +let c6 = 10n as const; +let c7 = -10n as const; +let c8 = true as const; +let c9 = false as const; + +let vv1 = v1; +let vc1 = c1; + +let a1 = [] as const; +let a2 = [1, 2, 3] as const; +let a3 = [10, 'hello', true] as const; +let a4 = [...[1, 2, 3]] as const; +let a5 = [1, 2, 3]; +let a6 = [...a5] as const; +let a7 = [...a6]; +let a8 = ['abc', ...a7] as const; +let a9 = [...a8]; + +declare let d: { [x: string]: string }; + +let o1 = { x: 10, y: 20 } as const; +let o2 = { a: 1, 'b': 2, ['c']: 3, d() {}, ['e' + '']: 4 } as const; +let o3 = { ...o1, ...o2 } as const; +let o4 = { a: 1, b: 2 }; +let o5 = { ...o4 } as const; +let o6 = { ...o5 }; +let o7 = { ...d } as const; +let o8 = { ...o7 }; +let o9 = { x: 10, foo() { this.x = 20 } } as const; // Error + +let p1 = (10) as const; +let p2 = ((-10)) as const; +let p3 = ([(10)]) as const; +let p4 = [[[[10]]]] as const; + +let x1 = { x: 10, y: [20, 30], z: { a: { b: 42 } } } as const; + +let q1 = 10; +let q2 = 'abc'; +let q3 = true; +let q4 = [1, 2, 3]; +let q5 = { x: 10, y: 20 }; + +declare function id(x: T): T; + +let e1 = v1 as const; // Error +let e2 = (true ? 1 : 0) as const; // Error +let e3 = id(1) as const; // Error From dbfef5356c60fc28ff1e0ea829acd57fe59e0228 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 19 Jan 2019 10:34:48 -0800 Subject: [PATCH 09/22] Accept baseline changes --- .../reference/constAssertions.errors.txt | 79 ++++ tests/baselines/reference/constAssertions.js | 220 +++++++++++ .../reference/constAssertions.symbols | 201 ++++++++++ .../baselines/reference/constAssertions.types | 356 ++++++++++++++++++ 4 files changed, 856 insertions(+) create mode 100644 tests/baselines/reference/constAssertions.errors.txt create mode 100644 tests/baselines/reference/constAssertions.js create mode 100644 tests/baselines/reference/constAssertions.symbols create mode 100644 tests/baselines/reference/constAssertions.types diff --git a/tests/baselines/reference/constAssertions.errors.txt b/tests/baselines/reference/constAssertions.errors.txt new file mode 100644 index 00000000000..24fce159901 --- /dev/null +++ b/tests/baselines/reference/constAssertions.errors.txt @@ -0,0 +1,79 @@ +tests/cases/conformance/expressions/typeAssertions/constAssertions.ts(44,32): error TS2540: Cannot assign to 'x' because it is a read-only property. +tests/cases/conformance/expressions/typeAssertions/constAssertions.ts(61,10): error TS1355: A 'const' assertion can only be applied to a string, number, boolean, array, or object literal. +tests/cases/conformance/expressions/typeAssertions/constAssertions.ts(62,10): error TS1355: A 'const' assertion can only be applied to a string, number, boolean, array, or object literal. +tests/cases/conformance/expressions/typeAssertions/constAssertions.ts(63,10): error TS1355: A 'const' assertion can only be applied to a string, number, boolean, array, or object literal. + + +==== tests/cases/conformance/expressions/typeAssertions/constAssertions.ts (4 errors) ==== + let v1 = 'abc' as const; + let v2 = `abc` as const; + let v3 = 10 as const; + let v4 = -10 as const; + let v5 = +10 as const; + let v6 = 10n as const; + let v7 = -10n as const; + let v8 = true as const; + let v9 = false as const; + + let c1 = 'abc' as const; + let c2 = `abc` as const; + let c3 = 10 as const; + let c4 = -10 as const; + let c5 = +10 as const; + let c6 = 10n as const; + let c7 = -10n as const; + let c8 = true as const; + let c9 = false as const; + + let vv1 = v1; + let vc1 = c1; + + let a1 = [] as const; + let a2 = [1, 2, 3] as const; + let a3 = [10, 'hello', true] as const; + let a4 = [...[1, 2, 3]] as const; + let a5 = [1, 2, 3]; + let a6 = [...a5] as const; + let a7 = [...a6]; + let a8 = ['abc', ...a7] as const; + let a9 = [...a8]; + + declare let d: { [x: string]: string }; + + let o1 = { x: 10, y: 20 } as const; + let o2 = { a: 1, 'b': 2, ['c']: 3, d() {}, ['e' + '']: 4 } as const; + let o3 = { ...o1, ...o2 } as const; + let o4 = { a: 1, b: 2 }; + let o5 = { ...o4 } as const; + let o6 = { ...o5 }; + let o7 = { ...d } as const; + let o8 = { ...o7 }; + let o9 = { x: 10, foo() { this.x = 20 } } as const; // Error + ~ +!!! error TS2540: Cannot assign to 'x' because it is a read-only property. + + let p1 = (10) as const; + let p2 = ((-10)) as const; + let p3 = ([(10)]) as const; + let p4 = [[[[10]]]] as const; + + let x1 = { x: 10, y: [20, 30], z: { a: { b: 42 } } } as const; + + let q1 = 10; + let q2 = 'abc'; + let q3 = true; + let q4 = [1, 2, 3]; + let q5 = { x: 10, y: 20 }; + + declare function id(x: T): T; + + let e1 = v1 as const; // Error + ~~ +!!! error TS1355: A 'const' assertion can only be applied to a string, number, boolean, array, or object literal. + let e2 = (true ? 1 : 0) as const; // Error + ~~~~~~~~~~~~~~ +!!! error TS1355: A 'const' assertion can only be applied to a string, number, boolean, array, or object literal. + let e3 = id(1) as const; // Error + ~~~~~ +!!! error TS1355: A 'const' assertion can only be applied to a string, number, boolean, array, or object literal. + \ No newline at end of file diff --git a/tests/baselines/reference/constAssertions.js b/tests/baselines/reference/constAssertions.js new file mode 100644 index 00000000000..9f173987d22 --- /dev/null +++ b/tests/baselines/reference/constAssertions.js @@ -0,0 +1,220 @@ +//// [constAssertions.ts] +let v1 = 'abc' as const; +let v2 = `abc` as const; +let v3 = 10 as const; +let v4 = -10 as const; +let v5 = +10 as const; +let v6 = 10n as const; +let v7 = -10n as const; +let v8 = true as const; +let v9 = false as const; + +let c1 = 'abc' as const; +let c2 = `abc` as const; +let c3 = 10 as const; +let c4 = -10 as const; +let c5 = +10 as const; +let c6 = 10n as const; +let c7 = -10n as const; +let c8 = true as const; +let c9 = false as const; + +let vv1 = v1; +let vc1 = c1; + +let a1 = [] as const; +let a2 = [1, 2, 3] as const; +let a3 = [10, 'hello', true] as const; +let a4 = [...[1, 2, 3]] as const; +let a5 = [1, 2, 3]; +let a6 = [...a5] as const; +let a7 = [...a6]; +let a8 = ['abc', ...a7] as const; +let a9 = [...a8]; + +declare let d: { [x: string]: string }; + +let o1 = { x: 10, y: 20 } as const; +let o2 = { a: 1, 'b': 2, ['c']: 3, d() {}, ['e' + '']: 4 } as const; +let o3 = { ...o1, ...o2 } as const; +let o4 = { a: 1, b: 2 }; +let o5 = { ...o4 } as const; +let o6 = { ...o5 }; +let o7 = { ...d } as const; +let o8 = { ...o7 }; +let o9 = { x: 10, foo() { this.x = 20 } } as const; // Error + +let p1 = (10) as const; +let p2 = ((-10)) as const; +let p3 = ([(10)]) as const; +let p4 = [[[[10]]]] as const; + +let x1 = { x: 10, y: [20, 30], z: { a: { b: 42 } } } as const; + +let q1 = 10; +let q2 = 'abc'; +let q3 = true; +let q4 = [1, 2, 3]; +let q5 = { x: 10, y: 20 }; + +declare function id(x: T): T; + +let e1 = v1 as const; // Error +let e2 = (true ? 1 : 0) as const; // Error +let e3 = id(1) as const; // Error + + +//// [constAssertions.js] +"use strict"; +let v1 = 'abc'; +let v2 = `abc`; +let v3 = 10; +let v4 = -10; +let v5 = +10; +let v6 = 10n; +let v7 = -10n; +let v8 = true; +let v9 = false; +let c1 = 'abc'; +let c2 = `abc`; +let c3 = 10; +let c4 = -10; +let c5 = +10; +let c6 = 10n; +let c7 = -10n; +let c8 = true; +let c9 = false; +let vv1 = v1; +let vc1 = c1; +let a1 = []; +let a2 = [1, 2, 3]; +let a3 = [10, 'hello', true]; +let a4 = [...[1, 2, 3]]; +let a5 = [1, 2, 3]; +let a6 = [...a5]; +let a7 = [...a6]; +let a8 = ['abc', ...a7]; +let a9 = [...a8]; +let o1 = { x: 10, y: 20 }; +let o2 = { a: 1, 'b': 2, ['c']: 3, d() { }, ['e' + '']: 4 }; +let o3 = { ...o1, ...o2 }; +let o4 = { a: 1, b: 2 }; +let o5 = { ...o4 }; +let o6 = { ...o5 }; +let o7 = { ...d }; +let o8 = { ...o7 }; +let o9 = { x: 10, foo() { this.x = 20; } }; // Error +let p1 = (10); +let p2 = ((-10)); +let p3 = ([(10)]); +let p4 = [[[[10]]]]; +let x1 = { x: 10, y: [20, 30], z: { a: { b: 42 } } }; +let q1 = 10; +let q2 = 'abc'; +let q3 = true; +let q4 = [1, 2, 3]; +let q5 = { x: 10, y: 20 }; +let e1 = v1; // Error +let e2 = (true ? 1 : 0); // Error +let e3 = id(1); // Error + + +//// [constAssertions.d.ts] +declare let v1: "abc"; +declare let v2: "abc"; +declare let v3: 10; +declare let v4: -10; +declare let v5: 10; +declare let v6: 10n; +declare let v7: -10n; +declare let v8: true; +declare let v9: false; +declare let c1: "abc"; +declare let c2: "abc"; +declare let c3: 10; +declare let c4: -10; +declare let c5: 10; +declare let c6: 10n; +declare let c7: -10n; +declare let c8: true; +declare let c9: false; +declare let vv1: "abc"; +declare let vc1: "abc"; +declare let a1: readonly []; +declare let a2: readonly [1, 2, 3]; +declare let a3: readonly [10, "hello", true]; +declare let a4: readonly (1 | 2 | 3)[]; +declare let a5: number[]; +declare let a6: readonly number[]; +declare let a7: number[]; +declare let a8: readonly ["abc", ...number[]]; +declare let a9: (number | "abc")[]; +declare let d: { + [x: string]: string; +}; +declare let o1: { + readonly x: 10; + readonly y: 20; +}; +declare let o2: { + readonly [x: string]: 1 | 2 | 3 | (() => void) | 4; + readonly a: 1; + readonly 'b': 2; + readonly ['c']: 3; + readonly d: () => void; +}; +declare let o3: { + readonly a: 1; + readonly 'b': 2; + readonly ['c']: 3; + readonly d: () => void; + readonly x: 10; + readonly y: 20; +}; +declare let o4: { + a: number; + b: number; +}; +declare let o5: { + readonly a: number; + readonly b: number; +}; +declare let o6: { + a: number; + b: number; +}; +declare let o7: { + readonly [x: string]: string; +}; +declare let o8: { + [x: string]: string; +}; +declare let o9: { + readonly x: 10; + readonly foo: () => void; +}; +declare let p1: 10; +declare let p2: -10; +declare let p3: readonly [10]; +declare let p4: readonly [readonly [readonly [readonly [10]]]]; +declare let x1: { + readonly x: 10; + readonly y: readonly [20, 30]; + z: { + a: { + readonly b: 42; + }; + }; +}; +declare let q1: 10; +declare let q2: "abc"; +declare let q3: true; +declare let q4: readonly [1, 2, 3]; +declare let q5: { + readonly x: 10; + readonly y: 20; +}; +declare function id(x: T): T; +declare let e1: "abc"; +declare let e2: 0 | 1; +declare let e3: 1; diff --git a/tests/baselines/reference/constAssertions.symbols b/tests/baselines/reference/constAssertions.symbols new file mode 100644 index 00000000000..598210f42b3 --- /dev/null +++ b/tests/baselines/reference/constAssertions.symbols @@ -0,0 +1,201 @@ +=== tests/cases/conformance/expressions/typeAssertions/constAssertions.ts === +let v1 = 'abc' as const; +>v1 : Symbol(v1, Decl(constAssertions.ts, 0, 3)) + +let v2 = `abc` as const; +>v2 : Symbol(v2, Decl(constAssertions.ts, 1, 3)) + +let v3 = 10 as const; +>v3 : Symbol(v3, Decl(constAssertions.ts, 2, 3)) + +let v4 = -10 as const; +>v4 : Symbol(v4, Decl(constAssertions.ts, 3, 3)) + +let v5 = +10 as const; +>v5 : Symbol(v5, Decl(constAssertions.ts, 4, 3)) + +let v6 = 10n as const; +>v6 : Symbol(v6, Decl(constAssertions.ts, 5, 3)) + +let v7 = -10n as const; +>v7 : Symbol(v7, Decl(constAssertions.ts, 6, 3)) + +let v8 = true as const; +>v8 : Symbol(v8, Decl(constAssertions.ts, 7, 3)) + +let v9 = false as const; +>v9 : Symbol(v9, Decl(constAssertions.ts, 8, 3)) + +let c1 = 'abc' as const; +>c1 : Symbol(c1, Decl(constAssertions.ts, 10, 3)) + +let c2 = `abc` as const; +>c2 : Symbol(c2, Decl(constAssertions.ts, 11, 3)) + +let c3 = 10 as const; +>c3 : Symbol(c3, Decl(constAssertions.ts, 12, 3)) + +let c4 = -10 as const; +>c4 : Symbol(c4, Decl(constAssertions.ts, 13, 3)) + +let c5 = +10 as const; +>c5 : Symbol(c5, Decl(constAssertions.ts, 14, 3)) + +let c6 = 10n as const; +>c6 : Symbol(c6, Decl(constAssertions.ts, 15, 3)) + +let c7 = -10n as const; +>c7 : Symbol(c7, Decl(constAssertions.ts, 16, 3)) + +let c8 = true as const; +>c8 : Symbol(c8, Decl(constAssertions.ts, 17, 3)) + +let c9 = false as const; +>c9 : Symbol(c9, Decl(constAssertions.ts, 18, 3)) + +let vv1 = v1; +>vv1 : Symbol(vv1, Decl(constAssertions.ts, 20, 3)) +>v1 : Symbol(v1, Decl(constAssertions.ts, 0, 3)) + +let vc1 = c1; +>vc1 : Symbol(vc1, Decl(constAssertions.ts, 21, 3)) +>c1 : Symbol(c1, Decl(constAssertions.ts, 10, 3)) + +let a1 = [] as const; +>a1 : Symbol(a1, Decl(constAssertions.ts, 23, 3)) + +let a2 = [1, 2, 3] as const; +>a2 : Symbol(a2, Decl(constAssertions.ts, 24, 3)) + +let a3 = [10, 'hello', true] as const; +>a3 : Symbol(a3, Decl(constAssertions.ts, 25, 3)) + +let a4 = [...[1, 2, 3]] as const; +>a4 : Symbol(a4, Decl(constAssertions.ts, 26, 3)) + +let a5 = [1, 2, 3]; +>a5 : Symbol(a5, Decl(constAssertions.ts, 27, 3)) + +let a6 = [...a5] as const; +>a6 : Symbol(a6, Decl(constAssertions.ts, 28, 3)) +>a5 : Symbol(a5, Decl(constAssertions.ts, 27, 3)) + +let a7 = [...a6]; +>a7 : Symbol(a7, Decl(constAssertions.ts, 29, 3)) +>a6 : Symbol(a6, Decl(constAssertions.ts, 28, 3)) + +let a8 = ['abc', ...a7] as const; +>a8 : Symbol(a8, Decl(constAssertions.ts, 30, 3)) +>a7 : Symbol(a7, Decl(constAssertions.ts, 29, 3)) + +let a9 = [...a8]; +>a9 : Symbol(a9, Decl(constAssertions.ts, 31, 3)) +>a8 : Symbol(a8, Decl(constAssertions.ts, 30, 3)) + +declare let d: { [x: string]: string }; +>d : Symbol(d, Decl(constAssertions.ts, 33, 11)) +>x : Symbol(x, Decl(constAssertions.ts, 33, 18)) + +let o1 = { x: 10, y: 20 } as const; +>o1 : Symbol(o1, Decl(constAssertions.ts, 35, 3)) +>x : Symbol(x, Decl(constAssertions.ts, 35, 10)) +>y : Symbol(y, Decl(constAssertions.ts, 35, 17)) + +let o2 = { a: 1, 'b': 2, ['c']: 3, d() {}, ['e' + '']: 4 } as const; +>o2 : Symbol(o2, Decl(constAssertions.ts, 36, 3)) +>a : Symbol(a, Decl(constAssertions.ts, 36, 10)) +>'b' : Symbol('b', Decl(constAssertions.ts, 36, 16)) +>['c'] : Symbol(['c'], Decl(constAssertions.ts, 36, 24)) +>'c' : Symbol(['c'], Decl(constAssertions.ts, 36, 24)) +>d : Symbol(d, Decl(constAssertions.ts, 36, 34)) +>['e' + ''] : Symbol(['e' + ''], Decl(constAssertions.ts, 36, 42)) + +let o3 = { ...o1, ...o2 } as const; +>o3 : Symbol(o3, Decl(constAssertions.ts, 37, 3)) +>o1 : Symbol(o1, Decl(constAssertions.ts, 35, 3)) +>o2 : Symbol(o2, Decl(constAssertions.ts, 36, 3)) + +let o4 = { a: 1, b: 2 }; +>o4 : Symbol(o4, Decl(constAssertions.ts, 38, 3)) +>a : Symbol(a, Decl(constAssertions.ts, 38, 10)) +>b : Symbol(b, Decl(constAssertions.ts, 38, 16)) + +let o5 = { ...o4 } as const; +>o5 : Symbol(o5, Decl(constAssertions.ts, 39, 3)) +>o4 : Symbol(o4, Decl(constAssertions.ts, 38, 3)) + +let o6 = { ...o5 }; +>o6 : Symbol(o6, Decl(constAssertions.ts, 40, 3)) +>o5 : Symbol(o5, Decl(constAssertions.ts, 39, 3)) + +let o7 = { ...d } as const; +>o7 : Symbol(o7, Decl(constAssertions.ts, 41, 3)) +>d : Symbol(d, Decl(constAssertions.ts, 33, 11)) + +let o8 = { ...o7 }; +>o8 : Symbol(o8, Decl(constAssertions.ts, 42, 3)) +>o7 : Symbol(o7, Decl(constAssertions.ts, 41, 3)) + +let o9 = { x: 10, foo() { this.x = 20 } } as const; // Error +>o9 : Symbol(o9, Decl(constAssertions.ts, 43, 3)) +>x : Symbol(x, Decl(constAssertions.ts, 43, 10)) +>foo : Symbol(foo, Decl(constAssertions.ts, 43, 17)) +>this.x : Symbol(x, Decl(constAssertions.ts, 43, 10)) +>this : Symbol(__object, Decl(constAssertions.ts, 43, 8)) +>x : Symbol(x, Decl(constAssertions.ts, 43, 10)) + +let p1 = (10) as const; +>p1 : Symbol(p1, Decl(constAssertions.ts, 45, 3)) + +let p2 = ((-10)) as const; +>p2 : Symbol(p2, Decl(constAssertions.ts, 46, 3)) + +let p3 = ([(10)]) as const; +>p3 : Symbol(p3, Decl(constAssertions.ts, 47, 3)) + +let p4 = [[[[10]]]] as const; +>p4 : Symbol(p4, Decl(constAssertions.ts, 48, 3)) + +let x1 = { x: 10, y: [20, 30], z: { a: { b: 42 } } } as const; +>x1 : Symbol(x1, Decl(constAssertions.ts, 50, 3)) +>x : Symbol(x, Decl(constAssertions.ts, 50, 10)) +>y : Symbol(y, Decl(constAssertions.ts, 50, 17)) +>z : Symbol(z, Decl(constAssertions.ts, 50, 30)) +>a : Symbol(a, Decl(constAssertions.ts, 50, 35)) +>b : Symbol(b, Decl(constAssertions.ts, 50, 40)) + +let q1 = 10; +>q1 : Symbol(q1, Decl(constAssertions.ts, 52, 3)) + +let q2 = 'abc'; +>q2 : Symbol(q2, Decl(constAssertions.ts, 53, 3)) + +let q3 = true; +>q3 : Symbol(q3, Decl(constAssertions.ts, 54, 3)) + +let q4 = [1, 2, 3]; +>q4 : Symbol(q4, Decl(constAssertions.ts, 55, 3)) + +let q5 = { x: 10, y: 20 }; +>q5 : Symbol(q5, Decl(constAssertions.ts, 56, 3)) +>x : Symbol(x, Decl(constAssertions.ts, 56, 18)) +>y : Symbol(y, Decl(constAssertions.ts, 56, 25)) + +declare function id(x: T): T; +>id : Symbol(id, Decl(constAssertions.ts, 56, 34)) +>T : Symbol(T, Decl(constAssertions.ts, 58, 20)) +>x : Symbol(x, Decl(constAssertions.ts, 58, 23)) +>T : Symbol(T, Decl(constAssertions.ts, 58, 20)) +>T : Symbol(T, Decl(constAssertions.ts, 58, 20)) + +let e1 = v1 as const; // Error +>e1 : Symbol(e1, Decl(constAssertions.ts, 60, 3)) +>v1 : Symbol(v1, Decl(constAssertions.ts, 0, 3)) + +let e2 = (true ? 1 : 0) as const; // Error +>e2 : Symbol(e2, Decl(constAssertions.ts, 61, 3)) + +let e3 = id(1) as const; // Error +>e3 : Symbol(e3, Decl(constAssertions.ts, 62, 3)) +>id : Symbol(id, Decl(constAssertions.ts, 56, 34)) + diff --git a/tests/baselines/reference/constAssertions.types b/tests/baselines/reference/constAssertions.types new file mode 100644 index 00000000000..b1f90df15f0 --- /dev/null +++ b/tests/baselines/reference/constAssertions.types @@ -0,0 +1,356 @@ +=== tests/cases/conformance/expressions/typeAssertions/constAssertions.ts === +let v1 = 'abc' as const; +>v1 : "abc" +>'abc' as const : "abc" +>'abc' : "abc" + +let v2 = `abc` as const; +>v2 : "abc" +>`abc` as const : "abc" +>`abc` : "abc" + +let v3 = 10 as const; +>v3 : 10 +>10 as const : 10 +>10 : 10 + +let v4 = -10 as const; +>v4 : -10 +>-10 as const : -10 +>-10 : -10 +>10 : 10 + +let v5 = +10 as const; +>v5 : 10 +>+10 as const : 10 +>+10 : 10 +>10 : 10 + +let v6 = 10n as const; +>v6 : 10n +>10n as const : 10n +>10n : 10n + +let v7 = -10n as const; +>v7 : -10n +>-10n as const : -10n +>-10n : -10n +>10n : 10n + +let v8 = true as const; +>v8 : true +>true as const : true +>true : true + +let v9 = false as const; +>v9 : false +>false as const : false +>false : false + +let c1 = 'abc' as const; +>c1 : "abc" +>'abc' as const : "abc" +>'abc' : "abc" + +let c2 = `abc` as const; +>c2 : "abc" +>`abc` as const : "abc" +>`abc` : "abc" + +let c3 = 10 as const; +>c3 : 10 +>10 as const : 10 +>10 : 10 + +let c4 = -10 as const; +>c4 : -10 +>-10 as const : -10 +>-10 : -10 +>10 : 10 + +let c5 = +10 as const; +>c5 : 10 +>+10 as const : 10 +>+10 : 10 +>10 : 10 + +let c6 = 10n as const; +>c6 : 10n +>10n as const : 10n +>10n : 10n + +let c7 = -10n as const; +>c7 : -10n +>-10n as const : -10n +>-10n : -10n +>10n : 10n + +let c8 = true as const; +>c8 : true +>true as const : true +>true : true + +let c9 = false as const; +>c9 : false +>false as const : false +>false : false + +let vv1 = v1; +>vv1 : "abc" +>v1 : "abc" + +let vc1 = c1; +>vc1 : "abc" +>c1 : "abc" + +let a1 = [] as const; +>a1 : readonly [] +>[] as const : readonly [] +>[] : readonly [] + +let a2 = [1, 2, 3] as const; +>a2 : readonly [1, 2, 3] +>[1, 2, 3] as const : readonly [1, 2, 3] +>[1, 2, 3] : readonly [1, 2, 3] +>1 : 1 +>2 : 2 +>3 : 3 + +let a3 = [10, 'hello', true] as const; +>a3 : readonly [10, "hello", true] +>[10, 'hello', true] as const : readonly [10, "hello", true] +>[10, 'hello', true] : readonly [10, "hello", true] +>10 : 10 +>'hello' : "hello" +>true : true + +let a4 = [...[1, 2, 3]] as const; +>a4 : readonly (1 | 2 | 3)[] +>[...[1, 2, 3]] as const : readonly (1 | 2 | 3)[] +>[...[1, 2, 3]] : readonly (1 | 2 | 3)[] +>...[1, 2, 3] : 1 | 2 | 3 +>[1, 2, 3] : readonly [1, 2, 3] +>1 : 1 +>2 : 2 +>3 : 3 + +let a5 = [1, 2, 3]; +>a5 : number[] +>[1, 2, 3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 + +let a6 = [...a5] as const; +>a6 : readonly number[] +>[...a5] as const : readonly number[] +>[...a5] : readonly number[] +>...a5 : number +>a5 : number[] + +let a7 = [...a6]; +>a7 : number[] +>[...a6] : number[] +>...a6 : number +>a6 : readonly number[] + +let a8 = ['abc', ...a7] as const; +>a8 : readonly ["abc", ...number[]] +>['abc', ...a7] as const : readonly ["abc", ...number[]] +>['abc', ...a7] : readonly ["abc", ...number[]] +>'abc' : "abc" +>...a7 : number +>a7 : number[] + +let a9 = [...a8]; +>a9 : (number | "abc")[] +>[...a8] : (number | "abc")[] +>...a8 : number | "abc" +>a8 : readonly ["abc", ...number[]] + +declare let d: { [x: string]: string }; +>d : { [x: string]: string; } +>x : string + +let o1 = { x: 10, y: 20 } as const; +>o1 : { readonly x: 10; readonly y: 20; } +>{ x: 10, y: 20 } as const : { readonly x: 10; readonly y: 20; } +>{ x: 10, y: 20 } : { readonly x: 10; readonly y: 20; } +>x : 10 +>10 : 10 +>y : 20 +>20 : 20 + +let o2 = { a: 1, 'b': 2, ['c']: 3, d() {}, ['e' + '']: 4 } as const; +>o2 : { readonly [x: string]: 1 | 2 | 3 | (() => void) | 4; readonly a: 1; readonly 'b': 2; readonly ['c']: 3; readonly d: () => void; } +>{ a: 1, 'b': 2, ['c']: 3, d() {}, ['e' + '']: 4 } as const : { readonly [x: string]: 1 | 2 | 3 | (() => void) | 4; readonly a: 1; readonly 'b': 2; readonly ['c']: 3; readonly d: () => void; } +>{ a: 1, 'b': 2, ['c']: 3, d() {}, ['e' + '']: 4 } : { readonly [x: string]: 1 | 2 | 3 | (() => void) | 4; readonly a: 1; readonly 'b': 2; readonly ['c']: 3; readonly d: () => void; } +>a : 1 +>1 : 1 +>'b' : 2 +>2 : 2 +>['c'] : 3 +>'c' : "c" +>3 : 3 +>d : () => void +>['e' + ''] : 4 +>'e' + '' : string +>'e' : "e" +>'' : "" +>4 : 4 + +let o3 = { ...o1, ...o2 } as const; +>o3 : { readonly a: 1; readonly 'b': 2; readonly ['c']: 3; readonly d: () => void; readonly x: 10; readonly y: 20; } +>{ ...o1, ...o2 } as const : { readonly a: 1; readonly 'b': 2; readonly ['c']: 3; readonly d: () => void; readonly x: 10; readonly y: 20; } +>{ ...o1, ...o2 } : { readonly a: 1; readonly 'b': 2; readonly ['c']: 3; readonly d: () => void; readonly x: 10; readonly y: 20; } +>o1 : { readonly x: 10; readonly y: 20; } +>o2 : { readonly [x: string]: 1 | 2 | 3 | (() => void) | 4; readonly a: 1; readonly 'b': 2; readonly ['c']: 3; readonly d: () => void; } + +let o4 = { a: 1, b: 2 }; +>o4 : { a: number; b: number; } +>{ a: 1, b: 2 } : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + +let o5 = { ...o4 } as const; +>o5 : { readonly a: number; readonly b: number; } +>{ ...o4 } as const : { readonly a: number; readonly b: number; } +>{ ...o4 } : { readonly a: number; readonly b: number; } +>o4 : { a: number; b: number; } + +let o6 = { ...o5 }; +>o6 : { a: number; b: number; } +>{ ...o5 } : { a: number; b: number; } +>o5 : { readonly a: number; readonly b: number; } + +let o7 = { ...d } as const; +>o7 : { readonly [x: string]: string; } +>{ ...d } as const : { readonly [x: string]: string; } +>{ ...d } : { readonly [x: string]: string; } +>d : { [x: string]: string; } + +let o8 = { ...o7 }; +>o8 : { [x: string]: string; } +>{ ...o7 } : { [x: string]: string; } +>o7 : { readonly [x: string]: string; } + +let o9 = { x: 10, foo() { this.x = 20 } } as const; // Error +>o9 : { readonly x: 10; readonly foo: () => void; } +>{ x: 10, foo() { this.x = 20 } } as const : { readonly x: 10; readonly foo: () => void; } +>{ x: 10, foo() { this.x = 20 } } : { readonly x: 10; readonly foo: () => void; } +>x : 10 +>10 : 10 +>foo : () => void +>this.x = 20 : 20 +>this.x : any +>this : { readonly x: 10; readonly foo: () => void; } +>x : any +>20 : 20 + +let p1 = (10) as const; +>p1 : 10 +>(10) as const : 10 +>(10) : 10 +>10 : 10 + +let p2 = ((-10)) as const; +>p2 : -10 +>((-10)) as const : -10 +>((-10)) : -10 +>(-10) : -10 +>-10 : -10 +>10 : 10 + +let p3 = ([(10)]) as const; +>p3 : readonly [10] +>([(10)]) as const : readonly [10] +>([(10)]) : readonly [10] +>[(10)] : readonly [10] +>(10) : 10 +>10 : 10 + +let p4 = [[[[10]]]] as const; +>p4 : readonly [readonly [readonly [readonly [10]]]] +>[[[[10]]]] as const : readonly [readonly [readonly [readonly [10]]]] +>[[[[10]]]] : readonly [readonly [readonly [readonly [10]]]] +>[[[10]]] : readonly [readonly [readonly [10]]] +>[[10]] : readonly [readonly [10]] +>[10] : readonly [10] +>10 : 10 + +let x1 = { x: 10, y: [20, 30], z: { a: { b: 42 } } } as const; +>x1 : { readonly x: 10; readonly y: readonly [20, 30]; z: { a: { readonly b: 42; }; }; } +>{ x: 10, y: [20, 30], z: { a: { b: 42 } } } as const : { readonly x: 10; readonly y: readonly [20, 30]; readonly z: { readonly a: { readonly b: 42; }; }; } +>{ x: 10, y: [20, 30], z: { a: { b: 42 } } } : { readonly x: 10; readonly y: readonly [20, 30]; readonly z: { readonly a: { readonly b: 42; }; }; } +>x : 10 +>10 : 10 +>y : readonly [20, 30] +>[20, 30] : readonly [20, 30] +>20 : 20 +>30 : 30 +>z : { readonly a: { readonly b: 42; }; } +>{ a: { b: 42 } } : { readonly a: { readonly b: 42; }; } +>a : { readonly b: 42; } +>{ b: 42 } : { readonly b: 42; } +>b : 42 +>42 : 42 + +let q1 = 10; +>q1 : 10 +> 10 : 10 +>10 : 10 + +let q2 = 'abc'; +>q2 : "abc" +> 'abc' : "abc" +>'abc' : "abc" + +let q3 = true; +>q3 : true +> true : true +>true : true + +let q4 = [1, 2, 3]; +>q4 : readonly [1, 2, 3] +> [1, 2, 3] : readonly [1, 2, 3] +>[1, 2, 3] : readonly [1, 2, 3] +>1 : 1 +>2 : 2 +>3 : 3 + +let q5 = { x: 10, y: 20 }; +>q5 : { readonly x: 10; readonly y: 20; } +> { x: 10, y: 20 } : { readonly x: 10; readonly y: 20; } +>{ x: 10, y: 20 } : { readonly x: 10; readonly y: 20; } +>x : 10 +>10 : 10 +>y : 20 +>20 : 20 + +declare function id(x: T): T; +>id : (x: T) => T +>x : T + +let e1 = v1 as const; // Error +>e1 : "abc" +>v1 as const : "abc" +>v1 : "abc" + +let e2 = (true ? 1 : 0) as const; // Error +>e2 : 0 | 1 +>(true ? 1 : 0) as const : 0 | 1 +>(true ? 1 : 0) : 0 | 1 +>true ? 1 : 0 : 0 | 1 +>true : true +>1 : 1 +>0 : 0 + +let e3 = id(1) as const; // Error +>e3 : 1 +>id(1) as const : 1 +>id(1) : 1 +>id : (x: T) => T +>1 : 1 + From 8f5ef10033e62f1e8fed93ccbdf4106e999ff2e5 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 24 Jan 2019 13:25:42 -0800 Subject: [PATCH 10/22] Don't infer from initializers of parameters of contextually typed functions --- src/compiler/checker.ts | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ac069d95fac..d49e984ce8a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4862,17 +4862,8 @@ namespace ts { function getTypeForBindingElement(declaration: BindingElement): Type | undefined { const pattern = declaration.parent; let parentType = getTypeForBindingElementParent(pattern.parent); - // If parent has the unknown (error) type, then so does this binding element - if (parentType === errorType) { - return errorType; - } - // If no type was specified or inferred for parent, - // infer from the initializer of the binding element if one is present. - // Otherwise, go with the undefined type of the parent. - if (!parentType) { - return declaration.initializer ? checkDeclarationInitializer(declaration) : parentType; - } - if (isTypeAny(parentType)) { + // If no type or an any type was inferred for parent, infer that for the binding element + if (!parentType || isTypeAny(parentType)) { return parentType; } // Relax null check on ambient destructuring parameters, since the parameters have no implementation and are just documentation @@ -5041,8 +5032,11 @@ namespace ts { } } - // Use the type of the initializer expression if one is present - if (declaration.initializer) { + const isParameterOfContextuallyTypedFunction = declaration.kind === SyntaxKind.Parameter && getContextualType(declaration.parent); + + // Use the type of the initializer expression if one is present and the declaration is + // not a parameter of a contextually typed function + if (declaration.initializer && !isParameterOfContextuallyTypedFunction) { const type = checkDeclarationInitializer(declaration); return addOptionality(type, isOptional); } @@ -5053,8 +5047,9 @@ namespace ts { return trueType; } - // If the declaration specifies a binding pattern, use the type implied by the binding pattern - if (isBindingPattern(declaration.name)) { + // If the declaration specifies a binding pattern and is not a parameter of a contextually + // typed function, use the type implied by the binding pattern + if (isBindingPattern(declaration.name) && !isParameterOfContextuallyTypedFunction) { return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ false, /*reportErrors*/ true); } @@ -25638,13 +25633,13 @@ namespace ts { const parent = node.parent.parent; const parentType = getTypeForBindingElementParent(parent); const name = node.propertyName || node.name; - if (!isBindingPattern(name)) { + if (parentType && !isBindingPattern(name)) { const nameText = getTextOfPropertyName(name); if (nameText) { - const property = getPropertyOfType(parentType!, nameText); // TODO: GH#18217 + const property = getPropertyOfType(parentType, nameText); if (property) { markPropertyAsReferenced(property, /*nodeForCheckWriteOnly*/ undefined, /*isThisAccess*/ false); // A destructuring is never a write-only reference. - checkPropertyAccessibility(parent, !!parent.initializer && parent.initializer.kind === SyntaxKind.SuperKeyword, parentType!, property); + checkPropertyAccessibility(parent, !!parent.initializer && parent.initializer.kind === SyntaxKind.SuperKeyword, parentType, property); } } } From 318678acccedfe45b9e8c6f7769e1c73dc00ec9a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 24 Jan 2019 17:07:35 -0800 Subject: [PATCH 11/22] Accept new baselines --- tests/baselines/reference/fatarrowfunctionsErrors.types | 6 +++--- .../reference/fatarrowfunctionsOptionalArgs.types | 8 ++++---- .../reference/fatarrowfunctionsOptionalArgsErrors4.types | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/baselines/reference/fatarrowfunctionsErrors.types b/tests/baselines/reference/fatarrowfunctionsErrors.types index 4a493734e09..36b123e338a 100644 --- a/tests/baselines/reference/fatarrowfunctionsErrors.types +++ b/tests/baselines/reference/fatarrowfunctionsErrors.types @@ -25,10 +25,10 @@ foo((x?)=>{return x;}) foo((x=0)=>{return x;}) >foo((x=0)=>{return x;}) : any >foo : any ->(x=0)=>{return x;} : (x?: number) => number ->x : number +>(x=0)=>{return x;} : (x?: any) => any +>x : any >0 : 0 ->x : number +>x : any var y = x:number => x*x; >y : any diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgs.types b/tests/baselines/reference/fatarrowfunctionsOptionalArgs.types index e9ae9488b91..ed7438dd6a0 100644 --- a/tests/baselines/reference/fatarrowfunctionsOptionalArgs.types +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgs.types @@ -653,8 +653,8 @@ foo( >116 : 116 (a = 0) => 117, ->(a = 0) => 117 : (a?: number) => number ->a : number +>(a = 0) => 117 : (a?: any) => number +>a : any >0 : 0 >117 : 117 @@ -670,9 +670,9 @@ foo( >119 : 119 (a, b? = 0, ...c: number[]) => 120, ->(a, b? = 0, ...c: number[]) => 120 : (a: any, b?: number, ...c: number[]) => number +>(a, b? = 0, ...c: number[]) => 120 : (a: any, b?: any, ...c: number[]) => number >a : any ->b : number +>b : any >0 : 0 >c : number[] >120 : 120 diff --git a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors4.types b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors4.types index 18860e274ca..7496677a194 100644 --- a/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors4.types +++ b/tests/baselines/reference/fatarrowfunctionsOptionalArgsErrors4.types @@ -88,8 +88,8 @@ >116 : 116 (a = 0) => 117, ->(a = 0) => 117 : (a?: number) => number ->a : number +>(a = 0) => 117 : (a?: any) => number +>a : any >0 : 0 >117 : 117 @@ -105,9 +105,9 @@ >119 : 119 (a, b? = 0, ...c: number[]) => 120, ->(a, b? = 0, ...c: number[]) => 120 : (a: any, b?: number, ...c: number[]) => number +>(a, b? = 0, ...c: number[]) => 120 : (a: any, b?: any, ...c: number[]) => number >a : any ->b : number +>b : any >0 : 0 >c : number[] >120 : 120 From 1bc438961579496fc9ebfe83d039afb6cdb284b0 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 24 Jan 2019 17:07:44 -0800 Subject: [PATCH 12/22] Add tests --- ...extuallyTypedParametersWithInitializers.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts diff --git a/tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts b/tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts new file mode 100644 index 00000000000..e68be5b7bfd --- /dev/null +++ b/tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts @@ -0,0 +1,32 @@ +// @strict: true +// @declaration: true + +declare function id1(input: T): T; +declare function id2 any>(input: T): T; +declare function id3 any>(input: T): T; +declare function id4 any>(input: T): T; +declare function id5 any>(input: T): T; + +const f10 = function ({ foo = 42 }) { return foo }; +const f11 = id1(function ({ foo = 42 }) { return foo }); // Implicit any error +const f12 = id2(function ({ foo = 42 }) { return foo }); +const f13 = id3(function ({ foo = 42 }) { return foo }); +const f14 = id4(function ({ foo = 42 }) { return foo }); + +const f20 = function (foo = 42) { return foo }; +const f21 = id1(function (foo = 42) { return foo }); // Implicit any error +const f22 = id2(function (foo = 42) { return foo }); +const f25 = id5(function (foo = 42) { return foo }); + +// Repro from #28816 + +function id(input: T): T { return input } + +function getFoo ({ foo = 42 }) { + return foo; +} + +const newGetFoo = id(getFoo); +const newGetFoo2 = id(function getFoo ({ foo = 42 }) { + return foo; +}); From 58e39ead4fdcb33af049381ed84920aad5b63d34 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 24 Jan 2019 17:07:53 -0800 Subject: [PATCH 13/22] Accept new baselines --- ...TypedParametersWithInitializers.errors.txt | 48 ++++++ ...extuallyTypedParametersWithInitializers.js | 114 ++++++++++++++ ...llyTypedParametersWithInitializers.symbols | 128 ++++++++++++++++ ...uallyTypedParametersWithInitializers.types | 140 ++++++++++++++++++ 4 files changed, 430 insertions(+) create mode 100644 tests/baselines/reference/contextuallyTypedParametersWithInitializers.errors.txt create mode 100644 tests/baselines/reference/contextuallyTypedParametersWithInitializers.js create mode 100644 tests/baselines/reference/contextuallyTypedParametersWithInitializers.symbols create mode 100644 tests/baselines/reference/contextuallyTypedParametersWithInitializers.types diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.errors.txt b/tests/baselines/reference/contextuallyTypedParametersWithInitializers.errors.txt new file mode 100644 index 00000000000..d28b6b05494 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers.errors.txt @@ -0,0 +1,48 @@ +tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts(8,27): error TS7022: '{ foo = 42 }' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts(8,29): error TS7031: Binding element 'foo' implicitly has an 'any' type. +tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts(14,27): error TS7006: Parameter 'foo' implicitly has an 'any' type. +tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts(27,40): error TS7022: '{ foo = 42 }' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts(27,42): error TS7031: Binding element 'foo' implicitly has an 'any' type. + + +==== tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts (5 errors) ==== + declare function id1(input: T): T; + declare function id2 any>(input: T): T; + declare function id3 any>(input: T): T; + declare function id4 any>(input: T): T; + declare function id5 any>(input: T): T; + + const f10 = function ({ foo = 42 }) { return foo }; + const f11 = id1(function ({ foo = 42 }) { return foo }); // Implicit any error + ~~~~~~~~~~~~ +!!! error TS7022: '{ foo = 42 }' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + ~~~ +!!! error TS7031: Binding element 'foo' implicitly has an 'any' type. + const f12 = id2(function ({ foo = 42 }) { return foo }); + const f13 = id3(function ({ foo = 42 }) { return foo }); + const f14 = id4(function ({ foo = 42 }) { return foo }); + + const f20 = function (foo = 42) { return foo }; + const f21 = id1(function (foo = 42) { return foo }); // Implicit any error + ~~~~~~~~ +!!! error TS7006: Parameter 'foo' implicitly has an 'any' type. + const f22 = id2(function (foo = 42) { return foo }); + const f25 = id5(function (foo = 42) { return foo }); + + // Repro from #28816 + + function id(input: T): T { return input } + + function getFoo ({ foo = 42 }) { + return foo; + } + + const newGetFoo = id(getFoo); + const newGetFoo2 = id(function getFoo ({ foo = 42 }) { + ~~~~~~~~~~~~ +!!! error TS7022: '{ foo = 42 }' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. + ~~~ +!!! error TS7031: Binding element 'foo' implicitly has an 'any' type. + return foo; + }); + \ No newline at end of file diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.js b/tests/baselines/reference/contextuallyTypedParametersWithInitializers.js new file mode 100644 index 00000000000..96b55c43157 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers.js @@ -0,0 +1,114 @@ +//// [contextuallyTypedParametersWithInitializers.ts] +declare function id1(input: T): T; +declare function id2 any>(input: T): T; +declare function id3 any>(input: T): T; +declare function id4 any>(input: T): T; +declare function id5 any>(input: T): T; + +const f10 = function ({ foo = 42 }) { return foo }; +const f11 = id1(function ({ foo = 42 }) { return foo }); // Implicit any error +const f12 = id2(function ({ foo = 42 }) { return foo }); +const f13 = id3(function ({ foo = 42 }) { return foo }); +const f14 = id4(function ({ foo = 42 }) { return foo }); + +const f20 = function (foo = 42) { return foo }; +const f21 = id1(function (foo = 42) { return foo }); // Implicit any error +const f22 = id2(function (foo = 42) { return foo }); +const f25 = id5(function (foo = 42) { return foo }); + +// Repro from #28816 + +function id(input: T): T { return input } + +function getFoo ({ foo = 42 }) { + return foo; +} + +const newGetFoo = id(getFoo); +const newGetFoo2 = id(function getFoo ({ foo = 42 }) { + return foo; +}); + + +//// [contextuallyTypedParametersWithInitializers.js] +"use strict"; +var f10 = function (_a) { + var _b = _a.foo, foo = _b === void 0 ? 42 : _b; + return foo; +}; +var f11 = id1(function (_a) { + var _b = _a.foo, foo = _b === void 0 ? 42 : _b; + return foo; +}); // Implicit any error +var f12 = id2(function (_a) { + var _b = _a.foo, foo = _b === void 0 ? 42 : _b; + return foo; +}); +var f13 = id3(function (_a) { + var _b = _a.foo, foo = _b === void 0 ? 42 : _b; + return foo; +}); +var f14 = id4(function (_a) { + var _b = _a.foo, foo = _b === void 0 ? 42 : _b; + return foo; +}); +var f20 = function (foo) { + if (foo === void 0) { foo = 42; } + return foo; +}; +var f21 = id1(function (foo) { + if (foo === void 0) { foo = 42; } + return foo; +}); // Implicit any error +var f22 = id2(function (foo) { + if (foo === void 0) { foo = 42; } + return foo; +}); +var f25 = id5(function (foo) { + if (foo === void 0) { foo = 42; } + return foo; +}); +// Repro from #28816 +function id(input) { return input; } +function getFoo(_a) { + var _b = _a.foo, foo = _b === void 0 ? 42 : _b; + return foo; +} +var newGetFoo = id(getFoo); +var newGetFoo2 = id(function getFoo(_a) { + var _b = _a.foo, foo = _b === void 0 ? 42 : _b; + return foo; +}); + + +//// [contextuallyTypedParametersWithInitializers.d.ts] +declare function id1(input: T): T; +declare function id2 any>(input: T): T; +declare function id3 any>(input: T): T; +declare function id4 any>(input: T): T; +declare function id5 any>(input: T): T; +declare const f10: ({ foo }: { + foo?: number | undefined; +}) => number; +declare const f11: ({ foo }: any) => any; +declare const f12: ({ foo }: any) => any; +declare const f13: ({ foo }: { + foo: any; +}) => any; +declare const f14: ({ foo }: { + foo?: number | undefined; +}) => number; +declare const f20: (foo?: number) => number; +declare const f21: (foo?: any) => any; +declare const f22: (foo?: any) => any; +declare const f25: (foo?: number | undefined) => number; +declare function id(input: T): T; +declare function getFoo({ foo }: { + foo?: number | undefined; +}): number; +declare const newGetFoo: typeof getFoo; +declare const newGetFoo2: ({ foo }: any) => any; diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.symbols b/tests/baselines/reference/contextuallyTypedParametersWithInitializers.symbols new file mode 100644 index 00000000000..6932f7b0cb8 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers.symbols @@ -0,0 +1,128 @@ +=== tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts === +declare function id1(input: T): T; +>id1 : Symbol(id1, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 0)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 21)) +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 24)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 21)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 21)) + +declare function id2 any>(input: T): T; +>id2 : Symbol(id2, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 37)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 21)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 32)) +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 48)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 21)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 21)) + +declare function id3 any>(input: T): T; +>id3 : Symbol(id3, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 61)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 21)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 32)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 36)) +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 57)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 21)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 21)) + +declare function id4 any>(input: T): T; +>id4 : Symbol(id4, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 70)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 21)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 32)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 36)) +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 61)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 21)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 21)) + +declare function id5 any>(input: T): T; +>id5 : Symbol(id5, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 74)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 21)) +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 32)) +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 52)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 21)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 21)) + +const f10 = function ({ foo = 42 }) { return foo }; +>f10 : Symbol(f10, Decl(contextuallyTypedParametersWithInitializers.ts, 6, 5)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 6, 23)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 6, 23)) + +const f11 = id1(function ({ foo = 42 }) { return foo }); // Implicit any error +>f11 : Symbol(f11, Decl(contextuallyTypedParametersWithInitializers.ts, 7, 5)) +>id1 : Symbol(id1, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 0)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 7, 27)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 7, 27)) + +const f12 = id2(function ({ foo = 42 }) { return foo }); +>f12 : Symbol(f12, Decl(contextuallyTypedParametersWithInitializers.ts, 8, 5)) +>id2 : Symbol(id2, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 37)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 8, 27)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 8, 27)) + +const f13 = id3(function ({ foo = 42 }) { return foo }); +>f13 : Symbol(f13, Decl(contextuallyTypedParametersWithInitializers.ts, 9, 5)) +>id3 : Symbol(id3, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 61)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 9, 27)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 9, 27)) + +const f14 = id4(function ({ foo = 42 }) { return foo }); +>f14 : Symbol(f14, Decl(contextuallyTypedParametersWithInitializers.ts, 10, 5)) +>id4 : Symbol(id4, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 70)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 10, 27)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 10, 27)) + +const f20 = function (foo = 42) { return foo }; +>f20 : Symbol(f20, Decl(contextuallyTypedParametersWithInitializers.ts, 12, 5)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 12, 22)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 12, 22)) + +const f21 = id1(function (foo = 42) { return foo }); // Implicit any error +>f21 : Symbol(f21, Decl(contextuallyTypedParametersWithInitializers.ts, 13, 5)) +>id1 : Symbol(id1, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 0)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 13, 26)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 13, 26)) + +const f22 = id2(function (foo = 42) { return foo }); +>f22 : Symbol(f22, Decl(contextuallyTypedParametersWithInitializers.ts, 14, 5)) +>id2 : Symbol(id2, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 37)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 14, 26)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 14, 26)) + +const f25 = id5(function (foo = 42) { return foo }); +>f25 : Symbol(f25, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 5)) +>id5 : Symbol(id5, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 74)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 26)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 26)) + +// Repro from #28816 + +function id(input: T): T { return input } +>id : Symbol(id, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 52)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 12)) +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 15)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 12)) +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 12)) +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 15)) + +function getFoo ({ foo = 42 }) { +>getFoo : Symbol(getFoo, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 44)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 21, 18)) + + return foo; +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 21, 18)) +} + +const newGetFoo = id(getFoo); +>newGetFoo : Symbol(newGetFoo, Decl(contextuallyTypedParametersWithInitializers.ts, 25, 5)) +>id : Symbol(id, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 52)) +>getFoo : Symbol(getFoo, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 44)) + +const newGetFoo2 = id(function getFoo ({ foo = 42 }) { +>newGetFoo2 : Symbol(newGetFoo2, Decl(contextuallyTypedParametersWithInitializers.ts, 26, 5)) +>id : Symbol(id, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 52)) +>getFoo : Symbol(getFoo, Decl(contextuallyTypedParametersWithInitializers.ts, 26, 22)) +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 26, 40)) + + return foo; +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 26, 40)) + +}); + diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.types b/tests/baselines/reference/contextuallyTypedParametersWithInitializers.types new file mode 100644 index 00000000000..3824b16ae62 --- /dev/null +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers.types @@ -0,0 +1,140 @@ +=== tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts === +declare function id1(input: T): T; +>id1 : (input: T) => T +>input : T + +declare function id2 any>(input: T): T; +>id2 : any>(input: T) => T +>x : any +>input : T + +declare function id3 any>(input: T): T; +>id3 : any>(input: T) => T +>x : { foo: any; } +>foo : any +>input : T + +declare function id4 any>(input: T): T; +>id4 : any>(input: T) => T +>x : { foo?: number | undefined; } +>foo : number | undefined +>input : T + +declare function id5 any>(input: T): T; +>id5 : any>(input: T) => T +>x : number | undefined +>input : T + +const f10 = function ({ foo = 42 }) { return foo }; +>f10 : ({ foo }: { foo?: number | undefined; }) => number +>function ({ foo = 42 }) { return foo } : ({ foo }: { foo?: number | undefined; }) => number +>foo : number +>42 : 42 +>foo : number + +const f11 = id1(function ({ foo = 42 }) { return foo }); // Implicit any error +>f11 : ({ foo }: any) => any +>id1(function ({ foo = 42 }) { return foo }) : ({ foo }: any) => any +>id1 : (input: T) => T +>function ({ foo = 42 }) { return foo } : ({ foo }: any) => any +>foo : any +>42 : 42 +>foo : any + +const f12 = id2(function ({ foo = 42 }) { return foo }); +>f12 : ({ foo }: any) => any +>id2(function ({ foo = 42 }) { return foo }) : ({ foo }: any) => any +>id2 : any>(input: T) => T +>function ({ foo = 42 }) { return foo } : ({ foo }: any) => any +>foo : any +>42 : 42 +>foo : any + +const f13 = id3(function ({ foo = 42 }) { return foo }); +>f13 : ({ foo }: { foo: any; }) => any +>id3(function ({ foo = 42 }) { return foo }) : ({ foo }: { foo: any; }) => any +>id3 : any>(input: T) => T +>function ({ foo = 42 }) { return foo } : ({ foo }: { foo: any; }) => any +>foo : any +>42 : 42 +>foo : any + +const f14 = id4(function ({ foo = 42 }) { return foo }); +>f14 : ({ foo }: { foo?: number | undefined; }) => number +>id4(function ({ foo = 42 }) { return foo }) : ({ foo }: { foo?: number | undefined; }) => number +>id4 : any>(input: T) => T +>function ({ foo = 42 }) { return foo } : ({ foo }: { foo?: number | undefined; }) => number +>foo : number +>42 : 42 +>foo : number + +const f20 = function (foo = 42) { return foo }; +>f20 : (foo?: number) => number +>function (foo = 42) { return foo } : (foo?: number) => number +>foo : number +>42 : 42 +>foo : number + +const f21 = id1(function (foo = 42) { return foo }); // Implicit any error +>f21 : (foo?: any) => any +>id1(function (foo = 42) { return foo }) : (foo?: any) => any +>id1 : (input: T) => T +>function (foo = 42) { return foo } : (foo?: any) => any +>foo : any +>42 : 42 +>foo : any + +const f22 = id2(function (foo = 42) { return foo }); +>f22 : (foo?: any) => any +>id2(function (foo = 42) { return foo }) : (foo?: any) => any +>id2 : any>(input: T) => T +>function (foo = 42) { return foo } : (foo?: any) => any +>foo : any +>42 : 42 +>foo : any + +const f25 = id5(function (foo = 42) { return foo }); +>f25 : (foo?: number | undefined) => number +>id5(function (foo = 42) { return foo }) : (foo?: number | undefined) => number +>id5 : any>(input: T) => T +>function (foo = 42) { return foo } : (foo?: number | undefined) => number +>foo : number | undefined +>42 : 42 +>foo : number + +// Repro from #28816 + +function id(input: T): T { return input } +>id : (input: T) => T +>input : T +>input : T + +function getFoo ({ foo = 42 }) { +>getFoo : ({ foo }: { foo?: number | undefined; }) => number +>foo : number +>42 : 42 + + return foo; +>foo : number +} + +const newGetFoo = id(getFoo); +>newGetFoo : ({ foo }: { foo?: number | undefined; }) => number +>id(getFoo) : ({ foo }: { foo?: number | undefined; }) => number +>id : (input: T) => T +>getFoo : ({ foo }: { foo?: number | undefined; }) => number + +const newGetFoo2 = id(function getFoo ({ foo = 42 }) { +>newGetFoo2 : ({ foo }: any) => any +>id(function getFoo ({ foo = 42 }) { return foo;}) : ({ foo }: any) => any +>id : (input: T) => T +>function getFoo ({ foo = 42 }) { return foo;} : ({ foo }: any) => any +>getFoo : ({ foo }: any) => any +>foo : any +>42 : 42 + + return foo; +>foo : any + +}); + From 680cc3dbf47c3febcabc2f734608561d5e674d43 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Fri, 25 Jan 2019 17:02:00 +0100 Subject: [PATCH 14/22] accept baseline change --- tests/baselines/reference/typingsSuggestion1.errors.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/typingsSuggestion1.errors.txt b/tests/baselines/reference/typingsSuggestion1.errors.txt index a9fa0a8a5e9..0fdb37f66b0 100644 --- a/tests/baselines/reference/typingsSuggestion1.errors.txt +++ b/tests/baselines/reference/typingsSuggestion1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/typings/a.ts(1,1): error TS2588: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/conformance/typings/a.ts(1,1): error TS2589: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. ==== tests/cases/conformance/typings/tsconfig.json (0 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/typings/a.ts(1,1): error TS2588: Cannot find name 'modul ==== tests/cases/conformance/typings/a.ts (1 errors) ==== module.exports = 1; ~~~~~~ -!!! error TS2588: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2589: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. \ No newline at end of file From 22d46ace7f11e15dd211c7e590dcc9d681b514ad Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 25 Jan 2019 09:11:59 -0800 Subject: [PATCH 15/22] Don't report circularities when parameter has itself as contextual type --- src/compiler/checker.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d49e984ce8a..7ede048ce7e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5685,17 +5685,21 @@ namespace ts { } function reportCircularityError(symbol: Symbol) { + const declaration = symbol.valueDeclaration; // Check if variable has type annotation that circularly references the variable itself - if (getEffectiveTypeAnnotationNode(symbol.valueDeclaration)) { + if (getEffectiveTypeAnnotationNode(declaration)) { error(symbol.valueDeclaration, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, symbolToString(symbol)); return errorType; } - // Otherwise variable has initializer that circularly references the variable itself - if (noImplicitAny) { + // Check if variable has initializer that circularly references the variable itself + if (noImplicitAny && (declaration).initializer) { error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); } + // Circularities could also result from parameters in function expressions that end up + // having themselves as contextual types following type argument inference. In those cases + // we have already reported an implicit any error so we don't report anything here. return anyType; } From c6ccc5b6cb3fa56765757b6a72c6b84cb596ca5d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 25 Jan 2019 09:43:12 -0800 Subject: [PATCH 16/22] Address CR feedback --- src/compiler/checker.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7ede048ce7e..159aa68562b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4949,6 +4949,12 @@ namespace ts { return strictNullChecks && optional ? getOptionalType(type) : type; } + function isParameterOfContextuallyTypedFunction(node: Declaration) { + return node.kind === SyntaxKind.Parameter && + (node.parent.kind === SyntaxKind.FunctionExpression || node.parent.kind === SyntaxKind.ArrowFunction) && + !!getContextualType(node.parent); + } + // Return the inferred type for a variable, parameter, or property declaration function getTypeForVariableLikeDeclaration(declaration: ParameterDeclaration | PropertyDeclaration | PropertySignature | VariableDeclaration | BindingElement, includeOptionality: boolean): Type | undefined { // A variable declared in a for..in statement is of type string, or of type keyof T when the @@ -5032,11 +5038,9 @@ namespace ts { } } - const isParameterOfContextuallyTypedFunction = declaration.kind === SyntaxKind.Parameter && getContextualType(declaration.parent); - // Use the type of the initializer expression if one is present and the declaration is // not a parameter of a contextually typed function - if (declaration.initializer && !isParameterOfContextuallyTypedFunction) { + if (declaration.initializer && !isParameterOfContextuallyTypedFunction(declaration)) { const type = checkDeclarationInitializer(declaration); return addOptionality(type, isOptional); } @@ -5049,7 +5053,7 @@ namespace ts { // If the declaration specifies a binding pattern and is not a parameter of a contextually // typed function, use the type implied by the binding pattern - if (isBindingPattern(declaration.name) && !isParameterOfContextuallyTypedFunction) { + if (isBindingPattern(declaration.name) && !isParameterOfContextuallyTypedFunction(declaration)) { return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ false, /*reportErrors*/ true); } @@ -5693,7 +5697,7 @@ namespace ts { return errorType; } // Check if variable has initializer that circularly references the variable itself - if (noImplicitAny && (declaration).initializer) { + if (noImplicitAny && (declaration.kind !== SyntaxKind.Parameter || (declaration).initializer)) { error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); } From 69d104897e83cf5d2892cd9a768b49a4d80771e8 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 25 Jan 2019 09:43:24 -0800 Subject: [PATCH 17/22] Accept new baselines --- ...contextuallyTypedParametersWithInitializers.errors.txt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.errors.txt b/tests/baselines/reference/contextuallyTypedParametersWithInitializers.errors.txt index d28b6b05494..61bb8b765b6 100644 --- a/tests/baselines/reference/contextuallyTypedParametersWithInitializers.errors.txt +++ b/tests/baselines/reference/contextuallyTypedParametersWithInitializers.errors.txt @@ -1,11 +1,9 @@ -tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts(8,27): error TS7022: '{ foo = 42 }' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts(8,29): error TS7031: Binding element 'foo' implicitly has an 'any' type. tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts(14,27): error TS7006: Parameter 'foo' implicitly has an 'any' type. -tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts(27,40): error TS7022: '{ foo = 42 }' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts(27,42): error TS7031: Binding element 'foo' implicitly has an 'any' type. -==== tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts (5 errors) ==== +==== tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts (3 errors) ==== declare function id1(input: T): T; declare function id2 any>(input: T): T; declare function id3 any>(input: T): T; @@ -14,8 +12,6 @@ tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts(27,42): erro const f10 = function ({ foo = 42 }) { return foo }; const f11 = id1(function ({ foo = 42 }) { return foo }); // Implicit any error - ~~~~~~~~~~~~ -!!! error TS7022: '{ foo = 42 }' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. ~~~ !!! error TS7031: Binding element 'foo' implicitly has an 'any' type. const f12 = id2(function ({ foo = 42 }) { return foo }); @@ -39,8 +35,6 @@ tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts(27,42): erro const newGetFoo = id(getFoo); const newGetFoo2 = id(function getFoo ({ foo = 42 }) { - ~~~~~~~~~~~~ -!!! error TS7022: '{ foo = 42 }' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. ~~~ !!! error TS7031: Binding element 'foo' implicitly has an 'any' type. return foo; From f30e8a284ac479a96ac660c94084ce5170543cc4 Mon Sep 17 00:00:00 2001 From: Matthew Aynalem Date: Tue, 16 Oct 2018 22:35:34 -0700 Subject: [PATCH 18/22] fix spelling errors --- doc/spec.md | 2 +- src/cancellationToken/cancellationToken.ts | 4 ++-- src/compiler/binder.ts | 4 ++-- src/compiler/builder.ts | 2 +- src/compiler/builderState.ts | 6 +++--- src/compiler/checker.ts | 12 ++++++------ src/compiler/commandLineParser.ts | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/doc/spec.md b/doc/spec.md index edf8455ac54..741d4f29cec 100644 --- a/doc/spec.md +++ b/doc/spec.md @@ -3715,7 +3715,7 @@ the array literal initializer expression is contextually typed by the implied ty ## 5.3 Let and Const Declarations -Let and const declarations are exended to include optional type annotations. +Let and const declarations are extended to include optional type annotations.   *LexicalBinding:* *( Modified )*    *SimpleLexicalBinding* diff --git a/src/cancellationToken/cancellationToken.ts b/src/cancellationToken/cancellationToken.ts index 9b74ebb713a..059ef37c8f1 100644 --- a/src/cancellationToken/cancellationToken.ts +++ b/src/cancellationToken/cancellationToken.ts @@ -35,8 +35,8 @@ function createCancellationToken(args: string[]): ServerCancellationToken { } // cancellationPipeName is a string without '*' inside that can optionally end with '*' // when client wants to signal cancellation it should create a named pipe with name= - // server will synchronously check the presence of the pipe and treat its existance as indicator that current request should be canceled. - // in case if client prefers to use more fine-grained schema than one name for all request it can add '*' to the end of cancelellationPipeName. + // server will synchronously check the presence of the pipe and treat its existence as indicator that current request should be canceled. + // in case if client prefers to use more fine-grained schema than one name for all request it can add '*' to the end of cancellationPipeName. // in this case pipe name will be build dynamically as . if (cancellationPipeName.charAt(cancellationPipeName.length - 1) === "*") { const namePrefix = cancellationPipeName.slice(0, -1); diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 27f85896a3b..6781f6f1701 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -550,7 +550,7 @@ namespace ts { } } // We create a return control flow graph for IIFEs and constructors. For constructors - // we use the return control flow graph in strict property intialization checks. + // we use the return control flow graph in strict property initialization checks. currentReturnTarget = isIIFE || node.kind === SyntaxKind.Constructor ? createBranchLabel() : undefined; currentBreakTarget = undefined; currentContinueTarget = undefined; @@ -3445,7 +3445,7 @@ namespace ts { // If a FunctionDeclaration is generator function and is the body of a // transformed async function, then this node can be transformed to a // down-level generator. - // Currently we do not support transforming any other generator fucntions + // Currently we do not support transforming any other generator functions // down level. if (node.asteriskToken) { transformFlags |= TransformFlags.AssertGenerator; diff --git a/src/compiler/builder.ts b/src/compiler/builder.ts index 44ae6a299d8..c95a8270052 100644 --- a/src/compiler/builder.ts +++ b/src/compiler/builder.ts @@ -27,7 +27,7 @@ namespace ts { currentChangedFilePath: Path | undefined; /** * Map of file signatures, with key being file path, calculated while getting current changed file's affected files - * These will be commited whenever the iteration through affected files of current changed file is complete + * These will be committed whenever the iteration through affected files of current changed file is complete */ currentAffectedFilesSignatures: Map | undefined; /** diff --git a/src/compiler/builderState.ts b/src/compiler/builderState.ts index 552f46c378d..a394ff56201 100644 --- a/src/compiler/builderState.ts +++ b/src/compiler/builderState.ts @@ -37,7 +37,7 @@ namespace ts { */ readonly referencedMap: ReadonlyMap | undefined; /** - * Contains the map of exported modules ReferencedSet=exorted module files from the file if module emit is enabled + * Contains the map of exported modules ReferencedSet=exported module files from the file if module emit is enabled * Otherwise undefined */ readonly exportedModulesMap: Map | undefined; @@ -268,9 +268,9 @@ namespace ts.BuilderState { */ export function getFilesAffectedBy(state: BuilderState, programOfThisState: Program, path: Path, cancellationToken: CancellationToken | undefined, computeHash: ComputeHash, cacheToUpdateSignature?: Map, exportedModulesMapCache?: ComputingExportedModulesMap): ReadonlyArray { // Since the operation could be cancelled, the signatures are always stored in the cache - // They will be commited once it is safe to use them + // They will be committed once it is safe to use them // eg when calling this api from tsserver, if there is no cancellation of the operation - // In the other cases the affected files signatures are commited only after the iteration through the result is complete + // In the other cases the affected files signatures are committed only after the iteration through the result is complete const signatureCache = cacheToUpdateSignature || createMap(); const sourceFile = programOfThisState.getSourceFileByPath(path); if (!sourceFile) { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6385d150a3e..59def3858db 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6311,7 +6311,7 @@ namespace ts { return false; } - /** A type parameter is thisless if its contraint is thisless, or if it has no constraint. */ + /** A type parameter is thisless if its constraint is thisless, or if it has no constraint. */ function isThislessTypeParameter(node: TypeParameterDeclaration) { const constraint = getEffectiveConstraintOfTypeParameter(node); return !constraint || isThislessType(constraint); @@ -10012,10 +10012,10 @@ namespace ts { if (checkType.flags & TypeFlags.Any) { return getUnionType([instantiateType(root.trueType, combinedMapper || mapper), instantiateType(root.falseType, mapper)]); } - // Return falseType for a definitely false extends check. We check an instantations of the two + // Return falseType for a definitely false extends check. We check an instantiations of the two // types with type parameters mapped to the wildcard type, the most permissive instantiations // possible (the wildcard type is assignable to and from all types). If those are not related, - // then no instatiations will be and we can just return the false branch type. + // then no instantiations will be and we can just return the false branch type. if (!isTypeAssignableTo(getPermissiveInstantiation(checkType), getPermissiveInstantiation(inferredExtendsType))) { return instantiateType(root.falseType, mapper); } @@ -14477,7 +14477,7 @@ namespace ts { // that is _too good_ in projects with complicated constraints (eg, fp-ts). In such cases, if we did not limit ourselves // here, we might produce more valid inferences for types, causing us to do more checks and perform more instantiations // (in addition to the extra stack depth here) which, in turn, can push the already close process over its limit. - // TL;DR: If we ever become generally more memory efficienct (or our resource budget ever increases), we should just + // TL;DR: If we ever become generally more memory efficient (or our resource budget ever increases), we should just // remove this `allowComplexConstraintInference` flag. allowComplexConstraintInference = false; return inferFromTypes(apparentSource, target); @@ -18906,7 +18906,7 @@ namespace ts { // if jsx emit was not react as there wont be error being emitted reactSym.isReferenced = SymbolFlags.All; - // If react symbol is alias, mark it as refereced + // If react symbol is alias, mark it as referenced if (reactSym.flags & SymbolFlags.Alias && !isConstEnumOrConstEnumOnlyModule(resolveAlias(reactSym))) { markAliasSymbolAsReferenced(reactSym); } @@ -28256,7 +28256,7 @@ namespace ts { throwIfNonDiagnosticsProducing(); if (sourceFile) { // Some global diagnostics are deferred until they are needed and - // may not be reported in the firt call to getGlobalDiagnostics. + // may not be reported in the first call to getGlobalDiagnostics. // We should catch these changes and report them. const previousGlobalDiagnostics = diagnostics.getGlobalDiagnostics(); const previousGlobalDiagnosticsSize = previousGlobalDiagnostics.length; diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 43275605e23..5f01e66e073 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1935,7 +1935,7 @@ namespace ts { function directoryOfCombinedPath(fileName: string, basePath: string) { // Use the `getNormalizedAbsolutePath` function to avoid canonicalizing the path, as it must remain noncanonical - // until consistient casing errors are reported + // until consistent casing errors are reported return getDirectoryPath(getNormalizedAbsolutePath(fileName, basePath)); } From 1515374a2b085ff708b68898bac55ed38293ed47 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 30 Jan 2019 11:36:30 -0800 Subject: [PATCH 19/22] Make 'gulp min' build tsc/tsserver in parallel --- Gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gulpfile.js b/Gulpfile.js index fb10563067b..68a2b79f222 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -232,7 +232,7 @@ task("watch-tsserver").flags = { " --built": "Compile using the built version of the compiler." } -task("min", series(lkgPreBuild, buildTsc, buildServer)); +task("min", series(lkgPreBuild, parallel(buildTsc, buildServer))); task("min").description = "Builds only tsc and tsserver"; task("min").flags = { " --built": "Compile using the built version of the compiler." From 62cf44cb9bbc6c716ddc0575dba8f164bb52ebbd Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Wed, 30 Jan 2019 19:08:30 -0800 Subject: [PATCH 20/22] Allow per-file setting for rename default behavior preferences (#29593) Fixes #29585. #29314 and #29385 made it so their respective settings are only recognized when provided to the host as a whole. This PR makes it so that the relevant settings for the preferences on the file override those of the preferences on the host. --- src/server/editorServices.ts | 2 +- src/server/session.ts | 7 +- src/services/findAllReferences.ts | 1 + src/testRunner/unittests/tsserver/rename.ts | 108 +++++++++++++++++++- 4 files changed, 112 insertions(+), 6 deletions(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 51833bb2e6e..6dccc08c4b5 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -904,7 +904,7 @@ namespace ts.server { getPreferences(file: NormalizedPath): protocol.UserPreferences { const info = this.getScriptInfoForNormalizedPath(file); - return info && info.getPreferences() || this.hostConfiguration.preferences; + return { ...this.hostConfiguration.preferences, ...info && info.getPreferences() }; } getHostFormatCodeOptions(): FormatCodeSettings { diff --git a/src/server/session.ts b/src/server/session.ts index 2257c6740f4..e5b128c984e 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1178,8 +1178,7 @@ namespace ts.server { private getRenameInfo(args: protocol.FileLocationRequestArgs): RenameInfo { const { file, project } = this.getFileAndProject(args); const position = this.getPositionInFile(args, file); - const preferences = this.getHostPreferences(); - return project.getLanguageService().getRenameInfo(file, position, { allowRenameOfImportPath: preferences.allowRenameOfImportPath }); + return project.getLanguageService().getRenameInfo(file, position, { allowRenameOfImportPath: this.getPreferences(file).allowRenameOfImportPath }); } private getProjects(args: protocol.FileRequestArgs, getScriptInfoEnsuringProjectsUptoDate?: boolean, ignoreNoProjectError?: boolean): Projects { @@ -1234,12 +1233,12 @@ namespace ts.server { { fileName: args.file, pos: position }, !!args.findInStrings, !!args.findInComments, - this.getHostPreferences() + this.getPreferences(file) ); if (!simplifiedResult) return locations; const defaultProject = this.getDefaultProject(args); - const renameInfo: protocol.RenameInfo = this.mapRenameInfo(defaultProject.getLanguageService().getRenameInfo(file, position, { allowRenameOfImportPath: this.getHostPreferences().allowRenameOfImportPath }), Debug.assertDefined(this.projectService.getScriptInfo(file))); + const renameInfo: protocol.RenameInfo = this.mapRenameInfo(defaultProject.getLanguageService().getRenameInfo(file, position, { allowRenameOfImportPath: this.getPreferences(file).allowRenameOfImportPath }), Debug.assertDefined(this.projectService.getScriptInfo(file))); return { info: renameInfo, locs: this.toSpanGroups(locations) }; } diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 52f3277574e..f96c53ee200 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -41,6 +41,7 @@ namespace ts.FindAllReferences { readonly implementations?: boolean; /** * True to opt in for enhanced renaming of shorthand properties and import/export specifiers. + * The options controls the behavior for the whole rename operation; it cannot be changed on a per-file basis. * Default is false for backwards compatibility. */ readonly providePrefixAndSuffixTextForRename?: boolean; diff --git a/src/testRunner/unittests/tsserver/rename.ts b/src/testRunner/unittests/tsserver/rename.ts index 571db235a6e..f565524aded 100644 --- a/src/testRunner/unittests/tsserver/rename.ts +++ b/src/testRunner/unittests/tsserver/rename.ts @@ -7,6 +7,7 @@ namespace ts.projectSystem { const session = createSession(createServerHost([aTs, bTs])); openFilesForSession([bTs], session); + // rename fails with allowRenameOfImportPath disabled const response1 = executeSessionRequest(session, protocol.CommandTypes.Rename, protocolFileLocationFromSubstring(bTs, 'a";')); assert.deepEqual(response1, { info: { @@ -16,6 +17,7 @@ namespace ts.projectSystem { locs: [{ file: bTs.path, locs: [protocolRenameSpanFromSubstring(bTs.content, "./a")] }], }); + // rename succeeds with allowRenameOfImportPath enabled in host session.getProjectService().setHostConfiguration({ preferences: { allowRenameOfImportPath: true } }); const response2 = executeSessionRequest(session, protocol.CommandTypes.Rename, protocolFileLocationFromSubstring(bTs, 'a";')); assert.deepEqual(response2, { @@ -30,6 +32,23 @@ namespace ts.projectSystem { }, locs: [{ file: bTs.path, locs: [protocolRenameSpanFromSubstring(bTs.content, "./a")] }], }); + + // rename succeeds with allowRenameOfImportPath enabled in file + session.getProjectService().setHostConfiguration({ preferences: { allowRenameOfImportPath: false } }); + session.getProjectService().setHostConfiguration({ file: "/b.ts", formatOptions: {}, preferences: { allowRenameOfImportPath: true } }); + const response3 = executeSessionRequest(session, protocol.CommandTypes.Rename, protocolFileLocationFromSubstring(bTs, 'a";')); + assert.deepEqual(response3, { + info: { + canRename: true, + fileToRename: aTs.path, + displayName: aTs.path, + fullDisplayName: aTs.path, + kind: ScriptElementKind.moduleElement, + kindModifiers: "", + triggerSpan: protocolTextSpanFromSubstring(bTs.content, "a", { index: 1 }), + }, + locs: [{ file: bTs.path, locs: [protocolRenameSpanFromSubstring(bTs.content, "./a")] }], + }); }); it("works with prefixText and suffixText when enabled", () => { @@ -61,7 +80,7 @@ namespace ts.projectSystem { ], }); - // rename with prefixText and suffixText enabled + // rename with prefixText and suffixText enabled in host session.getProjectService().setHostConfiguration({ preferences: { providePrefixAndSuffixTextForRename: true } }); const response2 = executeSessionRequest(session, protocol.CommandTypes.Rename, protocolFileLocationFromSubstring(aTs, "x")); assert.deepEqual(response2, { @@ -84,6 +103,93 @@ namespace ts.projectSystem { }, ], }); + + // rename with prefixText and suffixText enabled for file + session.getProjectService().setHostConfiguration({ preferences: { providePrefixAndSuffixTextForRename: false } }); + session.getProjectService().setHostConfiguration({ file: "/a.ts", formatOptions: {}, preferences: { providePrefixAndSuffixTextForRename: true } }); + const response3 = executeSessionRequest(session, protocol.CommandTypes.Rename, protocolFileLocationFromSubstring(aTs, "x")); + assert.deepEqual(response3, { + info: { + canRename: true, + fileToRename: undefined, + displayName: "x", + fullDisplayName: "x", + kind: ScriptElementKind.constElement, + kindModifiers: ScriptElementKindModifier.none, + triggerSpan: protocolTextSpanFromSubstring(aTs.content, "x"), + }, + locs: [ + { + file: aTs.path, + locs: [ + protocolRenameSpanFromSubstring(aTs.content, "x"), + protocolRenameSpanFromSubstring(aTs.content, "x", { index: 1 }, { prefixText: "x: " }), + ], + }, + ], + }); + }); + + it("rename behavior is based on file of rename initiation", () => { + const aTs: File = { path: "/a.ts", content: "const x = 1; export { x };" }; + const bTs: File = { path: "/b.ts", content: `import { x } from "./a"; const y = x + 1;` }; + const host = createServerHost([aTs, bTs]); + const session = createSession(host); + openFilesForSession([aTs, bTs], session); + + // rename from file with prefixText and suffixText enabled + session.getProjectService().setHostConfiguration({ file: "/a.ts", formatOptions: {}, preferences: { providePrefixAndSuffixTextForRename: true } }); + const response1 = executeSessionRequest(session, protocol.CommandTypes.Rename, protocolFileLocationFromSubstring(aTs, "x")); + assert.deepEqual(response1, { + info: { + canRename: true, + fileToRename: undefined, + displayName: "x", + fullDisplayName: "x", + kind: ScriptElementKind.constElement, + kindModifiers: ScriptElementKindModifier.none, + triggerSpan: protocolTextSpanFromSubstring(aTs.content, "x"), + }, + locs: [ + { + file: aTs.path, + locs: [ + protocolRenameSpanFromSubstring(aTs.content, "x"), + protocolRenameSpanFromSubstring(aTs.content, "x", { index: 2 }, { suffixText: " as x" }), + ], + }, + ], + }); + + // rename from file with prefixText and suffixText disabled + const response2 = executeSessionRequest(session, protocol.CommandTypes.Rename, protocolFileLocationFromSubstring(bTs, "x")); + assert.deepEqual(response2, { + info: { + canRename: true, + fileToRename: undefined, + displayName: "x", + fullDisplayName: "x", + kind: ScriptElementKind.alias, + kindModifiers: ScriptElementKindModifier.none, + triggerSpan: protocolTextSpanFromSubstring(bTs.content, "x"), + }, + locs: [ + { + file: bTs.path, + locs: [ + protocolRenameSpanFromSubstring(bTs.content, "x"), + protocolRenameSpanFromSubstring(bTs.content, "x", { index: 1 }) + ] + }, + { + file: aTs.path, + locs: [ + protocolRenameSpanFromSubstring(aTs.content, "x"), + protocolRenameSpanFromSubstring(aTs.content, "x", { index: 2 }), + ], + }, + ], + }); }); }); } From d72271b80033804e75dfa98de1c80a40ae6a664a Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Thu, 31 Jan 2019 11:29:29 +0100 Subject: [PATCH 21/22] update baseline --- tests/baselines/reference/typingsSuggestion1.errors.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/typingsSuggestion1.errors.txt b/tests/baselines/reference/typingsSuggestion1.errors.txt index 0fdb37f66b0..88766c2a613 100644 --- a/tests/baselines/reference/typingsSuggestion1.errors.txt +++ b/tests/baselines/reference/typingsSuggestion1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/typings/a.ts(1,1): error TS2589: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +tests/cases/conformance/typings/a.ts(1,1): error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. ==== tests/cases/conformance/typings/tsconfig.json (0 errors) ==== @@ -7,5 +7,5 @@ tests/cases/conformance/typings/a.ts(1,1): error TS2589: Cannot find name 'modul ==== tests/cases/conformance/typings/a.ts (1 errors) ==== module.exports = 1; ~~~~~~ -!!! error TS2589: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. +!!! error TS2591: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig. \ No newline at end of file From d2909a14aac82a2eab469f578bc3cabb866df77a Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Thu, 31 Jan 2019 15:02:49 -0800 Subject: [PATCH 22/22] Update user baselines (#29660) --- tests/baselines/reference/user/chrome-devtools-frontend.log | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/baselines/reference/user/chrome-devtools-frontend.log b/tests/baselines/reference/user/chrome-devtools-frontend.log index bfb66f46a67..7ae2531d383 100644 --- a/tests/baselines/reference/user/chrome-devtools-frontend.log +++ b/tests/baselines/reference/user/chrome-devtools-frontend.log @@ -759,7 +759,6 @@ node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighth Type 'number' is not assignable to type 'void'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(19744,7): error TS2339: Property 'expected' does not exist on type 'Error'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(20005,8): error TS2339: Property 'runLighthouseForConnection' does not exist on type 'Window'. -node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(20015,1): error TS2554: Expected 0 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(20035,8): error TS2339: Property 'runLighthouseInWorker' does not exist on type 'Window'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(20039,15): error TS2339: Property 'runLighthouseForConnection' does not exist on type 'Window'. node_modules/chrome-devtools-frontend/front_end/audits2_worker/lighthouse/lighthouse-background.js(20046,8): error TS2339: Property 'getDefaultCategories' does not exist on type 'Window'.