From 4ed80b62df9531db3863854c702809eb3b0e7bb7 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Wed, 16 Oct 2019 11:24:24 -0700 Subject: [PATCH 01/63] Stop pre-emptively creating directories Checking for directory existence is expensive and frequently indicates success. Instead of pre-emptively creating the directory containing a file to be written, attempt to create the file and only do the directory scaffolding if the write fails. Appears to reduce file write time by 10-20% for a file-I/O heavy partner build. Thanks to @rbuckton for the suggestion! --- src/compiler/program.ts | 22 +++++++++++++++++----- src/compiler/sys.ts | 17 +++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 0c8444daa2f..b9495c787ca 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -151,13 +151,16 @@ namespace ts { function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) { try { performance.mark("beforeIOWrite"); - ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName))); - if (isWatchSet(options) && system.createHash && system.getModifiedTime) { - writeFileIfUpdated(fileName, data, writeByteOrderMark); + // PERF: Checking for directory existence is expensive. + // Instead, assume the directory exists and fall back + // to creating it if the file write fails. + try { + writeFileWorker(fileName, data, writeByteOrderMark); } - else { - system.writeFile(fileName, data, writeByteOrderMark); + catch (_) { + ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName))); + writeFileWorker(fileName, data, writeByteOrderMark); } performance.mark("afterIOWrite"); @@ -170,6 +173,15 @@ namespace ts { } } + function writeFileWorker(fileName: string, data: string, writeByteOrderMark: boolean) { + if (isWatchSet(options) && system.createHash && system.getModifiedTime) { + writeFileIfUpdated(fileName, data, writeByteOrderMark); + } + else { + system.writeFile(fileName, data, writeByteOrderMark); + } + } + function getDefaultLibLocation(): string { return getDirectoryPath(normalizePath(system.getExecutingFilePath())); } diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index ad866cba130..c85bb48bb9e 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -541,11 +541,20 @@ namespace ts { // patch writefile to create folder before writing the file const originalWriteFile = sys.writeFile; sys.writeFile = (path, data, writeBom) => { - const directoryPath = getDirectoryPath(normalizeSlashes(path)); - if (directoryPath && !sys.directoryExists(directoryPath)) { - recursiveCreateDirectory(directoryPath, sys); + // PERF: Checking for directory existence is expensive. + // Instead, assume the directory exists and fall back + // to creating it if the file write fails. + try { + originalWriteFile.call(sys, path, data, writeBom); + } + catch (_) { + const directoryPath = getDirectoryPath(normalizeSlashes(path)); + if (directoryPath && !sys.directoryExists(directoryPath)) { + recursiveCreateDirectory(directoryPath, sys); + } + + originalWriteFile.call(sys, path, data, writeBom); } - originalWriteFile.call(sys, path, data, writeBom); }; } From b6659e5d6eed1a2daf5cca5a87febb5cfceb5372 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Wed, 16 Oct 2019 11:31:44 -0700 Subject: [PATCH 02/63] Inline function to tidy up control flow --- src/compiler/program.ts | 79 +++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index b9495c787ca..44cf374ea75 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -96,7 +96,7 @@ namespace ts { if (existingDirectories.has(directoryPath)) { return true; } - if (system.directoryExists(directoryPath)) { + if ((compilerHost.directoryExists || system.directoryExists)(directoryPath)) { existingDirectories.set(directoryPath, true); return true; } @@ -107,47 +107,10 @@ namespace ts { if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) { const parentDirectory = getDirectoryPath(directoryPath); ensureDirectoriesExist(parentDirectory); - if (compilerHost.createDirectory) { - compilerHost.createDirectory(directoryPath); - } - else { - system.createDirectory(directoryPath); - } + (compilerHost.createDirectory || system.createDirectory)(directoryPath); } } - let outputFingerprints: Map; - - function writeFileIfUpdated(fileName: string, data: string, writeByteOrderMark: boolean): void { - if (!outputFingerprints) { - outputFingerprints = createMap(); - } - - const hash = system.createHash!(data); // TODO: GH#18217 - const mtimeBefore = system.getModifiedTime!(fileName); // TODO: GH#18217 - - if (mtimeBefore) { - const fingerprint = outputFingerprints.get(fileName); - // If output has not been changed, and the file has no external modification - if (fingerprint && - fingerprint.byteOrderMark === writeByteOrderMark && - fingerprint.hash === hash && - fingerprint.mtime.getTime() === mtimeBefore.getTime()) { - return; - } - } - - system.writeFile(fileName, data, writeByteOrderMark); - - const mtimeAfter = system.getModifiedTime!(fileName) || missingFileModifiedTime; // TODO: GH#18217 - - outputFingerprints.set(fileName, { - hash, - byteOrderMark: writeByteOrderMark, - mtime: mtimeAfter - }); - } - function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) { try { performance.mark("beforeIOWrite"); @@ -155,6 +118,9 @@ namespace ts { // PERF: Checking for directory existence is expensive. // Instead, assume the directory exists and fall back // to creating it if the file write fails. + // NOTE: If patchWriteFileEnsuringDirectory has been called, + // the file write will do its own directory creation and + // the ensureDirectoriesExist call will always be redundant. try { writeFileWorker(fileName, data, writeByteOrderMark); } @@ -173,13 +139,40 @@ namespace ts { } } + let outputFingerprints: Map; function writeFileWorker(fileName: string, data: string, writeByteOrderMark: boolean) { - if (isWatchSet(options) && system.createHash && system.getModifiedTime) { - writeFileIfUpdated(fileName, data, writeByteOrderMark); - } - else { + if (!isWatchSet(options) || !system.createHash || !system.getModifiedTime) { system.writeFile(fileName, data, writeByteOrderMark); + return; } + + if (!outputFingerprints) { + outputFingerprints = createMap(); + } + + const hash = system.createHash(data); + const mtimeBefore = system.getModifiedTime(fileName); + + if (mtimeBefore) { + const fingerprint = outputFingerprints.get(fileName); + // If output has not been changed, and the file has no external modification + if (fingerprint && + fingerprint.byteOrderMark === writeByteOrderMark && + fingerprint.hash === hash && + fingerprint.mtime.getTime() === mtimeBefore.getTime()) { + return; + } + } + + system.writeFile(fileName, data, writeByteOrderMark); + + const mtimeAfter = system.getModifiedTime(fileName) || missingFileModifiedTime; + + outputFingerprints.set(fileName, { + hash, + byteOrderMark: writeByteOrderMark, + mtime: mtimeAfter + }); } function getDefaultLibLocation(): string { From f39b49d756110e24ac75c81413cb13e8a0a423b0 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Thu, 17 Oct 2019 11:36:45 -0700 Subject: [PATCH 03/63] Update another writeFile call-site --- src/compiler/program.ts | 2 +- src/compiler/sys.ts | 2 +- src/compiler/watch.ts | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 44cf374ea75..6a697b9c180 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -124,7 +124,7 @@ namespace ts { try { writeFileWorker(fileName, data, writeByteOrderMark); } - catch (_) { + catch { ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName))); writeFileWorker(fileName, data, writeByteOrderMark); } diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index c85bb48bb9e..c4a5012b265 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -547,7 +547,7 @@ namespace ts { try { originalWriteFile.call(sys, path, data, writeBom); } - catch (_) { + catch { const directoryPath = getDirectoryPath(normalizeSlashes(path)); if (directoryPath && !sys.directoryExists(directoryPath)) { recursiveCreateDirectory(directoryPath, sys); diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 06871fc9cac..f6e334aa47a 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -307,9 +307,20 @@ namespace ts { function writeFile(fileName: string, text: string, writeByteOrderMark: boolean, onError: (message: string) => void) { try { performance.mark("beforeIOWrite"); - ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName))); - host.writeFile!(fileName, text, writeByteOrderMark); + // PERF: Checking for directory existence is expensive. + // Instead, assume the directory exists and fall back + // to creating it if the file write fails. + // NOTE: If patchWriteFileEnsuringDirectory has been called, + // the file write will do its own directory creation and + // the ensureDirectoriesExist call will always be redundant. + try { + host.writeFile!(fileName, text, writeByteOrderMark); + } + catch { + ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName))); + host.writeFile!(fileName, text, writeByteOrderMark); + } performance.mark("afterIOWrite"); performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite"); From 205b3dae3bb86b7b78864f585364f73b0830d7e7 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Thu, 17 Oct 2019 16:26:43 -0700 Subject: [PATCH 04/63] Extract shared helper --- src/compiler/program.ts | 27 ++++++++------------------- src/compiler/sys.ts | 35 ++++++++--------------------------- src/compiler/utilities.ts | 30 ++++++++++++++++++++++++++++++ src/compiler/watch.ts | 21 ++------------------- 4 files changed, 48 insertions(+), 65 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 6a697b9c180..0be96b7d55f 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -103,31 +103,20 @@ namespace ts { return false; } - function ensureDirectoriesExist(directoryPath: string) { - if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) { - const parentDirectory = getDirectoryPath(directoryPath); - ensureDirectoriesExist(parentDirectory); - (compilerHost.createDirectory || system.createDirectory)(directoryPath); - } - } - function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) { try { performance.mark("beforeIOWrite"); - // PERF: Checking for directory existence is expensive. - // Instead, assume the directory exists and fall back - // to creating it if the file write fails. // NOTE: If patchWriteFileEnsuringDirectory has been called, - // the file write will do its own directory creation and + // the system.writeFile will do its own directory creation and // the ensureDirectoriesExist call will always be redundant. - try { - writeFileWorker(fileName, data, writeByteOrderMark); - } - catch { - ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName))); - writeFileWorker(fileName, data, writeByteOrderMark); - } + writeFileEnsuringDirectories( + fileName, + data, + writeByteOrderMark, + writeFileWorker, + compilerHost.createDirectory || system.createDirectory, + directoryExists); performance.mark("afterIOWrite"); performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite"); diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index c4a5012b265..9de6193d734 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -522,17 +522,6 @@ namespace ts { } } - function recursiveCreateDirectory(directoryPath: string, sys: System) { - const basePath = getDirectoryPath(directoryPath); - const shouldCreateParent = basePath !== "" && directoryPath !== basePath && !sys.directoryExists(basePath); - if (shouldCreateParent) { - recursiveCreateDirectory(basePath, sys); - } - if (shouldCreateParent || !sys.directoryExists(directoryPath)) { - sys.createDirectory(directoryPath); - } - } - /** * patch writefile to create folder before writing the file */ @@ -540,22 +529,14 @@ namespace ts { export function patchWriteFileEnsuringDirectory(sys: System) { // patch writefile to create folder before writing the file const originalWriteFile = sys.writeFile; - sys.writeFile = (path, data, writeBom) => { - // PERF: Checking for directory existence is expensive. - // Instead, assume the directory exists and fall back - // to creating it if the file write fails. - try { - originalWriteFile.call(sys, path, data, writeBom); - } - catch { - const directoryPath = getDirectoryPath(normalizeSlashes(path)); - if (directoryPath && !sys.directoryExists(directoryPath)) { - recursiveCreateDirectory(directoryPath, sys); - } - - originalWriteFile.call(sys, path, data, writeBom); - } - }; + sys.writeFile = (path, data, writeBom) => + writeFileEnsuringDirectories( + path, + data, + writeBom, + (p, d, w) => originalWriteFile.call(sys, p, d, w), + sys.createDirectory, + sys.directoryExists); } /*@internal*/ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 2fb1173deef..8f7602cbe2a 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3700,6 +3700,36 @@ namespace ts { }, sourceFiles); } + function ensureDirectoriesExist( + directoryPath: string, + createDirectory: (path: string) => void, + directoryExists: (path: string) => boolean): void { + if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) { + const parentDirectory = getDirectoryPath(directoryPath); + ensureDirectoriesExist(parentDirectory, createDirectory, directoryExists); + createDirectory(directoryPath); + } + } + + export function writeFileEnsuringDirectories( + path: string, + data: string, + writeByteOrderMark: boolean | undefined, + writeFile: (path: string, data: string, writeByteOrderMark?: boolean) => void, + createDirectory: (path: string) => void, + directoryExists: (path: string) => boolean): void { + + // PERF: Checking for directory existence is expensive. Instead, assume the directory exists + // and fall back to creating it if the file write fails. + try { + writeFile(path, data, writeByteOrderMark); + } + catch { + ensureDirectoriesExist(getDirectoryPath(normalizePath(path)), createDirectory, directoryExists); + writeFile(path, data, writeByteOrderMark); + } + } + export function getLineOfLocalPosition(currentSourceFile: SourceFile, pos: number) { return getLineAndCharacterOfPosition(currentSourceFile, pos).line; } diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index f6e334aa47a..cc6bd0bcced 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -296,31 +296,14 @@ namespace ts { readDirectory: maybeBind(host, host.readDirectory), }; - function ensureDirectoriesExist(directoryPath: string) { - if (directoryPath.length > getRootLength(directoryPath) && !host.directoryExists!(directoryPath)) { - const parentDirectory = getDirectoryPath(directoryPath); - ensureDirectoriesExist(parentDirectory); - if (host.createDirectory) host.createDirectory(directoryPath); - } - } - function writeFile(fileName: string, text: string, writeByteOrderMark: boolean, onError: (message: string) => void) { try { performance.mark("beforeIOWrite"); - // PERF: Checking for directory existence is expensive. - // Instead, assume the directory exists and fall back - // to creating it if the file write fails. // NOTE: If patchWriteFileEnsuringDirectory has been called, - // the file write will do its own directory creation and + // the host.writeFile will do its own directory creation and // the ensureDirectoriesExist call will always be redundant. - try { - host.writeFile!(fileName, text, writeByteOrderMark); - } - catch { - ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName))); - host.writeFile!(fileName, text, writeByteOrderMark); - } + writeFileEnsuringDirectories(fileName, text, writeByteOrderMark, host.writeFile!, host.createDirectory!, host.directoryExists!); performance.mark("afterIOWrite"); performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite"); From d2fab65df691b998c5a1acb2fcbca9c25e493b8d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Oct 2019 17:04:45 -0700 Subject: [PATCH 05/63] Added test. --- src/compiler/types.ts | 1 + ...InsertQuestionDotWithUserPreferencesOff.ts | 20 +++++++++++++++++++ tests/cases/fourslash/fourslash.ts | 1 + 3 files changed, 22 insertions(+) create mode 100644 tests/cases/fourslash/completionNoAutoInsertQuestionDotWithUserPreferencesOff.ts diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 03b849b36c7..b444c9d1042 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -6441,6 +6441,7 @@ namespace ts { readonly disableSuggestions?: boolean; readonly quotePreference?: "auto" | "double" | "single"; readonly includeCompletionsForModuleExports?: boolean; + readonly includeAutomaticOptionalChainCompletions?: boolean; readonly includeCompletionsWithInsertText?: boolean; readonly importModuleSpecifierPreference?: "relative" | "non-relative"; /** Determines whether we import `foo/index.ts` as "foo", "foo/index", or "foo/index.js" */ diff --git a/tests/cases/fourslash/completionNoAutoInsertQuestionDotWithUserPreferencesOff.ts b/tests/cases/fourslash/completionNoAutoInsertQuestionDotWithUserPreferencesOff.ts new file mode 100644 index 00000000000..a1071a37f93 --- /dev/null +++ b/tests/cases/fourslash/completionNoAutoInsertQuestionDotWithUserPreferencesOff.ts @@ -0,0 +1,20 @@ +/// +// @strict: true + +//// interface User { +//// address?: { +//// city: string; +//// "postal code": string; +//// } +//// }; +//// declare const user: User; +//// user.address[|./**/|] + +verify.completions({ + marker: "", + exact: [], + preferences: { + includeInsertTextCompletions: true, + includeAutomaticOptionalChainCompletions: false + }, +}); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 5672f430434..cd184df3bed 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -583,6 +583,7 @@ declare namespace FourSlashInterface { readonly quotePreference?: "double" | "single"; readonly includeCompletionsForModuleExports?: boolean; readonly includeInsertTextCompletions?: boolean; + readonly includeAutomaticOptionalChainCompletions?: boolean; readonly importModuleSpecifierPreference?: "relative" | "non-relative"; readonly importModuleSpecifierEnding?: "minimal" | "index" | "js"; } From 73e9715da5584b8be4001cdf5746e4d42516a57e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Oct 2019 17:05:08 -0700 Subject: [PATCH 06/63] Added option 'includeAutomaticOptionalChainCompletions' to disable '?.' completions. --- src/services/completions.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/services/completions.ts b/src/services/completions.ts index 11f92c3d4eb..75b0d3a1c1d 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -338,7 +338,12 @@ namespace ts.Completions { ): CompletionEntry | undefined { let insertText: string | undefined; let replacementSpan: TextSpan | undefined; + const insertQuestionDot = origin && originIsNullableMember(origin); + if (insertQuestionDot && preferences.includeAutomaticOptionalChainCompletions === false) { + return undefined; + } + const useBraces = origin && originIsSymbolMember(origin) || needsConvertPropertyAccess; if (origin && originIsThisType(origin)) { insertText = needsConvertPropertyAccess From 15445e156a8f26d7fa5db4fe90e510c66011d689 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Oct 2019 17:17:19 -0700 Subject: [PATCH 07/63] Add user preference to the protocol. --- src/server/protocol.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/server/protocol.ts b/src/server/protocol.ts index c86876f1caa..fb0969fbefd 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -3007,6 +3007,12 @@ namespace ts.server.protocol { * For those entries, The `insertText` and `replacementSpan` properties will be set to change from `.x` property access to `["x"]`. */ readonly includeCompletionsWithInsertText?: boolean; + /** + * Unless this option is disabled, or `includeCompletionsWithInsertText` is not enabled, + * member completion lists triggered with `.` will include entries on potentially-null and potentially-undefined + * values, with insertion text to replace preceding `.` tokens with `?.`. + */ + readonly includeAutomaticOptionalChainCompletions?: boolean; readonly importModuleSpecifierPreference?: "relative" | "non-relative"; readonly allowTextChangesInNewFiles?: boolean; readonly lazyConfiguredProjectsFromExternalProject?: boolean; From 3d7451c08f98f6710414fe2c90c4a4d1d5709b06 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Oct 2019 17:40:41 -0700 Subject: [PATCH 08/63] Accepted baselines. --- tests/baselines/reference/api/tsserverlibrary.d.ts | 7 +++++++ tests/baselines/reference/api/typescript.d.ts | 1 + 2 files changed, 8 insertions(+) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index aa1945e74b9..9aef5232027 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3171,6 +3171,7 @@ declare namespace ts { readonly disableSuggestions?: boolean; readonly quotePreference?: "auto" | "double" | "single"; readonly includeCompletionsForModuleExports?: boolean; + readonly includeAutomaticOptionalChainCompletions?: boolean; readonly includeCompletionsWithInsertText?: boolean; readonly importModuleSpecifierPreference?: "relative" | "non-relative"; /** Determines whether we import `foo/index.ts` as "foo", "foo/index", or "foo/index.js" */ @@ -8295,6 +8296,12 @@ declare namespace ts.server.protocol { * For those entries, The `insertText` and `replacementSpan` properties will be set to change from `.x` property access to `["x"]`. */ readonly includeCompletionsWithInsertText?: boolean; + /** + * Unless this option is disabled, or `includeCompletionsWithInsertText` is not enabled, + * member completion lists triggered with `.` will include entries on potentially-null and potentially-undefined + * values, with insertion text to replace preceding `.` tokens with `?.`. + */ + readonly includeAutomaticOptionalChainCompletions?: boolean; readonly importModuleSpecifierPreference?: "relative" | "non-relative"; readonly allowTextChangesInNewFiles?: boolean; readonly lazyConfiguredProjectsFromExternalProject?: boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 7c756d8a0a3..7361ccb6768 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3171,6 +3171,7 @@ declare namespace ts { readonly disableSuggestions?: boolean; readonly quotePreference?: "auto" | "double" | "single"; readonly includeCompletionsForModuleExports?: boolean; + readonly includeAutomaticOptionalChainCompletions?: boolean; readonly includeCompletionsWithInsertText?: boolean; readonly importModuleSpecifierPreference?: "relative" | "non-relative"; /** Determines whether we import `foo/index.ts` as "foo", "foo/index", or "foo/index.js" */ From 85e09134be6fbd0077486274672d4f67748e0203 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Oct 2019 17:45:13 -0700 Subject: [PATCH 09/63] Update comment. --- src/server/protocol.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/protocol.ts b/src/server/protocol.ts index fb0969fbefd..925e7638f9d 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -3008,7 +3008,7 @@ namespace ts.server.protocol { */ readonly includeCompletionsWithInsertText?: boolean; /** - * Unless this option is disabled, or `includeCompletionsWithInsertText` is not enabled, + * Unless this option is `false`, or `includeCompletionsWithInsertText` is not enabled, * member completion lists triggered with `.` will include entries on potentially-null and potentially-undefined * values, with insertion text to replace preceding `.` tokens with `?.`. */ From 30cca63eaf609261839aee091d36843acef5bb0f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 17 Oct 2019 17:45:25 -0700 Subject: [PATCH 10/63] Accepted baselines. --- tests/baselines/reference/api/tsserverlibrary.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 9aef5232027..b02074e75ef 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -8297,7 +8297,7 @@ declare namespace ts.server.protocol { */ readonly includeCompletionsWithInsertText?: boolean; /** - * Unless this option is disabled, or `includeCompletionsWithInsertText` is not enabled, + * Unless this option is `false`, or `includeCompletionsWithInsertText` is not enabled, * member completion lists triggered with `.` will include entries on potentially-null and potentially-undefined * values, with insertion text to replace preceding `.` tokens with `?.`. */ From d3df927c7ab899eba1d4c575d96de8a03ddc1ffd Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 18 Oct 2019 10:50:03 -0700 Subject: [PATCH 11/63] Optional chain control flow analysis fixes --- src/compiler/checker.ts | 57 ++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 96a783a6c9e..33c7962b647 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19175,20 +19175,25 @@ namespace ts { if (isMatchingReference(reference, expr)) { type = narrowTypeBySwitchOnDiscriminant(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd); } - else if (isMatchingReferenceDiscriminant(expr, type)) { - type = narrowTypeByDiscriminant( - type, - expr as AccessExpression, - t => narrowTypeBySwitchOnDiscriminant(t, flow.switchStatement, flow.clauseStart, flow.clauseEnd)); - } else if (expr.kind === SyntaxKind.TypeOfExpression && isMatchingReference(reference, (expr as TypeOfExpression).expression)) { type = narrowBySwitchOnTypeOf(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd); } - else if (containsMatchingReferenceDiscriminant(reference, expr)) { - type = declaredType; - } - else if (flow.clauseStart === flow.clauseEnd && isExhaustiveSwitchStatement(flow.switchStatement)) { - return unreachableNeverType; + else { + if (strictNullChecks && optionalChainContainsReference(expr, reference)) { + type = narrowTypeBySwitchOptionalChainContainment(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd); + } + if (isMatchingReferenceDiscriminant(expr, type)) { + type = narrowTypeByDiscriminant( + type, + expr as AccessExpression, + t => narrowTypeBySwitchOnDiscriminant(t, flow.switchStatement, flow.clauseStart, flow.clauseEnd)); + } + else if (containsMatchingReferenceDiscriminant(reference, expr)) { + type = declaredType; + } + else if (flow.clauseStart === flow.clauseEnd && isExhaustiveSwitchStatement(flow.switchStatement)) { + return unreachableNeverType; + } } return createFlowType(type, isIncomplete(flowType)); } @@ -19384,12 +19389,12 @@ namespace ts { if (isMatchingReference(reference, right)) { return narrowTypeByEquality(type, operator, left, assumeTrue); } - if (assumeTrue && strictNullChecks) { + if (strictNullChecks) { if (optionalChainContainsReference(left, reference)) { - type = narrowTypeByOptionalChainContainment(type, operator, right); + type = narrowTypeByOptionalChainContainment(type, operator, right, assumeTrue); } else if (optionalChainContainsReference(right, reference)) { - type = narrowTypeByOptionalChainContainment(type, operator, left); + type = narrowTypeByOptionalChainContainment(type, operator, left, assumeTrue); } } if (isMatchingReferenceDiscriminant(left, declaredType)) { @@ -19416,15 +19421,21 @@ namespace ts { return type; } - function narrowTypeByOptionalChainContainment(type: Type, operator: SyntaxKind, value: Expression): Type { - // We are in the true branch of obj?.foo === value or obj?.foo !== value. We remove undefined and null from + function narrowTypeByOptionalChainContainment(type: Type, operator: SyntaxKind, value: Expression, assumeTrue: boolean): Type { + const op = assumeTrue ? operator : + operator === SyntaxKind.EqualsEqualsToken ? SyntaxKind.ExclamationEqualsToken : + operator === SyntaxKind.EqualsEqualsEqualsToken ? SyntaxKind.ExclamationEqualsEqualsToken : + operator === SyntaxKind.ExclamationEqualsToken ? SyntaxKind.EqualsEqualsToken : + operator === SyntaxKind.ExclamationEqualsEqualsToken ? SyntaxKind.EqualsEqualsEqualsToken : + operator; + // We are in a branch of obj?.foo === value or obj?.foo !== value. We remove undefined and null from // the type of obj if (a) the operator is === and the type of value doesn't include undefined or (b) the // operator is !== and the type of value is undefined. const valueType = getTypeOfExpression(value); - return operator === SyntaxKind.EqualsEqualsToken && !(getTypeFacts(valueType) & TypeFacts.EQUndefinedOrNull) || - operator === SyntaxKind.EqualsEqualsEqualsToken && !(getTypeFacts(valueType) & TypeFacts.EQUndefined) || - operator === SyntaxKind.ExclamationEqualsToken && valueType.flags & TypeFlags.Nullable || - operator === SyntaxKind.ExclamationEqualsEqualsToken && valueType.flags & TypeFlags.Undefined ? + return op === SyntaxKind.EqualsEqualsToken && !(getTypeFacts(valueType) & TypeFacts.EQUndefinedOrNull) || + op === SyntaxKind.EqualsEqualsEqualsToken && !(getTypeFacts(valueType) & TypeFacts.EQUndefined) || + op === SyntaxKind.ExclamationEqualsToken && valueType.flags & TypeFlags.Nullable || + op === SyntaxKind.ExclamationEqualsEqualsToken && valueType.flags & TypeFlags.Undefined ? getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull) : type; } @@ -19526,6 +19537,12 @@ namespace ts { } } + function narrowTypeBySwitchOptionalChainContainment(type: Type, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number) { + const noClauseIsDefaultOrUndefined = clauseStart !== clauseEnd && + every(getSwitchClauseTypes(switchStatement).slice(clauseStart, clauseEnd), t => !(t.flags & (TypeFlags.Undefined | TypeFlags.Never))); + return noClauseIsDefaultOrUndefined ? getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull) : type; + } + function narrowTypeBySwitchOnDiscriminant(type: Type, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number) { // We only narrow if all case expressions specify // values with unit types, except for the case where From 9b6a02716798145a2edad7369178e02971fd9636 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 18 Oct 2019 13:03:25 -0700 Subject: [PATCH 12/63] Perform checks prior to calling `addTypeProperties`. --- src/services/completions.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index 75b0d3a1c1d..ac54cf9c69d 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -340,10 +340,6 @@ namespace ts.Completions { let replacementSpan: TextSpan | undefined; const insertQuestionDot = origin && originIsNullableMember(origin); - if (insertQuestionDot && preferences.includeAutomaticOptionalChainCompletions === false) { - return undefined; - } - const useBraces = origin && originIsSymbolMember(origin) || needsConvertPropertyAccess; if (origin && originIsThisType(origin)) { insertText = needsConvertPropertyAccess @@ -785,7 +781,7 @@ namespace ts.Completions { sourceFile: SourceFile, isUncheckedFile: boolean, position: number, - preferences: Pick, + preferences: Pick, detailsEntryId: CompletionEntryIdentifier | undefined, host: LanguageServiceHost, ): CompletionData | Request | undefined { @@ -1124,6 +1120,9 @@ namespace ts.Completions { insertQuestionDot = isRightOfDot && !isRightOfQuestionDot; type = type.getNonNullableType(); } + if (insertQuestionDot && preferences.includeAutomaticOptionalChainCompletions === false) { + return; + } addTypeProperties(type, !!(node.flags & NodeFlags.AwaitContext), insertQuestionDot); } @@ -1145,6 +1144,9 @@ namespace ts.Completions { insertQuestionDot = isRightOfDot && !isRightOfQuestionDot; type = type.getNonNullableType(); } + if (insertQuestionDot && preferences.includeAutomaticOptionalChainCompletions === false) { + return; + } addTypeProperties(type, !!(node.flags & NodeFlags.AwaitContext), insertQuestionDot); } } From 218bbcd669733b2df752501202730d8868480fac Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 18 Oct 2019 15:23:56 -0700 Subject: [PATCH 13/63] Don't immediately return in getMemberSymbols. --- src/services/completions.ts | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index ac54cf9c69d..076cc32f374 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1117,11 +1117,17 @@ namespace ts.Completions { let type = typeChecker.getTypeOfSymbolAtLocation(symbol, node).getNonOptionalType(); let insertQuestionDot = false; if (type.isNullableType()) { - insertQuestionDot = isRightOfDot && !isRightOfQuestionDot; - type = type.getNonNullableType(); - } - if (insertQuestionDot && preferences.includeAutomaticOptionalChainCompletions === false) { - return; + const canCorrectToQuestionDot = + isRightOfDot && + !isRightOfQuestionDot && + preferences.includeAutomaticOptionalChainCompletions !== false; + + if (canCorrectToQuestionDot || isRightOfQuestionDot) { + type = type.getNonNullableType(); + if (canCorrectToQuestionDot) { + insertQuestionDot = true; + } + } } addTypeProperties(type, !!(node.flags & NodeFlags.AwaitContext), insertQuestionDot); } @@ -1141,11 +1147,17 @@ namespace ts.Completions { let type = typeChecker.getTypeAtLocation(node).getNonOptionalType(); let insertQuestionDot = false; if (type.isNullableType()) { - insertQuestionDot = isRightOfDot && !isRightOfQuestionDot; - type = type.getNonNullableType(); - } - if (insertQuestionDot && preferences.includeAutomaticOptionalChainCompletions === false) { - return; + const canCorrectToQuestionDot = + isRightOfDot && + !isRightOfQuestionDot && + preferences.includeAutomaticOptionalChainCompletions !== false; + + if (canCorrectToQuestionDot || isRightOfQuestionDot) { + type = type.getNonNullableType(); + if (canCorrectToQuestionDot) { + insertQuestionDot = true; + } + } } addTypeProperties(type, !!(node.flags & NodeFlags.AwaitContext), insertQuestionDot); } From fbc070f328a98e8296c710c3cd1bf6877cffbdf0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 18 Oct 2019 16:12:26 -0700 Subject: [PATCH 14/63] Extend tsconfig.release.json from the sibling tsconfig.json to ensure files aren't forgotten. --- src/tsc/tsconfig.release.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/tsc/tsconfig.release.json b/src/tsc/tsconfig.release.json index 45a7577a342..2d2d28ac661 100644 --- a/src/tsc/tsconfig.release.json +++ b/src/tsc/tsconfig.release.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig-base", + "extends": "../tsconfig.json", "compilerOptions": { "outFile": "../../built/local/tsc.release.js", "stripInternal": true, @@ -10,9 +10,6 @@ "composite": false, "incremental": true }, - "files": [ - "tsc.ts" - ], "references": [ { "path": "../compiler/tsconfig.release.json", "prepend": true } ] From 98fe34225c28803b40ea67a2cb9ef7b17e64c88b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 18 Oct 2019 16:33:55 -0700 Subject: [PATCH 15/63] Handle more cases --- src/compiler/checker.ts | 60 +++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 33c7962b647..2c670397fe2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18787,6 +18787,14 @@ namespace ts { signature.declaration && (getReturnTypeFromAnnotation(signature.declaration) || unknownType).flags & TypeFlags.Never); } + function getTypePredicateArgument(predicate: TypePredicate, callExpression: CallExpression) { + if (predicate.kind === TypePredicateKind.Identifier || predicate.kind === TypePredicateKind.AssertsIdentifier) { + return callExpression.arguments[predicate.parameterIndex]; + } + const invokedExpression = skipParentheses(callExpression.expression); + return isAccessExpression(invokedExpression) ? skipParentheses(invokedExpression.expression) : undefined; + } + function reportFlowControlError(node: Node) { const block = findAncestor(node, isFunctionOrModuleBlock); const sourceFile = getSourceFileOfNode(node); @@ -19338,6 +19346,9 @@ namespace ts { if (isMatchingReference(reference, expr)) { return getTypeWithFacts(type, assumeTrue ? TypeFacts.Truthy : TypeFacts.Falsy); } + if (strictNullChecks && assumeTrue && optionalChainContainsReference(expr, reference)) { + type = getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull); + } if (isMatchingReferenceDiscriminant(expr, declaredType)) { return narrowTypeByDiscriminant(type, expr, t => getTypeWithFacts(t, assumeTrue ? TypeFacts.Truthy : TypeFacts.Falsy)); } @@ -19422,21 +19433,13 @@ namespace ts { } function narrowTypeByOptionalChainContainment(type: Type, operator: SyntaxKind, value: Expression, assumeTrue: boolean): Type { - const op = assumeTrue ? operator : - operator === SyntaxKind.EqualsEqualsToken ? SyntaxKind.ExclamationEqualsToken : - operator === SyntaxKind.EqualsEqualsEqualsToken ? SyntaxKind.ExclamationEqualsEqualsToken : - operator === SyntaxKind.ExclamationEqualsToken ? SyntaxKind.EqualsEqualsToken : - operator === SyntaxKind.ExclamationEqualsEqualsToken ? SyntaxKind.EqualsEqualsEqualsToken : - operator; // We are in a branch of obj?.foo === value or obj?.foo !== value. We remove undefined and null from // the type of obj if (a) the operator is === and the type of value doesn't include undefined or (b) the // operator is !== and the type of value is undefined. - const valueType = getTypeOfExpression(value); - return op === SyntaxKind.EqualsEqualsToken && !(getTypeFacts(valueType) & TypeFacts.EQUndefinedOrNull) || - op === SyntaxKind.EqualsEqualsEqualsToken && !(getTypeFacts(valueType) & TypeFacts.EQUndefined) || - op === SyntaxKind.ExclamationEqualsToken && valueType.flags & TypeFlags.Nullable || - op === SyntaxKind.ExclamationEqualsEqualsToken && valueType.flags & TypeFlags.Undefined ? - getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull) : type; + const effectiveTrue = operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.EqualsEqualsEqualsToken ? assumeTrue : !assumeTrue; + const doubleEquals = operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsToken; + const valueNonNullish = !(getTypeFacts(getTypeOfExpression(value)) & (doubleEquals ? TypeFacts.EQUndefinedOrNull : TypeFacts.EQUndefined)); + return effectiveTrue === valueNonNullish ? getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull) : type; } function narrowTypeByEquality(type: Type, operator: SyntaxKind, value: Expression, assumeTrue: boolean): Type { @@ -19487,10 +19490,12 @@ namespace ts { function narrowTypeByTypeof(type: Type, typeOfExpr: TypeOfExpression, operator: SyntaxKind, literal: LiteralExpression, assumeTrue: boolean): Type { // We have '==', '!=', '===', or !==' operator with 'typeof xxx' and string literal operands + if (operator === SyntaxKind.ExclamationEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken) { + assumeTrue = !assumeTrue; + } const target = getReferenceCandidate(typeOfExpr.expression); if (!isMatchingReference(reference, target)) { - if (assumeTrue && (operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.EqualsEqualsEqualsToken) && - strictNullChecks && optionalChainContainsReference(target, reference)) { + if (strictNullChecks && optionalChainContainsReference(target, reference) && assumeTrue === (literal.text !== "undefined")) { return getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull); } // For a reference of the form 'x.y', a 'typeof x === ...' type guard resets the @@ -19500,9 +19505,6 @@ namespace ts { } return type; } - if (operator === SyntaxKind.ExclamationEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken) { - assumeTrue = !assumeTrue; - } if (type.flags & TypeFlags.Any && literal.text === "function") { return type; } @@ -19763,32 +19765,20 @@ namespace ts { function narrowTypeByTypePredicate(type: Type, predicate: TypePredicate, callExpression: CallExpression, assumeTrue: boolean): Type { // Don't narrow from 'any' if the predicate type is exactly 'Object' or 'Function' - if (isTypeAny(type) && (predicate.type === globalObjectType || predicate.type === globalFunctionType)) { - return type; - } - if (predicate.kind === TypePredicateKind.Identifier || predicate.kind === TypePredicateKind.AssertsIdentifier) { - const predicateArgument = callExpression.arguments[predicate.parameterIndex]; - if (predicateArgument && predicate.type) { + if (predicate.type && !(isTypeAny(type) && (predicate.type === globalObjectType || predicate.type === globalFunctionType))) { + const predicateArgument = getTypePredicateArgument(predicate, callExpression); + if (predicateArgument) { if (isMatchingReference(reference, predicateArgument)) { return getNarrowedType(type, predicate.type, assumeTrue, isTypeSubtypeOf); } + if (strictNullChecks && assumeTrue && !(getTypeFacts(predicate.type) & TypeFacts.EQUndefined)) { + type = getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull); + } if (containsMatchingReference(reference, predicateArgument)) { return declaredType; } } } - else { - const invokedExpression = skipParentheses(callExpression.expression); - if (isAccessExpression(invokedExpression) && predicate.type) { - const possibleReference = skipParentheses(invokedExpression.expression); - if (isMatchingReference(reference, possibleReference)) { - return getNarrowedType(type, predicate.type, assumeTrue, isTypeSubtypeOf); - } - if (containsMatchingReference(reference, possibleReference)) { - return declaredType; - } - } - } return type; } From 0a0833b376c6b0b1eb89ae4c7772520ecc81d02e Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Fri, 18 Oct 2019 16:35:58 -0400 Subject: [PATCH 16/63] Improve the launch template --- .vscode/launch.template.json | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/.vscode/launch.template.json b/.vscode/launch.template.json index 4ba7f8ab880..ede5febb3bf 100644 --- a/.vscode/launch.template.json +++ b/.vscode/launch.template.json @@ -1,5 +1,17 @@ -// Rename this file 'launch.json' or merge its -// contents into your existing configurations. +/* + + Copy this file into '.vscode/launch.json' or merge its + contents into your existing configurations. + + If you want to remove the errors in comments for all JSON + files, add this to your settings in ~/.vscode/User/settings.json + + "files.associations": { + "*.json": "jsonc" + }, + +*/ + { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. @@ -10,7 +22,7 @@ "type": "node", "protocol": "inspector", "request": "launch", - "name": "Mocha Tests (currently opened test)", + "name": "Mocha Tests (currently opened test)", "runtimeArgs": ["--nolazy"], "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", "args": [ @@ -20,6 +32,8 @@ "--colors", "built/local/run.js", "-f", + // You can change this to be the name of a specific test file (without the file extension) + // to consistently launch the same test "${fileBasenameNoExtension}", "--skip-percent", "0" @@ -34,6 +48,13 @@ "outFiles": [ "${workspaceRoot}/built/local/run.js" ] + }, + { + // See: https://github.com/microsoft/TypeScript/wiki/Debugging-Language-Service-in-VS-Code + "type": "node", + "request": "attach", + "name": "Attach to VS Code TS Server via Port", + "processId": "${command:PickProcess}" } ] -} \ No newline at end of file +} From 60b391507e0ef2fa8d88c93312ccc0931d1ca0f2 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 19 Oct 2019 07:04:24 -0700 Subject: [PATCH 17/63] And a few more --- src/compiler/checker.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2c670397fe2..7c6336276f9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19187,13 +19187,18 @@ namespace ts { type = narrowBySwitchOnTypeOf(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd); } else { - if (strictNullChecks && optionalChainContainsReference(expr, reference)) { - type = narrowTypeBySwitchOptionalChainContainment(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd); + if (strictNullChecks) { + if (optionalChainContainsReference(expr, reference)) { + type = narrowTypeBySwitchOptionalChainContainment(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd, + t => !(t.flags & (TypeFlags.Undefined | TypeFlags.Never))); + } + else if (expr.kind === SyntaxKind.TypeOfExpression && optionalChainContainsReference((expr as TypeOfExpression).expression, reference)) { + type = narrowTypeBySwitchOptionalChainContainment(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd, + t => !(t.flags & TypeFlags.Never || t.flags & TypeFlags.StringLiteral && (t).value === "undefined")); + } } if (isMatchingReferenceDiscriminant(expr, type)) { - type = narrowTypeByDiscriminant( - type, - expr as AccessExpression, + type = narrowTypeByDiscriminant(type, expr as AccessExpression, t => narrowTypeBySwitchOnDiscriminant(t, flow.switchStatement, flow.clauseStart, flow.clauseEnd)); } else if (containsMatchingReferenceDiscriminant(reference, expr)) { @@ -19539,10 +19544,9 @@ namespace ts { } } - function narrowTypeBySwitchOptionalChainContainment(type: Type, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number) { - const noClauseIsDefaultOrUndefined = clauseStart !== clauseEnd && - every(getSwitchClauseTypes(switchStatement).slice(clauseStart, clauseEnd), t => !(t.flags & (TypeFlags.Undefined | TypeFlags.Never))); - return noClauseIsDefaultOrUndefined ? getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull) : type; + function narrowTypeBySwitchOptionalChainContainment(type: Type, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number, clauseCheck: (type: Type) => boolean) { + const everyClauseChecks = clauseStart !== clauseEnd && every(getSwitchClauseTypes(switchStatement).slice(clauseStart, clauseEnd), clauseCheck); + return everyClauseChecks ? getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull) : type; } function narrowTypeBySwitchOnDiscriminant(type: Type, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number) { @@ -19771,8 +19775,9 @@ namespace ts { if (isMatchingReference(reference, predicateArgument)) { return getNarrowedType(type, predicate.type, assumeTrue, isTypeSubtypeOf); } - if (strictNullChecks && assumeTrue && !(getTypeFacts(predicate.type) & TypeFacts.EQUndefined)) { - type = getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull); + if (strictNullChecks && assumeTrue && optionalChainContainsReference(predicateArgument, reference) && + !(getTypeFacts(predicate.type) & TypeFacts.EQUndefined)) { + return getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull); } if (containsMatchingReference(reference, predicateArgument)) { return declaredType; From d218a31a7dc5ec5407ef7b3cbed4c1338b0855e7 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 19 Oct 2019 10:51:59 -0700 Subject: [PATCH 18/63] Add tests --- .../controlFlow/controlFlowOptionalChain.ts | 197 ++++++++++++++++++ 1 file changed, 197 insertions(+) diff --git a/tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts b/tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts index f54275f309c..49ebd3807db 100644 --- a/tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts +++ b/tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts @@ -302,6 +302,60 @@ function f14(o: Thing | null) { } } +function f15(o: Thing | undefined, value: number) { + if (o?.foo === value) { + o.foo; + } + else { + o.foo; // Error + } + if (o?.foo !== value) { + o.foo; // Error + } + else { + o.foo; + } + if (o?.foo == value) { + o.foo; + } + else { + o.foo; // Error + } + if (o?.foo != value) { + o.foo; // Error + } + else { + o.foo; + } +} + +function f16(o: Thing | undefined) { + if (o?.foo === undefined) { + o.foo; // Error + } + else { + o.foo; + } + if (o?.foo !== undefined) { + o.foo; + } + else { + o.foo; // Error + } + if (o?.foo == undefined) { + o.foo; // Error + } + else { + o.foo; + } + if (o?.foo != undefined) { + o.foo; + } + else { + o.foo; // Error + } +} + function f20(o: Thing | undefined) { if (typeof o?.foo === "number") { o.foo; @@ -331,3 +385,146 @@ function f21(o: Thing | null) { o.baz; } } + +function f22(o: Thing | undefined) { + if (typeof o?.foo === "number") { + o.foo; + } + else { + o.foo; // Error + } + if (typeof o?.foo !== "number") { + o.foo; // Error + } + else { + o.foo; + } + if (typeof o?.foo == "number") { + o.foo; + } + else { + o.foo; // Error + } + if (typeof o?.foo != "number") { + o.foo; // Error + } + else { + o.foo; + } +} + +function f23(o: Thing | undefined) { + if (typeof o?.foo === "undefined") { + o.foo; // Error + } + else { + o.foo; + } + if (typeof o?.foo !== "undefined") { + o.foo; + } + else { + o.foo; // Error + } + if (typeof o?.foo == "undefined") { + o.foo; // Error + } + else { + o.foo; + } + if (typeof o?.foo != "undefined") { + o.foo; + } + else { + o.foo; // Error + } +} + +declare function assert(x: unknown): asserts x; +declare function assertNonNull(x: T): asserts x is NonNullable; + +function f30(o: Thing | undefined) { + if (!!true) { + assert(o?.foo); + o.foo; + } + if (!!true) { + assert(o?.foo === 42); + o.foo; + } + if (!!true) { + assert(typeof o?.foo === "number"); + o.foo; + } + if (!!true) { + assertNonNull(o?.foo); + o.foo; + } +} + +function f40(o: Thing | undefined) { + switch (o?.foo) { + case "abc": + o.foo; + break; + case 42: + o.foo; + break; + case undefined: + o.foo; // Error + break; + default: + o.foo; // Error + break; + } +} + +function f41(o: Thing | undefined) { + switch (typeof o?.foo) { + case "string": + o.foo; + break; + case "number": + o.foo; + break; + case "undefined": + o.foo; // Error + break; + default: + o.foo; // Error + break; + } +} + +// Repros from #34570 + +type Shape = + | { type: 'rectangle', width: number, height: number } + | { type: 'circle', radius: number } + +function getArea(shape?: Shape) { + switch (shape?.type) { + case 'circle': + return Math.PI * shape.radius ** 2 + case 'rectangle': + return shape.width * shape.height + default: + return 0 + } +} + +type Feature = { + id: string; + geometry?: { + type: string; + coordinates: number[]; + }; +}; + + +function extractCoordinates(f: Feature): number[] { + if (f.geometry?.type !== 'test') { + return []; + } + return f.geometry.coordinates; +} From ee846d95af9d55280fc5cc97741403268ef9b242 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 19 Oct 2019 10:52:04 -0700 Subject: [PATCH 19/63] Accept new baselines --- .../controlFlowOptionalChain.errors.txt | 259 +++++++- .../reference/controlFlowOptionalChain.js | 376 +++++++++++ .../controlFlowOptionalChain.symbols | 572 ++++++++++++++++- .../reference/controlFlowOptionalChain.types | 599 ++++++++++++++++++ 4 files changed, 1786 insertions(+), 20 deletions(-) diff --git a/tests/baselines/reference/controlFlowOptionalChain.errors.txt b/tests/baselines/reference/controlFlowOptionalChain.errors.txt index 987dca335dc..ee77494d1c8 100644 --- a/tests/baselines/reference/controlFlowOptionalChain.errors.txt +++ b/tests/baselines/reference/controlFlowOptionalChain.errors.txt @@ -31,9 +31,29 @@ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(244,9): error TS tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(271,9): error TS2532: Object is possibly 'undefined'. tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(274,9): error TS2532: Object is possibly 'undefined'. tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(277,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(307,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(310,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(319,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(322,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(331,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(340,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(343,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(352,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(391,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(394,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(403,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(406,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(415,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(424,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(427,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(436,9): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(471,13): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(474,13): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(488,13): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(491,13): error TS2532: Object is possibly 'undefined'. -==== tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts (33 errors) ==== +==== tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts (53 errors) ==== // assignments in shortcutting chain declare const o: undefined | { [key: string]: any; @@ -401,6 +421,76 @@ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(277,9): error TS } } + function f15(o: Thing | undefined, value: number) { + if (o?.foo === value) { + o.foo; + } + else { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + if (o?.foo !== value) { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + else { + o.foo; + } + if (o?.foo == value) { + o.foo; + } + else { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + if (o?.foo != value) { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + else { + o.foo; + } + } + + function f16(o: Thing | undefined) { + if (o?.foo === undefined) { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + else { + o.foo; + } + if (o?.foo !== undefined) { + o.foo; + } + else { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + if (o?.foo == undefined) { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + else { + o.foo; + } + if (o?.foo != undefined) { + o.foo; + } + else { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + } + function f20(o: Thing | undefined) { if (typeof o?.foo === "number") { o.foo; @@ -430,4 +520,171 @@ tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts(277,9): error TS o.baz; } } + + function f22(o: Thing | undefined) { + if (typeof o?.foo === "number") { + o.foo; + } + else { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + if (typeof o?.foo !== "number") { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + else { + o.foo; + } + if (typeof o?.foo == "number") { + o.foo; + } + else { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + if (typeof o?.foo != "number") { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + else { + o.foo; + } + } + + function f23(o: Thing | undefined) { + if (typeof o?.foo === "undefined") { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + else { + o.foo; + } + if (typeof o?.foo !== "undefined") { + o.foo; + } + else { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + if (typeof o?.foo == "undefined") { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + else { + o.foo; + } + if (typeof o?.foo != "undefined") { + o.foo; + } + else { + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + } + + declare function assert(x: unknown): asserts x; + declare function assertNonNull(x: T): asserts x is NonNullable; + + function f30(o: Thing | undefined) { + if (!!true) { + assert(o?.foo); + o.foo; + } + if (!!true) { + assert(o?.foo === 42); + o.foo; + } + if (!!true) { + assert(typeof o?.foo === "number"); + o.foo; + } + if (!!true) { + assertNonNull(o?.foo); + o.foo; + } + } + + function f40(o: Thing | undefined) { + switch (o?.foo) { + case "abc": + o.foo; + break; + case 42: + o.foo; + break; + case undefined: + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + break; + default: + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + break; + } + } + + function f41(o: Thing | undefined) { + switch (typeof o?.foo) { + case "string": + o.foo; + break; + case "number": + o.foo; + break; + case "undefined": + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + break; + default: + o.foo; // Error + ~ +!!! error TS2532: Object is possibly 'undefined'. + break; + } + } + + // Repros from #34570 + + type Shape = + | { type: 'rectangle', width: number, height: number } + | { type: 'circle', radius: number } + + function getArea(shape?: Shape) { + switch (shape?.type) { + case 'circle': + return Math.PI * shape.radius ** 2 + case 'rectangle': + return shape.width * shape.height + default: + return 0 + } + } + + type Feature = { + id: string; + geometry?: { + type: string; + coordinates: number[]; + }; + }; + + + function extractCoordinates(f: Feature): number[] { + if (f.geometry?.type !== 'test') { + return []; + } + return f.geometry.coordinates; + } \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowOptionalChain.js b/tests/baselines/reference/controlFlowOptionalChain.js index 21451528035..3bb2bab1c0d 100644 --- a/tests/baselines/reference/controlFlowOptionalChain.js +++ b/tests/baselines/reference/controlFlowOptionalChain.js @@ -300,6 +300,60 @@ function f14(o: Thing | null) { } } +function f15(o: Thing | undefined, value: number) { + if (o?.foo === value) { + o.foo; + } + else { + o.foo; // Error + } + if (o?.foo !== value) { + o.foo; // Error + } + else { + o.foo; + } + if (o?.foo == value) { + o.foo; + } + else { + o.foo; // Error + } + if (o?.foo != value) { + o.foo; // Error + } + else { + o.foo; + } +} + +function f16(o: Thing | undefined) { + if (o?.foo === undefined) { + o.foo; // Error + } + else { + o.foo; + } + if (o?.foo !== undefined) { + o.foo; + } + else { + o.foo; // Error + } + if (o?.foo == undefined) { + o.foo; // Error + } + else { + o.foo; + } + if (o?.foo != undefined) { + o.foo; + } + else { + o.foo; // Error + } +} + function f20(o: Thing | undefined) { if (typeof o?.foo === "number") { o.foo; @@ -329,6 +383,149 @@ function f21(o: Thing | null) { o.baz; } } + +function f22(o: Thing | undefined) { + if (typeof o?.foo === "number") { + o.foo; + } + else { + o.foo; // Error + } + if (typeof o?.foo !== "number") { + o.foo; // Error + } + else { + o.foo; + } + if (typeof o?.foo == "number") { + o.foo; + } + else { + o.foo; // Error + } + if (typeof o?.foo != "number") { + o.foo; // Error + } + else { + o.foo; + } +} + +function f23(o: Thing | undefined) { + if (typeof o?.foo === "undefined") { + o.foo; // Error + } + else { + o.foo; + } + if (typeof o?.foo !== "undefined") { + o.foo; + } + else { + o.foo; // Error + } + if (typeof o?.foo == "undefined") { + o.foo; // Error + } + else { + o.foo; + } + if (typeof o?.foo != "undefined") { + o.foo; + } + else { + o.foo; // Error + } +} + +declare function assert(x: unknown): asserts x; +declare function assertNonNull(x: T): asserts x is NonNullable; + +function f30(o: Thing | undefined) { + if (!!true) { + assert(o?.foo); + o.foo; + } + if (!!true) { + assert(o?.foo === 42); + o.foo; + } + if (!!true) { + assert(typeof o?.foo === "number"); + o.foo; + } + if (!!true) { + assertNonNull(o?.foo); + o.foo; + } +} + +function f40(o: Thing | undefined) { + switch (o?.foo) { + case "abc": + o.foo; + break; + case 42: + o.foo; + break; + case undefined: + o.foo; // Error + break; + default: + o.foo; // Error + break; + } +} + +function f41(o: Thing | undefined) { + switch (typeof o?.foo) { + case "string": + o.foo; + break; + case "number": + o.foo; + break; + case "undefined": + o.foo; // Error + break; + default: + o.foo; // Error + break; + } +} + +// Repros from #34570 + +type Shape = + | { type: 'rectangle', width: number, height: number } + | { type: 'circle', radius: number } + +function getArea(shape?: Shape) { + switch (shape?.type) { + case 'circle': + return Math.PI * shape.radius ** 2 + case 'rectangle': + return shape.width * shape.height + default: + return 0 + } +} + +type Feature = { + id: string; + geometry?: { + type: string; + coordinates: number[]; + }; +}; + + +function extractCoordinates(f: Feature): number[] { + if (f.geometry?.type !== 'test') { + return []; + } + return f.geometry.coordinates; +} //// [controlFlowOptionalChain.js] @@ -594,6 +791,60 @@ function f14(o) { o.bar; } } +function f15(o, value) { + var _a, _b, _c, _d; + if (((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === value) { + o.foo; + } + else { + o.foo; // Error + } + if (((_b = o) === null || _b === void 0 ? void 0 : _b.foo) !== value) { + o.foo; // Error + } + else { + o.foo; + } + if (((_c = o) === null || _c === void 0 ? void 0 : _c.foo) == value) { + o.foo; + } + else { + o.foo; // Error + } + if (((_d = o) === null || _d === void 0 ? void 0 : _d.foo) != value) { + o.foo; // Error + } + else { + o.foo; + } +} +function f16(o) { + var _a, _b, _c, _d; + if (((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === undefined) { + o.foo; // Error + } + else { + o.foo; + } + if (((_b = o) === null || _b === void 0 ? void 0 : _b.foo) !== undefined) { + o.foo; + } + else { + o.foo; // Error + } + if (((_c = o) === null || _c === void 0 ? void 0 : _c.foo) == undefined) { + o.foo; // Error + } + else { + o.foo; + } + if (((_d = o) === null || _d === void 0 ? void 0 : _d.foo) != undefined) { + o.foo; + } + else { + o.foo; // Error + } +} function f20(o) { var _a, _b, _c, _d; if (typeof ((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === "number") { @@ -624,3 +875,128 @@ function f21(o) { o.baz; } } +function f22(o) { + var _a, _b, _c, _d; + if (typeof ((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === "number") { + o.foo; + } + else { + o.foo; // Error + } + if (typeof ((_b = o) === null || _b === void 0 ? void 0 : _b.foo) !== "number") { + o.foo; // Error + } + else { + o.foo; + } + if (typeof ((_c = o) === null || _c === void 0 ? void 0 : _c.foo) == "number") { + o.foo; + } + else { + o.foo; // Error + } + if (typeof ((_d = o) === null || _d === void 0 ? void 0 : _d.foo) != "number") { + o.foo; // Error + } + else { + o.foo; + } +} +function f23(o) { + var _a, _b, _c, _d; + if (typeof ((_a = o) === null || _a === void 0 ? void 0 : _a.foo) === "undefined") { + o.foo; // Error + } + else { + o.foo; + } + if (typeof ((_b = o) === null || _b === void 0 ? void 0 : _b.foo) !== "undefined") { + o.foo; + } + else { + o.foo; // Error + } + if (typeof ((_c = o) === null || _c === void 0 ? void 0 : _c.foo) == "undefined") { + o.foo; // Error + } + else { + o.foo; + } + if (typeof ((_d = o) === null || _d === void 0 ? void 0 : _d.foo) != "undefined") { + o.foo; + } + else { + o.foo; // Error + } +} +function f30(o) { + var _a, _b, _c, _d; + if (!!true) { + assert((_a = o) === null || _a === void 0 ? void 0 : _a.foo); + o.foo; + } + if (!!true) { + assert(((_b = o) === null || _b === void 0 ? void 0 : _b.foo) === 42); + o.foo; + } + if (!!true) { + assert(typeof ((_c = o) === null || _c === void 0 ? void 0 : _c.foo) === "number"); + o.foo; + } + if (!!true) { + assertNonNull((_d = o) === null || _d === void 0 ? void 0 : _d.foo); + o.foo; + } +} +function f40(o) { + var _a; + switch ((_a = o) === null || _a === void 0 ? void 0 : _a.foo) { + case "abc": + o.foo; + break; + case 42: + o.foo; + break; + case undefined: + o.foo; // Error + break; + default: + o.foo; // Error + break; + } +} +function f41(o) { + var _a; + switch (typeof ((_a = o) === null || _a === void 0 ? void 0 : _a.foo)) { + case "string": + o.foo; + break; + case "number": + o.foo; + break; + case "undefined": + o.foo; // Error + break; + default: + o.foo; // Error + break; + } +} +function getArea(shape) { + var _a; + switch ((_a = shape) === null || _a === void 0 ? void 0 : _a.type) { + case 'circle': + return Math.PI * Math.pow(shape.radius, 2); + case 'rectangle': + return shape.width * shape.height; + default: + return 0; + } +} +function extractCoordinates(f) { + var _a; + if (((_a = f.geometry) === null || _a === void 0 ? void 0 : _a.type) !== 'test') { + return []; + } + return f.geometry.coordinates; +} diff --git a/tests/baselines/reference/controlFlowOptionalChain.symbols b/tests/baselines/reference/controlFlowOptionalChain.symbols index 2665a960a56..cac0899cc89 100644 --- a/tests/baselines/reference/controlFlowOptionalChain.symbols +++ b/tests/baselines/reference/controlFlowOptionalChain.symbols @@ -1039,93 +1039,627 @@ function f14(o: Thing | null) { } } -function f20(o: Thing | undefined) { ->f20 : Symbol(f20, Decl(controlFlowOptionalChain.ts, 299, 1)) +function f15(o: Thing | undefined, value: number) { +>f15 : Symbol(f15, Decl(controlFlowOptionalChain.ts, 299, 1)) >o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) >Thing : Symbol(Thing, Decl(controlFlowOptionalChain.ts, 159, 1)) +>value : Symbol(value, Decl(controlFlowOptionalChain.ts, 301, 34)) - if (typeof o?.foo === "number") { + if (o?.foo === value) { >o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) >o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) >foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>value : Symbol(value, Decl(controlFlowOptionalChain.ts, 301, 34)) o.foo; >o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) >o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) >foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) } - if (typeof o?.["foo"] === "number") { + else { + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) >o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (o?.foo !== value) { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>value : Symbol(value, Decl(controlFlowOptionalChain.ts, 301, 34)) + + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (o?.foo == value) { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>value : Symbol(value, Decl(controlFlowOptionalChain.ts, 301, 34)) + + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (o?.foo != value) { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>value : Symbol(value, Decl(controlFlowOptionalChain.ts, 301, 34)) + + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } +} + +function f16(o: Thing | undefined) { +>f16 : Symbol(f16, Decl(controlFlowOptionalChain.ts, 326, 1)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 328, 13)) +>Thing : Symbol(Thing, Decl(controlFlowOptionalChain.ts, 159, 1)) + + if (o?.foo === undefined) { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 328, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>undefined : Symbol(undefined) + + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 328, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 328, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (o?.foo !== undefined) { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 328, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>undefined : Symbol(undefined) + + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 328, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 328, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (o?.foo == undefined) { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 328, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>undefined : Symbol(undefined) + + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 328, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 328, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (o?.foo != undefined) { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 328, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>undefined : Symbol(undefined) + + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 328, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 328, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } +} + +function f20(o: Thing | undefined) { +>f20 : Symbol(f20, Decl(controlFlowOptionalChain.ts, 353, 1)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 355, 13)) +>Thing : Symbol(Thing, Decl(controlFlowOptionalChain.ts, 159, 1)) + + if (typeof o?.foo === "number") { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 355, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 355, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (typeof o?.["foo"] === "number") { +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 355, 13)) o["foo"]; ->o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 355, 13)) >"foo" : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) } if (typeof o?.bar() === "number") { >o?.bar : Symbol(bar, Decl(controlFlowOptionalChain.ts, 161, 36)) ->o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 355, 13)) >bar : Symbol(bar, Decl(controlFlowOptionalChain.ts, 161, 36)) o.bar; >o.bar : Symbol(bar, Decl(controlFlowOptionalChain.ts, 161, 36)) ->o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 355, 13)) >bar : Symbol(bar, Decl(controlFlowOptionalChain.ts, 161, 36)) } if (o?.baz instanceof Error) { >o?.baz : Symbol(baz, Decl(controlFlowOptionalChain.ts, 161, 51)) ->o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 355, 13)) >baz : Symbol(baz, Decl(controlFlowOptionalChain.ts, 161, 51)) >Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) o.baz; >o.baz : Symbol(baz, Decl(controlFlowOptionalChain.ts, 161, 51)) ->o : Symbol(o, Decl(controlFlowOptionalChain.ts, 301, 13)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 355, 13)) >baz : Symbol(baz, Decl(controlFlowOptionalChain.ts, 161, 51)) } } function f21(o: Thing | null) { ->f21 : Symbol(f21, Decl(controlFlowOptionalChain.ts, 314, 1)) ->o : Symbol(o, Decl(controlFlowOptionalChain.ts, 316, 13)) +>f21 : Symbol(f21, Decl(controlFlowOptionalChain.ts, 368, 1)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 370, 13)) >Thing : Symbol(Thing, Decl(controlFlowOptionalChain.ts, 159, 1)) if (typeof o?.foo === "number") { >o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) ->o : Symbol(o, Decl(controlFlowOptionalChain.ts, 316, 13)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 370, 13)) >foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) o.foo; >o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) ->o : Symbol(o, Decl(controlFlowOptionalChain.ts, 316, 13)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 370, 13)) >foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) } if (typeof o?.["foo"] === "number") { ->o : Symbol(o, Decl(controlFlowOptionalChain.ts, 316, 13)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 370, 13)) o["foo"]; ->o : Symbol(o, Decl(controlFlowOptionalChain.ts, 316, 13)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 370, 13)) >"foo" : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) } if (typeof o?.bar() === "number") { >o?.bar : Symbol(bar, Decl(controlFlowOptionalChain.ts, 161, 36)) ->o : Symbol(o, Decl(controlFlowOptionalChain.ts, 316, 13)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 370, 13)) >bar : Symbol(bar, Decl(controlFlowOptionalChain.ts, 161, 36)) o.bar; >o.bar : Symbol(bar, Decl(controlFlowOptionalChain.ts, 161, 36)) ->o : Symbol(o, Decl(controlFlowOptionalChain.ts, 316, 13)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 370, 13)) >bar : Symbol(bar, Decl(controlFlowOptionalChain.ts, 161, 36)) } if (o?.baz instanceof Error) { >o?.baz : Symbol(baz, Decl(controlFlowOptionalChain.ts, 161, 51)) ->o : Symbol(o, Decl(controlFlowOptionalChain.ts, 316, 13)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 370, 13)) >baz : Symbol(baz, Decl(controlFlowOptionalChain.ts, 161, 51)) >Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) o.baz; >o.baz : Symbol(baz, Decl(controlFlowOptionalChain.ts, 161, 51)) ->o : Symbol(o, Decl(controlFlowOptionalChain.ts, 316, 13)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 370, 13)) >baz : Symbol(baz, Decl(controlFlowOptionalChain.ts, 161, 51)) } } +function f22(o: Thing | undefined) { +>f22 : Symbol(f22, Decl(controlFlowOptionalChain.ts, 383, 1)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 385, 13)) +>Thing : Symbol(Thing, Decl(controlFlowOptionalChain.ts, 159, 1)) + + if (typeof o?.foo === "number") { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 385, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 385, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 385, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (typeof o?.foo !== "number") { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 385, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 385, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 385, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (typeof o?.foo == "number") { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 385, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 385, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 385, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (typeof o?.foo != "number") { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 385, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 385, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 385, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } +} + +function f23(o: Thing | undefined) { +>f23 : Symbol(f23, Decl(controlFlowOptionalChain.ts, 410, 1)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 412, 13)) +>Thing : Symbol(Thing, Decl(controlFlowOptionalChain.ts, 159, 1)) + + if (typeof o?.foo === "undefined") { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 412, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 412, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 412, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (typeof o?.foo !== "undefined") { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 412, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 412, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 412, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (typeof o?.foo == "undefined") { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 412, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 412, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 412, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (typeof o?.foo != "undefined") { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 412, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 412, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + else { + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 412, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } +} + +declare function assert(x: unknown): asserts x; +>assert : Symbol(assert, Decl(controlFlowOptionalChain.ts, 437, 1)) +>x : Symbol(x, Decl(controlFlowOptionalChain.ts, 439, 24)) +>x : Symbol(x, Decl(controlFlowOptionalChain.ts, 439, 24)) + +declare function assertNonNull(x: T): asserts x is NonNullable; +>assertNonNull : Symbol(assertNonNull, Decl(controlFlowOptionalChain.ts, 439, 47)) +>T : Symbol(T, Decl(controlFlowOptionalChain.ts, 440, 31)) +>x : Symbol(x, Decl(controlFlowOptionalChain.ts, 440, 34)) +>T : Symbol(T, Decl(controlFlowOptionalChain.ts, 440, 31)) +>x : Symbol(x, Decl(controlFlowOptionalChain.ts, 440, 34)) +>NonNullable : Symbol(NonNullable, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(controlFlowOptionalChain.ts, 440, 31)) + +function f30(o: Thing | undefined) { +>f30 : Symbol(f30, Decl(controlFlowOptionalChain.ts, 440, 69)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 442, 13)) +>Thing : Symbol(Thing, Decl(controlFlowOptionalChain.ts, 159, 1)) + + if (!!true) { + assert(o?.foo); +>assert : Symbol(assert, Decl(controlFlowOptionalChain.ts, 437, 1)) +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 442, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 442, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (!!true) { + assert(o?.foo === 42); +>assert : Symbol(assert, Decl(controlFlowOptionalChain.ts, 437, 1)) +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 442, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 442, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (!!true) { + assert(typeof o?.foo === "number"); +>assert : Symbol(assert, Decl(controlFlowOptionalChain.ts, 437, 1)) +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 442, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 442, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } + if (!!true) { + assertNonNull(o?.foo); +>assertNonNull : Symbol(assertNonNull, Decl(controlFlowOptionalChain.ts, 439, 47)) +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 442, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 442, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + } +} + +function f40(o: Thing | undefined) { +>f40 : Symbol(f40, Decl(controlFlowOptionalChain.ts, 459, 1)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 461, 13)) +>Thing : Symbol(Thing, Decl(controlFlowOptionalChain.ts, 159, 1)) + + switch (o?.foo) { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 461, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + case "abc": + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 461, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + break; + case 42: + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 461, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + break; + case undefined: +>undefined : Symbol(undefined) + + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 461, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + break; + default: + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 461, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + break; + } +} + +function f41(o: Thing | undefined) { +>f41 : Symbol(f41, Decl(controlFlowOptionalChain.ts, 476, 1)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 478, 13)) +>Thing : Symbol(Thing, Decl(controlFlowOptionalChain.ts, 159, 1)) + + switch (typeof o?.foo) { +>o?.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 478, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + case "string": + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 478, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + break; + case "number": + o.foo; +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 478, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + break; + case "undefined": + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 478, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + break; + default: + o.foo; // Error +>o.foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) +>o : Symbol(o, Decl(controlFlowOptionalChain.ts, 478, 13)) +>foo : Symbol(foo, Decl(controlFlowOptionalChain.ts, 161, 14)) + + break; + } +} + +// Repros from #34570 + +type Shape = +>Shape : Symbol(Shape, Decl(controlFlowOptionalChain.ts, 493, 1)) + + | { type: 'rectangle', width: number, height: number } +>type : Symbol(type, Decl(controlFlowOptionalChain.ts, 498, 7)) +>width : Symbol(width, Decl(controlFlowOptionalChain.ts, 498, 26)) +>height : Symbol(height, Decl(controlFlowOptionalChain.ts, 498, 41)) + + | { type: 'circle', radius: number } +>type : Symbol(type, Decl(controlFlowOptionalChain.ts, 499, 7)) +>radius : Symbol(radius, Decl(controlFlowOptionalChain.ts, 499, 23)) + +function getArea(shape?: Shape) { +>getArea : Symbol(getArea, Decl(controlFlowOptionalChain.ts, 499, 40)) +>shape : Symbol(shape, Decl(controlFlowOptionalChain.ts, 501, 17)) +>Shape : Symbol(Shape, Decl(controlFlowOptionalChain.ts, 493, 1)) + + switch (shape?.type) { +>shape?.type : Symbol(type, Decl(controlFlowOptionalChain.ts, 498, 7), Decl(controlFlowOptionalChain.ts, 499, 7)) +>shape : Symbol(shape, Decl(controlFlowOptionalChain.ts, 501, 17)) +>type : Symbol(type, Decl(controlFlowOptionalChain.ts, 498, 7), Decl(controlFlowOptionalChain.ts, 499, 7)) + + case 'circle': + return Math.PI * shape.radius ** 2 +>Math.PI : Symbol(Math.PI, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>PI : Symbol(Math.PI, Decl(lib.es5.d.ts, --, --)) +>shape.radius : Symbol(radius, Decl(controlFlowOptionalChain.ts, 499, 23)) +>shape : Symbol(shape, Decl(controlFlowOptionalChain.ts, 501, 17)) +>radius : Symbol(radius, Decl(controlFlowOptionalChain.ts, 499, 23)) + + case 'rectangle': + return shape.width * shape.height +>shape.width : Symbol(width, Decl(controlFlowOptionalChain.ts, 498, 26)) +>shape : Symbol(shape, Decl(controlFlowOptionalChain.ts, 501, 17)) +>width : Symbol(width, Decl(controlFlowOptionalChain.ts, 498, 26)) +>shape.height : Symbol(height, Decl(controlFlowOptionalChain.ts, 498, 41)) +>shape : Symbol(shape, Decl(controlFlowOptionalChain.ts, 501, 17)) +>height : Symbol(height, Decl(controlFlowOptionalChain.ts, 498, 41)) + + default: + return 0 + } +} + +type Feature = { +>Feature : Symbol(Feature, Decl(controlFlowOptionalChain.ts, 510, 1)) + + id: string; +>id : Symbol(id, Decl(controlFlowOptionalChain.ts, 512, 16)) + + geometry?: { +>geometry : Symbol(geometry, Decl(controlFlowOptionalChain.ts, 513, 13)) + + type: string; +>type : Symbol(type, Decl(controlFlowOptionalChain.ts, 514, 14)) + + coordinates: number[]; +>coordinates : Symbol(coordinates, Decl(controlFlowOptionalChain.ts, 515, 17)) + + }; +}; + + +function extractCoordinates(f: Feature): number[] { +>extractCoordinates : Symbol(extractCoordinates, Decl(controlFlowOptionalChain.ts, 518, 2)) +>f : Symbol(f, Decl(controlFlowOptionalChain.ts, 521, 28)) +>Feature : Symbol(Feature, Decl(controlFlowOptionalChain.ts, 510, 1)) + + if (f.geometry?.type !== 'test') { +>f.geometry?.type : Symbol(type, Decl(controlFlowOptionalChain.ts, 514, 14)) +>f.geometry : Symbol(geometry, Decl(controlFlowOptionalChain.ts, 513, 13)) +>f : Symbol(f, Decl(controlFlowOptionalChain.ts, 521, 28)) +>geometry : Symbol(geometry, Decl(controlFlowOptionalChain.ts, 513, 13)) +>type : Symbol(type, Decl(controlFlowOptionalChain.ts, 514, 14)) + + return []; + } + return f.geometry.coordinates; +>f.geometry.coordinates : Symbol(coordinates, Decl(controlFlowOptionalChain.ts, 515, 17)) +>f.geometry : Symbol(geometry, Decl(controlFlowOptionalChain.ts, 513, 13)) +>f : Symbol(f, Decl(controlFlowOptionalChain.ts, 521, 28)) +>geometry : Symbol(geometry, Decl(controlFlowOptionalChain.ts, 513, 13)) +>coordinates : Symbol(coordinates, Decl(controlFlowOptionalChain.ts, 515, 17)) +} + diff --git a/tests/baselines/reference/controlFlowOptionalChain.types b/tests/baselines/reference/controlFlowOptionalChain.types index ffec7d1525e..13dd6cd5fd0 100644 --- a/tests/baselines/reference/controlFlowOptionalChain.types +++ b/tests/baselines/reference/controlFlowOptionalChain.types @@ -1170,6 +1170,163 @@ function f14(o: Thing | null) { } } +function f15(o: Thing | undefined, value: number) { +>f15 : (o: Thing | undefined, value: number) => void +>o : Thing | undefined +>value : number + + if (o?.foo === value) { +>o?.foo === value : boolean +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>value : number + + o.foo; +>o.foo : number +>o : Thing +>foo : number + } + else { + o.foo; // Error +>o.foo : string | number +>o : Thing | undefined +>foo : string | number + } + if (o?.foo !== value) { +>o?.foo !== value : boolean +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>value : number + + o.foo; // Error +>o.foo : string | number +>o : Thing | undefined +>foo : string | number + } + else { + o.foo; +>o.foo : number +>o : Thing +>foo : number + } + if (o?.foo == value) { +>o?.foo == value : boolean +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>value : number + + o.foo; +>o.foo : string | number +>o : Thing +>foo : string | number + } + else { + o.foo; // Error +>o.foo : string | number +>o : Thing | undefined +>foo : string | number + } + if (o?.foo != value) { +>o?.foo != value : boolean +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>value : number + + o.foo; // Error +>o.foo : string | number +>o : Thing | undefined +>foo : string | number + } + else { + o.foo; +>o.foo : number +>o : Thing +>foo : number + } +} + +function f16(o: Thing | undefined) { +>f16 : (o: Thing | undefined) => void +>o : Thing | undefined + + if (o?.foo === undefined) { +>o?.foo === undefined : boolean +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>undefined : undefined + + o.foo; // Error +>o.foo : never +>o : Thing | undefined +>foo : never + } + else { + o.foo; +>o.foo : string | number +>o : Thing +>foo : string | number + } + if (o?.foo !== undefined) { +>o?.foo !== undefined : boolean +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>undefined : undefined + + o.foo; +>o.foo : string | number +>o : Thing +>foo : string | number + } + else { + o.foo; // Error +>o.foo : never +>o : Thing | undefined +>foo : never + } + if (o?.foo == undefined) { +>o?.foo == undefined : boolean +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>undefined : undefined + + o.foo; // Error +>o.foo : never +>o : Thing | undefined +>foo : never + } + else { + o.foo; +>o.foo : string | number +>o : Thing +>foo : string | number + } + if (o?.foo != undefined) { +>o?.foo != undefined : boolean +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>undefined : undefined + + o.foo; +>o.foo : string | number +>o : Thing +>foo : string | number + } + else { + o.foo; // Error +>o.foo : never +>o : Thing | undefined +>foo : never + } +} + function f20(o: Thing | undefined) { >f20 : (o: Thing | undefined) => void >o : Thing | undefined @@ -1287,3 +1444,445 @@ function f21(o: Thing | null) { } } +function f22(o: Thing | undefined) { +>f22 : (o: Thing | undefined) => void +>o : Thing | undefined + + if (typeof o?.foo === "number") { +>typeof o?.foo === "number" : boolean +>typeof o?.foo : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>"number" : "number" + + o.foo; +>o.foo : number +>o : Thing +>foo : number + } + else { + o.foo; // Error +>o.foo : string +>o : Thing | undefined +>foo : string + } + if (typeof o?.foo !== "number") { +>typeof o?.foo !== "number" : boolean +>typeof o?.foo : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>"number" : "number" + + o.foo; // Error +>o.foo : string +>o : Thing | undefined +>foo : string + } + else { + o.foo; +>o.foo : number +>o : Thing +>foo : number + } + if (typeof o?.foo == "number") { +>typeof o?.foo == "number" : boolean +>typeof o?.foo : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>"number" : "number" + + o.foo; +>o.foo : number +>o : Thing +>foo : number + } + else { + o.foo; // Error +>o.foo : string +>o : Thing | undefined +>foo : string + } + if (typeof o?.foo != "number") { +>typeof o?.foo != "number" : boolean +>typeof o?.foo : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>"number" : "number" + + o.foo; // Error +>o.foo : string +>o : Thing | undefined +>foo : string + } + else { + o.foo; +>o.foo : number +>o : Thing +>foo : number + } +} + +function f23(o: Thing | undefined) { +>f23 : (o: Thing | undefined) => void +>o : Thing | undefined + + if (typeof o?.foo === "undefined") { +>typeof o?.foo === "undefined" : boolean +>typeof o?.foo : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>"undefined" : "undefined" + + o.foo; // Error +>o.foo : never +>o : Thing | undefined +>foo : never + } + else { + o.foo; +>o.foo : string | number +>o : Thing +>foo : string | number + } + if (typeof o?.foo !== "undefined") { +>typeof o?.foo !== "undefined" : boolean +>typeof o?.foo : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>"undefined" : "undefined" + + o.foo; +>o.foo : string | number +>o : Thing +>foo : string | number + } + else { + o.foo; // Error +>o.foo : never +>o : Thing | undefined +>foo : never + } + if (typeof o?.foo == "undefined") { +>typeof o?.foo == "undefined" : boolean +>typeof o?.foo : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>"undefined" : "undefined" + + o.foo; // Error +>o.foo : never +>o : Thing | undefined +>foo : never + } + else { + o.foo; +>o.foo : string | number +>o : Thing +>foo : string | number + } + if (typeof o?.foo != "undefined") { +>typeof o?.foo != "undefined" : boolean +>typeof o?.foo : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>"undefined" : "undefined" + + o.foo; +>o.foo : string | number +>o : Thing +>foo : string | number + } + else { + o.foo; // Error +>o.foo : never +>o : Thing | undefined +>foo : never + } +} + +declare function assert(x: unknown): asserts x; +>assert : (x: unknown) => asserts x +>x : unknown + +declare function assertNonNull(x: T): asserts x is NonNullable; +>assertNonNull : (x: T) => asserts x is NonNullable +>x : T + +function f30(o: Thing | undefined) { +>f30 : (o: Thing | undefined) => void +>o : Thing | undefined + + if (!!true) { +>!!true : true +>!true : false +>true : true + + assert(o?.foo); +>assert(o?.foo) : void +>assert : (x: unknown) => asserts x +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined + + o.foo; +>o.foo : string | number +>o : Thing +>foo : string | number + } + if (!!true) { +>!!true : true +>!true : false +>true : true + + assert(o?.foo === 42); +>assert(o?.foo === 42) : void +>assert : (x: unknown) => asserts x +>o?.foo === 42 : boolean +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>42 : 42 + + o.foo; +>o.foo : 42 +>o : Thing +>foo : 42 + } + if (!!true) { +>!!true : true +>!true : false +>true : true + + assert(typeof o?.foo === "number"); +>assert(typeof o?.foo === "number") : void +>assert : (x: unknown) => asserts x +>typeof o?.foo === "number" : boolean +>typeof o?.foo : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined +>"number" : "number" + + o.foo; +>o.foo : number +>o : Thing +>foo : number + } + if (!!true) { +>!!true : true +>!true : false +>true : true + + assertNonNull(o?.foo); +>assertNonNull(o?.foo) : void +>assertNonNull : (x: T) => asserts x is NonNullable +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined + + o.foo; +>o.foo : string | number +>o : Thing +>foo : string | number + } +} + +function f40(o: Thing | undefined) { +>f40 : (o: Thing | undefined) => void +>o : Thing | undefined + + switch (o?.foo) { +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined + + case "abc": +>"abc" : "abc" + + o.foo; +>o.foo : "abc" +>o : Thing +>foo : "abc" + + break; + case 42: +>42 : 42 + + o.foo; +>o.foo : 42 +>o : Thing +>foo : 42 + + break; + case undefined: +>undefined : undefined + + o.foo; // Error +>o.foo : never +>o : Thing | undefined +>foo : never + + break; + default: + o.foo; // Error +>o.foo : string | number +>o : Thing | undefined +>foo : string | number + + break; + } +} + +function f41(o: Thing | undefined) { +>f41 : (o: Thing | undefined) => void +>o : Thing | undefined + + switch (typeof o?.foo) { +>typeof o?.foo : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>o?.foo : string | number | undefined +>o : Thing | undefined +>foo : string | number | undefined + + case "string": +>"string" : "string" + + o.foo; +>o.foo : string +>o : Thing +>foo : string + + break; + case "number": +>"number" : "number" + + o.foo; +>o.foo : number +>o : Thing +>foo : number + + break; + case "undefined": +>"undefined" : "undefined" + + o.foo; // Error +>o.foo : never +>o : Thing | undefined +>foo : never + + break; + default: + o.foo; // Error +>o.foo : never +>o : Thing | undefined +>foo : never + + break; + } +} + +// Repros from #34570 + +type Shape = +>Shape : Shape + + | { type: 'rectangle', width: number, height: number } +>type : "rectangle" +>width : number +>height : number + + | { type: 'circle', radius: number } +>type : "circle" +>radius : number + +function getArea(shape?: Shape) { +>getArea : (shape?: { type: "rectangle"; width: number; height: number; } | { type: "circle"; radius: number; } | undefined) => number +>shape : { type: "rectangle"; width: number; height: number; } | { type: "circle"; radius: number; } | undefined + + switch (shape?.type) { +>shape?.type : "rectangle" | "circle" | undefined +>shape : { type: "rectangle"; width: number; height: number; } | { type: "circle"; radius: number; } | undefined +>type : "rectangle" | "circle" | undefined + + case 'circle': +>'circle' : "circle" + + return Math.PI * shape.radius ** 2 +>Math.PI * shape.radius ** 2 : number +>Math.PI : number +>Math : Math +>PI : number +>shape.radius ** 2 : number +>shape.radius : number +>shape : { type: "circle"; radius: number; } +>radius : number +>2 : 2 + + case 'rectangle': +>'rectangle' : "rectangle" + + return shape.width * shape.height +>shape.width * shape.height : number +>shape.width : number +>shape : { type: "rectangle"; width: number; height: number; } +>width : number +>shape.height : number +>shape : { type: "rectangle"; width: number; height: number; } +>height : number + + default: + return 0 +>0 : 0 + } +} + +type Feature = { +>Feature : Feature + + id: string; +>id : string + + geometry?: { +>geometry : { type: string; coordinates: number[]; } | undefined + + type: string; +>type : string + + coordinates: number[]; +>coordinates : number[] + + }; +}; + + +function extractCoordinates(f: Feature): number[] { +>extractCoordinates : (f: Feature) => number[] +>f : Feature + + if (f.geometry?.type !== 'test') { +>f.geometry?.type !== 'test' : boolean +>f.geometry?.type : string | undefined +>f.geometry : { type: string; coordinates: number[]; } | undefined +>f : Feature +>geometry : { type: string; coordinates: number[]; } | undefined +>type : string | undefined +>'test' : "test" + + return []; +>[] : never[] + } + return f.geometry.coordinates; +>f.geometry.coordinates : number[] +>f.geometry : { type: string; coordinates: number[]; } +>f : Feature +>geometry : { type: string; coordinates: number[]; } +>coordinates : number[] +} + From 8f15a2e639ccc5182e922b0f9d1c8c698310ab32 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 20 Oct 2019 17:59:21 -0700 Subject: [PATCH 20/63] Fix type inference regression --- src/compiler/checker.ts | 58 ++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b83fa543a89..02718c6aa9c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -17354,10 +17354,7 @@ namespace ts { // inferring a type parameter constraint. Instead, make a lower priority inference from // the full source to whatever remains in the target. For example, when inferring from // string to 'string | T', make a lower priority inference of string for T. - const savePriority = priority; - priority |= InferencePriority.NakedTypeVariable; - inferFromTypes(source, target); - priority = savePriority; + inferWithPriority(source, target, InferencePriority.NakedTypeVariable); return; } source = getUnionType(sources); @@ -17459,10 +17456,7 @@ namespace ts { else if ((isLiteralType(source) || source.flags & TypeFlags.String) && target.flags & TypeFlags.Index) { const empty = createEmptyObjectTypeFromStringLiteral(source); contravariant = !contravariant; - const savePriority = priority; - priority |= InferencePriority.LiteralKeyof; - inferFromTypes(empty, (target as IndexType).type); - priority = savePriority; + inferWithPriority(empty, (target as IndexType).type, InferencePriority.LiteralKeyof); contravariant = !contravariant; } else if (source.flags & TypeFlags.IndexedAccess && target.flags & TypeFlags.IndexedAccess) { @@ -17514,6 +17508,13 @@ namespace ts { } } + function inferWithPriority(source: Type, target: Type, newPriority: InferencePriority) { + const savePriority = priority; + priority |= newPriority; + inferFromTypes(source, target); + priority = savePriority; + } + function invokeOnce(source: Type, target: Type, action: (source: Type, target: Type) => void) { const key = source.id + "," + target.id; const status = visited && visited.get(key); @@ -17581,6 +17582,18 @@ namespace ts { return undefined; } + function getSingleTypeVariableFromIntersectionTypes(types: Type[]) { + let typeVariable: Type | undefined; + for (const type of types) { + const t = type.flags & TypeFlags.Intersection && find((type).types, t => !!getInferenceInfoForType(t)); + if (!t || typeVariable && t !== typeVariable) { + return undefined; + } + typeVariable = t; + } + return typeVariable; + } + function inferToMultipleTypes(source: Type, targets: Type[], targetFlags: TypeFlags) { let typeVariableCount = 0; if (targetFlags & TypeFlags.Union) { @@ -17608,6 +17621,16 @@ namespace ts { } } } + if (typeVariableCount === 0) { + // If every target is an intersection of types containing a single naked type variable, + // make a lower priority inference to that type variable. This handles inferring from + // 'A | B' to 'T & (X | Y)' where we want to infer 'A | B' for T. + const intersectionTypeVariable = getSingleTypeVariableFromIntersectionTypes(targets); + if (intersectionTypeVariable) { + inferWithPriority(source, intersectionTypeVariable, InferencePriority.NakedTypeVariable); + } + return; + } // If the target has a single naked type variable and no inference circularities were // encountered above (meaning we explored the types fully), create a union of the source // types from which no inferences have been made so far and infer from that union to the @@ -17638,14 +17661,11 @@ namespace ts { // we want to infer string for T, not Promise | string. For intersection types // we only infer to single naked type variables. if (targetFlags & TypeFlags.Intersection ? typeVariableCount === 1 : typeVariableCount > 0) { - const savePriority = priority; - priority |= InferencePriority.NakedTypeVariable; for (const t of targets) { if (getInferenceInfoForType(t)) { - inferFromTypes(source, t); + inferWithPriority(source, t, InferencePriority.NakedTypeVariable); } } - priority = savePriority; } } @@ -17666,14 +17686,13 @@ namespace ts { if (inference && !inference.isFixed) { const inferredType = inferTypeForHomomorphicMappedType(source, target, constraintType); if (inferredType) { - const savePriority = priority; // We assign a lower priority to inferences made from types containing non-inferrable // types because we may only have a partial result (i.e. we may have failed to make // reverse inferences for some properties). - priority |= getObjectFlags(source) & ObjectFlags.NonInferrableType ? - InferencePriority.PartialHomomorphicMappedType : InferencePriority.HomomorphicMappedType; - inferFromTypes(inferredType, inference.typeParameter); - priority = savePriority; + inferWithPriority(inferredType, inference.typeParameter, + getObjectFlags(source) & ObjectFlags.NonInferrableType ? + InferencePriority.PartialHomomorphicMappedType : + InferencePriority.HomomorphicMappedType); } } return true; @@ -17681,10 +17700,7 @@ namespace ts { if (constraintType.flags & TypeFlags.TypeParameter) { // We're inferring from some source type S to a mapped type { [P in K]: X }, where K is a type // parameter. First infer from 'keyof S' to K. - const savePriority = priority; - priority |= InferencePriority.MappedTypeConstraint; - inferFromTypes(getIndexType(source), constraintType); - priority = savePriority; + inferWithPriority(getIndexType(source), constraintType, InferencePriority.MappedTypeConstraint); // If K is constrained to a type C, also infer to C. Thus, for a mapped type { [P in K]: X }, // where K extends keyof T, we make the same inferences as for a homomorphic mapped type // { [P in keyof T]: X }. This enables us to make meaningful inferences when the target is a From 56520da6f0af3ed013f8557207cb3c04d2a1158e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 20 Oct 2019 18:00:08 -0700 Subject: [PATCH 21/63] Add regression tests --- .../unionAndIntersectionInference3.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/unionAndIntersectionInference3.ts b/tests/cases/conformance/types/typeRelationships/typeInference/unionAndIntersectionInference3.ts index d64b1973695..12a5e8b17cb 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/unionAndIntersectionInference3.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/unionAndIntersectionInference3.ts @@ -54,3 +54,37 @@ let y1 = foo1(sx); // string let x2 = foo2(sa); // unknown let y2 = foo2(sx); // { extra: number } + +// Repro from #33490 + +declare class Component

{ props: P } + +export type ComponentClass

= new (props: P) => Component

; +export type FunctionComponent

= (props: P) => null; + +export type ComponentType

= FunctionComponent

| ComponentClass

; + +export interface RouteComponentProps { route: string } + +declare function withRouter< + P extends RouteComponentProps, + C extends ComponentType

+>( + component: C & ComponentType

+): ComponentClass>; + +interface Props extends RouteComponentProps { username: string } + +declare const MyComponent: ComponentType; + +withRouter(MyComponent); + +// Repro from #33490 + +type AB = { a: T } | { b: T }; + +// T & AB normalizes to T & { a: U } | T & { b: U } below +declare function foo(obj: T & AB): [T, U]; +declare let ab: AB; + +let z = foo(ab); // [AB, string] From 82019d616dc8a56290d1b22b5d32cd12598c214e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 20 Oct 2019 18:01:41 -0700 Subject: [PATCH 22/63] Accept new baselines --- .../unionAndIntersectionInference3.js | 37 ++++++- .../unionAndIntersectionInference3.symbols | 104 ++++++++++++++++++ .../unionAndIntersectionInference3.types | 64 +++++++++++ 3 files changed, 204 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/unionAndIntersectionInference3.js b/tests/baselines/reference/unionAndIntersectionInference3.js index 415d98220a5..12ce5a9a19b 100644 --- a/tests/baselines/reference/unionAndIntersectionInference3.js +++ b/tests/baselines/reference/unionAndIntersectionInference3.js @@ -52,10 +52,43 @@ let y1 = foo1(sx); // string let x2 = foo2(sa); // unknown let y2 = foo2(sx); // { extra: number } + +// Repro from #33490 + +declare class Component

{ props: P } + +export type ComponentClass

= new (props: P) => Component

; +export type FunctionComponent

= (props: P) => null; + +export type ComponentType

= FunctionComponent

| ComponentClass

; + +export interface RouteComponentProps { route: string } + +declare function withRouter< + P extends RouteComponentProps, + C extends ComponentType

+>( + component: C & ComponentType

+): ComponentClass>; + +interface Props extends RouteComponentProps { username: string } + +declare const MyComponent: ComponentType; + +withRouter(MyComponent); + +// Repro from #33490 + +type AB = { a: T } | { b: T }; + +// T & AB normalizes to T & { a: U } | T & { b: U } below +declare function foo(obj: T & AB): [T, U]; +declare let ab: AB; + +let z = foo(ab); // [AB, string] //// [unionAndIntersectionInference3.js] -"use strict"; // Repro from #30720 concatMaybe([1, 2, 3], 4); // Repros from #32247 @@ -70,3 +103,5 @@ let x1 = foo1(sa); // string let y1 = foo1(sx); // string let x2 = foo2(sa); // unknown let y2 = foo2(sx); // { extra: number } +withRouter(MyComponent); +let z = foo(ab); // [AB, string] diff --git a/tests/baselines/reference/unionAndIntersectionInference3.symbols b/tests/baselines/reference/unionAndIntersectionInference3.symbols index 1d237951b4f..43079f9e8a9 100644 --- a/tests/baselines/reference/unionAndIntersectionInference3.symbols +++ b/tests/baselines/reference/unionAndIntersectionInference3.symbols @@ -205,3 +205,107 @@ let y2 = foo2(sx); // { extra: number } >foo2 : Symbol(foo2, Decl(unionAndIntersectionInference3.ts, 42, 57)) >sx : Symbol(sx, Decl(unionAndIntersectionInference3.ts, 46, 11)) +// Repro from #33490 + +declare class Component

{ props: P } +>Component : Symbol(Component, Decl(unionAndIntersectionInference3.ts, 52, 18)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 56, 24)) +>props : Symbol(Component.props, Decl(unionAndIntersectionInference3.ts, 56, 28)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 56, 24)) + +export type ComponentClass

= new (props: P) => Component

; +>ComponentClass : Symbol(ComponentClass, Decl(unionAndIntersectionInference3.ts, 56, 39)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 58, 27)) +>props : Symbol(props, Decl(unionAndIntersectionInference3.ts, 58, 37)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 58, 27)) +>Component : Symbol(Component, Decl(unionAndIntersectionInference3.ts, 52, 18)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 58, 27)) + +export type FunctionComponent

= (props: P) => null; +>FunctionComponent : Symbol(FunctionComponent, Decl(unionAndIntersectionInference3.ts, 58, 63)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 59, 30)) +>props : Symbol(props, Decl(unionAndIntersectionInference3.ts, 59, 36)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 59, 30)) + +export type ComponentType

= FunctionComponent

| ComponentClass

; +>ComponentType : Symbol(ComponentType, Decl(unionAndIntersectionInference3.ts, 59, 54)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 61, 26)) +>FunctionComponent : Symbol(FunctionComponent, Decl(unionAndIntersectionInference3.ts, 58, 63)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 61, 26)) +>ComponentClass : Symbol(ComponentClass, Decl(unionAndIntersectionInference3.ts, 56, 39)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 61, 26)) + +export interface RouteComponentProps { route: string } +>RouteComponentProps : Symbol(RouteComponentProps, Decl(unionAndIntersectionInference3.ts, 61, 72)) +>route : Symbol(RouteComponentProps.route, Decl(unionAndIntersectionInference3.ts, 63, 38)) + +declare function withRouter< +>withRouter : Symbol(withRouter, Decl(unionAndIntersectionInference3.ts, 63, 54)) + + P extends RouteComponentProps, +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 65, 28)) +>RouteComponentProps : Symbol(RouteComponentProps, Decl(unionAndIntersectionInference3.ts, 61, 72)) + + C extends ComponentType

+>C : Symbol(C, Decl(unionAndIntersectionInference3.ts, 66, 32)) +>ComponentType : Symbol(ComponentType, Decl(unionAndIntersectionInference3.ts, 59, 54)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 65, 28)) + +>( + component: C & ComponentType

+>component : Symbol(component, Decl(unionAndIntersectionInference3.ts, 68, 2)) +>C : Symbol(C, Decl(unionAndIntersectionInference3.ts, 66, 32)) +>ComponentType : Symbol(ComponentType, Decl(unionAndIntersectionInference3.ts, 59, 54)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 65, 28)) + +): ComponentClass>; +>ComponentClass : Symbol(ComponentClass, Decl(unionAndIntersectionInference3.ts, 56, 39)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>P : Symbol(P, Decl(unionAndIntersectionInference3.ts, 65, 28)) +>RouteComponentProps : Symbol(RouteComponentProps, Decl(unionAndIntersectionInference3.ts, 61, 72)) + +interface Props extends RouteComponentProps { username: string } +>Props : Symbol(Props, Decl(unionAndIntersectionInference3.ts, 70, 54)) +>RouteComponentProps : Symbol(RouteComponentProps, Decl(unionAndIntersectionInference3.ts, 61, 72)) +>username : Symbol(Props.username, Decl(unionAndIntersectionInference3.ts, 72, 45)) + +declare const MyComponent: ComponentType; +>MyComponent : Symbol(MyComponent, Decl(unionAndIntersectionInference3.ts, 74, 13)) +>ComponentType : Symbol(ComponentType, Decl(unionAndIntersectionInference3.ts, 59, 54)) +>Props : Symbol(Props, Decl(unionAndIntersectionInference3.ts, 70, 54)) + +withRouter(MyComponent); +>withRouter : Symbol(withRouter, Decl(unionAndIntersectionInference3.ts, 63, 54)) +>MyComponent : Symbol(MyComponent, Decl(unionAndIntersectionInference3.ts, 74, 13)) + +// Repro from #33490 + +type AB = { a: T } | { b: T }; +>AB : Symbol(AB, Decl(unionAndIntersectionInference3.ts, 76, 24)) +>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 80, 8)) +>a : Symbol(a, Decl(unionAndIntersectionInference3.ts, 80, 14)) +>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 80, 8)) +>b : Symbol(b, Decl(unionAndIntersectionInference3.ts, 80, 25)) +>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 80, 8)) + +// T & AB normalizes to T & { a: U } | T & { b: U } below +declare function foo(obj: T & AB): [T, U]; +>foo : Symbol(foo, Decl(unionAndIntersectionInference3.ts, 80, 33)) +>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 83, 21)) +>U : Symbol(U, Decl(unionAndIntersectionInference3.ts, 83, 23)) +>obj : Symbol(obj, Decl(unionAndIntersectionInference3.ts, 83, 27)) +>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 83, 21)) +>AB : Symbol(AB, Decl(unionAndIntersectionInference3.ts, 76, 24)) +>U : Symbol(U, Decl(unionAndIntersectionInference3.ts, 83, 23)) +>T : Symbol(T, Decl(unionAndIntersectionInference3.ts, 83, 21)) +>U : Symbol(U, Decl(unionAndIntersectionInference3.ts, 83, 23)) + +declare let ab: AB; +>ab : Symbol(ab, Decl(unionAndIntersectionInference3.ts, 84, 11)) +>AB : Symbol(AB, Decl(unionAndIntersectionInference3.ts, 76, 24)) + +let z = foo(ab); // [AB, string] +>z : Symbol(z, Decl(unionAndIntersectionInference3.ts, 86, 3)) +>foo : Symbol(foo, Decl(unionAndIntersectionInference3.ts, 80, 33)) +>ab : Symbol(ab, Decl(unionAndIntersectionInference3.ts, 84, 11)) + diff --git a/tests/baselines/reference/unionAndIntersectionInference3.types b/tests/baselines/reference/unionAndIntersectionInference3.types index fb507474321..05cb9368f83 100644 --- a/tests/baselines/reference/unionAndIntersectionInference3.types +++ b/tests/baselines/reference/unionAndIntersectionInference3.types @@ -135,3 +135,67 @@ let y2 = foo2(sx); // { extra: number } >foo2 : (obj: string[] & T) => T >sx : string[] & { extra: number; } +// Repro from #33490 + +declare class Component

{ props: P } +>Component : Component

+>props : P + +export type ComponentClass

= new (props: P) => Component

; +>ComponentClass : ComponentClass

+>props : P + +export type FunctionComponent

= (props: P) => null; +>FunctionComponent : FunctionComponent

+>props : P +>null : null + +export type ComponentType

= FunctionComponent

| ComponentClass

; +>ComponentType : ComponentType

+ +export interface RouteComponentProps { route: string } +>route : string + +declare function withRouter< +>withRouter :

>(component: (C & FunctionComponent

) | (C & ComponentClass

)) => ComponentClass>> + + P extends RouteComponentProps, + C extends ComponentType

+>( + component: C & ComponentType

+>component : (C & FunctionComponent

) | (C & ComponentClass

) + +): ComponentClass>; + +interface Props extends RouteComponentProps { username: string } +>username : string + +declare const MyComponent: ComponentType; +>MyComponent : ComponentType + +withRouter(MyComponent); +>withRouter(MyComponent) : ComponentClass> +>withRouter :

>(component: (C & FunctionComponent

) | (C & ComponentClass

)) => ComponentClass>> +>MyComponent : ComponentType + +// Repro from #33490 + +type AB = { a: T } | { b: T }; +>AB : AB +>a : T +>b : T + +// T & AB normalizes to T & { a: U } | T & { b: U } below +declare function foo(obj: T & AB): [T, U]; +>foo : (obj: (T & { a: U; }) | (T & { b: U; })) => [T, U] +>obj : (T & { a: U; }) | (T & { b: U; }) + +declare let ab: AB; +>ab : AB + +let z = foo(ab); // [AB, string] +>z : [AB, string] +>foo(ab) : [AB, string] +>foo : (obj: (T & { a: U; }) | (T & { b: U; })) => [T, U] +>ab : AB + From 1d3ecc061088e67777ccfd22c89b77ef940f1343 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Mon, 21 Oct 2019 09:56:02 -0700 Subject: [PATCH 23/63] Ensure export= symbol from JavaScript always has a valueDeclaration (#34553) --- src/compiler/binder.ts | 3 ++- ...avascriptImportDefaultBadExport.errors.txt | 16 ++++++++++++++++ .../javascriptImportDefaultBadExport.symbols | 17 +++++++++++++++++ .../javascriptImportDefaultBadExport.types | 19 +++++++++++++++++++ .../javascriptImportDefaultBadExport.ts | 12 ++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/javascriptImportDefaultBadExport.errors.txt create mode 100644 tests/baselines/reference/javascriptImportDefaultBadExport.symbols create mode 100644 tests/baselines/reference/javascriptImportDefaultBadExport.types create mode 100644 tests/cases/compiler/javascriptImportDefaultBadExport.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 9646aabe0a3..e1fdfc258e0 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2690,7 +2690,8 @@ namespace ts { const flags = exportAssignmentIsAlias(node) ? SymbolFlags.Alias // An export= with an EntityNameExpression or a ClassExpression exports all meanings of that identifier or class : SymbolFlags.Property | SymbolFlags.ExportValue | SymbolFlags.ValueModule; - declareSymbol(file.symbol.exports!, file.symbol, node, flags | SymbolFlags.Assignment, SymbolFlags.None); + const symbol = declareSymbol(file.symbol.exports!, file.symbol, node, flags | SymbolFlags.Assignment, SymbolFlags.None); + setValueDeclaration(symbol, node); } function bindThisPropertyAssignment(node: BindablePropertyAssignmentExpression | PropertyAccessExpression | LiteralLikeElementAccessExpression) { diff --git a/tests/baselines/reference/javascriptImportDefaultBadExport.errors.txt b/tests/baselines/reference/javascriptImportDefaultBadExport.errors.txt new file mode 100644 index 00000000000..71ff85e2155 --- /dev/null +++ b/tests/baselines/reference/javascriptImportDefaultBadExport.errors.txt @@ -0,0 +1,16 @@ +/b.js(1,8): error TS1259: Module '"/a"' can only be default-imported using the 'esModuleInterop' flag + + +==== /a.js (0 errors) ==== + // https://github.com/microsoft/TypeScript/issues/34481 + + + const alias = {}; + module.exports = alias; + +==== /b.js (1 errors) ==== + import a from "./a"; + ~ +!!! error TS1259: Module '"/a"' can only be default-imported using the 'esModuleInterop' flag +!!! related TS2594 /a.js:5:1: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. + \ No newline at end of file diff --git a/tests/baselines/reference/javascriptImportDefaultBadExport.symbols b/tests/baselines/reference/javascriptImportDefaultBadExport.symbols new file mode 100644 index 00000000000..b5506996aff --- /dev/null +++ b/tests/baselines/reference/javascriptImportDefaultBadExport.symbols @@ -0,0 +1,17 @@ +=== /a.js === +// https://github.com/microsoft/TypeScript/issues/34481 + + +const alias = {}; +>alias : Symbol(alias, Decl(a.js, 3, 5)) + +module.exports = alias; +>module.exports : Symbol("/a", Decl(a.js, 0, 0)) +>module : Symbol(export=, Decl(a.js, 3, 17)) +>exports : Symbol(export=, Decl(a.js, 3, 17)) +>alias : Symbol(alias, Decl(a.js, 3, 5)) + +=== /b.js === +import a from "./a"; +>a : Symbol(a, Decl(b.js, 0, 6)) + diff --git a/tests/baselines/reference/javascriptImportDefaultBadExport.types b/tests/baselines/reference/javascriptImportDefaultBadExport.types new file mode 100644 index 00000000000..81d68cbdf96 --- /dev/null +++ b/tests/baselines/reference/javascriptImportDefaultBadExport.types @@ -0,0 +1,19 @@ +=== /a.js === +// https://github.com/microsoft/TypeScript/issues/34481 + + +const alias = {}; +>alias : {} +>{} : {} + +module.exports = alias; +>module.exports = alias : {} +>module.exports : {} +>module : { "/a": {}; } +>exports : {} +>alias : {} + +=== /b.js === +import a from "./a"; +>a : any + diff --git a/tests/cases/compiler/javascriptImportDefaultBadExport.ts b/tests/cases/compiler/javascriptImportDefaultBadExport.ts new file mode 100644 index 00000000000..c1f2455e11d --- /dev/null +++ b/tests/cases/compiler/javascriptImportDefaultBadExport.ts @@ -0,0 +1,12 @@ +// https://github.com/microsoft/TypeScript/issues/34481 + +// @allowJs: true +// @checkJs: true +// @noEmit: true + +// @Filename: /a.js +const alias = {}; +module.exports = alias; + +// @Filename: /b.js +import a from "./a"; From b167012561586a405407d6949738a5ea4cc36e7e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 21 Oct 2019 10:46:41 -0700 Subject: [PATCH 24/63] Extend the correct tsconfig.json. --- src/tsc/tsconfig.release.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tsc/tsconfig.release.json b/src/tsc/tsconfig.release.json index 2d2d28ac661..5d6e1687c24 100644 --- a/src/tsc/tsconfig.release.json +++ b/src/tsc/tsconfig.release.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig.json", + "extends": "./tsconfig.json", "compilerOptions": { "outFile": "../../built/local/tsc.release.js", "stripInternal": true, @@ -8,7 +8,7 @@ "declarationMap": false, "sourceMap": false, "composite": false, - "incremental": true + "incremental": true }, "references": [ { "path": "../compiler/tsconfig.release.json", "prepend": true } From 6429e4cd36f136ac11cda325ecdfdd8ea4d0dc9e Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Mon, 21 Oct 2019 13:32:42 -0700 Subject: [PATCH 25/63] Fix undefined `this` --- src/compiler/sys.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 9de6193d734..772eb148fc0 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -535,8 +535,8 @@ namespace ts { data, writeBom, (p, d, w) => originalWriteFile.call(sys, p, d, w), - sys.createDirectory, - sys.directoryExists); + p => sys.createDirectory.call(sys, p), + p => sys.directoryExists.call(sys, p)); } /*@internal*/ From ca31f008a83801d60d564fd4f6194ac1aa352302 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Mon, 21 Oct 2019 14:01:12 -0700 Subject: [PATCH 26/63] Address more potential `this` issues --- src/compiler/program.ts | 6 +++--- src/compiler/sys.ts | 6 +++--- src/compiler/utilities.ts | 4 ++-- src/compiler/watch.ts | 8 +++++++- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 0be96b7d55f..0b22d78f35a 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -114,9 +114,9 @@ namespace ts { fileName, data, writeByteOrderMark, - writeFileWorker, - compilerHost.createDirectory || system.createDirectory, - directoryExists); + (f, d, w) => writeFileWorker(f, d, w), + p => (compilerHost.createDirectory || system.createDirectory)(p), + p => directoryExists(p)); performance.mark("afterIOWrite"); performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite"); diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 772eb148fc0..933cea7b729 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -533,10 +533,10 @@ namespace ts { writeFileEnsuringDirectories( path, data, - writeBom, + !!writeBom, (p, d, w) => originalWriteFile.call(sys, p, d, w), - p => sys.createDirectory.call(sys, p), - p => sys.directoryExists.call(sys, p)); + p => sys.createDirectory(p), + p => sys.directoryExists(p)); } /*@internal*/ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 8f7602cbe2a..ac29da93899 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3714,8 +3714,8 @@ namespace ts { export function writeFileEnsuringDirectories( path: string, data: string, - writeByteOrderMark: boolean | undefined, - writeFile: (path: string, data: string, writeByteOrderMark?: boolean) => void, + writeByteOrderMark: boolean, + writeFile: (path: string, data: string, writeByteOrderMark: boolean) => void, createDirectory: (path: string) => void, directoryExists: (path: string) => boolean): void { diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index cc6bd0bcced..eef4a03c07b 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -303,7 +303,13 @@ namespace ts { // NOTE: If patchWriteFileEnsuringDirectory has been called, // the host.writeFile will do its own directory creation and // the ensureDirectoriesExist call will always be redundant. - writeFileEnsuringDirectories(fileName, text, writeByteOrderMark, host.writeFile!, host.createDirectory!, host.directoryExists!); + writeFileEnsuringDirectories( + fileName, + text, + writeByteOrderMark, + (f, w, d) => host.writeFile!(f, w, d), + p => host.createDirectory!(p), + p => host.directoryExists!(p)); performance.mark("afterIOWrite"); performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite"); From 1b0fca5df5dcc757b995341b3fe479e182c3e265 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 21 Oct 2019 14:51:21 -0700 Subject: [PATCH 27/63] Update version to 3.8. --- package.json | 2 +- src/compiler/core.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1e314c216c4..bbba0c28e93 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "https://www.typescriptlang.org/", - "version": "3.7.0", + "version": "3.8.0", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 4941257cabf..d03b7e1c85c 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1,7 +1,7 @@ namespace ts { // WARNING: The script `configureNightly.ts` uses a regexp to parse out these values. // If changing the text in this section, be sure to test `configureNightly` too. - export const versionMajorMinor = "3.7"; + export const versionMajorMinor = "3.8"; /** The version of the TypeScript compiler release */ export const version = `${versionMajorMinor}.0-dev`; } From def1e7163daf5af3544aaaf70c3667a8c9404a2b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 21 Oct 2019 15:11:16 -0700 Subject: [PATCH 28/63] Accepted baselines. --- tests/baselines/reference/api/tsserverlibrary.d.ts | 2 +- tests/baselines/reference/api/typescript.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index b02074e75ef..c43f28c6e90 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -14,7 +14,7 @@ and limitations under the License. ***************************************************************************** */ declare namespace ts { - const versionMajorMinor = "3.7"; + const versionMajorMinor = "3.8"; /** The version of the TypeScript compiler release */ const version: string; } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 7361ccb6768..e84b948c938 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -14,7 +14,7 @@ and limitations under the License. ***************************************************************************** */ declare namespace ts { - const versionMajorMinor = "3.7"; + const versionMajorMinor = "3.8"; /** The version of the TypeScript compiler release */ const version: string; } From af2f46e8996476053e3e6d0c64d2f9d972191564 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Mon, 21 Oct 2019 16:22:10 -0700 Subject: [PATCH 29/63] Use longer lambda parameter names --- src/compiler/program.ts | 6 +++--- src/compiler/sys.ts | 6 +++--- src/compiler/watch.ts | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 0b22d78f35a..59b57bfa99a 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -114,9 +114,9 @@ namespace ts { fileName, data, writeByteOrderMark, - (f, d, w) => writeFileWorker(f, d, w), - p => (compilerHost.createDirectory || system.createDirectory)(p), - p => directoryExists(p)); + (path, data, writeByteOrderMark) => writeFileWorker(path, data, writeByteOrderMark), + path => (compilerHost.createDirectory || system.createDirectory)(path), + path => directoryExists(path)); performance.mark("afterIOWrite"); performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite"); diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 933cea7b729..31b422a12b9 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -534,9 +534,9 @@ namespace ts { path, data, !!writeBom, - (p, d, w) => originalWriteFile.call(sys, p, d, w), - p => sys.createDirectory(p), - p => sys.directoryExists(p)); + (path, data, writeByteOrderMark) => originalWriteFile.call(sys, path, data, writeByteOrderMark), + path => sys.createDirectory(path), + path => sys.directoryExists(path)); } /*@internal*/ diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index eef4a03c07b..5e8991dbb61 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -307,9 +307,9 @@ namespace ts { fileName, text, writeByteOrderMark, - (f, w, d) => host.writeFile!(f, w, d), - p => host.createDirectory!(p), - p => host.directoryExists!(p)); + (path, data, writeByteOrderMark) => host.writeFile!(path, data, writeByteOrderMark), + path => host.createDirectory!(path), + path => host.directoryExists!(path)); performance.mark("afterIOWrite"); performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite"); From 7862e58354888d5ccf9c378ac74863d5febabc21 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Mon, 21 Oct 2019 17:41:06 -0700 Subject: [PATCH 30/63] Handle undefined from getPropertyNameForPropertyNameNode ...which can be returned when the property name is computed. Part of #34404 --- src/services/navigationBar.ts | 3 +- .../navigationBarComputedPropertyName.ts | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/navigationBarComputedPropertyName.ts diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 03b9d6216c8..49310ef827f 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -648,7 +648,8 @@ namespace ts.NavigationBar { const declName = getNameOfDeclaration(node); if (declName && isPropertyName(declName)) { - return unescapeLeadingUnderscores(getPropertyNameForPropertyNameNode(declName)!); // TODO: GH#18217 + const propertyName = getPropertyNameForPropertyNameNode(declName); + return propertyName && unescapeLeadingUnderscores(propertyName); } switch (node.kind) { case SyntaxKind.FunctionExpression: diff --git a/tests/cases/fourslash/navigationBarComputedPropertyName.ts b/tests/cases/fourslash/navigationBarComputedPropertyName.ts new file mode 100644 index 00000000000..fc6fb808f74 --- /dev/null +++ b/tests/cases/fourslash/navigationBarComputedPropertyName.ts @@ -0,0 +1,57 @@ +/// + +////function F(key, value) { +//// return { +//// [key]: value, +//// "prop": true +//// } +////} + +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "F", + "kind": "function", + "childItems": [ + { + "text": "[key]", + "kind": "property" + }, + { + "text": "\"prop\"", + "kind": "property" + } + ] + } + ] +}); + +verify.navigationBar([ + { + "text": "", + "kind": "script", + "childItems": [ + { + "text": "F", + "kind": "function" + } + ] + }, + { + "text": "F", + "kind": "function", + "childItems": [ + { + "text": "[key]", + "kind": "property" + }, + { + "text": "\"prop\"", + "kind": "property" + } + ], + "indent": 1 + } +]); From 73a206b47f02a41650851ae616cda52ef375fa3d Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Tue, 22 Oct 2019 13:43:52 -0400 Subject: [PATCH 31/63] Update the README links --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 459cebe95b9..a422999ce19 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,15 @@ # TypeScript -[![Join the chat at https://gitter.im/microsoft/TypeScript](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/microsoft/TypeScript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/microsoft/TypeScript.svg?branch=master)](https://travis-ci.org/microsoft/TypeScript) [![VSTS Build Status](https://dev.azure.com/typescript/TypeScript/_apis/build/status/Typescript/node10)](https://dev.azure.com/typescript/TypeScript/_build/latest?definitionId=4&view=logs) [![npm version](https://badge.fury.io/js/typescript.svg)](https://www.npmjs.com/package/typescript) [![Downloads](https://img.shields.io/npm/dm/typescript.svg)](https://www.npmjs.com/package/typescript) - - [TypeScript](https://www.typescriptlang.org/) is a language for application-scale JavaScript. TypeScript adds optional types to JavaScript that support tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the [playground](https://www.typescriptlang.org/play/), and stay up to date via [our blog](https://blogs.msdn.microsoft.com/typescript) and [Twitter account](https://twitter.com/typescript). +Find others who are using TypeScript at [our community page](https://www.typescriptlang.org/community/). + ## Installing For the latest stable version: @@ -31,6 +30,7 @@ There are many ways to [contribute](https://github.com/microsoft/TypeScript/blob * [Submit bugs](https://github.com/microsoft/TypeScript/issues) and help us verify fixes as they are checked in. * Review the [source code changes](https://github.com/microsoft/TypeScript/pulls). * Engage with other TypeScript users and developers on [StackOverflow](https://stackoverflow.com/questions/tagged/typescript). +* Help each other in the [TypeScript Community Discord](https://discord.gg/typescript). * Join the [#typescript](https://twitter.com/search?q=%23TypeScript) discussion on Twitter. * [Contribute bug fixes](https://github.com/microsoft/TypeScript/blob/master/CONTRIBUTING.md). * Read the language specification ([docx](https://github.com/microsoft/TypeScript/blob/master/doc/TypeScript%20Language%20Specification.docx?raw=true), From 1cbbe288ac6e67f1b50e0a239ae36fe0105d4458 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 22 Oct 2019 11:28:28 -0700 Subject: [PATCH 32/63] Treat any mix of element/prop access as declaration in JS (#34649) Fixes #34642 but, notably, doesn't actually make the assignment into a working declaration. It just fixes the crash. --- src/compiler/utilities.ts | 20 +++++++++++-------- ...pertyElementAccessAssignmentDeclaration.js | 10 ++++++++++ ...ElementAccessAssignmentDeclaration.symbols | 8 ++++++++ ...tyElementAccessAssignmentDeclaration.types | 17 ++++++++++++++++ ...pertyElementAccessAssignmentDeclaration.ts | 3 +++ 5 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/mixedPropertyElementAccessAssignmentDeclaration.js create mode 100644 tests/baselines/reference/mixedPropertyElementAccessAssignmentDeclaration.symbols create mode 100644 tests/baselines/reference/mixedPropertyElementAccessAssignmentDeclaration.types create mode 100644 tests/cases/conformance/salsa/mixedPropertyElementAccessAssignmentDeclaration.ts diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 12c83b71697..e86f79b360a 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2061,26 +2061,30 @@ namespace ts { isBindableStaticNameExpression(expr.arguments[0], /*excludeThisKeyword*/ true); } - export function isBindableStaticElementAccessExpression(node: Node, excludeThisKeyword?: boolean): node is BindableStaticElementAccessExpression { - return isLiteralLikeElementAccess(node) - && ((!excludeThisKeyword && node.expression.kind === SyntaxKind.ThisKeyword) || - isEntityNameExpression(node.expression) || - isBindableStaticElementAccessExpression(node.expression, /*excludeThisKeyword*/ true)); - } - + /** x.y OR x[0] */ export function isLiteralLikeAccess(node: Node): node is LiteralLikeElementAccessExpression | PropertyAccessExpression { return isPropertyAccessExpression(node) || isLiteralLikeElementAccess(node); } + /** x[0] OR x['a'] OR x[Symbol.y] */ export function isLiteralLikeElementAccess(node: Node): node is LiteralLikeElementAccessExpression { return isElementAccessExpression(node) && ( isStringOrNumericLiteralLike(node.argumentExpression) || isWellKnownSymbolSyntactically(node.argumentExpression)); } + /** Any series of property and element accesses. */ export function isBindableStaticAccessExpression(node: Node, excludeThisKeyword?: boolean): node is BindableStaticAccessExpression { return isPropertyAccessExpression(node) && (!excludeThisKeyword && node.expression.kind === SyntaxKind.ThisKeyword || isBindableStaticNameExpression(node.expression, /*excludeThisKeyword*/ true)) - || isBindableStaticElementAccessExpression(node, excludeThisKeyword); + || isBindableStaticElementAccessExpression(node, excludeThisKeyword); + } + + /** Any series of property and element accesses, ending in a literal element access */ + export function isBindableStaticElementAccessExpression(node: Node, excludeThisKeyword?: boolean): node is BindableStaticElementAccessExpression { + return isLiteralLikeElementAccess(node) + && ((!excludeThisKeyword && node.expression.kind === SyntaxKind.ThisKeyword) || + isEntityNameExpression(node.expression) || + isBindableStaticAccessExpression(node.expression, /*excludeThisKeyword*/ true)); } export function isBindableStaticNameExpression(node: Node, excludeThisKeyword?: boolean): node is BindableStaticNameExpression { diff --git a/tests/baselines/reference/mixedPropertyElementAccessAssignmentDeclaration.js b/tests/baselines/reference/mixedPropertyElementAccessAssignmentDeclaration.js new file mode 100644 index 00000000000..ee5b3d9e895 --- /dev/null +++ b/tests/baselines/reference/mixedPropertyElementAccessAssignmentDeclaration.js @@ -0,0 +1,10 @@ +//// [mixedPropertyElementAccessAssignmentDeclaration.ts] +// Should not crash: #34642 +var arr = []; +arr[0].prop[2] = {}; + + +//// [mixedPropertyElementAccessAssignmentDeclaration.js] +// Should not crash: #34642 +var arr = []; +arr[0].prop[2] = {}; diff --git a/tests/baselines/reference/mixedPropertyElementAccessAssignmentDeclaration.symbols b/tests/baselines/reference/mixedPropertyElementAccessAssignmentDeclaration.symbols new file mode 100644 index 00000000000..d414e979f17 --- /dev/null +++ b/tests/baselines/reference/mixedPropertyElementAccessAssignmentDeclaration.symbols @@ -0,0 +1,8 @@ +=== tests/cases/conformance/salsa/mixedPropertyElementAccessAssignmentDeclaration.ts === +// Should not crash: #34642 +var arr = []; +>arr : Symbol(arr, Decl(mixedPropertyElementAccessAssignmentDeclaration.ts, 1, 3)) + +arr[0].prop[2] = {}; +>arr : Symbol(arr, Decl(mixedPropertyElementAccessAssignmentDeclaration.ts, 1, 3)) + diff --git a/tests/baselines/reference/mixedPropertyElementAccessAssignmentDeclaration.types b/tests/baselines/reference/mixedPropertyElementAccessAssignmentDeclaration.types new file mode 100644 index 00000000000..18d20dfd936 --- /dev/null +++ b/tests/baselines/reference/mixedPropertyElementAccessAssignmentDeclaration.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/salsa/mixedPropertyElementAccessAssignmentDeclaration.ts === +// Should not crash: #34642 +var arr = []; +>arr : any[] +>[] : undefined[] + +arr[0].prop[2] = {}; +>arr[0].prop[2] = {} : {} +>arr[0].prop[2] : any +>arr[0].prop : any +>arr[0] : any +>arr : any[] +>0 : 0 +>prop : any +>2 : 2 +>{} : {} + diff --git a/tests/cases/conformance/salsa/mixedPropertyElementAccessAssignmentDeclaration.ts b/tests/cases/conformance/salsa/mixedPropertyElementAccessAssignmentDeclaration.ts new file mode 100644 index 00000000000..8dd13383df0 --- /dev/null +++ b/tests/cases/conformance/salsa/mixedPropertyElementAccessAssignmentDeclaration.ts @@ -0,0 +1,3 @@ +// Should not crash: #34642 +var arr = []; +arr[0].prop[2] = {}; From 479d30646f16e02c294fe5963dc8a59487796218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C4=81rlis=20Ga=C5=86=C4=A3is?= Date: Wed, 23 Oct 2019 00:33:45 +0300 Subject: [PATCH 33/63] Fix crash in assigning function with this ref to alias (#34650) --- src/compiler/binder.ts | 2 +- .../importAliasModuleExports.errors.txt | 15 +++++++++++-- .../importAliasModuleExports.symbols | 9 ++++++++ .../reference/importAliasModuleExports.types | 21 +++++++++++++++++++ .../salsa/importAliasModuleExports.ts | 2 ++ 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index e1fdfc258e0..10700204010 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2709,7 +2709,7 @@ namespace ts { } } - if (constructorSymbol) { + if (constructorSymbol && constructorSymbol.valueDeclaration) { // Declare a 'member' if the container is an ES5 class or ES6 constructor constructorSymbol.members = constructorSymbol.members || createSymbolTable(); // It's acceptable for multiple 'this' assignments of the same identifier to occur diff --git a/tests/baselines/reference/importAliasModuleExports.errors.txt b/tests/baselines/reference/importAliasModuleExports.errors.txt index ea3dd9ef0e0..9cd2cd9768e 100644 --- a/tests/baselines/reference/importAliasModuleExports.errors.txt +++ b/tests/baselines/reference/importAliasModuleExports.errors.txt @@ -1,5 +1,8 @@ tests/cases/conformance/salsa/main.js(2,13): error TS2339: Property 'foo' does not exist on type 'Alias'. -tests/cases/conformance/salsa/main.js(4,9): error TS2339: Property 'foo' does not exist on type 'Alias'. +tests/cases/conformance/salsa/main.js(3,13): error TS2339: Property 'func' does not exist on type 'Alias'. +tests/cases/conformance/salsa/main.js(3,38): error TS2339: Property '_func' does not exist on type 'Alias'. +tests/cases/conformance/salsa/main.js(5,9): error TS2339: Property 'foo' does not exist on type 'Alias'. +tests/cases/conformance/salsa/main.js(6,9): error TS2339: Property 'func' does not exist on type 'Alias'. ==== tests/cases/conformance/salsa/mod1.js (0 errors) ==== @@ -8,13 +11,21 @@ tests/cases/conformance/salsa/main.js(4,9): error TS2339: Property 'foo' does no } module.exports = Alias; -==== tests/cases/conformance/salsa/main.js (2 errors) ==== +==== tests/cases/conformance/salsa/main.js (5 errors) ==== import A from './mod1' A.prototype.foo = 0 ~~~ !!! error TS2339: Property 'foo' does not exist on type 'Alias'. + A.prototype.func = function() { this._func = 0; } + ~~~~ +!!! error TS2339: Property 'func' does not exist on type 'Alias'. + ~~~~~ +!!! error TS2339: Property '_func' does not exist on type 'Alias'. new A().bar new A().foo ~~~ !!! error TS2339: Property 'foo' does not exist on type 'Alias'. + new A().func() + ~~~~ +!!! error TS2339: Property 'func' does not exist on type 'Alias'. \ No newline at end of file diff --git a/tests/baselines/reference/importAliasModuleExports.symbols b/tests/baselines/reference/importAliasModuleExports.symbols index 4ab081d608f..4d67eb8e197 100644 --- a/tests/baselines/reference/importAliasModuleExports.symbols +++ b/tests/baselines/reference/importAliasModuleExports.symbols @@ -20,6 +20,12 @@ A.prototype.foo = 0 >A : Symbol(A, Decl(main.js, 0, 6)) >prototype : Symbol(A.prototype) +A.prototype.func = function() { this._func = 0; } +>A.prototype : Symbol(A.prototype) +>A : Symbol(A, Decl(main.js, 0, 6)) +>prototype : Symbol(A.prototype) +>this : Symbol(A, Decl(mod1.js, 0, 0)) + new A().bar >new A().bar : Symbol(A.bar, Decl(mod1.js, 0, 13)) >A : Symbol(A, Decl(main.js, 0, 6)) @@ -28,3 +34,6 @@ new A().bar new A().foo >A : Symbol(A, Decl(main.js, 0, 6)) +new A().func() +>A : Symbol(A, Decl(main.js, 0, 6)) + diff --git a/tests/baselines/reference/importAliasModuleExports.types b/tests/baselines/reference/importAliasModuleExports.types index 1303ba6e8c4..6c9b0509549 100644 --- a/tests/baselines/reference/importAliasModuleExports.types +++ b/tests/baselines/reference/importAliasModuleExports.types @@ -26,6 +26,20 @@ A.prototype.foo = 0 >foo : any >0 : 0 +A.prototype.func = function() { this._func = 0; } +>A.prototype.func = function() { this._func = 0; } : () => void +>A.prototype.func : any +>A.prototype : A +>A : typeof A +>prototype : A +>func : any +>function() { this._func = 0; } : () => void +>this._func = 0 : 0 +>this._func : any +>this : A +>_func : any +>0 : 0 + new A().bar >new A().bar : () => number >new A() : A @@ -38,3 +52,10 @@ new A().foo >A : typeof A >foo : any +new A().func() +>new A().func() : any +>new A().func : any +>new A() : A +>A : typeof A +>func : any + diff --git a/tests/cases/conformance/salsa/importAliasModuleExports.ts b/tests/cases/conformance/salsa/importAliasModuleExports.ts index 5e850206676..691dde20269 100644 --- a/tests/cases/conformance/salsa/importAliasModuleExports.ts +++ b/tests/cases/conformance/salsa/importAliasModuleExports.ts @@ -11,5 +11,7 @@ module.exports = Alias; // @filename: main.js import A from './mod1' A.prototype.foo = 0 +A.prototype.func = function() { this._func = 0; } new A().bar new A().foo +new A().func() From 590fd3f2a28a72b7d3520768b01b9d355e5fc54c Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Tue, 22 Oct 2019 15:00:30 -0700 Subject: [PATCH 34/63] Don't assume that all symbols have declarations ...in Find All References. For example, global `this` doesn't in modules. Part of #34404 --- src/services/findAllReferences.ts | 2 +- .../fourslash/findAllRefsGlobalThisKeywordInModule.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/findAllRefsGlobalThisKeywordInModule.ts diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index bd0e63561da..8d41211439b 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -584,7 +584,7 @@ namespace ts.FindAllReferences.Core { } function getReferencedSymbolsForModuleIfDeclaredBySourceFile(symbol: Symbol, program: Program, sourceFiles: readonly SourceFile[], cancellationToken: CancellationToken, options: Options, sourceFilesSet: ReadonlyMap) { - const moduleSourceFile = symbol.flags & SymbolFlags.Module ? find(symbol.declarations, isSourceFile) : undefined; + const moduleSourceFile = (symbol.flags & SymbolFlags.Module) && symbol.declarations && find(symbol.declarations, isSourceFile); if (!moduleSourceFile) return undefined; const exportEquals = symbol.exports!.get(InternalSymbolName.ExportEquals); // If !!exportEquals, we're about to add references to `import("mod")` anyway, so don't double-count them. diff --git a/tests/cases/fourslash/findAllRefsGlobalThisKeywordInModule.ts b/tests/cases/fourslash/findAllRefsGlobalThisKeywordInModule.ts new file mode 100644 index 00000000000..40222b2530b --- /dev/null +++ b/tests/cases/fourslash/findAllRefsGlobalThisKeywordInModule.ts @@ -0,0 +1,8 @@ +/// +// @noLib: true + +////[|this|]; +////export const c = 1; + +const [glob] = test.ranges(); +verify.referenceGroups(glob, undefined); From f689982c9f2081bc90d2192eee96b404f75c4705 Mon Sep 17 00:00:00 2001 From: Keen Yee Liau Date: Wed, 23 Oct 2019 11:28:44 -0700 Subject: [PATCH 35/63] Prioritize loading plugin from probeLocations over peer node_modules This commit reoroders the loading sequence of a tsserver plugin. It should first check `pluginProbeLocations` before checking peer node_modules. PR closes https://github.com/microsoft/TypeScript/issues/34616 --- src/server/project.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/server/project.ts b/src/server/project.ts index c98e7660b38..28f9166064d 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -1359,9 +1359,12 @@ namespace ts.server { return; } - // Search our peer node_modules, then any globally-specified probe paths - // ../../.. to walk from X/node_modules/typescript/lib/tsserver.js to X/node_modules/ - const searchPaths = [combinePaths(this.projectService.getExecutingFilePath(), "../../.."), ...this.projectService.pluginProbeLocations]; + // Search any globally-specified probe paths, then our peer node_modules + const searchPaths = [ + ...this.projectService.pluginProbeLocations, + // ../../.. to walk from X/node_modules/typescript/lib/tsserver.js to X/node_modules/ + combinePaths(this.projectService.getExecutingFilePath(), "../../.."), + ]; if (this.projectService.globalPlugins) { // Enable global plugins with synthetic configuration entries From eb08ee6848125ccaabcf0ebb34d2e44081df7f1b Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 23 Oct 2019 21:57:49 +0100 Subject: [PATCH 36/63] Add GitHub Actions (#34614) --- .github/workflows/ci.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000000..69f2bf06f8b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: CI + +on: + push: + branches: + - master + - release-* + pull_request: + branches: + - master + - release-* + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [8.x, 10.x, 12.x] + + steps: + - uses: actions/checkout@v1 + with: + fetch-depth: 5 + - name: Use node version ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: Remove existing TypeScript + run: | + npm uninstall typescript --no-save + npm uninstall tslint --no-save + - name: npm install and test + run: | + npm install + npm update + npm test From 8223c0752773ed6d4d42934adadd3d2cb15d5c3d Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 23 Oct 2019 15:53:38 -0700 Subject: [PATCH 37/63] getTypeFromJSDocValueReference: handle import types (#34683) Previously it only handled types whose declaration was from `require`, but now it handles types whose reference is an import type as well. --- src/compiler/checker.ts | 4 +-- ...docImportTypeReferenceToClassAlias.symbols | 28 ++++++++++++++++++ ...jsdocImportTypeReferenceToClassAlias.types | 29 +++++++++++++++++++ .../jsdocImportTypeReferenceToClassAlias.ts | 15 ++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/jsdocImportTypeReferenceToClassAlias.symbols create mode 100644 tests/baselines/reference/jsdocImportTypeReferenceToClassAlias.types create mode 100644 tests/cases/conformance/jsdoc/jsdocImportTypeReferenceToClassAlias.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 647a5e8f57b..f30e765ab42 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10754,7 +10754,7 @@ namespace ts { /** * A JSdoc TypeReference may be to a value, but resolve it as a type anyway. * Note: If the value is imported from commonjs, it should really be an alias, - * but this function fakes special-case code fakes alias resolution as well. + * but this function's special-case code fakes alias resolution as well. */ function getTypeFromJSDocValueReference(node: NodeWithTypeArguments, symbol: Symbol): Type | undefined { const valueType = getTypeOfSymbol(symbol); @@ -10766,7 +10766,7 @@ namespace ts { && isCallExpression(decl.initializer) && isRequireCall(decl.initializer, /*requireStringLiteralLikeArgument*/ true) && valueType.symbol; - if (isRequireAlias) { + if (isRequireAlias || node.kind === SyntaxKind.ImportType) { typeType = getTypeReferenceType(node, valueType.symbol); } } diff --git a/tests/baselines/reference/jsdocImportTypeReferenceToClassAlias.symbols b/tests/baselines/reference/jsdocImportTypeReferenceToClassAlias.symbols new file mode 100644 index 00000000000..c62d8e0676f --- /dev/null +++ b/tests/baselines/reference/jsdocImportTypeReferenceToClassAlias.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/jsdoc/mod1.js === +class C { +>C : Symbol(C, Decl(mod1.js, 0, 0)) + + s() { } +>s : Symbol(C.s, Decl(mod1.js, 0, 9)) +} +module.exports.C = C +>module.exports.C : Symbol(C, Decl(mod1.js, 2, 1)) +>module.exports : Symbol(C, Decl(mod1.js, 2, 1)) +>module : Symbol(module, Decl(mod1.js, 2, 1)) +>exports : Symbol("tests/cases/conformance/jsdoc/mod1", Decl(mod1.js, 0, 0)) +>C : Symbol(C, Decl(mod1.js, 2, 1)) +>C : Symbol(C, Decl(mod1.js, 0, 0)) + +=== tests/cases/conformance/jsdoc/test.js === +/** @typedef {import('./mod1').C} X */ +/** @param {X} c */ +function demo(c) { +>demo : Symbol(demo, Decl(test.js, 0, 0)) +>c : Symbol(c, Decl(test.js, 2, 14)) + + c.s +>c.s : Symbol(C.s, Decl(mod1.js, 0, 9)) +>c : Symbol(c, Decl(test.js, 2, 14)) +>s : Symbol(C.s, Decl(mod1.js, 0, 9)) +} + diff --git a/tests/baselines/reference/jsdocImportTypeReferenceToClassAlias.types b/tests/baselines/reference/jsdocImportTypeReferenceToClassAlias.types new file mode 100644 index 00000000000..880288d7197 --- /dev/null +++ b/tests/baselines/reference/jsdocImportTypeReferenceToClassAlias.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/jsdoc/mod1.js === +class C { +>C : C + + s() { } +>s : () => void +} +module.exports.C = C +>module.exports.C = C : typeof C +>module.exports.C : typeof C +>module.exports : typeof import("tests/cases/conformance/jsdoc/mod1") +>module : { "tests/cases/conformance/jsdoc/mod1": typeof import("tests/cases/conformance/jsdoc/mod1"); } +>exports : typeof import("tests/cases/conformance/jsdoc/mod1") +>C : typeof C +>C : typeof C + +=== tests/cases/conformance/jsdoc/test.js === +/** @typedef {import('./mod1').C} X */ +/** @param {X} c */ +function demo(c) { +>demo : (c: C) => void +>c : C + + c.s +>c.s : () => void +>c : C +>s : () => void +} + diff --git a/tests/cases/conformance/jsdoc/jsdocImportTypeReferenceToClassAlias.ts b/tests/cases/conformance/jsdoc/jsdocImportTypeReferenceToClassAlias.ts new file mode 100644 index 00000000000..d53da960035 --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocImportTypeReferenceToClassAlias.ts @@ -0,0 +1,15 @@ +// @noEmit: true +// @allowJs: true +// @checkJs: true +// @Filename: mod1.js +class C { + s() { } +} +module.exports.C = C + +// @Filename: test.js +/** @typedef {import('./mod1').C} X */ +/** @param {X} c */ +function demo(c) { + c.s +} From 07d3a2ec7e4bba39df98a9f1bd16bc04112b9716 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 23 Oct 2019 16:01:25 -0700 Subject: [PATCH 38/63] Do not consider element accesses which are neither statically bindable nor late bound as special assignments (#34679) --- src/compiler/utilities.ts | 8 +++++--- .../jsNegativeElementAccessNotBound.symbols | 7 +++++++ .../reference/jsNegativeElementAccessNotBound.types | 13 +++++++++++++ .../compiler/jsNegativeElementAccessNotBound.ts | 6 ++++++ 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/jsNegativeElementAccessNotBound.symbols create mode 100644 tests/baselines/reference/jsNegativeElementAccessNotBound.types create mode 100644 tests/cases/compiler/jsNegativeElementAccessNotBound.ts diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index e86f79b360a..12b11eeae29 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2115,7 +2115,7 @@ namespace ts { if (expr.operatorToken.kind !== SyntaxKind.EqualsToken || !isAccessExpression(expr.left)) { return AssignmentDeclarationKind.None; } - if (isBindableStaticNameExpression(expr.left.expression) && getElementOrPropertyAccessName(expr.left) === "prototype" && isObjectLiteralExpression(getInitializerOfBinaryExpression(expr))) { + if (isBindableStaticNameExpression(expr.left.expression, /*excludeThisKeyword*/ true) && getElementOrPropertyAccessName(expr.left) === "prototype" && isObjectLiteralExpression(getInitializerOfBinaryExpression(expr))) { // F.prototype = { ... } return AssignmentDeclarationKind.Prototype; } @@ -2183,8 +2183,10 @@ namespace ts { // exports.name = expr OR module.exports.name = expr OR exports["name"] = expr ... return AssignmentDeclarationKind.ExportsProperty; } - // F.G...x = expr - return AssignmentDeclarationKind.Property; + if (isBindableStaticNameExpression(lhs, /*excludeThisKeyword*/ true) || (isElementAccessExpression(lhs) && isDynamicName(lhs) && lhs.expression.kind !== SyntaxKind.ThisKeyword)) { + // F.G...x = expr + return AssignmentDeclarationKind.Property; + } } return AssignmentDeclarationKind.None; diff --git a/tests/baselines/reference/jsNegativeElementAccessNotBound.symbols b/tests/baselines/reference/jsNegativeElementAccessNotBound.symbols new file mode 100644 index 00000000000..d8ff3f52e23 --- /dev/null +++ b/tests/baselines/reference/jsNegativeElementAccessNotBound.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/jsNegativeELementAccessNotBound.js === +var indexMap = {}; +>indexMap : Symbol(indexMap, Decl(jsNegativeELementAccessNotBound.js, 0, 3)) + +indexMap[-1] = 0; +>indexMap : Symbol(indexMap, Decl(jsNegativeELementAccessNotBound.js, 0, 3)) + diff --git a/tests/baselines/reference/jsNegativeElementAccessNotBound.types b/tests/baselines/reference/jsNegativeElementAccessNotBound.types new file mode 100644 index 00000000000..dbd5d4c005d --- /dev/null +++ b/tests/baselines/reference/jsNegativeElementAccessNotBound.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/jsNegativeELementAccessNotBound.js === +var indexMap = {}; +>indexMap : {} +>{} : {} + +indexMap[-1] = 0; +>indexMap[-1] = 0 : 0 +>indexMap[-1] : any +>indexMap : {} +>-1 : -1 +>1 : 1 +>0 : 0 + diff --git a/tests/cases/compiler/jsNegativeElementAccessNotBound.ts b/tests/cases/compiler/jsNegativeElementAccessNotBound.ts new file mode 100644 index 00000000000..c7a204e578f --- /dev/null +++ b/tests/cases/compiler/jsNegativeElementAccessNotBound.ts @@ -0,0 +1,6 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @filename: jsNegativeELementAccessNotBound.js +var indexMap = {}; +indexMap[-1] = 0; From 969634b97c22d73eccb6cda96fcb036c13ad0601 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 24 Oct 2019 09:24:58 -0700 Subject: [PATCH 39/63] Restore delayed merge check to getTypeFromJSDocValueReference (#34706) * Restore delayed merge check to getTypeFromJSDocValueReference This is needed when a function merges with a prototype assignment. The resulting *merged* symbol is a constructor function marked with SymbolFlags.Class. However, the merge doesn't happen until getTypeOfFuncClassEnumModule is called, which, in the getTypeReferenceType code path, doesn't happen until getTypeFromJSDocValueReference. That means the check for SymbolFlags.Class is missed. Previously, getTypeFromJSDocValueReference had a weird check `symbol !== getTypeOfSymbol(symbol).symbol`, which, if true, ran getTypeReferenceType again on `getTypeOfSymbol(symbol).symbol`. For JS "aliases", this had the effect of dereferencing the alias, and for function-prototype merges, this had the effect of ... just trying again after the merge had happened. This is a confusing way to run things. getTypeReferenceType should instead detect a function-prototype merge, cause it to happen, and *then* run the rest of its code instead of relying on try-again logic at the very end. However, for the RC, I want to fix this code by restoring the old check, with an additional check to make sure that #33106 doesn't break again: ```ts const valueType = getTypeOfSymbol(symbol) symbol !== valueType.symbol && getMergedSymbol(symbol) === valueType.symbol ``` I'll work on the real fix afterwards and put it into 3.8. * Add bug number --- src/compiler/checker.ts | 4 +- .../jsdocTypeReferenceToMergedClass.symbols | 35 ++++++++++++++++ .../jsdocTypeReferenceToMergedClass.types | 41 +++++++++++++++++++ .../jsdoc/jsdocTypeReferenceToMergedClass.ts | 17 ++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/jsdocTypeReferenceToMergedClass.symbols create mode 100644 tests/baselines/reference/jsdocTypeReferenceToMergedClass.types create mode 100644 tests/cases/conformance/jsdoc/jsdocTypeReferenceToMergedClass.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f30e765ab42..ed3057895fa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10766,7 +10766,9 @@ namespace ts { && isCallExpression(decl.initializer) && isRequireCall(decl.initializer, /*requireStringLiteralLikeArgument*/ true) && valueType.symbol; - if (isRequireAlias || node.kind === SyntaxKind.ImportType) { + const isImportType = node.kind === SyntaxKind.ImportType; + const isDelayedMergeClass = symbol !== valueType.symbol && getMergedSymbol(symbol) === valueType.symbol; + if (isRequireAlias || isImportType || isDelayedMergeClass) { typeType = getTypeReferenceType(node, valueType.symbol); } } diff --git a/tests/baselines/reference/jsdocTypeReferenceToMergedClass.symbols b/tests/baselines/reference/jsdocTypeReferenceToMergedClass.symbols new file mode 100644 index 00000000000..229163c5d78 --- /dev/null +++ b/tests/baselines/reference/jsdocTypeReferenceToMergedClass.symbols @@ -0,0 +1,35 @@ +=== tests/cases/conformance/jsdoc/test.js === +// https://github.com/microsoft/TypeScript/issues/34685 + +/** @param {Workspace.Project} p */ +function demo(p) { +>demo : Symbol(demo, Decl(test.js, 0, 0)) +>p : Symbol(p, Decl(test.js, 3, 14)) + + p.isServiceProject() +>p.isServiceProject : Symbol(isServiceProject, Decl(mod1.js, 3, 31)) +>p : Symbol(p, Decl(test.js, 3, 14)) +>isServiceProject : Symbol(isServiceProject, Decl(mod1.js, 3, 31)) +} +=== tests/cases/conformance/jsdoc/mod1.js === +// Note: mod1.js needs to appear second to trigger the bug +var Workspace = {} +>Workspace : Symbol(Workspace, Decl(mod1.js, 1, 3), Decl(mod1.js, 1, 18), Decl(mod1.js, 2, 37)) + +Workspace.Project = function wp() { } +>Workspace.Project : Symbol(Workspace.Project, Decl(mod1.js, 1, 18), Decl(mod1.js, 3, 10)) +>Workspace : Symbol(Workspace, Decl(mod1.js, 1, 3), Decl(mod1.js, 1, 18), Decl(mod1.js, 2, 37)) +>Project : Symbol(Workspace.Project, Decl(mod1.js, 1, 18), Decl(mod1.js, 3, 10)) +>wp : Symbol(wp, Decl(mod1.js, 2, 19)) + +Workspace.Project.prototype = { +>Workspace.Project.prototype : Symbol(Workspace.Project.prototype, Decl(mod1.js, 2, 37)) +>Workspace.Project : Symbol(Workspace.Project, Decl(mod1.js, 1, 18), Decl(mod1.js, 3, 10)) +>Workspace : Symbol(Workspace, Decl(mod1.js, 1, 3), Decl(mod1.js, 1, 18), Decl(mod1.js, 2, 37)) +>Project : Symbol(Workspace.Project, Decl(mod1.js, 1, 18), Decl(mod1.js, 3, 10)) +>prototype : Symbol(Workspace.Project.prototype, Decl(mod1.js, 2, 37)) + + isServiceProject() {} +>isServiceProject : Symbol(isServiceProject, Decl(mod1.js, 3, 31)) +} + diff --git a/tests/baselines/reference/jsdocTypeReferenceToMergedClass.types b/tests/baselines/reference/jsdocTypeReferenceToMergedClass.types new file mode 100644 index 00000000000..c4e380f8c0e --- /dev/null +++ b/tests/baselines/reference/jsdocTypeReferenceToMergedClass.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/jsdoc/test.js === +// https://github.com/microsoft/TypeScript/issues/34685 + +/** @param {Workspace.Project} p */ +function demo(p) { +>demo : (p: wp) => void +>p : wp + + p.isServiceProject() +>p.isServiceProject() : void +>p.isServiceProject : () => void +>p : wp +>isServiceProject : () => void +} +=== tests/cases/conformance/jsdoc/mod1.js === +// Note: mod1.js needs to appear second to trigger the bug +var Workspace = {} +>Workspace : typeof Workspace +>{} : {} + +Workspace.Project = function wp() { } +>Workspace.Project = function wp() { } : typeof wp +>Workspace.Project : typeof wp +>Workspace : typeof Workspace +>Project : typeof wp +>function wp() { } : typeof wp +>wp : typeof wp + +Workspace.Project.prototype = { +>Workspace.Project.prototype = { isServiceProject() {}} : { isServiceProject(): void; } +>Workspace.Project.prototype : { isServiceProject(): void; } +>Workspace.Project : typeof wp +>Workspace : typeof Workspace +>Project : typeof wp +>prototype : { isServiceProject(): void; } +>{ isServiceProject() {}} : { isServiceProject(): void; } + + isServiceProject() {} +>isServiceProject : () => void +} + diff --git a/tests/cases/conformance/jsdoc/jsdocTypeReferenceToMergedClass.ts b/tests/cases/conformance/jsdoc/jsdocTypeReferenceToMergedClass.ts new file mode 100644 index 00000000000..e559ffd27ca --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocTypeReferenceToMergedClass.ts @@ -0,0 +1,17 @@ +// https://github.com/microsoft/TypeScript/issues/34685 +// @noEmit: true +// @allowJs: true +// @checkJs: true + +// @Filename: test.js +/** @param {Workspace.Project} p */ +function demo(p) { + p.isServiceProject() +} +// @Filename: mod1.js +// Note: mod1.js needs to appear second to trigger the bug +var Workspace = {} +Workspace.Project = function wp() { } +Workspace.Project.prototype = { + isServiceProject() {} +} From d892fd408fecc86cf2f262821344b8c2429be392 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 24 Oct 2019 13:12:44 -0700 Subject: [PATCH 40/63] Fix expando handling in getTypeReferenceType (#34712) * Fix expando handling in getTypeReferenceType getExpandoSymbol looks for the initialiser of a symbol when it is an expando value (IIFEs, function exprs, class exprs and empty object literals) and returns the symbol. Previously, however, it returned the symbol of the initialiser without merging with the declaration symbol itself. This missed, in particular, the prototype assignment in the following pattern: ```js var x = function x() { this.y = 1 } x.prototype = { z() { } } /** @type {x} */ var xx; xx.z // missed! ``` getJSDocValueReference had weird try-again code that relied on calling getTypeOfSymbol, which *does* correctly merge the symbols. This PR re-removes that code and instead makes getExpandoSymbol call mergeJSSymbols itself. * Remove extra newline --- src/compiler/checker.ts | 13 +++--- .../jsdocTypeReferenceToMergedClass.symbols | 45 +++++++++---------- .../jsdocTypeReferenceToMergedClass.types | 19 ++++---- .../jsdoc/jsdocTypeReferenceToMergedClass.ts | 12 +++-- 4 files changed, 42 insertions(+), 47 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ed3057895fa..052c89a7b09 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2629,7 +2629,12 @@ namespace ts { return undefined; } const init = isVariableDeclaration(decl) ? getDeclaredExpandoInitializer(decl) : getAssignedExpandoInitializer(decl); - return init && getSymbolOfNode(init) || undefined; + if (init) { + const initSymbol = getSymbolOfNode(init); + if (initSymbol) { + return mergeJSSymbols(initSymbol, symbol); + } + } } @@ -10766,9 +10771,7 @@ namespace ts { && isCallExpression(decl.initializer) && isRequireCall(decl.initializer, /*requireStringLiteralLikeArgument*/ true) && valueType.symbol; - const isImportType = node.kind === SyntaxKind.ImportType; - const isDelayedMergeClass = symbol !== valueType.symbol && getMergedSymbol(symbol) === valueType.symbol; - if (isRequireAlias || isImportType || isDelayedMergeClass) { + if (isRequireAlias || node.kind === SyntaxKind.ImportType) { typeType = getTypeReferenceType(node, valueType.symbol); } } @@ -24997,7 +25000,7 @@ namespace ts { } function mergeJSSymbols(target: Symbol, source: Symbol | undefined) { - if (source && (hasEntries(source.exports) || hasEntries(source.members))) { + if (source) { const links = getSymbolLinks(source); if (!links.inferredClassSymbol || !links.inferredClassSymbol.has("" + getSymbolId(target))) { const inferred = isTransientSymbol(target) ? target : cloneSymbol(target) as TransientSymbol; diff --git a/tests/baselines/reference/jsdocTypeReferenceToMergedClass.symbols b/tests/baselines/reference/jsdocTypeReferenceToMergedClass.symbols index 229163c5d78..86dcb536419 100644 --- a/tests/baselines/reference/jsdocTypeReferenceToMergedClass.symbols +++ b/tests/baselines/reference/jsdocTypeReferenceToMergedClass.symbols @@ -1,35 +1,32 @@ -=== tests/cases/conformance/jsdoc/test.js === +=== tests/cases/conformance/jsdoc/jsdocTypeReferenceToMergedClass.js === // https://github.com/microsoft/TypeScript/issues/34685 -/** @param {Workspace.Project} p */ -function demo(p) { ->demo : Symbol(demo, Decl(test.js, 0, 0)) ->p : Symbol(p, Decl(test.js, 3, 14)) - - p.isServiceProject() ->p.isServiceProject : Symbol(isServiceProject, Decl(mod1.js, 3, 31)) ->p : Symbol(p, Decl(test.js, 3, 14)) ->isServiceProject : Symbol(isServiceProject, Decl(mod1.js, 3, 31)) -} -=== tests/cases/conformance/jsdoc/mod1.js === -// Note: mod1.js needs to appear second to trigger the bug var Workspace = {} ->Workspace : Symbol(Workspace, Decl(mod1.js, 1, 3), Decl(mod1.js, 1, 18), Decl(mod1.js, 2, 37)) +>Workspace : Symbol(Workspace, Decl(jsdocTypeReferenceToMergedClass.js, 2, 3), Decl(jsdocTypeReferenceToMergedClass.js, 5, 20), Decl(jsdocTypeReferenceToMergedClass.js, 7, 37)) + +/** @type {Workspace.Project} */ +var p; +>p : Symbol(p, Decl(jsdocTypeReferenceToMergedClass.js, 4, 3)) + +p.isServiceProject() +>p.isServiceProject : Symbol(isServiceProject, Decl(jsdocTypeReferenceToMergedClass.js, 8, 31)) +>p : Symbol(p, Decl(jsdocTypeReferenceToMergedClass.js, 4, 3)) +>isServiceProject : Symbol(isServiceProject, Decl(jsdocTypeReferenceToMergedClass.js, 8, 31)) Workspace.Project = function wp() { } ->Workspace.Project : Symbol(Workspace.Project, Decl(mod1.js, 1, 18), Decl(mod1.js, 3, 10)) ->Workspace : Symbol(Workspace, Decl(mod1.js, 1, 3), Decl(mod1.js, 1, 18), Decl(mod1.js, 2, 37)) ->Project : Symbol(Workspace.Project, Decl(mod1.js, 1, 18), Decl(mod1.js, 3, 10)) ->wp : Symbol(wp, Decl(mod1.js, 2, 19)) +>Workspace.Project : Symbol(Workspace.Project, Decl(jsdocTypeReferenceToMergedClass.js, 5, 20), Decl(jsdocTypeReferenceToMergedClass.js, 8, 10)) +>Workspace : Symbol(Workspace, Decl(jsdocTypeReferenceToMergedClass.js, 2, 3), Decl(jsdocTypeReferenceToMergedClass.js, 5, 20), Decl(jsdocTypeReferenceToMergedClass.js, 7, 37)) +>Project : Symbol(Workspace.Project, Decl(jsdocTypeReferenceToMergedClass.js, 5, 20), Decl(jsdocTypeReferenceToMergedClass.js, 8, 10)) +>wp : Symbol(wp, Decl(jsdocTypeReferenceToMergedClass.js, 7, 19)) Workspace.Project.prototype = { ->Workspace.Project.prototype : Symbol(Workspace.Project.prototype, Decl(mod1.js, 2, 37)) ->Workspace.Project : Symbol(Workspace.Project, Decl(mod1.js, 1, 18), Decl(mod1.js, 3, 10)) ->Workspace : Symbol(Workspace, Decl(mod1.js, 1, 3), Decl(mod1.js, 1, 18), Decl(mod1.js, 2, 37)) ->Project : Symbol(Workspace.Project, Decl(mod1.js, 1, 18), Decl(mod1.js, 3, 10)) ->prototype : Symbol(Workspace.Project.prototype, Decl(mod1.js, 2, 37)) +>Workspace.Project.prototype : Symbol(Workspace.Project.prototype, Decl(jsdocTypeReferenceToMergedClass.js, 7, 37)) +>Workspace.Project : Symbol(Workspace.Project, Decl(jsdocTypeReferenceToMergedClass.js, 5, 20), Decl(jsdocTypeReferenceToMergedClass.js, 8, 10)) +>Workspace : Symbol(Workspace, Decl(jsdocTypeReferenceToMergedClass.js, 2, 3), Decl(jsdocTypeReferenceToMergedClass.js, 5, 20), Decl(jsdocTypeReferenceToMergedClass.js, 7, 37)) +>Project : Symbol(Workspace.Project, Decl(jsdocTypeReferenceToMergedClass.js, 5, 20), Decl(jsdocTypeReferenceToMergedClass.js, 8, 10)) +>prototype : Symbol(Workspace.Project.prototype, Decl(jsdocTypeReferenceToMergedClass.js, 7, 37)) isServiceProject() {} ->isServiceProject : Symbol(isServiceProject, Decl(mod1.js, 3, 31)) +>isServiceProject : Symbol(isServiceProject, Decl(jsdocTypeReferenceToMergedClass.js, 8, 31)) } diff --git a/tests/baselines/reference/jsdocTypeReferenceToMergedClass.types b/tests/baselines/reference/jsdocTypeReferenceToMergedClass.types index c4e380f8c0e..3fd1661fa29 100644 --- a/tests/baselines/reference/jsdocTypeReferenceToMergedClass.types +++ b/tests/baselines/reference/jsdocTypeReferenceToMergedClass.types @@ -1,22 +1,19 @@ -=== tests/cases/conformance/jsdoc/test.js === +=== tests/cases/conformance/jsdoc/jsdocTypeReferenceToMergedClass.js === // https://github.com/microsoft/TypeScript/issues/34685 -/** @param {Workspace.Project} p */ -function demo(p) { ->demo : (p: wp) => void +var Workspace = {} +>Workspace : typeof Workspace +>{} : {} + +/** @type {Workspace.Project} */ +var p; >p : wp - p.isServiceProject() +p.isServiceProject() >p.isServiceProject() : void >p.isServiceProject : () => void >p : wp >isServiceProject : () => void -} -=== tests/cases/conformance/jsdoc/mod1.js === -// Note: mod1.js needs to appear second to trigger the bug -var Workspace = {} ->Workspace : typeof Workspace ->{} : {} Workspace.Project = function wp() { } >Workspace.Project = function wp() { } : typeof wp diff --git a/tests/cases/conformance/jsdoc/jsdocTypeReferenceToMergedClass.ts b/tests/cases/conformance/jsdoc/jsdocTypeReferenceToMergedClass.ts index e559ffd27ca..931ad69cfb0 100644 --- a/tests/cases/conformance/jsdoc/jsdocTypeReferenceToMergedClass.ts +++ b/tests/cases/conformance/jsdoc/jsdocTypeReferenceToMergedClass.ts @@ -3,14 +3,12 @@ // @allowJs: true // @checkJs: true -// @Filename: test.js -/** @param {Workspace.Project} p */ -function demo(p) { - p.isServiceProject() -} -// @Filename: mod1.js -// Note: mod1.js needs to appear second to trigger the bug +// @Filename: jsdocTypeReferenceToMergedClass.js var Workspace = {} +/** @type {Workspace.Project} */ +var p; +p.isServiceProject() + Workspace.Project = function wp() { } Workspace.Project.prototype = { isServiceProject() {} From 7cfa1dfb8a16d62d6df6f422c1efefd252f27012 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 24 Oct 2019 14:02:37 -0700 Subject: [PATCH 41/63] Fix regression in mixin emit by removing unneeded line of code (#34715) * Fix regression in mixin emit by removing unneeded line of code * Double the test, double the fun --- src/compiler/checker.ts | 2 - .../anonClassDeclarationEmitIsAnon.js | 142 ++++++++++++++++++ .../anonClassDeclarationEmitIsAnon.symbols | 68 +++++++++ .../anonClassDeclarationEmitIsAnon.types | 72 +++++++++ .../anonClassDeclarationEmitIsAnon.ts | 34 +++++ 5 files changed, 316 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/anonClassDeclarationEmitIsAnon.js create mode 100644 tests/baselines/reference/anonClassDeclarationEmitIsAnon.symbols create mode 100644 tests/baselines/reference/anonClassDeclarationEmitIsAnon.types create mode 100644 tests/cases/compiler/anonClassDeclarationEmitIsAnon.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 052c89a7b09..bf50e8b15cd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4092,8 +4092,6 @@ namespace ts { else if (context.flags & NodeBuilderFlags.WriteClassExpressionAsTypeLiteral && type.symbol.valueDeclaration && isClassLike(type.symbol.valueDeclaration) && - // Use `import` types for refs to other scopes, only anonymize something defined in the same scope - findAncestor(type.symbol.valueDeclaration, d => d === getSourceFileOfNode(context.enclosingDeclaration)) && !isValueSymbolAccessible(type.symbol, context.enclosingDeclaration) ) { return createAnonymousTypeNode(type); diff --git a/tests/baselines/reference/anonClassDeclarationEmitIsAnon.js b/tests/baselines/reference/anonClassDeclarationEmitIsAnon.js new file mode 100644 index 00000000000..697348e1ba8 --- /dev/null +++ b/tests/baselines/reference/anonClassDeclarationEmitIsAnon.js @@ -0,0 +1,142 @@ +//// [tests/cases/compiler/anonClassDeclarationEmitIsAnon.ts] //// + +//// [wrapClass.ts] +export function wrapClass(param: any) { + return class Wrapped { + foo() { + return param; + } + } +} + +export type Constructor = new (...args: any[]) => T; + +export function Timestamped(Base: TBase) { + return class extends Base { + timestamp = Date.now(); + }; +} + +//// [index.ts] +import { wrapClass, Timestamped } from "./wrapClass"; + +export default wrapClass(0); + +// Simple class +export class User { + name = ''; +} + +// User that is Timestamped +export class TimestampedUser extends Timestamped(User) { + constructor() { + super(); + } +} + +//// [wrapClass.js] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +function wrapClass(param) { + return /** @class */ (function () { + function Wrapped() { + } + Wrapped.prototype.foo = function () { + return param; + }; + return Wrapped; + }()); +} +exports.wrapClass = wrapClass; +function Timestamped(Base) { + return /** @class */ (function (_super) { + __extends(class_1, _super); + function class_1() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.timestamp = Date.now(); + return _this; + } + return class_1; + }(Base)); +} +exports.Timestamped = Timestamped; +//// [index.js] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +var wrapClass_1 = require("./wrapClass"); +exports["default"] = wrapClass_1.wrapClass(0); +// Simple class +var User = /** @class */ (function () { + function User() { + this.name = ''; + } + return User; +}()); +exports.User = User; +// User that is Timestamped +var TimestampedUser = /** @class */ (function (_super) { + __extends(TimestampedUser, _super); + function TimestampedUser() { + return _super.call(this) || this; + } + return TimestampedUser; +}(wrapClass_1.Timestamped(User))); +exports.TimestampedUser = TimestampedUser; + + +//// [wrapClass.d.ts] +export declare function wrapClass(param: any): { + new (): { + foo(): any; + }; +}; +export declare type Constructor = new (...args: any[]) => T; +export declare function Timestamped(Base: TBase): { + new (...args: any[]): { + timestamp: number; + }; +} & TBase; +//// [index.d.ts] +declare const _default: { + new (): { + foo(): any; + }; +}; +export default _default; +export declare class User { + name: string; +} +declare const TimestampedUser_base: { + new (...args: any[]): { + timestamp: number; + }; +} & typeof User; +export declare class TimestampedUser extends TimestampedUser_base { + constructor(); +} diff --git a/tests/baselines/reference/anonClassDeclarationEmitIsAnon.symbols b/tests/baselines/reference/anonClassDeclarationEmitIsAnon.symbols new file mode 100644 index 00000000000..f2988d8cb2e --- /dev/null +++ b/tests/baselines/reference/anonClassDeclarationEmitIsAnon.symbols @@ -0,0 +1,68 @@ +=== tests/cases/compiler/wrapClass.ts === +export function wrapClass(param: any) { +>wrapClass : Symbol(wrapClass, Decl(wrapClass.ts, 0, 0)) +>param : Symbol(param, Decl(wrapClass.ts, 0, 26)) + + return class Wrapped { +>Wrapped : Symbol(Wrapped, Decl(wrapClass.ts, 1, 10)) + + foo() { +>foo : Symbol(Wrapped.foo, Decl(wrapClass.ts, 1, 26)) + + return param; +>param : Symbol(param, Decl(wrapClass.ts, 0, 26)) + } + } +} + +export type Constructor = new (...args: any[]) => T; +>Constructor : Symbol(Constructor, Decl(wrapClass.ts, 6, 1)) +>T : Symbol(T, Decl(wrapClass.ts, 8, 24)) +>args : Symbol(args, Decl(wrapClass.ts, 8, 39)) +>T : Symbol(T, Decl(wrapClass.ts, 8, 24)) + +export function Timestamped(Base: TBase) { +>Timestamped : Symbol(Timestamped, Decl(wrapClass.ts, 8, 60)) +>TBase : Symbol(TBase, Decl(wrapClass.ts, 10, 28)) +>Constructor : Symbol(Constructor, Decl(wrapClass.ts, 6, 1)) +>Base : Symbol(Base, Decl(wrapClass.ts, 10, 55)) +>TBase : Symbol(TBase, Decl(wrapClass.ts, 10, 28)) + + return class extends Base { +>Base : Symbol(Base, Decl(wrapClass.ts, 10, 55)) + + timestamp = Date.now(); +>timestamp : Symbol((Anonymous class).timestamp, Decl(wrapClass.ts, 11, 31)) +>Date.now : Symbol(DateConstructor.now, Decl(lib.es5.d.ts, --, --)) +>Date : Symbol(Date, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.scripthost.d.ts, --, --)) +>now : Symbol(DateConstructor.now, Decl(lib.es5.d.ts, --, --)) + + }; +} + +=== tests/cases/compiler/index.ts === +import { wrapClass, Timestamped } from "./wrapClass"; +>wrapClass : Symbol(wrapClass, Decl(index.ts, 0, 8)) +>Timestamped : Symbol(Timestamped, Decl(index.ts, 0, 19)) + +export default wrapClass(0); +>wrapClass : Symbol(wrapClass, Decl(index.ts, 0, 8)) + +// Simple class +export class User { +>User : Symbol(User, Decl(index.ts, 2, 28)) + + name = ''; +>name : Symbol(User.name, Decl(index.ts, 5, 19)) +} + +// User that is Timestamped +export class TimestampedUser extends Timestamped(User) { +>TimestampedUser : Symbol(TimestampedUser, Decl(index.ts, 7, 1)) +>Timestamped : Symbol(Timestamped, Decl(index.ts, 0, 19)) +>User : Symbol(User, Decl(index.ts, 2, 28)) + + constructor() { + super(); + } +} diff --git a/tests/baselines/reference/anonClassDeclarationEmitIsAnon.types b/tests/baselines/reference/anonClassDeclarationEmitIsAnon.types new file mode 100644 index 00000000000..038b0a49bfb --- /dev/null +++ b/tests/baselines/reference/anonClassDeclarationEmitIsAnon.types @@ -0,0 +1,72 @@ +=== tests/cases/compiler/wrapClass.ts === +export function wrapClass(param: any) { +>wrapClass : (param: any) => typeof Wrapped +>param : any + + return class Wrapped { +>class Wrapped { foo() { return param; } } : typeof Wrapped +>Wrapped : typeof Wrapped + + foo() { +>foo : () => any + + return param; +>param : any + } + } +} + +export type Constructor = new (...args: any[]) => T; +>Constructor : Constructor +>args : any[] + +export function Timestamped(Base: TBase) { +>Timestamped : >(Base: TBase) => { new (...args: any[]): (Anonymous class); prototype: Timestamped.(Anonymous class); } & TBase +>Base : TBase + + return class extends Base { +>class extends Base { timestamp = Date.now(); } : { new (...args: any[]): (Anonymous class); prototype: Timestamped.(Anonymous class); } & TBase +>Base : {} + + timestamp = Date.now(); +>timestamp : number +>Date.now() : number +>Date.now : () => number +>Date : DateConstructor +>now : () => number + + }; +} + +=== tests/cases/compiler/index.ts === +import { wrapClass, Timestamped } from "./wrapClass"; +>wrapClass : (param: any) => typeof Wrapped +>Timestamped : >(Base: TBase) => { new (...args: any[]): (Anonymous class); prototype: Timestamped.(Anonymous class); } & TBase + +export default wrapClass(0); +>wrapClass(0) : typeof Wrapped +>wrapClass : (param: any) => typeof Wrapped +>0 : 0 + +// Simple class +export class User { +>User : User + + name = ''; +>name : string +>'' : "" +} + +// User that is Timestamped +export class TimestampedUser extends Timestamped(User) { +>TimestampedUser : TimestampedUser +>Timestamped(User) : Timestamped.(Anonymous class) & User +>Timestamped : >(Base: TBase) => { new (...args: any[]): (Anonymous class); prototype: Timestamped.(Anonymous class); } & TBase +>User : typeof User + + constructor() { + super(); +>super() : void +>super : { new (...args: any[]): Timestamped.(Anonymous class); prototype: Timestamped.(Anonymous class); } & typeof User + } +} diff --git a/tests/cases/compiler/anonClassDeclarationEmitIsAnon.ts b/tests/cases/compiler/anonClassDeclarationEmitIsAnon.ts new file mode 100644 index 00000000000..e7718e5c01b --- /dev/null +++ b/tests/cases/compiler/anonClassDeclarationEmitIsAnon.ts @@ -0,0 +1,34 @@ +// @declaration: true +// @filename: wrapClass.ts +export function wrapClass(param: any) { + return class Wrapped { + foo() { + return param; + } + } +} + +export type Constructor = new (...args: any[]) => T; + +export function Timestamped(Base: TBase) { + return class extends Base { + timestamp = Date.now(); + }; +} + +// @filename: index.ts +import { wrapClass, Timestamped } from "./wrapClass"; + +export default wrapClass(0); + +// Simple class +export class User { + name = ''; +} + +// User that is Timestamped +export class TimestampedUser extends Timestamped(User) { + constructor() { + super(); + } +} \ No newline at end of file From a03227d60e2da470a8a964903016e2b3d0106950 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Thu, 24 Oct 2019 23:04:42 +0200 Subject: [PATCH 42/63] Avoid a crash with `@typedef` in a script file. (#33847) * Avoid a crash with `@typedef` in a script file. Scripts (as opposed to modules) do not have a symbol object. If a script contains a `@typdef` defined on a namespace called `exports`, TypeScript crashes because it attempts to create an exported symbol on the (non-existent) symbol of the SourceFile. This change avoids the crash by explicitly checking if the source file has a symbol object, i.e. whether it is a module. * Add usage of exports.SomeName typedef. * Fix bug at bind site rather than in declare func --- src/compiler/binder.ts | 11 +++++++-- ...checkJsdocTypedefOnlySourceFile.errors.txt | 18 +++++++++++++++ .../checkJsdocTypedefOnlySourceFile.js | 23 +++++++++++++++++++ .../checkJsdocTypedefOnlySourceFile.symbols | 16 +++++++++++++ .../checkJsdocTypedefOnlySourceFile.types | 20 ++++++++++++++++ .../jsdoc/checkJsdocTypedefOnlySourceFile.ts | 15 ++++++++++++ 6 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/checkJsdocTypedefOnlySourceFile.errors.txt create mode 100644 tests/baselines/reference/checkJsdocTypedefOnlySourceFile.js create mode 100644 tests/baselines/reference/checkJsdocTypedefOnlySourceFile.symbols create mode 100644 tests/baselines/reference/checkJsdocTypedefOnlySourceFile.types create mode 100644 tests/cases/conformance/jsdoc/checkJsdocTypedefOnlySourceFile.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 10700204010..5f36d429556 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2003,7 +2003,12 @@ namespace ts { switch (getAssignmentDeclarationPropertyAccessKind(declName.parent)) { case AssignmentDeclarationKind.ExportsProperty: case AssignmentDeclarationKind.ModuleExports: - container = file; + if (!isExternalOrCommonJsModule(file)) { + container = undefined!; + } + else { + container = file; + } break; case AssignmentDeclarationKind.ThisProperty: container = declName.parent.expression; @@ -2017,7 +2022,9 @@ namespace ts { case AssignmentDeclarationKind.None: return Debug.fail("Shouldn't have detected typedef or enum on non-assignment declaration"); } - declareModuleMember(typeAlias, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes); + if (container) { + declareModuleMember(typeAlias, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes); + } container = oldContainer; } } diff --git a/tests/baselines/reference/checkJsdocTypedefOnlySourceFile.errors.txt b/tests/baselines/reference/checkJsdocTypedefOnlySourceFile.errors.txt new file mode 100644 index 00000000000..52b43068c04 --- /dev/null +++ b/tests/baselines/reference/checkJsdocTypedefOnlySourceFile.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/jsdoc/0.js(10,20): error TS2694: Namespace 'exports' has no exported member 'SomeName'. + + +==== tests/cases/conformance/jsdoc/0.js (1 errors) ==== + // @ts-check + + var exports = {}; + + /** + * @typedef {string} + */ + exports.SomeName; + + /** @type {exports.SomeName} */ + ~~~~~~~~ +!!! error TS2694: Namespace 'exports' has no exported member 'SomeName'. + const myString = 'str'; + \ No newline at end of file diff --git a/tests/baselines/reference/checkJsdocTypedefOnlySourceFile.js b/tests/baselines/reference/checkJsdocTypedefOnlySourceFile.js new file mode 100644 index 00000000000..7f4d7f4bcfd --- /dev/null +++ b/tests/baselines/reference/checkJsdocTypedefOnlySourceFile.js @@ -0,0 +1,23 @@ +//// [0.js] +// @ts-check + +var exports = {}; + +/** + * @typedef {string} + */ +exports.SomeName; + +/** @type {exports.SomeName} */ +const myString = 'str'; + + +//// [0.js] +// @ts-check +var exports = {}; +/** + * @typedef {string} + */ +exports.SomeName; +/** @type {exports.SomeName} */ +var myString = 'str'; diff --git a/tests/baselines/reference/checkJsdocTypedefOnlySourceFile.symbols b/tests/baselines/reference/checkJsdocTypedefOnlySourceFile.symbols new file mode 100644 index 00000000000..0adf9a93444 --- /dev/null +++ b/tests/baselines/reference/checkJsdocTypedefOnlySourceFile.symbols @@ -0,0 +1,16 @@ +=== tests/cases/conformance/jsdoc/0.js === +// @ts-check + +var exports = {}; +>exports : Symbol(exports, Decl(0.js, 2, 3)) + +/** + * @typedef {string} + */ +exports.SomeName; +>exports : Symbol(exports, Decl(0.js, 2, 3)) + +/** @type {exports.SomeName} */ +const myString = 'str'; +>myString : Symbol(myString, Decl(0.js, 10, 5)) + diff --git a/tests/baselines/reference/checkJsdocTypedefOnlySourceFile.types b/tests/baselines/reference/checkJsdocTypedefOnlySourceFile.types new file mode 100644 index 00000000000..fbb4f3ed0ba --- /dev/null +++ b/tests/baselines/reference/checkJsdocTypedefOnlySourceFile.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/jsdoc/0.js === +// @ts-check + +var exports = {}; +>exports : {} +>{} : {} + +/** + * @typedef {string} + */ +exports.SomeName; +>exports.SomeName : any +>exports : {} +>SomeName : any + +/** @type {exports.SomeName} */ +const myString = 'str'; +>myString : any +>'str' : "str" + diff --git a/tests/cases/conformance/jsdoc/checkJsdocTypedefOnlySourceFile.ts b/tests/cases/conformance/jsdoc/checkJsdocTypedefOnlySourceFile.ts new file mode 100644 index 00000000000..d991d2f6e16 --- /dev/null +++ b/tests/cases/conformance/jsdoc/checkJsdocTypedefOnlySourceFile.ts @@ -0,0 +1,15 @@ +// @allowJS: true +// @suppressOutputPathCheck: true + +// @filename: 0.js +// @ts-check + +var exports = {}; + +/** + * @typedef {string} + */ +exports.SomeName; + +/** @type {exports.SomeName} */ +const myString = 'str'; From c404c08fdefde5306e49df2d87f4d55435ddad44 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 24 Oct 2019 15:57:14 -0700 Subject: [PATCH 43/63] Fix reachability analysis for ?? operator (#34702) * Exclude ?? operator from true/false literal check in createFlowCondition * Accept new API baselines * Add tests * Accept new baselines * Address CR feedback * Accept new API baselines --- src/compiler/binder.ts | 10 ++-- src/compiler/utilities.ts | 4 ++ .../reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + .../reference/nullishCoalescingOperator1.js | 44 +++++++++++++++- .../nullishCoalescingOperator1.symbols | 35 +++++++++++++ .../nullishCoalescingOperator1.types | 51 +++++++++++++++++++ .../nullishCoalescingOperator1.ts | 27 +++++++++- 8 files changed, 166 insertions(+), 7 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 5f36d429556..1cc29326660 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1,3 +1,4 @@ + /* @internal */ namespace ts { export const enum ModuleInstanceState { @@ -951,11 +952,10 @@ namespace ts { if (!expression) { return flags & FlowFlags.TrueCondition ? antecedent : unreachableFlow; } - if (expression.kind === SyntaxKind.TrueKeyword && flags & FlowFlags.FalseCondition || - expression.kind === SyntaxKind.FalseKeyword && flags & FlowFlags.TrueCondition) { - if (!isExpressionOfOptionalChainRoot(expression)) { - return unreachableFlow; - } + if ((expression.kind === SyntaxKind.TrueKeyword && flags & FlowFlags.FalseCondition || + expression.kind === SyntaxKind.FalseKeyword && flags & FlowFlags.TrueCondition) && + !isExpressionOfOptionalChainRoot(expression) && !isNullishCoalesce(expression.parent)) { + return unreachableFlow; } if (!isNarrowingExpression(expression)) { return antecedent; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 12b11eeae29..4bff443754b 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -5955,6 +5955,10 @@ namespace ts { return isOptionalChainRoot(node.parent) && node.parent.expression === node; } + export function isNullishCoalesce(node: Node) { + return node.kind === SyntaxKind.BinaryExpression && (node).operatorToken.kind === SyntaxKind.QuestionQuestionToken; + } + export function isNewExpression(node: Node): node is NewExpression { return node.kind === SyntaxKind.NewExpression; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index c43f28c6e90..c06d040800d 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3525,6 +3525,7 @@ declare namespace ts { function isCallExpression(node: Node): node is CallExpression; function isCallChain(node: Node): node is CallChain; function isOptionalChain(node: Node): node is PropertyAccessChain | ElementAccessChain | CallChain; + function isNullishCoalesce(node: Node): boolean; function isNewExpression(node: Node): node is NewExpression; function isTaggedTemplateExpression(node: Node): node is TaggedTemplateExpression; function isTypeAssertion(node: Node): node is TypeAssertion; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index e84b948c938..fe23df054da 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3525,6 +3525,7 @@ declare namespace ts { function isCallExpression(node: Node): node is CallExpression; function isCallChain(node: Node): node is CallChain; function isOptionalChain(node: Node): node is PropertyAccessChain | ElementAccessChain | CallChain; + function isNullishCoalesce(node: Node): boolean; function isNewExpression(node: Node): node is NewExpression; function isTaggedTemplateExpression(node: Node): node is TaggedTemplateExpression; function isTypeAssertion(node: Node): node is TypeAssertion; diff --git a/tests/baselines/reference/nullishCoalescingOperator1.js b/tests/baselines/reference/nullishCoalescingOperator1.js index 87a149c1855..9b857a1473d 100644 --- a/tests/baselines/reference/nullishCoalescingOperator1.js +++ b/tests/baselines/reference/nullishCoalescingOperator1.js @@ -38,10 +38,36 @@ const cc4 = c4 ?? true; const dd1 = d1 ?? {b: 1}; const dd2 = d2 ?? {b: 1}; const dd3 = d3 ?? {b: 1}; -const dd4 = d4 ?? {b: 1}; +const dd4 = d4 ?? {b: 1}; + +// Repro from #34635 + +declare function foo(): void; + +const maybeBool = false; + +if (!(maybeBool ?? true)) { + foo(); +} + +if (maybeBool ?? true) { + foo(); +} +else { + foo(); +} + +if (false ?? true) { + foo(); +} +else { + foo(); +} + //// [nullishCoalescingOperator1.js] "use strict"; +var _a; var aa1 = (a1 !== null && a1 !== void 0 ? a1 : 'whatever'); var aa2 = (a2 !== null && a2 !== void 0 ? a2 : 'whatever'); var aa3 = (a3 !== null && a3 !== void 0 ? a3 : 'whatever'); @@ -58,3 +84,19 @@ var dd1 = (d1 !== null && d1 !== void 0 ? d1 : { b: 1 }); var dd2 = (d2 !== null && d2 !== void 0 ? d2 : { b: 1 }); var dd3 = (d3 !== null && d3 !== void 0 ? d3 : { b: 1 }); var dd4 = (d4 !== null && d4 !== void 0 ? d4 : { b: 1 }); +var maybeBool = false; +if (!((maybeBool !== null && maybeBool !== void 0 ? maybeBool : true))) { + foo(); +} +if ((maybeBool !== null && maybeBool !== void 0 ? maybeBool : true)) { + foo(); +} +else { + foo(); +} +if (_a = false, (_a !== null && _a !== void 0 ? _a : true)) { + foo(); +} +else { + foo(); +} diff --git a/tests/baselines/reference/nullishCoalescingOperator1.symbols b/tests/baselines/reference/nullishCoalescingOperator1.symbols index fb95dee5096..83bd5162280 100644 --- a/tests/baselines/reference/nullishCoalescingOperator1.symbols +++ b/tests/baselines/reference/nullishCoalescingOperator1.symbols @@ -123,3 +123,38 @@ const dd4 = d4 ?? {b: 1}; >d4 : Symbol(d4, Decl(nullishCoalescingOperator1.ts, 19, 13)) >b : Symbol(b, Decl(nullishCoalescingOperator1.ts, 39, 19)) +// Repro from #34635 + +declare function foo(): void; +>foo : Symbol(foo, Decl(nullishCoalescingOperator1.ts, 39, 25)) + +const maybeBool = false; +>maybeBool : Symbol(maybeBool, Decl(nullishCoalescingOperator1.ts, 45, 5)) + +if (!(maybeBool ?? true)) { +>maybeBool : Symbol(maybeBool, Decl(nullishCoalescingOperator1.ts, 45, 5)) + + foo(); +>foo : Symbol(foo, Decl(nullishCoalescingOperator1.ts, 39, 25)) +} + +if (maybeBool ?? true) { +>maybeBool : Symbol(maybeBool, Decl(nullishCoalescingOperator1.ts, 45, 5)) + + foo(); +>foo : Symbol(foo, Decl(nullishCoalescingOperator1.ts, 39, 25)) +} +else { + foo(); +>foo : Symbol(foo, Decl(nullishCoalescingOperator1.ts, 39, 25)) +} + +if (false ?? true) { + foo(); +>foo : Symbol(foo, Decl(nullishCoalescingOperator1.ts, 39, 25)) +} +else { + foo(); +>foo : Symbol(foo, Decl(nullishCoalescingOperator1.ts, 39, 25)) +} + diff --git a/tests/baselines/reference/nullishCoalescingOperator1.types b/tests/baselines/reference/nullishCoalescingOperator1.types index 0e800540ee8..81aa6a7404c 100644 --- a/tests/baselines/reference/nullishCoalescingOperator1.types +++ b/tests/baselines/reference/nullishCoalescingOperator1.types @@ -170,3 +170,54 @@ const dd4 = d4 ?? {b: 1}; >b : number >1 : 1 +// Repro from #34635 + +declare function foo(): void; +>foo : () => void + +const maybeBool = false; +>maybeBool : false +>false : false + +if (!(maybeBool ?? true)) { +>!(maybeBool ?? true) : true +>(maybeBool ?? true) : false +>maybeBool ?? true : false +>maybeBool : false +>true : true + + foo(); +>foo() : void +>foo : () => void +} + +if (maybeBool ?? true) { +>maybeBool ?? true : false +>maybeBool : false +>true : true + + foo(); +>foo() : void +>foo : () => void +} +else { + foo(); +>foo() : void +>foo : () => void +} + +if (false ?? true) { +>false ?? true : false +>false : false +>true : true + + foo(); +>foo() : void +>foo : () => void +} +else { + foo(); +>foo() : void +>foo : () => void +} + diff --git a/tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator1.ts b/tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator1.ts index 80f0c64e7d9..f7024fd8292 100644 --- a/tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator1.ts +++ b/tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator1.ts @@ -1,4 +1,5 @@ // @strict: true +// @allowUnreachableCode: false declare const a1: string | undefined | null declare const a2: string | undefined | null @@ -39,4 +40,28 @@ const cc4 = c4 ?? true; const dd1 = d1 ?? {b: 1}; const dd2 = d2 ?? {b: 1}; const dd3 = d3 ?? {b: 1}; -const dd4 = d4 ?? {b: 1}; \ No newline at end of file +const dd4 = d4 ?? {b: 1}; + +// Repro from #34635 + +declare function foo(): void; + +const maybeBool = false; + +if (!(maybeBool ?? true)) { + foo(); +} + +if (maybeBool ?? true) { + foo(); +} +else { + foo(); +} + +if (false ?? true) { + foo(); +} +else { + foo(); +} From 5e4cd0594e885c3e950cb0b2046c930ed8032837 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 24 Oct 2019 16:49:51 -0700 Subject: [PATCH 44/63] Update CONTRIBUTING.md --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dda3ab28a7b..85fd6ddb233 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -59,11 +59,11 @@ Run `gulp` to build a version of the compiler/language service that reflects cha ## Contributing bug fixes -TypeScript is currently accepting contributions in the form of bug fixes. A bug must have an issue tracking it in the issue tracker that has been approved (labelled ["help wanted"](https://github.com/Microsoft/TypeScript/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22)) by the TypeScript team. Your pull request should include a link to the bug that you are fixing. If you've submitted a PR for a bug, please post a comment in the bug to avoid duplication of effort. +TypeScript is currently accepting contributions in the form of bug fixes. A bug must have an issue tracking it in the issue tracker that has been approved (labelled ["help wanted"](https://github.com/Microsoft/TypeScript/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) or in the "Backlog milestone") by the TypeScript team. Your pull request should include a link to the bug that you are fixing. If you've submitted a PR for a bug, please post a comment in the bug to avoid duplication of effort. ## Contributing features -Features (things that add new or improved functionality to TypeScript) may be accepted, but will need to first be approved ([labelled "help wanted"](https://github.com/Microsoft/TypeScript/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) by a TypeScript project maintainer) in the suggestion issue. Features with language design impact, or that are adequately satisfied with external tools, will not be accepted. +Features (things that add new or improved functionality to TypeScript) may be accepted, but will need to first be approved ([labelled "help wanted"](https://github.com/Microsoft/TypeScript/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22 or in the "Backlog" milestone) by a TypeScript project maintainer) in the suggestion issue. Features with language design impact, or that are adequately satisfied with external tools, will not be accepted. Design changes will not be accepted at this time. If you have a design change proposal, please log a suggestion issue. From 8e1d228a44ebf148c0a4813d18ada8821ed34ffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gorka=20Hern=C3=A1ndez=20Estomba?= Date: Fri, 25 Oct 2019 20:28:50 +0200 Subject: [PATCH 45/63] Update inconsistent use of the word multiline/multi-line in test cases (#34733) The word multi-line and multiline are used interchangeably within the file. Multiline seems to be the most used spelling of the word across the TypeScript repository codebase so a few strings have been updated to keep consistency within a single file. Additionally, corrected a minor capitalization mistake. --- .../unittests/services/colorization.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/testRunner/unittests/services/colorization.ts b/src/testRunner/unittests/services/colorization.ts index 1970fea7b03..c8052cfc17b 100644 --- a/src/testRunner/unittests/services/colorization.ts +++ b/src/testRunner/unittests/services/colorization.ts @@ -57,7 +57,7 @@ describe("unittests:: services:: Colorization", () => { } describe("test getClassifications", () => { - it("Returns correct token classes", () => { + it("returns correct token classes", () => { testLexicalClassification("var x: string = \"foo\" ?? \"bar\"; //Hello", ts.EndOfLineState.None, keyword("var"), @@ -96,14 +96,14 @@ describe("unittests:: services:: Colorization", () => { operator(",")); }); - it("correctly classifies a multi-line string with one backslash", () => { + it("correctly classifies a multiline string with one backslash", () => { testLexicalClassification("'line1\\", ts.EndOfLineState.None, stringLiteral("'line1\\"), finalEndOfLineState(ts.EndOfLineState.InSingleQuoteStringLiteral)); }); - it("correctly classifies a multi-line string with three backslashes", () => { + it("correctly classifies a multiline string with three backslashes", () => { testLexicalClassification("'line1\\\\\\", ts.EndOfLineState.None, stringLiteral("'line1\\\\\\"), @@ -131,42 +131,42 @@ describe("unittests:: services:: Colorization", () => { finalEndOfLineState(ts.EndOfLineState.None)); }); - it("correctly classifies the continuing line of a multi-line string ending in one backslash", () => { + it("correctly classifies the continuing line of a multiline string ending in one backslash", () => { testLexicalClassification("\\", ts.EndOfLineState.InDoubleQuoteStringLiteral, stringLiteral("\\"), finalEndOfLineState(ts.EndOfLineState.InDoubleQuoteStringLiteral)); }); - it("correctly classifies the continuing line of a multi-line string ending in three backslashes", () => { + it("correctly classifies the continuing line of a multiline string ending in three backslashes", () => { testLexicalClassification("\\", ts.EndOfLineState.InDoubleQuoteStringLiteral, stringLiteral("\\"), finalEndOfLineState(ts.EndOfLineState.InDoubleQuoteStringLiteral)); }); - it("correctly classifies the last line of an unterminated multi-line string ending in no backslashes", () => { + it("correctly classifies the last line of an unterminated multiline string ending in no backslashes", () => { testLexicalClassification(" ", ts.EndOfLineState.InDoubleQuoteStringLiteral, stringLiteral(" "), finalEndOfLineState(ts.EndOfLineState.None)); }); - it("correctly classifies the last line of an unterminated multi-line string ending in two backslashes", () => { + it("correctly classifies the last line of an unterminated multiline string ending in two backslashes", () => { testLexicalClassification("\\\\", ts.EndOfLineState.InDoubleQuoteStringLiteral, stringLiteral("\\\\"), finalEndOfLineState(ts.EndOfLineState.None)); }); - it("correctly classifies the last line of an unterminated multi-line string ending in four backslashes", () => { + it("correctly classifies the last line of an unterminated multiline string ending in four backslashes", () => { testLexicalClassification("\\\\\\\\", ts.EndOfLineState.InDoubleQuoteStringLiteral, stringLiteral("\\\\\\\\"), finalEndOfLineState(ts.EndOfLineState.None)); }); - it("correctly classifies the last line of a multi-line string", () => { + it("correctly classifies the last line of a multiline string", () => { testLexicalClassification("'", ts.EndOfLineState.InSingleQuoteStringLiteral, stringLiteral("'"), From a01c8ef7640c811812f8037a3f43a85d3c72746f Mon Sep 17 00:00:00 2001 From: Sangmin Lee Date: Sat, 26 Oct 2019 05:13:00 +0900 Subject: [PATCH 46/63] Fix typo in watchMode.ts (#34701) --- src/testRunner/unittests/tsbuild/watchMode.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/testRunner/unittests/tsbuild/watchMode.ts b/src/testRunner/unittests/tsbuild/watchMode.ts index b2f2eac1582..9e3a0eb9388 100644 --- a/src/testRunner/unittests/tsbuild/watchMode.ts +++ b/src/testRunner/unittests/tsbuild/watchMode.ts @@ -283,8 +283,8 @@ function foo() { }`, /*local*/ true); }); it("builds when new file is added, and its subsequent updates", () => { - const additinalFiles: readonly [SubProject, string][] = [[SubProject.core, newFileWithoutExtension]]; - const { verifyChangeWithFile } = createSolutionInWatchModeToVerifyChanges(additinalFiles); + const additionalFiles: readonly [SubProject, string][] = [[SubProject.core, newFileWithoutExtension]]; + const { verifyChangeWithFile } = createSolutionInWatchModeToVerifyChanges(additionalFiles); verifyChange(newFile.content); // Another change requeues and builds it From f12eee2e4b5b1604c6825672befc262e26531fcb Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 25 Oct 2019 13:48:38 -0700 Subject: [PATCH 47/63] Include *.json in the root files if they are specified as root (#34676) Fixes #33827 --- src/services/services.ts | 4 +- .../unittests/tsserver/projectErrors.ts | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index acd3688f332..a9bdcef8c5f 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -953,9 +953,7 @@ namespace ts { names.push(entry); } else { - if (entry.scriptKind !== ScriptKind.JSON) { - names.push(entry.hostFileName); - } + names.push(entry.hostFileName); } }); return names; diff --git a/src/testRunner/unittests/tsserver/projectErrors.ts b/src/testRunner/unittests/tsserver/projectErrors.ts index f5c28eb7a74..64c07c77010 100644 --- a/src/testRunner/unittests/tsserver/projectErrors.ts +++ b/src/testRunner/unittests/tsserver/projectErrors.ts @@ -861,4 +861,76 @@ declare module '@custom/plugin' { ]); }); }); + + describe("unittests:: tsserver:: Project Errors with resolveJsonModule", () => { + function createSessionForTest({ include }: { include: readonly string[]; }) { + const test: File = { + path: `${projectRoot}/src/test.ts`, + content: `import * as blabla from "./blabla.json"; +declare var console: any; +console.log(blabla);` + }; + const blabla: File = { + path: `${projectRoot}/src/blabla.json`, + content: "{}" + }; + const tsconfig: File = { + path: `${projectRoot}/tsconfig.json`, + content: JSON.stringify({ + compilerOptions: { + resolveJsonModule: true, + composite: true + }, + include + }) + }; + + const host = createServerHost([test, blabla, libFile, tsconfig]); + const session = createSession(host, { canUseEvents: true }); + openFilesForSession([test], session); + return { host, session, test, blabla, tsconfig }; + } + + it("should not report incorrect error when json is root file found by tsconfig", () => { + const { host, session, test } = createSessionForTest({ + include: ["./src/*.ts", "./src/*.json"] + }); + verifyGetErrRequest({ + session, + host, + expected: [ + { + file: test, + syntax: [], + semantic: [], + suggestion: [] + } + ] + }); + }); + + it("should report error when json is not root file found by tsconfig", () => { + const { host, session, test, blabla, tsconfig } = createSessionForTest({ + include: ["./src/*.ts"] + }); + const span = protocolTextSpanFromSubstring(test.content, `"./blabla.json"`); + verifyGetErrRequest({ + session, + host, + expected: [{ + file: test, + syntax: [], + semantic: [ + createDiagnostic( + span.start, + span.end, + Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, + [blabla.path, tsconfig.path] + ) + ], + suggestion: [] + }] + }); + }); + }); } From 88f35937427ca79163a8456528fbf592eb291a2d Mon Sep 17 00:00:00 2001 From: Evan Cahill Date: Fri, 25 Oct 2019 16:04:44 -0700 Subject: [PATCH 48/63] Fix error when exporting const enums (#33060) (#34721) * Allow export declaration to reference const enums * Update baselines * Add test to verify reexported const enums are elided --- src/compiler/checker.ts | 2 +- .../reference/constEnumNoEmitReexport.js | 59 ++++++++++++++++ .../reference/constEnumNoEmitReexport.symbols | 69 +++++++++++++++++++ .../reference/constEnumNoEmitReexport.types | 69 +++++++++++++++++++ .../exportsAndImports1-amd.errors.txt | 40 ----------- .../exportsAndImports1-es6.errors.txt | 40 ----------- .../reference/exportsAndImports1.errors.txt | 40 ----------- .../exportsAndImports3-amd.errors.txt | 40 ----------- .../exportsAndImports3-es6.errors.txt | 40 ----------- .../reference/exportsAndImports3.errors.txt | 40 ----------- .../cases/compiler/constEnumNoEmitReexport.ts | 26 +++++++ 11 files changed, 224 insertions(+), 241 deletions(-) create mode 100644 tests/baselines/reference/constEnumNoEmitReexport.js create mode 100644 tests/baselines/reference/constEnumNoEmitReexport.symbols create mode 100644 tests/baselines/reference/constEnumNoEmitReexport.types delete mode 100644 tests/baselines/reference/exportsAndImports1-amd.errors.txt delete mode 100644 tests/baselines/reference/exportsAndImports1-es6.errors.txt delete mode 100644 tests/baselines/reference/exportsAndImports1.errors.txt delete mode 100644 tests/baselines/reference/exportsAndImports3-amd.errors.txt delete mode 100644 tests/baselines/reference/exportsAndImports3-es6.errors.txt delete mode 100644 tests/baselines/reference/exportsAndImports3.errors.txt create mode 100644 tests/cases/compiler/constEnumNoEmitReexport.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bf50e8b15cd..6314f98bcff 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -27465,7 +27465,7 @@ namespace ts { (node.parent.kind === SyntaxKind.ElementAccessExpression && (node.parent).expression === node) || ((node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName) && isInRightSideOfImportOrExportAssignment(node) || (node.parent.kind === SyntaxKind.TypeQuery && (node.parent).exprName === node)) || - (node.parent.kind === SyntaxKind.ExportSpecifier && (compilerOptions.preserveConstEnums || node.flags & NodeFlags.Ambient)); // We allow reexporting const enums + (node.parent.kind === SyntaxKind.ExportSpecifier); // We allow reexporting const enums if (!ok) { error(node, Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment_or_type_query); diff --git a/tests/baselines/reference/constEnumNoEmitReexport.js b/tests/baselines/reference/constEnumNoEmitReexport.js new file mode 100644 index 00000000000..de1ed1ff032 --- /dev/null +++ b/tests/baselines/reference/constEnumNoEmitReexport.js @@ -0,0 +1,59 @@ +//// [tests/cases/compiler/constEnumNoEmitReexport.ts] //// + +//// [ConstEnum.ts] +export const enum MyConstEnum { + Foo, + Bar +}; +//// [ImportExport.ts] +import { MyConstEnum } from './ConstEnum'; +export { MyConstEnum }; +//// [ImportExportDefault.ts] +import { MyConstEnum } from './ConstEnum'; +export default MyConstEnum; +//// [ReExportDefault.ts] +export { MyConstEnum as default } from './ConstEnum'; +//// [ReExport.ts] +export { MyConstEnum } from './ConstEnum'; +//// [Usage1.ts] +import MyConstEnum1 from './ImportExportDefault'; +import MyConstEnum2 from './ReExportDefault'; +MyConstEnum1.Foo; +MyConstEnum2.Foo; +//// [Usage2.ts] +import { MyConstEnum } from './ImportExport'; +MyConstEnum.Foo; +//// [Usage3.ts] +import { MyConstEnum } from './ReExport'; +MyConstEnum.Foo; + + +//// [ConstEnum.js] +"use strict"; +exports.__esModule = true; +; +//// [ImportExport.js] +"use strict"; +exports.__esModule = true; +//// [ImportExportDefault.js] +"use strict"; +exports.__esModule = true; +//// [ReExportDefault.js] +"use strict"; +exports.__esModule = true; +//// [ReExport.js] +"use strict"; +exports.__esModule = true; +//// [Usage1.js] +"use strict"; +exports.__esModule = true; +0 /* Foo */; +0 /* Foo */; +//// [Usage2.js] +"use strict"; +exports.__esModule = true; +0 /* Foo */; +//// [Usage3.js] +"use strict"; +exports.__esModule = true; +0 /* Foo */; diff --git a/tests/baselines/reference/constEnumNoEmitReexport.symbols b/tests/baselines/reference/constEnumNoEmitReexport.symbols new file mode 100644 index 00000000000..894da1c6705 --- /dev/null +++ b/tests/baselines/reference/constEnumNoEmitReexport.symbols @@ -0,0 +1,69 @@ +=== tests/cases/compiler/ConstEnum.ts === +export const enum MyConstEnum { +>MyConstEnum : Symbol(MyConstEnum, Decl(ConstEnum.ts, 0, 0)) + + Foo, +>Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.ts, 0, 31)) + + Bar +>Bar : Symbol(MyConstEnum.Bar, Decl(ConstEnum.ts, 1, 8)) + +}; +=== tests/cases/compiler/ImportExport.ts === +import { MyConstEnum } from './ConstEnum'; +>MyConstEnum : Symbol(MyConstEnum, Decl(ImportExport.ts, 0, 8)) + +export { MyConstEnum }; +>MyConstEnum : Symbol(MyConstEnum, Decl(ImportExport.ts, 1, 8)) + +=== tests/cases/compiler/ImportExportDefault.ts === +import { MyConstEnum } from './ConstEnum'; +>MyConstEnum : Symbol(MyConstEnum, Decl(ImportExportDefault.ts, 0, 8)) + +export default MyConstEnum; +>MyConstEnum : Symbol(MyConstEnum, Decl(ImportExportDefault.ts, 0, 8)) + +=== tests/cases/compiler/ReExportDefault.ts === +export { MyConstEnum as default } from './ConstEnum'; +>MyConstEnum : Symbol(MyConstEnum, Decl(ConstEnum.ts, 0, 0)) +>default : Symbol(default, Decl(ReExportDefault.ts, 0, 8)) + +=== tests/cases/compiler/ReExport.ts === +export { MyConstEnum } from './ConstEnum'; +>MyConstEnum : Symbol(MyConstEnum, Decl(ReExport.ts, 0, 8)) + +=== tests/cases/compiler/Usage1.ts === +import MyConstEnum1 from './ImportExportDefault'; +>MyConstEnum1 : Symbol(MyConstEnum1, Decl(Usage1.ts, 0, 6)) + +import MyConstEnum2 from './ReExportDefault'; +>MyConstEnum2 : Symbol(MyConstEnum2, Decl(Usage1.ts, 1, 6)) + +MyConstEnum1.Foo; +>MyConstEnum1.Foo : Symbol(MyConstEnum1.Foo, Decl(ConstEnum.ts, 0, 31)) +>MyConstEnum1 : Symbol(MyConstEnum1, Decl(Usage1.ts, 0, 6)) +>Foo : Symbol(MyConstEnum1.Foo, Decl(ConstEnum.ts, 0, 31)) + +MyConstEnum2.Foo; +>MyConstEnum2.Foo : Symbol(MyConstEnum1.Foo, Decl(ConstEnum.ts, 0, 31)) +>MyConstEnum2 : Symbol(MyConstEnum2, Decl(Usage1.ts, 1, 6)) +>Foo : Symbol(MyConstEnum1.Foo, Decl(ConstEnum.ts, 0, 31)) + +=== tests/cases/compiler/Usage2.ts === +import { MyConstEnum } from './ImportExport'; +>MyConstEnum : Symbol(MyConstEnum, Decl(Usage2.ts, 0, 8)) + +MyConstEnum.Foo; +>MyConstEnum.Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.ts, 0, 31)) +>MyConstEnum : Symbol(MyConstEnum, Decl(Usage2.ts, 0, 8)) +>Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.ts, 0, 31)) + +=== tests/cases/compiler/Usage3.ts === +import { MyConstEnum } from './ReExport'; +>MyConstEnum : Symbol(MyConstEnum, Decl(Usage3.ts, 0, 8)) + +MyConstEnum.Foo; +>MyConstEnum.Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.ts, 0, 31)) +>MyConstEnum : Symbol(MyConstEnum, Decl(Usage3.ts, 0, 8)) +>Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.ts, 0, 31)) + diff --git a/tests/baselines/reference/constEnumNoEmitReexport.types b/tests/baselines/reference/constEnumNoEmitReexport.types new file mode 100644 index 00000000000..cec0dfeb03f --- /dev/null +++ b/tests/baselines/reference/constEnumNoEmitReexport.types @@ -0,0 +1,69 @@ +=== tests/cases/compiler/ConstEnum.ts === +export const enum MyConstEnum { +>MyConstEnum : MyConstEnum + + Foo, +>Foo : MyConstEnum.Foo + + Bar +>Bar : MyConstEnum.Bar + +}; +=== tests/cases/compiler/ImportExport.ts === +import { MyConstEnum } from './ConstEnum'; +>MyConstEnum : typeof MyConstEnum + +export { MyConstEnum }; +>MyConstEnum : typeof MyConstEnum + +=== tests/cases/compiler/ImportExportDefault.ts === +import { MyConstEnum } from './ConstEnum'; +>MyConstEnum : typeof MyConstEnum + +export default MyConstEnum; +>MyConstEnum : MyConstEnum + +=== tests/cases/compiler/ReExportDefault.ts === +export { MyConstEnum as default } from './ConstEnum'; +>MyConstEnum : typeof import("tests/cases/compiler/ConstEnum").MyConstEnum +>default : typeof import("tests/cases/compiler/ConstEnum").MyConstEnum + +=== tests/cases/compiler/ReExport.ts === +export { MyConstEnum } from './ConstEnum'; +>MyConstEnum : typeof import("tests/cases/compiler/ConstEnum").MyConstEnum + +=== tests/cases/compiler/Usage1.ts === +import MyConstEnum1 from './ImportExportDefault'; +>MyConstEnum1 : typeof MyConstEnum1 + +import MyConstEnum2 from './ReExportDefault'; +>MyConstEnum2 : typeof MyConstEnum1 + +MyConstEnum1.Foo; +>MyConstEnum1.Foo : MyConstEnum1.Foo +>MyConstEnum1 : typeof MyConstEnum1 +>Foo : MyConstEnum1.Foo + +MyConstEnum2.Foo; +>MyConstEnum2.Foo : MyConstEnum1.Foo +>MyConstEnum2 : typeof MyConstEnum1 +>Foo : MyConstEnum1.Foo + +=== tests/cases/compiler/Usage2.ts === +import { MyConstEnum } from './ImportExport'; +>MyConstEnum : typeof MyConstEnum + +MyConstEnum.Foo; +>MyConstEnum.Foo : MyConstEnum.Foo +>MyConstEnum : typeof MyConstEnum +>Foo : MyConstEnum.Foo + +=== tests/cases/compiler/Usage3.ts === +import { MyConstEnum } from './ReExport'; +>MyConstEnum : typeof MyConstEnum + +MyConstEnum.Foo; +>MyConstEnum.Foo : MyConstEnum.Foo +>MyConstEnum : typeof MyConstEnum +>Foo : MyConstEnum.Foo + diff --git a/tests/baselines/reference/exportsAndImports1-amd.errors.txt b/tests/baselines/reference/exportsAndImports1-amd.errors.txt deleted file mode 100644 index 713f464a608..00000000000 --- a/tests/baselines/reference/exportsAndImports1-amd.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/conformance/es6/modules/t1.ts(23,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. -tests/cases/conformance/es6/modules/t3.ts(2,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - - -==== tests/cases/conformance/es6/modules/t1.ts (1 errors) ==== - var v = 1; - function f() { } - class C { - } - interface I { - } - enum E { - A, B, C - } - const enum D { - A, B, C - } - module M { - export var x; - } - module N { - export interface I { - } - } - type T = number; - import a = M.x; - - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - -==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== - export { v, f, C, I, E, D, M, N, T, a } from "./t1"; - -==== tests/cases/conformance/es6/modules/t3.ts (1 errors) ==== - import { v, f, C, I, E, D, M, N, T, a } from "./t1"; - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - \ No newline at end of file diff --git a/tests/baselines/reference/exportsAndImports1-es6.errors.txt b/tests/baselines/reference/exportsAndImports1-es6.errors.txt deleted file mode 100644 index 713f464a608..00000000000 --- a/tests/baselines/reference/exportsAndImports1-es6.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/conformance/es6/modules/t1.ts(23,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. -tests/cases/conformance/es6/modules/t3.ts(2,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - - -==== tests/cases/conformance/es6/modules/t1.ts (1 errors) ==== - var v = 1; - function f() { } - class C { - } - interface I { - } - enum E { - A, B, C - } - const enum D { - A, B, C - } - module M { - export var x; - } - module N { - export interface I { - } - } - type T = number; - import a = M.x; - - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - -==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== - export { v, f, C, I, E, D, M, N, T, a } from "./t1"; - -==== tests/cases/conformance/es6/modules/t3.ts (1 errors) ==== - import { v, f, C, I, E, D, M, N, T, a } from "./t1"; - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - \ No newline at end of file diff --git a/tests/baselines/reference/exportsAndImports1.errors.txt b/tests/baselines/reference/exportsAndImports1.errors.txt deleted file mode 100644 index 713f464a608..00000000000 --- a/tests/baselines/reference/exportsAndImports1.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/conformance/es6/modules/t1.ts(23,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. -tests/cases/conformance/es6/modules/t3.ts(2,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - - -==== tests/cases/conformance/es6/modules/t1.ts (1 errors) ==== - var v = 1; - function f() { } - class C { - } - interface I { - } - enum E { - A, B, C - } - const enum D { - A, B, C - } - module M { - export var x; - } - module N { - export interface I { - } - } - type T = number; - import a = M.x; - - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - -==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== - export { v, f, C, I, E, D, M, N, T, a } from "./t1"; - -==== tests/cases/conformance/es6/modules/t3.ts (1 errors) ==== - import { v, f, C, I, E, D, M, N, T, a } from "./t1"; - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - \ No newline at end of file diff --git a/tests/baselines/reference/exportsAndImports3-amd.errors.txt b/tests/baselines/reference/exportsAndImports3-amd.errors.txt deleted file mode 100644 index b084c1193f4..00000000000 --- a/tests/baselines/reference/exportsAndImports3-amd.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/conformance/es6/modules/t1.ts(23,55): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. -tests/cases/conformance/es6/modules/t3.ts(2,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - - -==== tests/cases/conformance/es6/modules/t1.ts (1 errors) ==== - export var v = 1; - export function f() { } - export class C { - } - export interface I { - } - export enum E { - A, B, C - } - export const enum D { - A, B, C - } - export module M { - export var x; - } - export module N { - export interface I { - } - } - export type T = number; - export import a = M.x; - - export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - -==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== - export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; - -==== tests/cases/conformance/es6/modules/t3.ts (1 errors) ==== - import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - \ No newline at end of file diff --git a/tests/baselines/reference/exportsAndImports3-es6.errors.txt b/tests/baselines/reference/exportsAndImports3-es6.errors.txt deleted file mode 100644 index b084c1193f4..00000000000 --- a/tests/baselines/reference/exportsAndImports3-es6.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/conformance/es6/modules/t1.ts(23,55): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. -tests/cases/conformance/es6/modules/t3.ts(2,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - - -==== tests/cases/conformance/es6/modules/t1.ts (1 errors) ==== - export var v = 1; - export function f() { } - export class C { - } - export interface I { - } - export enum E { - A, B, C - } - export const enum D { - A, B, C - } - export module M { - export var x; - } - export module N { - export interface I { - } - } - export type T = number; - export import a = M.x; - - export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - -==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== - export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; - -==== tests/cases/conformance/es6/modules/t3.ts (1 errors) ==== - import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - \ No newline at end of file diff --git a/tests/baselines/reference/exportsAndImports3.errors.txt b/tests/baselines/reference/exportsAndImports3.errors.txt deleted file mode 100644 index b084c1193f4..00000000000 --- a/tests/baselines/reference/exportsAndImports3.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/conformance/es6/modules/t1.ts(23,55): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. -tests/cases/conformance/es6/modules/t3.ts(2,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - - -==== tests/cases/conformance/es6/modules/t1.ts (1 errors) ==== - export var v = 1; - export function f() { } - export class C { - } - export interface I { - } - export enum E { - A, B, C - } - export const enum D { - A, B, C - } - export module M { - export var x; - } - export module N { - export interface I { - } - } - export type T = number; - export import a = M.x; - - export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - -==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== - export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; - -==== tests/cases/conformance/es6/modules/t3.ts (1 errors) ==== - import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - \ No newline at end of file diff --git a/tests/cases/compiler/constEnumNoEmitReexport.ts b/tests/cases/compiler/constEnumNoEmitReexport.ts new file mode 100644 index 00000000000..9ef57f12550 --- /dev/null +++ b/tests/cases/compiler/constEnumNoEmitReexport.ts @@ -0,0 +1,26 @@ +// @filename: ConstEnum.ts +export const enum MyConstEnum { + Foo, + Bar +}; +// @filename: ImportExport.ts +import { MyConstEnum } from './ConstEnum'; +export { MyConstEnum }; +// @filename: ImportExportDefault.ts +import { MyConstEnum } from './ConstEnum'; +export default MyConstEnum; +// @filename: ReExportDefault.ts +export { MyConstEnum as default } from './ConstEnum'; +// @filename: ReExport.ts +export { MyConstEnum } from './ConstEnum'; +// @filename: Usage1.ts +import MyConstEnum1 from './ImportExportDefault'; +import MyConstEnum2 from './ReExportDefault'; +MyConstEnum1.Foo; +MyConstEnum2.Foo; +// @filename: Usage2.ts +import { MyConstEnum } from './ImportExport'; +MyConstEnum.Foo; +// @filename: Usage3.ts +import { MyConstEnum } from './ReExport'; +MyConstEnum.Foo; From d8840f8a185a8e428f47d04b5a2294d81c3c0cf2 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Fri, 25 Oct 2019 16:27:24 -0700 Subject: [PATCH 49/63] Show all matching enum flags in debug flag formatter (#34689) * Show all matching enum flags in debug formatter * Revert "Show all matching enum flags in debug formatter" This reverts commit 073099722a297ac0d483566ebd806357dafbb63d. * Same thing but simpler * Lint --- src/compiler/debug.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/debug.ts b/src/compiler/debug.ts index 40ac6c9c94f..9adc4095054 100644 --- a/src/compiler/debug.ts +++ b/src/compiler/debug.ts @@ -100,11 +100,13 @@ namespace ts { if (isFlags) { let result = ""; let remainingFlags = value; - for (let i = members.length - 1; i >= 0 && remainingFlags !== 0; i--) { - const [enumValue, enumName] = members[i]; - if (enumValue !== 0 && (remainingFlags & enumValue) === enumValue) { + for (const [enumValue, enumName] of members) { + if (enumValue > value) { + break; + } + if (enumValue !== 0 && enumValue & value) { + result = `${result}${result ? "|" : ""}${enumName}`; remainingFlags &= ~enumValue; - result = `${enumName}${result ? "|" : ""}${result}`; } } if (remainingFlags === 0) { From eb0208c5892d9feb7eccc723bc9cca212acc0ad6 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Fri, 25 Oct 2019 22:49:31 -0400 Subject: [PATCH 50/63] make `globalThis` have an empty `declarations` (#34561) Fixes #33860 by making it an error. This is an improvement, but sounds like it would be better to make it work later. --- src/compiler/checker.ts | 1 + tests/baselines/reference/extendGlobalThis.symbols | 6 +++--- .../reference/extendGlobalThis2.errors.txt | 10 ++++++++++ tests/baselines/reference/extendGlobalThis2.js | 12 ++++++++++++ tests/baselines/reference/extendGlobalThis2.symbols | 11 +++++++++++ tests/baselines/reference/extendGlobalThis2.types | 13 +++++++++++++ .../reference/globalThisPropertyAssignment.symbols | 4 ++-- tests/cases/compiler/extendGlobalThis2.ts | 3 +++ 8 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/extendGlobalThis2.errors.txt create mode 100644 tests/baselines/reference/extendGlobalThis2.js create mode 100644 tests/baselines/reference/extendGlobalThis2.symbols create mode 100644 tests/baselines/reference/extendGlobalThis2.types create mode 100644 tests/cases/compiler/extendGlobalThis2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6314f98bcff..69f4983ca72 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -319,6 +319,7 @@ namespace ts { const globalThisSymbol = createSymbol(SymbolFlags.Module, "globalThis" as __String, CheckFlags.Readonly); globalThisSymbol.exports = globals; + globalThisSymbol.declarations = []; globals.set(globalThisSymbol.escapedName, globalThisSymbol); const argumentsSymbol = createSymbol(SymbolFlags.Property, "arguments" as __String); diff --git a/tests/baselines/reference/extendGlobalThis.symbols b/tests/baselines/reference/extendGlobalThis.symbols index 944d7b23715..91cd0bf2530 100644 --- a/tests/baselines/reference/extendGlobalThis.symbols +++ b/tests/baselines/reference/extendGlobalThis.symbols @@ -3,7 +3,7 @@ declare global { >global : Symbol(global, Decl(extension.d.ts, 0, 0)) namespace globalThis { ->globalThis : Symbol(globalThis) +>globalThis : Symbol(globalThis, Decl(extension.d.ts, 0, 16)) var test: string; >test : Symbol(test, Decl(extension.d.ts, 2, 11)) @@ -16,7 +16,7 @@ export {} import "./extention"; globalThis.tests = "a-b"; ->globalThis : Symbol(globalThis) +>globalThis : Symbol(globalThis, Decl(extension.d.ts, 0, 16)) console.log(globalThis.test.split("-")); >console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) @@ -24,7 +24,7 @@ console.log(globalThis.test.split("-")); >log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) >globalThis.test.split : Symbol(String.split, Decl(lib.es5.d.ts, --, --)) >globalThis.test : Symbol(test, Decl(extension.d.ts, 2, 11)) ->globalThis : Symbol(globalThis) +>globalThis : Symbol(globalThis, Decl(extension.d.ts, 0, 16)) >test : Symbol(test, Decl(extension.d.ts, 2, 11)) >split : Symbol(String.split, Decl(lib.es5.d.ts, --, --)) diff --git a/tests/baselines/reference/extendGlobalThis2.errors.txt b/tests/baselines/reference/extendGlobalThis2.errors.txt new file mode 100644 index 00000000000..09e78cba92d --- /dev/null +++ b/tests/baselines/reference/extendGlobalThis2.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/extendGlobalThis2.ts(1,11): error TS2397: Declaration name conflicts with built-in global identifier 'globalThis'. + + +==== tests/cases/compiler/extendGlobalThis2.ts (1 errors) ==== + namespace globalThis { + ~~~~~~~~~~ +!!! error TS2397: Declaration name conflicts with built-in global identifier 'globalThis'. + export function foo() { console.log("x"); } + } + \ No newline at end of file diff --git a/tests/baselines/reference/extendGlobalThis2.js b/tests/baselines/reference/extendGlobalThis2.js new file mode 100644 index 00000000000..63f06536ce5 --- /dev/null +++ b/tests/baselines/reference/extendGlobalThis2.js @@ -0,0 +1,12 @@ +//// [extendGlobalThis2.ts] +namespace globalThis { + export function foo() { console.log("x"); } +} + + +//// [extendGlobalThis2.js] +var globalThis; +(function (globalThis) { + function foo() { console.log("x"); } + globalThis.foo = foo; +})(globalThis || (globalThis = {})); diff --git a/tests/baselines/reference/extendGlobalThis2.symbols b/tests/baselines/reference/extendGlobalThis2.symbols new file mode 100644 index 00000000000..f16727a674b --- /dev/null +++ b/tests/baselines/reference/extendGlobalThis2.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/extendGlobalThis2.ts === +namespace globalThis { +>globalThis : Symbol(globalThis, Decl(extendGlobalThis2.ts, 0, 0)) + + export function foo() { console.log("x"); } +>foo : Symbol(foo, Decl(extendGlobalThis2.ts, 0, 22)) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +} + diff --git a/tests/baselines/reference/extendGlobalThis2.types b/tests/baselines/reference/extendGlobalThis2.types new file mode 100644 index 00000000000..4a062194742 --- /dev/null +++ b/tests/baselines/reference/extendGlobalThis2.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/extendGlobalThis2.ts === +namespace globalThis { +>globalThis : typeof globalThis + + export function foo() { console.log("x"); } +>foo : () => void +>console.log("x") : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>"x" : "x" +} + diff --git a/tests/baselines/reference/globalThisPropertyAssignment.symbols b/tests/baselines/reference/globalThisPropertyAssignment.symbols index 1ae4dd5af63..3bc852cbba1 100644 --- a/tests/baselines/reference/globalThisPropertyAssignment.symbols +++ b/tests/baselines/reference/globalThisPropertyAssignment.symbols @@ -1,7 +1,7 @@ === tests/cases/conformance/es2019/globalThisPropertyAssignment.js === this.x = 1 >this.x : Symbol(x, Decl(globalThisPropertyAssignment.js, 0, 0)) ->this : Symbol(globalThis) +>this : Symbol(globalThis, Decl(globalThisPropertyAssignment.js, 3, 12)) >x : Symbol(x, Decl(globalThisPropertyAssignment.js, 0, 0)) var y = 2 @@ -14,6 +14,6 @@ window.z = 3 // should work in JS (even though it's a secondary declaration) globalThis.alpha = 4 >globalThis.alpha : Symbol(alpha, Decl(globalThisPropertyAssignment.js, 3, 12)) ->globalThis : Symbol(globalThis) +>globalThis : Symbol(globalThis, Decl(globalThisPropertyAssignment.js, 3, 12)) >alpha : Symbol(alpha, Decl(globalThisPropertyAssignment.js, 3, 12)) diff --git a/tests/cases/compiler/extendGlobalThis2.ts b/tests/cases/compiler/extendGlobalThis2.ts new file mode 100644 index 00000000000..4949c91cf22 --- /dev/null +++ b/tests/cases/compiler/extendGlobalThis2.ts @@ -0,0 +1,3 @@ +namespace globalThis { + export function foo() { console.log("x"); } +} From 080e41dc90eef45522a83874cb67cb52838ca596 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 28 Oct 2019 10:14:04 -0700 Subject: [PATCH 51/63] Fix type reference to merged prototype property assignment (#34764) The constructor function code path in the return type checking of signatures needs to pass the *merged* symbol of the declaration to getDeclaredTypeOfClassOrInterface. Other callers of getDeclaredTypeOfClassOrInterface do this, or used an already-merged symbol. Fixes #33993 --- src/compiler/checker.ts | 4 +-- ...pertyAssignmentMergedTypeReference.symbols | 20 ++++++++++++++ ...ropertyAssignmentMergedTypeReference.types | 26 +++++++++++++++++++ ...pePropertyAssignmentMergedTypeReference.ts | 14 ++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/prototypePropertyAssignmentMergedTypeReference.symbols create mode 100644 tests/baselines/reference/prototypePropertyAssignmentMergedTypeReference.types create mode 100644 tests/cases/conformance/salsa/prototypePropertyAssignmentMergedTypeReference.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 69f4983ca72..c8df4873377 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13962,13 +13962,13 @@ namespace ts { // If a signature resolution is already in-flight, skip issuing a circularity error // here and just use the `any` type directly const targetReturnType = isResolvingReturnTypeOfSignature(target) ? anyType - : target.declaration && isJSConstructor(target.declaration) ? getDeclaredTypeOfClassOrInterface(target.declaration.symbol) + : target.declaration && isJSConstructor(target.declaration) ? getDeclaredTypeOfClassOrInterface(getMergedSymbol(target.declaration.symbol)) : getReturnTypeOfSignature(target); if (targetReturnType === voidType) { return result; } const sourceReturnType = isResolvingReturnTypeOfSignature(source) ? anyType - : source.declaration && isJSConstructor(source.declaration) ? getDeclaredTypeOfClassOrInterface(source.declaration.symbol) + : source.declaration && isJSConstructor(source.declaration) ? getDeclaredTypeOfClassOrInterface(getMergedSymbol(source.declaration.symbol)) : getReturnTypeOfSignature(source); // The following block preserves behavior forbidding boolean returning functions from being assignable to type guard returning functions diff --git a/tests/baselines/reference/prototypePropertyAssignmentMergedTypeReference.symbols b/tests/baselines/reference/prototypePropertyAssignmentMergedTypeReference.symbols new file mode 100644 index 00000000000..7e3f503c7bc --- /dev/null +++ b/tests/baselines/reference/prototypePropertyAssignmentMergedTypeReference.symbols @@ -0,0 +1,20 @@ +=== tests/cases/conformance/salsa/prototypePropertyAssignmentMergedTypeReference.js === +// https://github.com/microsoft/TypeScript/issues/33993 +var f = function() { +>f : Symbol(f, Decl(prototypePropertyAssignmentMergedTypeReference.js, 1, 3)) + + return 12; +}; + +f.prototype.a = "a"; +>f.prototype : Symbol(f.a, Decl(prototypePropertyAssignmentMergedTypeReference.js, 3, 2)) +>f : Symbol(f, Decl(prototypePropertyAssignmentMergedTypeReference.js, 1, 3)) +>prototype : Symbol(Function.prototype, Decl(lib.es5.d.ts, --, --)) +>a : Symbol(f.a, Decl(prototypePropertyAssignmentMergedTypeReference.js, 3, 2)) + +/** @type {new () => f} */ +var x = f; +>x : Symbol(x, Decl(prototypePropertyAssignmentMergedTypeReference.js, 8, 3)) +>f : Symbol(f, Decl(prototypePropertyAssignmentMergedTypeReference.js, 1, 3)) + + diff --git a/tests/baselines/reference/prototypePropertyAssignmentMergedTypeReference.types b/tests/baselines/reference/prototypePropertyAssignmentMergedTypeReference.types new file mode 100644 index 00000000000..2fa4bcee43b --- /dev/null +++ b/tests/baselines/reference/prototypePropertyAssignmentMergedTypeReference.types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/salsa/prototypePropertyAssignmentMergedTypeReference.js === +// https://github.com/microsoft/TypeScript/issues/33993 +var f = function() { +>f : typeof f +>function() { return 12;} : typeof f + + return 12; +>12 : 12 + +}; + +f.prototype.a = "a"; +>f.prototype.a = "a" : "a" +>f.prototype.a : any +>f.prototype : any +>f : typeof f +>prototype : any +>a : any +>"a" : "a" + +/** @type {new () => f} */ +var x = f; +>x : new () => f +>f : typeof f + + diff --git a/tests/cases/conformance/salsa/prototypePropertyAssignmentMergedTypeReference.ts b/tests/cases/conformance/salsa/prototypePropertyAssignmentMergedTypeReference.ts new file mode 100644 index 00000000000..f79b9e01b5f --- /dev/null +++ b/tests/cases/conformance/salsa/prototypePropertyAssignmentMergedTypeReference.ts @@ -0,0 +1,14 @@ +// https://github.com/microsoft/TypeScript/issues/33993 +// @noEmit: true +// @allowJs: true +// @checkJS: true +// @filename: prototypePropertyAssignmentMergedTypeReference.js +var f = function() { + return 12; +}; + +f.prototype.a = "a"; + +/** @type {new () => f} */ +var x = f; + From 634e0ad52b08ea15f19b7e6359a6249d8491f5c2 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Mon, 28 Oct 2019 10:30:59 -0700 Subject: [PATCH 52/63] Fix extract type on JS function params (#34745) --- src/services/refactors/extractType.ts | 6 +----- .../cases/fourslash/refactorExtractType_js7.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 tests/cases/fourslash/refactorExtractType_js7.ts diff --git a/src/services/refactors/extractType.ts b/src/services/refactors/extractType.ts index ba06814c4ea..70934ef7a7c 100644 --- a/src/services/refactors/extractType.ts +++ b/src/services/refactors/extractType.ts @@ -68,7 +68,7 @@ namespace ts.refactor { if (!selection || !isTypeNode(selection)) return undefined; const checker = context.program.getTypeChecker(); - const firstStatement = Debug.assertDefined(isJS ? findAncestor(selection, isStatementAndHasJSDoc) : findAncestor(selection, isStatement), "Should find a statement"); + const firstStatement = Debug.assertDefined(findAncestor(selection, isStatement), "Should find a statement"); const typeParameters = collectTypeParameters(checker, selection, firstStatement, file); if (!typeParameters) return undefined; @@ -100,10 +100,6 @@ namespace ts.refactor { return undefined; } - function isStatementAndHasJSDoc(n: Node): n is (Statement & HasJSDoc) { - return isStatement(n) && hasJSDocNodes(n); - } - function rangeContainsSkipTrivia(r1: TextRange, node: Node, file: SourceFile): boolean { return rangeContainsStartEnd(r1, skipTrivia(file.text, node.pos), node.end); } diff --git a/tests/cases/fourslash/refactorExtractType_js7.ts b/tests/cases/fourslash/refactorExtractType_js7.ts new file mode 100644 index 00000000000..c3543ef36e2 --- /dev/null +++ b/tests/cases/fourslash/refactorExtractType_js7.ts @@ -0,0 +1,18 @@ +/// + +// @allowJs: true +// @Filename: a.js +////function a(/** @type {/*a*/string/*b*/} */ b) {} + +goTo.file('a.js') +goTo.select("a", "b"); +edit.applyRefactor({ + refactorName: "Extract type", + actionName: "Extract to typedef", + actionDescription: "Extract to typedef", + newContent: `/** + * @typedef {string} /*RENAME*/NewType + */ + +function a(/** @type {NewType} */ b) {}`, +}); From 72b7a6527eff1bbcceeac0ae7f991c74c00947f9 Mon Sep 17 00:00:00 2001 From: Orta Date: Mon, 28 Oct 2019 14:07:36 -0400 Subject: [PATCH 53/63] Adds accept header to the dispatch request when requesting a playground build of monaco (#34763) --- scripts/post-vsts-artifact-comment.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/post-vsts-artifact-comment.js b/scripts/post-vsts-artifact-comment.js index 5b1685ae040..4e2abb3e7e5 100644 --- a/scripts/post-vsts-artifact-comment.js +++ b/scripts/post-vsts-artifact-comment.js @@ -49,7 +49,8 @@ and then running \`npm install\`. }); // Send a ping to https://github.com/orta/make-monaco-builds#pull-request-builds - await gh.request("POST /repos/orta/make-monaco-builds/dispatches", { event_type: +process.env.SOURCE_ISSUE }) + await gh.request("POST /repos/orta/make-monaco-builds/dispatches", + { event_type: +process.env.SOURCE_ISSUE, headers: { "Accept": "application/vnd.github.everest-preview+json" }}) } main().catch(async e => { From a28fcebff2ef93b985cbc1cb6967f47f2411e149 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 28 Oct 2019 11:12:20 -0700 Subject: [PATCH 54/63] Update issue templates (#34767) * Update issue templates * Add config.yml --- .github/ISSUE_TEMPLATE/Bug_report.md | 85 +++++++++++---------- .github/ISSUE_TEMPLATE/Feature_request.md | 92 ++++++++++++----------- .github/ISSUE_TEMPLATE/Question.md | 32 ++++---- .github/ISSUE_TEMPLATE/config.yml | 8 ++ 4 files changed, 116 insertions(+), 101 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/config.yml diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md index 62647a8b163..fe61f3d35e7 100644 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -1,41 +1,44 @@ ---- -name: Bug report -about: Create a report to help us improve - ---- - - - - -**TypeScript Version:** 3.7.x-dev.201xxxxx - - -**Search Terms:** - -**Code** - -```ts -// A *self-contained* demonstration of the problem follows... -// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc. -``` - -**Expected behavior:** - -**Actual behavior:** - -**Playground Link:** - -**Related Issues:** +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + + + + +**TypeScript Version:** 3.7.x-dev.201xxxxx + + +**Search Terms:** + +**Code** + +```ts +// A *self-contained* demonstration of the problem follows... +// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc. +``` + +**Expected behavior:** + +**Actual behavior:** + +**Playground Link:** + +**Related Issues:** diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md index 74525bf2f80..0ef996b5579 100644 --- a/.github/ISSUE_TEMPLATE/Feature_request.md +++ b/.github/ISSUE_TEMPLATE/Feature_request.md @@ -1,45 +1,47 @@ ---- -name: Feature request -about: Suggest an idea for this project - ---- - - - -## Search Terms - - - -## Suggestion - - - -## Use Cases - - - -## Examples - - - -## Checklist - -My suggestion meets these guidelines: - -* [ ] This wouldn't be a breaking change in existing TypeScript/JavaScript code -* [ ] This wouldn't change the runtime behavior of existing JavaScript code -* [ ] This could be implemented without emitting different JS based on the types of the expressions -* [ ] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.) -* [ ] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals). - +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + + + +## Search Terms + + + +## Suggestion + + + +## Use Cases + + + +## Examples + + + +## Checklist + +My suggestion meets these guidelines: + +* [ ] This wouldn't be a breaking change in existing TypeScript/JavaScript code +* [ ] This wouldn't change the runtime behavior of existing JavaScript code +* [ ] This could be implemented without emitting different JS based on the types of the expressions +* [ ] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.) +* [ ] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals). diff --git a/.github/ISSUE_TEMPLATE/Question.md b/.github/ISSUE_TEMPLATE/Question.md index fbb9d150a7c..5b71053ade8 100644 --- a/.github/ISSUE_TEMPLATE/Question.md +++ b/.github/ISSUE_TEMPLATE/Question.md @@ -1,15 +1,17 @@ ---- -name: Question -about: The issue tracker is not for questions. Please use Stack Overflow or other resources for help writing TypeScript code. - ---- - -THE ISSUE TRACKER IS NOT FOR QUESTIONS. - -DO NOT CREATE A NEW ISSUE TO ASK A QUESTION. - -IF YOU ARE HAVING PROBLEMS WITH YOUR TYPESCRIPT CODE, DO NOT ASK A QUESTION HERE. - -Tens of thousands of TypeScript questions have been asked and answered on StackOverflow; see https://stackoverflow.com/questions/tagged/typescript . You can ask questions there or on other websites. - -The only exception is if you have a question about *the TypeScript compiler API itself*. Please post a complete example of what you're trying to do and precisely describe what your question is. +--- +name: Question +about: The issue tracker is not for questions. Please use Stack Overflow or other + resources for help writing TypeScript code. +title: '' +labels: Question +assignees: '' + +--- + +THE ISSUE TRACKER IS NOT FOR QUESTIONS. + +IF YOU ARE HAVING PROBLEMS WITH YOUR TYPESCRIPT CODE, DO NOT ASK A QUESTION HERE. + +Tens of thousands of TypeScript questions have been asked and answered on StackOverflow; see https://stackoverflow.com/questions/tagged/typescript . You can ask questions there or on other websites. + +The only exception is if you have a question about *the TypeScript compiler API itself*. Please post a complete example of what you're trying to do and precisely describe what your question is. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000000..a28b38e80df --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: false +contact_links: + - name: Stack Overflow + url: https://stackoverflow.com/questions/tagged/typescript + about: Please ask and answer questions here. + - name: TypeScript FAQ + url: https://github.com/microsoft/TypeScript/wiki/FAQ + about: Please check the FAQ before filing new issues \ No newline at end of file From 05cbe5ac8ec6163eea3b606df1b8eb8c238559f3 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 28 Oct 2019 11:15:31 -0700 Subject: [PATCH 55/63] Update issue reports agian (#34768) * Update issue templates * Add config.yml * Updates * Updates --- .github/ISSUE_TEMPLATE/Bug_report.md | 4 ++-- .github/ISSUE_TEMPLATE/Feature_request.md | 4 ++-- .github/ISSUE_TEMPLATE/Question.md | 17 ----------------- .github/ISSUE_TEMPLATE/config.yml | 2 +- 4 files changed, 5 insertions(+), 22 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/Question.md diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md index fe61f3d35e7..7b9b2c4a630 100644 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -1,6 +1,6 @@ --- -name: Bug report -about: Create a report to help us improve +name: Bug +about: Create a report to help us improve TypeScript title: '' labels: '' assignees: '' diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md index 0ef996b5579..e5f21faeafe 100644 --- a/.github/ISSUE_TEMPLATE/Feature_request.md +++ b/.github/ISSUE_TEMPLATE/Feature_request.md @@ -1,6 +1,6 @@ --- -name: Feature request -about: Suggest an idea for this project +name: Feature Request +about: Suggest an idea title: '' labels: '' assignees: '' diff --git a/.github/ISSUE_TEMPLATE/Question.md b/.github/ISSUE_TEMPLATE/Question.md deleted file mode 100644 index 5b71053ade8..00000000000 --- a/.github/ISSUE_TEMPLATE/Question.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -name: Question -about: The issue tracker is not for questions. Please use Stack Overflow or other - resources for help writing TypeScript code. -title: '' -labels: Question -assignees: '' - ---- - -THE ISSUE TRACKER IS NOT FOR QUESTIONS. - -IF YOU ARE HAVING PROBLEMS WITH YOUR TYPESCRIPT CODE, DO NOT ASK A QUESTION HERE. - -Tens of thousands of TypeScript questions have been asked and answered on StackOverflow; see https://stackoverflow.com/questions/tagged/typescript . You can ask questions there or on other websites. - -The only exception is if you have a question about *the TypeScript compiler API itself*. Please post a complete example of what you're trying to do and precisely describe what your question is. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index a28b38e80df..e4c59996bd0 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,6 +1,6 @@ blank_issues_enabled: false contact_links: - - name: Stack Overflow + - name: Question url: https://stackoverflow.com/questions/tagged/typescript about: Please ask and answer questions here. - name: TypeScript FAQ From cbbbcfa4c58fb21e5777c8943b18e7ad745dce26 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 28 Oct 2019 14:02:09 -0700 Subject: [PATCH 56/63] Fix incorrectly looking for position in call/new expression arguments when looking for indentation of type arguments (#34779) * Fix incorrectly looking for position in call/new expression arguments when looking for indentation of type arguments Fixes #32487 * Update src/services/formatting/smartIndenter.ts Co-Authored-By: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> --- src/services/formatting/smartIndenter.ts | 5 +++-- .../fourslash/formatTypeArgumentOnNewLine.ts | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/formatTypeArgumentOnNewLine.ts diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 6cc654453e4..5539a8e30cb 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -326,8 +326,9 @@ namespace ts.formatting { export function argumentStartsOnSameLineAsPreviousArgument(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFileLike): boolean { if (isCallOrNewExpression(parent)) { if (!parent.arguments) return false; - - const currentNode = Debug.assertDefined(find(parent.arguments, arg => arg.pos === child.pos)); + const currentNode = find(parent.arguments, arg => arg.pos === child.pos); + // If it's not one of the arguments, don't look past this + if (!currentNode) return false; const currentIndex = parent.arguments.indexOf(currentNode); if (currentIndex === 0) return false; // Can't look at previous node if first diff --git a/tests/cases/fourslash/formatTypeArgumentOnNewLine.ts b/tests/cases/fourslash/formatTypeArgumentOnNewLine.ts new file mode 100644 index 00000000000..8567a5ff06d --- /dev/null +++ b/tests/cases/fourslash/formatTypeArgumentOnNewLine.ts @@ -0,0 +1,18 @@ +/// + +////const genericObject = new GenericObject< +//// /*1*/{} +////>(); +////const genericObject2 = new GenericObject2< +//// /*2*/{}, +//// /*3*/{} +////>(); + +format.document(); + +goTo.marker("1"); +verify.currentLineContentIs(" {}"); +goTo.marker("2"); +verify.currentLineContentIs(" {},"); +goTo.marker("3"); +verify.currentLineContentIs(" {}"); \ No newline at end of file From ff590b622ed01bb93a771e5452204b7da6bc4835 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Tue, 29 Oct 2019 08:40:49 -0700 Subject: [PATCH 57/63] Fix a crash when transforming functions in modules. (#34513) When transforming a module declaration and block, parse tree nodes contained in the module block have their parent pointers reset due to `shouldEmitModuleDeclaration` calling into `isInstantiatedModule`, which needs to set parent pointers to operate. That causes a crash when later transforming any nodes within the module, as retrieving their source file in `getSourceFileOfNode` (via `getOrCreateEmitNode`) fails, due to their new synthesized parent nodes not being in a source file. This change avoids the issue by using the parse tree node in `ts.ts` to decide whether a module declaration should be emitted (i.e. whether the module contains values). This means transformers cannot add values to modules that previously did not contain any. Fixes #34644. --- src/compiler/transformers/ts.ts | 7 ++++- src/testRunner/unittests/transform.ts | 29 +++++++++++++++++++ ...msCorrectly.transformUpdateModuleMember.js | 5 ++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/transformApi/transformsCorrectly.transformUpdateModuleMember.js diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index bdd0f5efcc7..d413a835d0d 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -2452,7 +2452,12 @@ namespace ts { * * @param node The module declaration node. */ - function shouldEmitModuleDeclaration(node: ModuleDeclaration) { + function shouldEmitModuleDeclaration(nodeIn: ModuleDeclaration) { + const node = getParseTreeNode(nodeIn, isModuleDeclaration); + if (!node) { + // If we can't find a parse tree node, assume the node is instantiated. + return true; + } return isInstantiatedModule(node, !!compilerOptions.preserveConstEnums || !!compilerOptions.isolatedModules); } diff --git a/src/testRunner/unittests/transform.ts b/src/testRunner/unittests/transform.ts index ffd5ba7609f..bcb0c93d1a8 100644 --- a/src/testRunner/unittests/transform.ts +++ b/src/testRunner/unittests/transform.ts @@ -447,6 +447,35 @@ namespace Foo { }).outputText; }); + testBaseline("transformUpdateModuleMember", () => { + return transpileModule(` +module MyModule { + const myVariable = 1; + function foo(param: string) {} +} +`, { + transformers: { + before: [renameVariable], + }, + compilerOptions: { + target: ScriptTarget.ES2015, + newLine: NewLineKind.CarriageReturnLineFeed, + } + }).outputText; + + function renameVariable(context: TransformationContext) { + return (sourceFile: SourceFile): SourceFile => { + return visitNode(sourceFile, rootTransform, isSourceFile); + }; + function rootTransform(node: T): Node { + if (isVariableDeclaration(node)) { + return updateVariableDeclaration(node, createIdentifier("newName"), /* type */ undefined, node.initializer); + } + return visitEachChild(node, rootTransform, context); + } + } + }); + // https://github.com/Microsoft/TypeScript/issues/24709 testBaseline("issue24709", () => { const fs = vfs.createFromFileSystem(Harness.IO, /*caseSensitive*/ true); diff --git a/tests/baselines/reference/transformApi/transformsCorrectly.transformUpdateModuleMember.js b/tests/baselines/reference/transformApi/transformsCorrectly.transformUpdateModuleMember.js new file mode 100644 index 00000000000..4dad11f737c --- /dev/null +++ b/tests/baselines/reference/transformApi/transformsCorrectly.transformUpdateModuleMember.js @@ -0,0 +1,5 @@ +var MyModule; +(function (MyModule) { + const newName = 1; + function foo(param) { } +})(MyModule || (MyModule = {})); From 554bd24734f95a4d82f43c01df1fefbfe1021a88 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 29 Oct 2019 08:56:11 -0700 Subject: [PATCH 58/63] Fix checker handling for empty type argument lists (#34790) --- src/compiler/checker.ts | 6 +++--- .../reference/emptyTypeArgumentList.errors.txt | 10 +++++++--- tests/baselines/reference/emptyTypeArgumentList.js | 9 ++++++++- .../reference/emptyTypeArgumentList.symbols | 7 +++++++ .../baselines/reference/emptyTypeArgumentList.types | 10 +++++++++- .../emptyTypeArgumentListWithNew.errors.txt | 10 +++++++--- .../reference/emptyTypeArgumentListWithNew.js | 13 ++++++++++++- .../reference/emptyTypeArgumentListWithNew.symbols | 7 +++++++ .../reference/emptyTypeArgumentListWithNew.types | 10 +++++++++- .../reference/tsxTypeArgumentResolution.errors.txt | 8 +------- tests/cases/compiler/emptyTypeArgumentList.ts | 6 +++++- .../cases/compiler/emptyTypeArgumentListWithNew.ts | 6 +++++- 12 files changed, 80 insertions(+), 22 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c8df4873377..145e3351754 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -23435,7 +23435,7 @@ namespace ts { // the declared number of type parameters, the call has an incorrect arity. const numTypeParameters = length(signature.typeParameters); const minTypeArgumentCount = getMinTypeArgumentCount(signature.typeParameters); - return !typeArguments || + return !some(typeArguments) || (typeArguments.length >= minTypeArgumentCount && typeArguments.length <= numTypeParameters); } @@ -24195,7 +24195,7 @@ namespace ts { if (isSingleNonGenericCandidate) { const candidate = candidates[0]; - if (typeArguments || !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { + if (some(typeArguments) || !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) { return undefined; } if (getSignatureApplicabilityError(node, args, candidate, relation, CheckMode.Normal, /*reportErrors*/ false, /*containingMessageChain*/ undefined)) { @@ -24216,7 +24216,7 @@ namespace ts { if (candidate.typeParameters) { let typeArgumentTypes: Type[] | undefined; - if (typeArguments) { + if (some(typeArguments)) { typeArgumentTypes = checkTypeArguments(candidate, typeArguments, /*reportErrors*/ false); if (!typeArgumentTypes) { candidateForTypeArgumentError = candidate; diff --git a/tests/baselines/reference/emptyTypeArgumentList.errors.txt b/tests/baselines/reference/emptyTypeArgumentList.errors.txt index 395c990a3d9..4f970efb5f2 100644 --- a/tests/baselines/reference/emptyTypeArgumentList.errors.txt +++ b/tests/baselines/reference/emptyTypeArgumentList.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/emptyTypeArgumentList.ts(2,4): error TS1099: Type argument list cannot be empty. -tests/cases/compiler/emptyTypeArgumentList.ts(2,5): error TS2558: Expected 1 type arguments, but got 0. +tests/cases/compiler/emptyTypeArgumentList.ts(6,9): error TS1099: Type argument list cannot be empty. ==== tests/cases/compiler/emptyTypeArgumentList.ts (2 errors) ==== @@ -7,5 +7,9 @@ tests/cases/compiler/emptyTypeArgumentList.ts(2,5): error TS2558: Expected 1 typ foo<>(); ~~ !!! error TS1099: Type argument list cannot be empty. - -!!! error TS2558: Expected 1 type arguments, but got 0. \ No newline at end of file + + // https://github.com/microsoft/TypeScript/issues/33041 + function noParams() {} + noParams<>(); + ~~ +!!! error TS1099: Type argument list cannot be empty. \ No newline at end of file diff --git a/tests/baselines/reference/emptyTypeArgumentList.js b/tests/baselines/reference/emptyTypeArgumentList.js index 30093113be4..8662c255dc2 100644 --- a/tests/baselines/reference/emptyTypeArgumentList.js +++ b/tests/baselines/reference/emptyTypeArgumentList.js @@ -1,7 +1,14 @@ //// [emptyTypeArgumentList.ts] function foo() { } -foo<>(); +foo<>(); + +// https://github.com/microsoft/TypeScript/issues/33041 +function noParams() {} +noParams<>(); //// [emptyTypeArgumentList.js] function foo() { } foo(); +// https://github.com/microsoft/TypeScript/issues/33041 +function noParams() { } +noParams(); diff --git a/tests/baselines/reference/emptyTypeArgumentList.symbols b/tests/baselines/reference/emptyTypeArgumentList.symbols index efbe5705f4f..78573ea57c5 100644 --- a/tests/baselines/reference/emptyTypeArgumentList.symbols +++ b/tests/baselines/reference/emptyTypeArgumentList.symbols @@ -6,3 +6,10 @@ function foo() { } foo<>(); >foo : Symbol(foo, Decl(emptyTypeArgumentList.ts, 0, 0)) +// https://github.com/microsoft/TypeScript/issues/33041 +function noParams() {} +>noParams : Symbol(noParams, Decl(emptyTypeArgumentList.ts, 1, 8)) + +noParams<>(); +>noParams : Symbol(noParams, Decl(emptyTypeArgumentList.ts, 1, 8)) + diff --git a/tests/baselines/reference/emptyTypeArgumentList.types b/tests/baselines/reference/emptyTypeArgumentList.types index 94eb2d878c8..32f6f64d1dc 100644 --- a/tests/baselines/reference/emptyTypeArgumentList.types +++ b/tests/baselines/reference/emptyTypeArgumentList.types @@ -3,6 +3,14 @@ function foo() { } >foo : () => void foo<>(); ->foo<>() : any +>foo<>() : void >foo : () => void +// https://github.com/microsoft/TypeScript/issues/33041 +function noParams() {} +>noParams : () => void + +noParams<>(); +>noParams<>() : void +>noParams : () => void + diff --git a/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt b/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt index 92eb250291a..f0e756d8d93 100644 --- a/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt +++ b/tests/baselines/reference/emptyTypeArgumentListWithNew.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,8): error TS1099: Type argument list cannot be empty. -tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,9): error TS2558: Expected 1 type arguments, but got 0. +tests/cases/compiler/emptyTypeArgumentListWithNew.ts(6,13): error TS1099: Type argument list cannot be empty. ==== tests/cases/compiler/emptyTypeArgumentListWithNew.ts (2 errors) ==== @@ -7,5 +7,9 @@ tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,9): error TS2558: Expecte new foo<>(); ~~ !!! error TS1099: Type argument list cannot be empty. - -!!! error TS2558: Expected 1 type arguments, but got 0. \ No newline at end of file + + // https://github.com/microsoft/TypeScript/issues/33041 + class noParams {} + new noParams<>(); + ~~ +!!! error TS1099: Type argument list cannot be empty. \ No newline at end of file diff --git a/tests/baselines/reference/emptyTypeArgumentListWithNew.js b/tests/baselines/reference/emptyTypeArgumentListWithNew.js index c30fa31609a..bda839b5361 100644 --- a/tests/baselines/reference/emptyTypeArgumentListWithNew.js +++ b/tests/baselines/reference/emptyTypeArgumentListWithNew.js @@ -1,6 +1,10 @@ //// [emptyTypeArgumentListWithNew.ts] class foo { } -new foo<>(); +new foo<>(); + +// https://github.com/microsoft/TypeScript/issues/33041 +class noParams {} +new noParams<>(); //// [emptyTypeArgumentListWithNew.js] var foo = /** @class */ (function () { @@ -9,3 +13,10 @@ var foo = /** @class */ (function () { return foo; }()); new foo(); +// https://github.com/microsoft/TypeScript/issues/33041 +var noParams = /** @class */ (function () { + function noParams() { + } + return noParams; +}()); +new noParams(); diff --git a/tests/baselines/reference/emptyTypeArgumentListWithNew.symbols b/tests/baselines/reference/emptyTypeArgumentListWithNew.symbols index 34ce38aa478..9b2404960af 100644 --- a/tests/baselines/reference/emptyTypeArgumentListWithNew.symbols +++ b/tests/baselines/reference/emptyTypeArgumentListWithNew.symbols @@ -6,3 +6,10 @@ class foo { } new foo<>(); >foo : Symbol(foo, Decl(emptyTypeArgumentListWithNew.ts, 0, 0)) +// https://github.com/microsoft/TypeScript/issues/33041 +class noParams {} +>noParams : Symbol(noParams, Decl(emptyTypeArgumentListWithNew.ts, 1, 12)) + +new noParams<>(); +>noParams : Symbol(noParams, Decl(emptyTypeArgumentListWithNew.ts, 1, 12)) + diff --git a/tests/baselines/reference/emptyTypeArgumentListWithNew.types b/tests/baselines/reference/emptyTypeArgumentListWithNew.types index d89c3dd041f..57f1947c574 100644 --- a/tests/baselines/reference/emptyTypeArgumentListWithNew.types +++ b/tests/baselines/reference/emptyTypeArgumentListWithNew.types @@ -3,6 +3,14 @@ class foo { } >foo : foo new foo<>(); ->new foo<>() : any +>new foo<>() : foo >foo : typeof foo +// https://github.com/microsoft/TypeScript/issues/33041 +class noParams {} +>noParams : noParams + +new noParams<>(); +>new noParams<>() : noParams +>noParams : typeof noParams + diff --git a/tests/baselines/reference/tsxTypeArgumentResolution.errors.txt b/tests/baselines/reference/tsxTypeArgumentResolution.errors.txt index 7b429f073dd..cf6dedd16dd 100644 --- a/tests/baselines/reference/tsxTypeArgumentResolution.errors.txt +++ b/tests/baselines/reference/tsxTypeArgumentResolution.errors.txt @@ -3,9 +3,7 @@ tests/cases/conformance/jsx/file.tsx(18,26): error TS2322: Type 'number' is not tests/cases/conformance/jsx/file.tsx(20,13): error TS2558: Expected 1 type arguments, but got 2. tests/cases/conformance/jsx/file.tsx(22,13): error TS2558: Expected 1 type arguments, but got 2. tests/cases/conformance/jsx/file.tsx(24,12): error TS1099: Type argument list cannot be empty. -tests/cases/conformance/jsx/file.tsx(24,13): error TS2558: Expected 1 type arguments, but got 0. tests/cases/conformance/jsx/file.tsx(26,12): error TS1099: Type argument list cannot be empty. -tests/cases/conformance/jsx/file.tsx(26,13): error TS2558: Expected 1 type arguments, but got 0. tests/cases/conformance/jsx/file.tsx(39,14): error TS2344: Type 'Prop' does not satisfy the constraint '{ a: string; }'. Types of property 'a' are incompatible. Type 'number' is not assignable to type 'string'. @@ -16,7 +14,7 @@ tests/cases/conformance/jsx/file.tsx(51,47): error TS2322: Type 'string' is not tests/cases/conformance/jsx/file.tsx(53,47): error TS2322: Type 'string' is not assignable to type 'number'. -==== tests/cases/conformance/jsx/file.tsx (14 errors) ==== +==== tests/cases/conformance/jsx/file.tsx (12 errors) ==== import React = require('react'); interface Prop { @@ -53,14 +51,10 @@ tests/cases/conformance/jsx/file.tsx(53,47): error TS2322: Type 'string' is not x = a={10} b="hi" />; // error ~~ !!! error TS1099: Type argument list cannot be empty. - -!!! error TS2558: Expected 1 type arguments, but got 0. x = a={10} b="hi">; // error ~~ !!! error TS1099: Type argument list cannot be empty. - -!!! error TS2558: Expected 1 type arguments, but got 0. x= /> // OK diff --git a/tests/cases/compiler/emptyTypeArgumentList.ts b/tests/cases/compiler/emptyTypeArgumentList.ts index f06bbc3afd2..8089b3ed2b1 100644 --- a/tests/cases/compiler/emptyTypeArgumentList.ts +++ b/tests/cases/compiler/emptyTypeArgumentList.ts @@ -1,2 +1,6 @@ function foo() { } -foo<>(); \ No newline at end of file +foo<>(); + +// https://github.com/microsoft/TypeScript/issues/33041 +function noParams() {} +noParams<>(); \ No newline at end of file diff --git a/tests/cases/compiler/emptyTypeArgumentListWithNew.ts b/tests/cases/compiler/emptyTypeArgumentListWithNew.ts index 3a4926f5a8a..f7350ac8017 100644 --- a/tests/cases/compiler/emptyTypeArgumentListWithNew.ts +++ b/tests/cases/compiler/emptyTypeArgumentListWithNew.ts @@ -1,2 +1,6 @@ class foo { } -new foo<>(); \ No newline at end of file +new foo<>(); + +// https://github.com/microsoft/TypeScript/issues/33041 +class noParams {} +new noParams<>(); \ No newline at end of file From dbef230eb84d9bd6de539400de9ee4b9295a09e4 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 29 Oct 2019 10:49:14 -0700 Subject: [PATCH 59/63] This handles when packages are symbol links in mono repo like scenarios to use source files instead of output d.ts from project reference (#34743) * Fix incorrect outDir usage instead of out * Handle symlinks of packages in mono repo like packages Fixes #34723 * Added clarified comment --- src/compiler/program.ts | 14 +- src/server/project.ts | 128 +++++++++++++++--- .../unittests/tsserver/projectReferences.ts | 94 ++++++++++++- .../reference/api/tsserverlibrary.d.ts | 8 ++ 4 files changed, 226 insertions(+), 18 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 59b57bfa99a..c9592d55cf9 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2271,7 +2271,19 @@ namespace ts { // Get source file from normalized fileName function findSourceFile(fileName: string, path: Path, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, refFile: RefFile | undefined, packageId: PackageId | undefined): SourceFile | undefined { if (useSourceOfProjectReferenceRedirect) { - const source = getSourceOfProjectReferenceRedirect(fileName); + let source = getSourceOfProjectReferenceRedirect(fileName); + // If preserveSymlinks is true, module resolution wont jump the symlink + // but the resolved real path may be the .d.ts from project reference + // Note:: Currently we try the real path only if the + // file is from node_modules to avoid having to run real path on all file paths + if (!source && + host.realpath && + options.preserveSymlinks && + isDeclarationFileName(fileName) && + stringContains(fileName, nodeModulesPathPart)) { + const realPath = host.realpath(fileName); + if (realPath !== fileName) source = getSourceOfProjectReferenceRedirect(realPath); + } if (source) { const file = isString(source) ? findSourceFile(source, toPath(source), isDefaultLib, ignoreNoDefaultLib, refFile, packageId) : diff --git a/src/server/project.ts b/src/server/project.ts index 28f9166064d..5121556f53b 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -258,7 +258,8 @@ namespace ts.server { private compilerOptions: CompilerOptions, public compileOnSaveEnabled: boolean, directoryStructureHost: DirectoryStructureHost, - currentDirectory: string | undefined) { + currentDirectory: string | undefined, + customRealpath?: (s: string) => string) { this.directoryStructureHost = directoryStructureHost; this.currentDirectory = this.projectService.getNormalizedAbsolutePath(currentDirectory || ""); this.getCanonicalFileName = this.projectService.toCanonicalFileName; @@ -286,7 +287,7 @@ namespace ts.server { } if (host.realpath) { - this.realpath = path => host.realpath!(path); + this.realpath = customRealpath || (path => host.realpath!(path)); } // Use the current directory as resolution root only if the project created using current directory string @@ -1660,6 +1661,12 @@ namespace ts.server { } } + /*@internal*/ + interface SymlinkedDirectory { + real: string; + realPath: Path; + } + /** * If a file is opened, the server will look for a tsconfig (or jsconfig) * and if successfull create a ConfiguredProject for it. @@ -1673,6 +1680,8 @@ namespace ts.server { readonly canonicalConfigFilePath: NormalizedPath; private projectReferenceCallbacks: ResolvedProjectReferenceCallbacks | undefined; private mapOfDeclarationDirectories: Map | undefined; + private symlinkedDirectories: Map | undefined; + private symlinkedFiles: Map | undefined; /* @internal */ pendingReload: ConfigFileProgramReloadLevel | undefined; @@ -1714,7 +1723,9 @@ namespace ts.server { /*compilerOptions*/ {}, /*compileOnSaveEnabled*/ false, cachedDirectoryStructureHost, - getDirectoryPath(configFileName)); + getDirectoryPath(configFileName), + projectService.host.realpath && (s => this.getRealpath(s)) + ); this.canonicalConfigFilePath = asNormalizedPath(projectService.toCanonicalFileName(configFileName)); } @@ -1727,18 +1738,34 @@ namespace ts.server { useSourceOfProjectReferenceRedirect = () => !!this.languageServiceEnabled && !this.getCompilerOptions().disableSourceOfProjectReferenceRedirect; + private fileExistsIfProjectReferenceDts(file: string) { + const source = this.projectReferenceCallbacks!.getSourceOfProjectReferenceRedirect(file); + return source !== undefined ? + isString(source) ? super.fileExists(source) : true : + undefined; + } + /** * This implementation of fileExists checks if the file being requested is * .d.ts file for the referenced Project. * If it is it returns true irrespective of whether that file exists on host */ fileExists(file: string): boolean { + if (super.fileExists(file)) return true; + if (!this.useSourceOfProjectReferenceRedirect() || !this.projectReferenceCallbacks) return false; + if (!isDeclarationFileName(file)) return false; + // Project references go to source file instead of .d.ts file - if (this.useSourceOfProjectReferenceRedirect() && this.projectReferenceCallbacks) { - const source = this.projectReferenceCallbacks.getSourceOfProjectReferenceRedirect(file); - if (source) return isString(source) ? super.fileExists(source) : true; - } - return super.fileExists(file); + return this.fileOrDirectoryExistsUsingSource(file, /*isFile*/ true); + } + + private directoryExistsIfProjectReferenceDeclDir(dir: string) { + const dirPath = this.toPath(dir); + const dirPathWithTrailingDirectorySeparator = `${dirPath}${directorySeparator}`; + return forEachKey( + this.mapOfDeclarationDirectories!, + declDirPath => dirPath === declDirPath || startsWith(declDirPath, dirPathWithTrailingDirectorySeparator) + ); } /** @@ -1747,14 +1774,17 @@ namespace ts.server { * If it is it returns true irrespective of whether that directory exists on host */ directoryExists(path: string): boolean { - if (super.directoryExists(path)) return true; + if (super.directoryExists(path)) { + this.handleDirectoryCouldBeSymlink(path); + return true; + } if (!this.useSourceOfProjectReferenceRedirect() || !this.projectReferenceCallbacks) return false; if (!this.mapOfDeclarationDirectories) { this.mapOfDeclarationDirectories = createMap(); this.projectReferenceCallbacks.forEachResolvedProjectReference(ref => { if (!ref) return; - const out = ref.commandLine.options.outFile || ref.commandLine.options.outDir; + const out = ref.commandLine.options.outFile || ref.commandLine.options.out; if (out) { this.mapOfDeclarationDirectories!.set(getDirectoryPath(this.toPath(out)), true); } @@ -1767,12 +1797,74 @@ namespace ts.server { } }); } - const dirPath = this.toPath(path); - const dirPathWithTrailingDirectorySeparator = `${dirPath}${directorySeparator}`; - return !!forEachKey( - this.mapOfDeclarationDirectories, - declDirPath => dirPath === declDirPath || startsWith(declDirPath, dirPathWithTrailingDirectorySeparator) - ); + + return this.fileOrDirectoryExistsUsingSource(path, /*isFile*/ false); + } + + private realpathIfSymlinkedProjectReferenceDts(s: string): string | undefined { + return this.symlinkedFiles && this.symlinkedFiles.get(this.toPath(s)); + } + + private getRealpath(s: string): string { + return this.realpathIfSymlinkedProjectReferenceDts(s) || + this.projectService.host.realpath!(s); + } + + private handleDirectoryCouldBeSymlink(directory: string) { + if (!this.useSourceOfProjectReferenceRedirect() || !this.projectReferenceCallbacks) return; + + // Because we already watch node_modules, handle symlinks in there + if (!this.realpath || !stringContains(directory, nodeModulesPathPart)) return; + if (!this.symlinkedDirectories) this.symlinkedDirectories = createMap(); + const directoryPath = ensureTrailingDirectorySeparator(this.toPath(directory)); + if (this.symlinkedDirectories.has(directoryPath)) return; + + const real = this.projectService.host.realpath!(directory); + let realPath: Path; + if (real === directory || + (realPath = ensureTrailingDirectorySeparator(this.toPath(real))) === directoryPath) { + // not symlinked + this.symlinkedDirectories.set(directoryPath, false); + return; + } + + this.symlinkedDirectories.set(directoryPath, { + real: ensureTrailingDirectorySeparator(real), + realPath + }); + } + + private fileOrDirectoryExistsUsingSource(fileOrDirectory: string, isFile: boolean): boolean { + const fileOrDirectoryExistsUsingSource = isFile ? + (file: string) => this.fileExistsIfProjectReferenceDts(file) : + (dir: string) => this.directoryExistsIfProjectReferenceDeclDir(dir); + // Check current directory or file + const result = fileOrDirectoryExistsUsingSource(fileOrDirectory); + if (result !== undefined) return result; + + if (!this.symlinkedDirectories) return false; + const fileOrDirectoryPath = this.toPath(fileOrDirectory); + if (!stringContains(fileOrDirectoryPath, nodeModulesPathPart)) return false; + if (isFile && this.symlinkedFiles && this.symlinkedFiles.has(fileOrDirectoryPath)) return true; + + // If it contains node_modules check if its one of the symlinked path we know of + return firstDefinedIterator( + this.symlinkedDirectories.entries(), + ([directoryPath, symlinkedDirectory]) => { + if (!symlinkedDirectory || !startsWith(fileOrDirectoryPath, directoryPath)) return undefined; + const result = fileOrDirectoryExistsUsingSource(fileOrDirectoryPath.replace(directoryPath, symlinkedDirectory.realPath)); + if (isFile && result) { + if (!this.symlinkedFiles) this.symlinkedFiles = createMap(); + // Store the real path for the file' + const absolutePath = getNormalizedAbsolutePath(fileOrDirectory, this.currentDirectory); + this.symlinkedFiles.set( + fileOrDirectoryPath, + `${symlinkedDirectory.real}${absolutePath.replace(new RegExp(directoryPath, "i"), "")}` + ); + } + return result; + } + ) || false; } /** @@ -1785,6 +1877,8 @@ namespace ts.server { this.pendingReload = ConfigFileProgramReloadLevel.None; this.projectReferenceCallbacks = undefined; this.mapOfDeclarationDirectories = undefined; + this.symlinkedDirectories = undefined; + this.symlinkedFiles = undefined; let result: boolean; switch (reloadLevel) { case ConfigFileProgramReloadLevel.Partial: @@ -1917,6 +2011,8 @@ namespace ts.server { this.configFileSpecs = undefined; this.projectReferenceCallbacks = undefined; this.mapOfDeclarationDirectories = undefined; + this.symlinkedDirectories = undefined; + this.symlinkedFiles = undefined; super.close(); } diff --git a/src/testRunner/unittests/tsserver/projectReferences.ts b/src/testRunner/unittests/tsserver/projectReferences.ts index bbc368b6d8a..0966ad911e3 100644 --- a/src/testRunner/unittests/tsserver/projectReferences.ts +++ b/src/testRunner/unittests/tsserver/projectReferences.ts @@ -1,6 +1,6 @@ namespace ts.projectSystem { describe("unittests:: tsserver:: with project references and tsbuild", () => { - function createHost(files: readonly File[], rootNames: readonly string[]) { + function createHost(files: readonly TestFSWithWatch.FileOrFolderOrSymLink[], rootNames: readonly string[]) { const host = createServerHost(files); // ts build should succeed @@ -1373,5 +1373,97 @@ function foo() { assert.isTrue(projectA.dirty); projectA.updateGraph(); }); + + describe("when references are monorepo like with symlinks", () => { + function verifySession(alreadyBuilt: boolean, extraOptions: CompilerOptions) { + const bPackageJson: File = { + path: `${projectRoot}/packages/B/package.json`, + content: JSON.stringify({ + main: "lib/index.js", + types: "lib/index.d.ts" + }) + }; + const aConfig = config("A", extraOptions, ["../B"]); + const bConfig = config("B", extraOptions); + const aIndex = index("A", `import { foo } from 'b'; +import { bar } from 'b/lib/bar'; +foo(); +bar();`); + const bIndex = index("B", `export function foo() { }`); + const bBar: File = { + path: `${projectRoot}/packages/B/src/bar.ts`, + content: `export function bar() { }` + }; + const bSymlink: SymLink = { + path: `${projectRoot}/node_modules/b`, + symLink: `${projectRoot}/packages/B` + }; + + const files = [libFile, bPackageJson, aConfig, bConfig, aIndex, bIndex, bBar, bSymlink]; + const host = alreadyBuilt ? + createHost(files, [aConfig.path]) : + createServerHost(files); + + // Create symlink in node module + const session = createSession(host, { canUseEvents: true }); + openFilesForSession([aIndex], session); + const service = session.getProjectService(); + const project = service.configuredProjects.get(aConfig.path.toLowerCase())!; + assert.deepEqual(project.getAllProjectErrors(), []); + checkProjectActualFiles( + project, + [aConfig.path, aIndex.path, bIndex.path, bBar.path, libFile.path] + ); + verifyGetErrRequest({ + host, + session, + expected: [ + { file: aIndex, syntax: [], semantic: [], suggestion: [] } + ] + }); + } + + function verifySymlinkScenario(alreadyBuilt: boolean) { + it("with preserveSymlinks turned off", () => { + verifySession(alreadyBuilt, {}); + }); + + it("with preserveSymlinks turned on", () => { + verifySession(alreadyBuilt, { preserveSymlinks: true }); + }); + } + + describe("when solution is not built", () => { + verifySymlinkScenario(/*alreadyBuilt*/ false); + }); + + describe("when solution is already built", () => { + verifySymlinkScenario(/*alreadyBuilt*/ true); + }); + + function config(packageName: string, extraOptions: CompilerOptions, references?: string[]): File { + return { + path: `${projectRoot}/packages/${packageName}/tsconfig.json`, + content: JSON.stringify({ + compilerOptions: { + baseUrl: ".", + outDir: "lib", + rootDir: "src", + composite: true, + ...extraOptions + }, + include: ["src"], + ...(references ? { references: references.map(path => ({ path })) } : {}) + }) + }; + } + + function index(packageName: string, content: string): File { + return { + path: `${projectRoot}/packages/${packageName}/src/index.ts`, + content + }; + } + }); }); } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index c06d040800d..e775580c1fb 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -8684,23 +8684,31 @@ declare namespace ts.server { readonly canonicalConfigFilePath: NormalizedPath; private projectReferenceCallbacks; private mapOfDeclarationDirectories; + private symlinkedDirectories; + private symlinkedFiles; /** Ref count to the project when opened from external project */ private externalProjectRefCount; private projectErrors; private projectReferences; protected isInitialLoadPending: () => boolean; + private fileExistsIfProjectReferenceDts; /** * This implementation of fileExists checks if the file being requested is * .d.ts file for the referenced Project. * If it is it returns true irrespective of whether that file exists on host */ fileExists(file: string): boolean; + private directoryExistsIfProjectReferenceDeclDir; /** * This implementation of directoryExists checks if the directory being requested is * directory of .d.ts file for the referenced Project. * If it is it returns true irrespective of whether that directory exists on host */ directoryExists(path: string): boolean; + private realpathIfSymlinkedProjectReferenceDts; + private getRealpath; + private handleDirectoryCouldBeSymlink; + private fileOrDirectoryExistsUsingSource; /** * If the project has reload from disk pending, it reloads (and then updates graph as part of that) instead of just updating the graph * @returns: true if set of files in the project stays the same and false - otherwise. From f7cb2f2b86e8bb5ced2e8611cebc58b4981ee161 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Tue, 29 Oct 2019 14:26:50 -0700 Subject: [PATCH 60/63] Update user baselines (#34759) --- .../baselines/reference/docker/azure-sdk.log | 91 +++++----- tests/baselines/reference/docker/vscode.log | 23 +-- .../user/TypeScript-React-Native-Starter.log | 2 +- tests/baselines/reference/user/axios-src.log | 4 +- tests/baselines/reference/user/bluebird.log | 159 ---------------- .../user/chrome-devtools-frontend.log | 76 +++----- .../baselines/reference/user/graceful-fs.log | 10 +- tests/baselines/reference/user/prettier.log | 87 ++++----- tests/baselines/reference/user/puppeteer.log | 40 ++-- tests/baselines/reference/user/uglify-js.log | 171 +++++++++--------- tests/baselines/reference/user/webpack.log | 67 ++++--- 11 files changed, 272 insertions(+), 458 deletions(-) diff --git a/tests/baselines/reference/docker/azure-sdk.log b/tests/baselines/reference/docker/azure-sdk.log index 03b78facc92..7d3ea51f7c0 100644 --- a/tests/baselines/reference/docker/azure-sdk.log +++ b/tests/baselines/reference/docker/azure-sdk.log @@ -2,30 +2,33 @@ Exit Code: 1 Standard output: Rush Multi-Project Build Tool 5.X.X - https://rushjs.io -Node.js version is 12.12.0 (pre-LTS) +Node.js version is 12.13.0 (LTS) Starting "rush rebuild" Executing a maximum of ?simultaneous processes... XX of XX: [@azure/core-tracing] completed successfully in ? seconds +XX of XX: [@azure/core-auth] completed successfully in ? seconds +XX of XX: [@azure/logger] completed successfully in ? seconds npm ERR! code ELIFECYCLE npm ERR! errno 2 -npm ERR! @azure/core-http@X.X.X-preview.5 build:tsc: `tsc -p tsconfig.es.json` +npm ERR! @azure/core-http@X.X.X-preview.6 build:tsc: `tsc -p tsconfig.es.json` npm ERR! Exit status 2 npm ERR! -npm ERR! Failed at the @azure/core-http@X.X.X-preview.5 build:tsc script. +npm ERR! Failed at the @azure/core-http@X.X.X-preview.6 build:tsc script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log ERROR: "build:tsc" exited with 2. npm ERR! code ELIFECYCLE npm ERR! errno 1 -npm ERR! @azure/core-http@X.X.X-preview.5 build:lib: `run-s build:tsc build:rollup build:minify-browser` +npm ERR! @azure/core-http@X.X.X-preview.6 build:lib: `run-s build:tsc build:rollup build:minify-browser` npm ERR! Exit status 1 npm ERR! -npm ERR! Failed at the @azure/core-http@X.X.X-preview.5 build:lib script. +npm ERR! Failed at the @azure/core-http@X.X.X-preview.6 build:lib script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log ERROR: "build:lib" exited with 1. +XX of XX: [@azure/test-utils-recorder] completed successfully in ? seconds Warning: You have changed the public API signature for this project. Updating review/event-processor-host.api.md Warning: typings/src/eventProcessorHost.d.ts:32:9 - (TS1086) An accessor cannot be declared in an ambient context. Warning: typings/src/eventProcessorHost.d.ts:36:9 - (TS1086) An accessor cannot be declared in an ambient context. @@ -35,10 +38,8 @@ Warning: typings/src/partitionContext.d.ts:27:9 - (TS1086) An accessor cannot be Warning: typings/src/partitionContext.d.ts:32:9 - (TS1086) An accessor cannot be declared in an ambient context. Warning: typings/src/partitionPump.d.ts:17:9 - (TS1086) An accessor cannot be declared in an ambient context. Warning: typings/src/partitionPump.d.ts:18:9 - (TS1086) An accessor cannot be declared in an ambient context. -XX of XX: [@azure/test-utils-recorder] completed successfully in ? seconds XX of XX: [@azure/abort-controller] completed successfully in ? seconds XX of XX: [@azure/core-asynciterator-polyfill] completed successfully in ? seconds -XX of XX: [@azure/core-auth] completed successfully in ? seconds XX of XX: [@azure/core-paging] completed successfully in ? seconds Warning: You have changed the public API signature for this project. Updating review/cosmos.api.md Warning: dist-esm/ChangeFeedIterator.d.ts:27:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. @@ -77,8 +78,14 @@ Warning: dist-esm/request/ResourceResponse.d.ts:9:9 - (TS1056) Accessors are onl Warning: dist-esm/request/ResourceResponse.d.ts:10:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. Warning: dist-esm/request/ResourceResponse.d.ts:11:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. dist-esm/index.js → dist/index.js... +(!) Unresolved dependencies +https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency +os-name (imported by dist-esm/utils/user-agent.js) +(!) Missing global variable name +Use output.globals to specify browser global variable names corresponding to external modules +os-name (guessing 'osName') created dist/index.js in ?s -XX of XX: [@azure/logger] completed successfully in ? seconds +XX of XX: [@azure/eventhubs-checkpointstore-blob] completed successfully in ? seconds Warning: You have changed the public API signature for this project. Updating review/service-bus.api.md Warning: typings/src/receiver.d.ts:28:9 - (TS1086) An accessor cannot be declared in an ambient context. Warning: typings/src/receiver.d.ts:34:9 - (TS1086) An accessor cannot be declared in an ambient context. @@ -88,22 +95,17 @@ Warning: typings/src/receiver.d.ts:165:9 - (TS1086) An accessor cannot be declar Warning: typings/src/receiver.d.ts:175:9 - (TS1086) An accessor cannot be declared in an ambient context. Warning: typings/src/sender.d.ts:24:9 - (TS1086) An accessor cannot be declared in an ambient context. Warning: typings/src/serviceBusMessage.d.ts:453:9 - (TS1086) An accessor cannot be declared in an ambient context. -XX of XX: [@azure/storage-blob] completed successfully in ? seconds -XX of XX: [@azure/storage-file] completed successfully in ? seconds -XX of XX: [@azure/storage-queue] completed successfully in ? seconds XX of XX: [testhub] completed successfully in ? seconds -SUCCESS (11) +SUCCESS (9) ================================ @azure/core-tracing (? seconds) +@azure/core-auth (? seconds) +@azure/logger (? seconds) @azure/test-utils-recorder (? seconds) @azure/abort-controller (? seconds) @azure/core-asynciterator-polyfill (? seconds) -@azure/core-auth (? seconds) @azure/core-paging (? seconds) -@azure/logger (? seconds) -@azure/storage-blob (? seconds) -@azure/storage-file (? seconds) -@azure/storage-queue (? seconds) +@azure/eventhubs-checkpointstore-blob (? seconds) testhub (? seconds) ================================ SUCCESS WITH WARNINGS (3) @@ -129,20 +131,7 @@ Warning: dist-esm/ChangeFeedResponse.d.ts:45:9 - (TS1056) Accessors are only ava Warning: dist-esm/client/Conflict/Conflict.d.ts:17:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. Warning: dist-esm/client/Container/Container.d.ts:39:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. Warning: dist-esm/client/Container/Container.d.ts:44:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. -Warning: dist-esm/client/Container/Container.d.ts:51:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. -Warning: dist-esm/client/Container/Container.d.ts:55:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. -Warning: dist-esm/client/Database/Database.d.ts:41:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. -Warning: dist-esm/client/Item/Item.d.ts:20:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. -Warning: dist-esm/client/Offer/Offer.d.ts:18:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. -Warning: dist-esm/client/Permission/Permission.d.ts:18:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. -Warning: dist-esm/client/Script/Scripts.d.ts:41:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. -Warning: dist-esm/client/Script/Scripts.d.ts:48:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. -Warning: dist-esm/client/Script/Scripts.d.ts:55:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. -Warning: dist-esm/client/StoredProcedure/StoredProcedure.d.ts:18:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. -Warning: dist-esm/client/StoredProcedure/StoredProcedureResponse.d.ts:17:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. -Warning: dist-esm/client/Trigger/Trigger.d.ts:18:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. -Warning: dist-esm/client/User/User.d.ts:27:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. -Warning: dist-esm/client/UserDefinedFunction/UserDefinedFunction.d.ts:18:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. +[...14 lines omitted...] Warning: dist-esm/client/UserDefinedFunction/UserDefinedFunctionResponse.d.ts:15:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. Warning: dist-esm/queryMetrics/queryMetrics.d.ts:26:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. Warning: dist-esm/request/FeedResponse.d.ts:7:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. @@ -156,6 +145,12 @@ Warning: dist-esm/request/ResourceResponse.d.ts:9:9 - (TS1056) Accessors are onl Warning: dist-esm/request/ResourceResponse.d.ts:10:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. Warning: dist-esm/request/ResourceResponse.d.ts:11:9 - (TS1056) Accessors are only available when targeting ECMAScript 5 and higher. dist-esm/index.js → dist/index.js... +(!) Unresolved dependencies +https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency +os-name (imported by dist-esm/utils/user-agent.js) +(!) Missing global variable name +Use output.globals to specify browser global variable names corresponding to external modules +os-name (guessing 'osName') created dist/index.js in ?s @azure/service-bus (? seconds) Warning: You have changed the public API signature for this project. Updating review/service-bus.api.md @@ -168,18 +163,21 @@ Warning: typings/src/receiver.d.ts:175:9 - (TS1086) An accessor cannot be declar Warning: typings/src/sender.d.ts:24:9 - (TS1086) An accessor cannot be declared in an ambient context. Warning: typings/src/serviceBusMessage.d.ts:453:9 - (TS1086) An accessor cannot be declared in an ambient context. ================================ -BLOCKED (11) +BLOCKED (14) ================================ -@azure/identity -@azure/core-amqp @azure/core-arm -@azure/event-hubs -@azure/app-configuration +@azure/identity @azure/core-lro -@azure/eventhubs-checkpointstore-blob -@azure/keyvault-certificates +@azure/core-amqp @azure/keyvault-keys @azure/keyvault-secrets +@azure/app-configuration +@azure/cognitiveservices-inkrecognizer +@azure/event-hubs +@azure/keyvault-certificates +@azure/storage-blob +@azure/storage-file-share +@azure/storage-queue @azure/template ================================ FAILURE (1) @@ -187,20 +185,20 @@ FAILURE (1) @azure/core-http ( ? seconds) npm ERR! code ELIFECYCLE npm ERR! errno 2 -npm ERR! @azure/core-http@X.X.X-preview.5 build:tsc: `tsc -p tsconfig.es.json` +npm ERR! @azure/core-http@X.X.X-preview.6 build:tsc: `tsc -p tsconfig.es.json` npm ERR! Exit status 2 npm ERR! -npm ERR! Failed at the @azure/core-http@X.X.X-preview.5 build:tsc script. +npm ERR! Failed at the @azure/core-http@X.X.X-preview.6 build:tsc script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log ERROR: "build:tsc" exited with 2. npm ERR! code ELIFECYCLE npm ERR! errno 1 -npm ERR! @azure/core-http@X.X.X-preview.5 build:lib: `run-s build:tsc build:rollup build:minify-browser` +npm ERR! @azure/core-http@X.X.X-preview.6 build:lib: `run-s build:tsc build:rollup build:minify-browser` npm ERR! Exit status 1 npm ERR! -npm ERR! Failed at the @azure/core-http@X.X.X-preview.5 build:lib script. +npm ERR! Failed at the @azure/core-http@X.X.X-preview.6 build:lib script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/XXXX-XX-XXXXXXXXX-debug.log @@ -215,15 +213,18 @@ Standard error: XX of XX: [@azure/core-http] failed to build! XX of XX: [@azure/app-configuration] blocked by [@azure/core-http]! +XX of XX: [@azure/cognitiveservices-inkrecognizer] blocked by [@azure/core-http]! XX of XX: [@azure/core-arm] blocked by [@azure/core-http]! XX of XX: [@azure/core-lro] blocked by [@azure/core-http]! +XX of XX: [@azure/keyvault-keys] blocked by [@azure/core-http]! XX of XX: [@azure/keyvault-certificates] blocked by [@azure/core-http]! +XX of XX: [@azure/keyvault-secrets] blocked by [@azure/core-http]! +XX of XX: [@azure/storage-blob] blocked by [@azure/core-http]! XX of XX: [@azure/identity] blocked by [@azure/core-http]! XX of XX: [@azure/core-amqp] blocked by [@azure/core-http]! XX of XX: [@azure/event-hubs] blocked by [@azure/core-http]! -XX of XX: [@azure/eventhubs-checkpointstore-blob] blocked by [@azure/core-http]! -XX of XX: [@azure/keyvault-keys] blocked by [@azure/core-http]! -XX of XX: [@azure/keyvault-secrets] blocked by [@azure/core-http]! +XX of XX: [@azure/storage-queue] blocked by [@azure/core-http]! +XX of XX: [@azure/storage-file-share] blocked by [@azure/core-http]! XX of XX: [@azure/template] blocked by [@azure/core-http]! XX of XX: [@azure/event-processor-host] completed with warnings in ? seconds XX of XX: [@azure/cosmos] completed with warnings in ? seconds diff --git a/tests/baselines/reference/docker/vscode.log b/tests/baselines/reference/docker/vscode.log index fdd7db9d713..c1a5c3eb6f9 100644 --- a/tests/baselines/reference/docker/vscode.log +++ b/tests/baselines/reference/docker/vscode.log @@ -4,21 +4,22 @@ yarn run vX.X.X $ gulp compile --max_old_space_size=4095 [XX:XX:XX] Node flags detected: --max_old_space_size=4095 [XX:XX:XX] Using gulpfile /vscode/gulpfile.js +[XX:XX:XX] Error: /vscode/extensions/typescript-language-features/src/features/fileConfigurationManager.ts(170,4): Type 'string | undefined' is not assignable to type 'SemicolonPreference | undefined'. + Type 'string' is not assignable to type 'SemicolonPreference | undefined'. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. Standard error: [XX:XX:XX] 'compile' errored after ?s -[XX:XX:XX] TypeError: Cannot read property 'text' of undefined - at DeclarationResolver._getDeclarationSourceFile (/vscode/build/monaco/api.js:519:75) - at DeclarationResolver.getDeclarationSourceFile (/vscode/build/monaco/api.js:493:52) - at sourceFileGetter (/vscode/build/monaco/api.js:525:53) - at lines.forEach.line (/vscode/build/monaco/api.js:330:32) - at Array.forEach () - at generateDeclarationFile (/vscode/build/monaco/api.js:319:11) - at _run (/vscode/build/monaco/api.js:438:15) - at Object.run3 (/vscode/build/monaco/api.js:526:12) - at MonacoGenerator._run (/vscode/build/lib/compilation.js:142:27) - at MonacoGenerator.execute (/vscode/build/lib/compilation.js:154:29) +[XX:XX:XX] Error: Found 1 errors + at Stream. (/vscode/build/lib/reporter.js:74:29) + at _end (/vscode/node_modules/through/index.js:65:9) + at Stream.stream.end (/vscode/node_modules/through/index.js:74:5) + at StreamFilter.onend (/vscode/node_modules/readable-stream/lib/_stream_readable.js:570:10) + at Object.onceWrapper (events.js:286:20) + at StreamFilter.emit (events.js:203:15) + at StreamFilter.EventEmitter.emit (domain.js:466:23) + at endReadableNT (/vscode/node_modules/readable-stream/lib/_stream_readable.js:992:12) + at process._tickCallback (internal/process/next_tick.js:63:19) error Command failed with exit code 1. diff --git a/tests/baselines/reference/user/TypeScript-React-Native-Starter.log b/tests/baselines/reference/user/TypeScript-React-Native-Starter.log index 7741454bfa0..b1e05a3af26 100644 --- a/tests/baselines/reference/user/TypeScript-React-Native-Starter.log +++ b/tests/baselines/reference/user/TypeScript-React-Native-Starter.log @@ -3,7 +3,7 @@ Standard output: node_modules/@types/react-native/index.d.ts(3425,42): error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later. node_modules/@types/react-native/index.d.ts(3438,42): error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later. node_modules/@types/react-native/index.d.ts(8745,18): error TS2717: Subsequent property declarations must have the same type. Property 'geolocation' must be of type 'Geolocation', but here has type 'GeolocationStatic'. -node_modules/@types/react/index.d.ts(373,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. +node_modules/@types/react/index.d.ts(386,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. diff --git a/tests/baselines/reference/user/axios-src.log b/tests/baselines/reference/user/axios-src.log index 472cb6dd8e9..b9c1388292a 100644 --- a/tests/baselines/reference/user/axios-src.log +++ b/tests/baselines/reference/user/axios-src.log @@ -14,8 +14,8 @@ lib/adapters/xhr.js(64,7): error TS2322: Type 'null' is not assignable to type ' lib/adapters/xhr.js(76,7): error TS2322: Type 'null' is not assignable to type 'XMLHttpRequest'. lib/adapters/xhr.js(83,51): error TS2345: Argument of type 'null' is not assignable to parameter of type 'string | undefined'. lib/adapters/xhr.js(86,7): error TS2322: Type 'null' is not assignable to type 'XMLHttpRequest'. -lib/adapters/xhr.js(95,7): error TS2322: Type 'null' is not assignable to type 'XMLHttpRequest'. -lib/adapters/xhr.js(165,9): error TS2322: Type 'null' is not assignable to type 'XMLHttpRequest'. +lib/adapters/xhr.js(99,7): error TS2322: Type 'null' is not assignable to type 'XMLHttpRequest'. +lib/adapters/xhr.js(169,9): error TS2322: Type 'null' is not assignable to type 'XMLHttpRequest'. lib/axios.js(23,9): error TS2554: Expected 3 arguments, but got 2. lib/axios.js(25,3): error TS2739: Type '(...args: any[]) => any' is missing the following properties from type 'Axios': defaults, interceptors, request, getUri lib/axios.js(32,7): error TS2339: Property 'Axios' does not exist on type 'Axios'. diff --git a/tests/baselines/reference/user/bluebird.log b/tests/baselines/reference/user/bluebird.log index 7f91d19ebd4..4026f5c7f0f 100644 --- a/tests/baselines/reference/user/bluebird.log +++ b/tests/baselines/reference/user/bluebird.log @@ -3,90 +3,23 @@ Standard output: node_modules/bluebird/js/release/assert.js(11,30): error TS2339: Property 'constructor$' does not exist on type 'Error'. node_modules/bluebird/js/release/bluebird.js(5,15): error TS2367: This condition will always return 'false' since the types 'PromiseConstructor' and 'typeof Promise' have no overlap. node_modules/bluebird/js/release/bluebird.js(10,10): error TS2339: Property 'noConflict' does not exist on type 'typeof Promise'. -node_modules/bluebird/js/release/call_get.js(11,24): error TS2339: Property 'canEvaluate' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/call_get.js(12,25): error TS2339: Property 'isIdentifier' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/call_get.js(73,40): error TS2339: Property 'classString' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/call_get.js(74,27): error TS2554: Expected 0 arguments, but got 1. -node_modules/bluebird/js/release/cancel.js(4,21): error TS2339: Property 'tryCatch' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/cancel.js(5,21): error TS2339: Property 'errorObj' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/cancel.js(93,14): error TS2339: Property 'isArray' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/catch_filter.js(5,21): error TS2339: Property 'tryCatch' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/catch_filter.js(6,21): error TS2339: Property 'errorObj' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/catch_filter.js(26,29): error TS2339: Property 'isObject' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(8,27): error TS2339: Property 'canAttachTrace' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(19,25): error TS2339: Property 'env' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(21,31): error TS2339: Property 'env' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(22,31): error TS2339: Property 'env' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(24,24): error TS2339: Property 'env' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(25,24): error TS2339: Property 'env' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(27,31): error TS2339: Property 'env' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(28,24): error TS2339: Property 'env' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(30,29): error TS2339: Property 'env' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(31,25): error TS2339: Property 'env' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(156,39): error TS2339: Property 'contextBind' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(161,38): error TS2339: Property 'contextBind' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(199,28): error TS2339: Property 'global' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(200,18): error TS2339: Property 'global' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(204,18): error TS2339: Property 'global' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(209,28): error TS2339: Property 'global' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(210,18): error TS2339: Property 'global' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(214,18): error TS2339: Property 'global' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(225,30): error TS2339: Property 'global' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(230,26): error TS2339: Property 'global' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(236,18): error TS2339: Property 'global' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/debuggability.js(252,17): error TS2403: Subsequent variable declarations must have the same type. Variable 'event' must be of type 'CustomEvent', but here has type 'Event'. -node_modules/bluebird/js/release/debuggability.js(253,18): error TS2339: Property 'global' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/debuggability.js(259,26): error TS2339: Property 'detail' does not exist on type 'Event'. -node_modules/bluebird/js/release/debuggability.js(267,18): error TS2339: Property 'global' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(283,14): error TS2339: Property 'isNode' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/debuggability.js(285,48): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '["multipleResolves", MultipleResolveListener]'. -node_modules/bluebird/js/release/debuggability.js(288,19): error TS2339: Property 'global' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(295,31): error TS2339: Property 'global' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(297,31): error TS2339: Property 'global' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/debuggability.js(328,56): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type 'any[]'. Type 'IArguments' is missing the following properties from type 'any[]': pop, push, concat, join, and 26 more. -node_modules/bluebird/js/release/debuggability.js(360,18): error TS2339: Property 'isObject' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(436,51): error TS2554: Expected 0 arguments, but got 1. -node_modules/bluebird/js/release/debuggability.js(450,18): error TS2339: Property 'isArray' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(522,18): error TS2339: Property 'notEnumerableProp' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(524,18): error TS2339: Property 'notEnumerableProp' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/debuggability.js(589,19): error TS2350: Only a void function can be called with the 'new' keyword. node_modules/bluebird/js/release/debuggability.js(660,59): error TS2554: Expected 0 arguments, but got 1. -node_modules/bluebird/js/release/debuggability.js(699,18): error TS2339: Property 'isObject' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(746,46): error TS2554: Expected 0 arguments, but got 1. node_modules/bluebird/js/release/debuggability.js(834,5): error TS2721: Cannot invoke an object which is possibly 'null'. -node_modules/bluebird/js/release/debuggability.js(837,6): error TS2339: Property 'inherits' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/debuggability.js(852,30): error TS2339: Property 'stack' does not exist on type 'CapturedTrace'. node_modules/bluebird/js/release/debuggability.js(858,37): error TS2339: Property 'stack' does not exist on type 'CapturedTrace'. node_modules/bluebird/js/release/debuggability.js(897,38): error TS2339: Property 'stack' does not exist on type 'CapturedTrace'. -node_modules/bluebird/js/release/debuggability.js(902,10): error TS2339: Property 'notEnumerableProp' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(903,10): error TS2339: Property 'notEnumerableProp' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/debuggability.js(977,4): error TS2554: Expected 0 arguments, but got 1. -node_modules/bluebird/js/release/debuggability.js(983,14): error TS2339: Property 'isNode' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/debuggability.js(988,22): error TS2339: Property 'isNode' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/errors.js(5,21): error TS2339: Property 'inherits' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/errors.js(6,30): error TS2339: Property 'notEnumerableProp' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/errors.js(10,49): error TS2350: Only a void function can be called with the 'new' keyword. -node_modules/bluebird/js/release/finally.js(5,21): error TS2339: Property 'errorObj' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/finally.js(126,22): error TS2339: Property 'isObject' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/finally.js(131,61): error TS2339: Property 'classString' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/generators.js(11,21): error TS2339: Property 'errorObj' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/generators.js(12,21): error TS2339: Property 'tryCatch' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/generators.js(55,6): error TS2339: Property 'inherits' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/generators.js(159,21): error TS2350: Only a void function can be called with the 'new' keyword. node_modules/bluebird/js/release/generators.js(190,15): error TS2350: Only a void function can be called with the 'new' keyword. node_modules/bluebird/js/release/generators.js(208,15): error TS2350: Only a void function can be called with the 'new' keyword. -node_modules/bluebird/js/release/generators.js(208,68): error TS2339: Property 'classString' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/generators.js(220,16): error TS2554: Expected 0 arguments, but got 1. -node_modules/bluebird/js/release/join.js(5,24): error TS2339: Property 'canEvaluate' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/join.js(6,21): error TS2339: Property 'tryCatch' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/join.js(7,21): error TS2339: Property 'errorObj' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/join.js(150,42): error TS2339: Property 'contextBind' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/map.js(9,21): error TS2339: Property 'tryCatch' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/map.js(10,21): error TS2339: Property 'errorObj' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/map.js(17,27): error TS2339: Property 'contextBind' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/map.js(25,14): error TS2339: Property 'isArray' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/map.js(34,6): error TS2339: Property 'inherits' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/map.js(37,10): error TS2551: Property '_init$' does not exist on type 'MappingPromiseArray'. Did you mean '_init'? node_modules/bluebird/js/release/map.js(43,23): error TS2339: Property '_values' does not exist on type 'MappingPromiseArray'. node_modules/bluebird/js/release/map.js(44,23): error TS2339: Property 'length' does not exist on type 'MappingPromiseArray'. @@ -101,77 +34,40 @@ node_modules/bluebird/js/release/map.js(108,18): error TS2339: Property '_resolv node_modules/bluebird/js/release/map.js(118,23): error TS2339: Property '_values' does not exist on type 'MappingPromiseArray'. node_modules/bluebird/js/release/map.js(120,18): error TS2339: Property '_isResolved' does not exist on type 'MappingPromiseArray'. node_modules/bluebird/js/release/map.js(134,10): error TS2339: Property '_resolve' does not exist on type 'MappingPromiseArray'. -node_modules/bluebird/js/release/map.js(143,68): error TS2339: Property 'classString' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/map.js(152,42): error TS2339: Property 'classString' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/map.js(158,35): error TS2339: Property 'classString' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/map.js(163,66): error TS2339: Property 'promise' does not exist on type 'MappingPromiseArray'. -node_modules/bluebird/js/release/method.js(5,21): error TS2339: Property 'tryCatch' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/method.js(9,76): error TS2339: Property 'classString' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/method.js(26,68): error TS2339: Property 'classString' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/method.js(36,22): error TS2339: Property 'isArray' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/method.js(49,24): error TS2339: Property 'errorObj' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/nodeback.js(3,29): error TS2339: Property 'maybeWrapAsError' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/nodeback.js(30,10): error TS2339: Property 'markAsOriginatingFromRejection' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/nodeify.js(5,21): error TS2339: Property 'tryCatch' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/nodeify.js(6,21): error TS2339: Property 'errorObj' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/nodeify.js(10,15): error TS2339: Property 'isArray' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/nodeify.js(32,19): error TS2339: Property 'cause' does not exist on type 'Error'. node_modules/bluebird/js/release/promise.js(4,12): error TS2350: Only a void function can be called with the 'new' keyword. node_modules/bluebird/js/release/promise.js(7,24): error TS2339: Property 'PromiseInspection' does not exist on type 'typeof Promise'. node_modules/bluebird/js/release/promise.js(10,27): error TS2350: Only a void function can be called with the 'new' keyword. -node_modules/bluebird/js/release/promise.js(15,6): error TS2339: Property 'setReflectHandler' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise.js(33,26): error TS2339: Property 'isNode' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promise.js(38,20): error TS2531: Object is possibly 'null'. -node_modules/bluebird/js/release/promise.js(41,23): error TS2339: Property 'isNode' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise.js(42,6): error TS2339: Property 'notEnumerableProp' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promise.js(44,5): error TS2322: Type '() => { domain: Domain | null; async: AsyncResource; }' is not assignable to type '(() => null) | (() => { domain: Domain | null; async: null; })'. Type '() => { domain: Domain | null; async: AsyncResource; }' is not assignable to type '() => null'. Type '{ domain: NodeJS.Domain | null; async: AsyncResource; }' is not assignable to type 'null'. -node_modules/bluebird/js/release/promise.js(45,10): error TS2339: Property 'notEnumerableProp' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise.js(49,10): error TS2339: Property 'notEnumerableProp' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise.js(82,21): error TS2339: Property 'errorObj' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise.js(83,21): error TS2339: Property 'tryCatch' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promise.js(86,15): error TS2350: Only a void function can be called with the 'new' keyword. node_modules/bluebird/js/release/promise.js(89,15): error TS2350: Only a void function can be called with the 'new' keyword. -node_modules/bluebird/js/release/promise.js(89,68): error TS2339: Property 'classString' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise.js(119,22): error TS2339: Property 'isObject' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise.js(123,59): error TS2339: Property 'classString' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promise.js(130,19): error TS2350: Only a void function can be called with the 'new' keyword. -node_modules/bluebird/js/release/promise.js(131,60): error TS2554: Expected 0 arguments, but got 1. -node_modules/bluebird/js/release/promise.js(148,22): error TS2339: Property 'classString' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise.js(150,32): error TS2339: Property 'classString' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promise.js(152,14): error TS2339: Property '_warn' does not exist on type 'Promise'. -node_modules/bluebird/js/release/promise.js(165,68): error TS2339: Property 'classString' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promise.js(177,14): error TS2551: Property 'isFulfilled' does not exist on type 'Promise'. Did you mean '_setFulfilled'? node_modules/bluebird/js/release/promise.js(178,37): error TS2339: Property 'value' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(180,21): error TS2551: Property 'isRejected' does not exist on type 'Promise'. Did you mean '_setRejected'? node_modules/bluebird/js/release/promise.js(181,36): error TS2339: Property 'reason' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(189,14): error TS2339: Property '_warn' does not exist on type 'Promise'. -node_modules/bluebird/js/release/promise.js(195,29): error TS2339: Property 'originatesFromRejection' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promise.js(206,9): error TS2339: Property '_captureStackTrace' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(236,9): error TS2339: Property '_captureStackTrace' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(243,15): error TS2350: Only a void function can be called with the 'new' keyword. -node_modules/bluebird/js/release/promise.js(243,68): error TS2339: Property 'classString' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promise.js(267,63): error TS2339: Property '_boundTo' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(270,14): error TS2339: Property '_fireEvent' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(282,20): error TS2339: Property '_unsetRejectionIsUnhandled' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(286,20): error TS2339: Property '_attachExtraTrace' does not exist on type 'Promise'. -node_modules/bluebird/js/release/promise.js(291,27): error TS2339: Property 'contextBind' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promise.js(323,10): error TS2339: Property '_fireEvent' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(328,10): error TS2339: Property '_fireEvent' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(333,10): error TS2339: Property '_fireEvent' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(350,10): error TS2339: Property '_fireEvent' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(375,42): error TS2339: Property '_isBound' does not exist on type 'Promise'. -node_modules/bluebird/js/release/promise.js(435,46): error TS2339: Property 'contextBind' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise.js(438,44): error TS2339: Property 'contextBind' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise.js(446,22): error TS2339: Property 'contextBind' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise.js(450,22): error TS2339: Property 'contextBind' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promise.js(468,26): error TS2339: Property '_propagateFrom' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(489,31): error TS2339: Property '_value' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(491,30): error TS2339: Property '_reason' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(494,17): error TS2339: Property '_attachExtraTrace' does not exist on type 'Promise'. -node_modules/bluebird/js/release/promise.js(501,22): error TS2339: Property 'ensureErrorObject' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise.js(505,18): error TS2339: Property 'classString' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promise.js(506,14): error TS2339: Property '_warn' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(508,10): error TS2339: Property '_attachExtraTrace' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(515,10): error TS2339: Property '_captureStackTrace' does not exist on type 'Promise'. @@ -179,55 +75,25 @@ node_modules/bluebird/js/release/promise.js(516,10): error TS2339: Property '_pu node_modules/bluebird/js/release/promise.js(518,18): error TS2339: Property '_execute' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(524,10): error TS2339: Property '_popContext' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(541,19): error TS2350: Only a void function can be called with the 'new' keyword. -node_modules/bluebird/js/release/promise.js(542,42): error TS2339: Property 'classString' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promise.js(593,22): error TS2339: Property '_promiseCancelled' does not exist on type '{}'. node_modules/bluebird/js/release/promise.js(607,23): error TS2339: Property '_isResolved' does not exist on type '{}'. node_modules/bluebird/js/release/promise.js(609,26): error TS2339: Property '_promiseFulfilled' does not exist on type '{}'. node_modules/bluebird/js/release/promise.js(611,26): error TS2339: Property '_promiseRejected' does not exist on type '{}'. node_modules/bluebird/js/release/promise.js(665,14): error TS2339: Property '_attachExtraTrace' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(677,14): error TS2339: Property '_dereferenceTrace' does not exist on type 'Promise'. -node_modules/bluebird/js/release/promise.js(688,46): error TS2339: Property 'isNode' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promise.js(694,14): error TS2339: Property '_ensurePossibleRejectionHandled' does not exist on type 'Promise'. node_modules/bluebird/js/release/promise.js(734,10): error TS2339: Property '_clearCancellationData' does not exist on type 'Promise'. -node_modules/bluebird/js/release/promise.js(767,6): error TS2339: Property 'notEnumerableProp' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise.js(797,10): error TS2339: Property 'toFastProperties' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise.js(798,10): error TS2339: Property 'toFastProperties' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise_array.js(5,20): error TS2339: Property 'isArray' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise_array.js(27,6): error TS2339: Property 'inherits' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise_array.js(62,19): error TS2339: Property 'asArray' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promise_array.js(65,72): error TS2339: Property 'classString' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promise_array.js(72,18): error TS2339: Property '_resolveEmptyArray' does not exist on type 'PromiseArray'. node_modules/bluebird/js/release/promise_array.js(110,76): error TS2554: Expected 0-1 arguments, but got 2. node_modules/bluebird/js/release/promise_array.js(112,53): error TS2554: Expected 0 arguments, but got 1. -node_modules/bluebird/js/release/promisify.js(6,25): error TS2339: Property 'withAppended' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promisify.js(7,29): error TS2339: Property 'maybeWrapAsError' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promisify.js(8,24): error TS2339: Property 'canEvaluate' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promisify.js(24,17): error TS2339: Property 'isIdentifier' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promisify.js(43,20): error TS2339: Property 'getDataPropertyOrDefault' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promisify.js(54,27): error TS2350: Only a void function can be called with the 'new' keyword. -node_modules/bluebird/js/release/promisify.js(63,21): error TS2339: Property 'inheritedDataKeys' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promisify.js(69,41): error TS2554: Expected 0-1 arguments, but got 3. node_modules/bluebird/js/release/promisify.js(93,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'number', but here has type 'any'. -node_modules/bluebird/js/release/promisify.js(100,17): error TS2339: Property 'filledRange' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promisify.js(104,17): error TS2339: Property 'filledRange' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promisify.js(201,26): error TS2339: Property 'tryCatch' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promisify.js(202,26): error TS2339: Property 'errorObj' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promisify.js(203,26): error TS2339: Property 'notEnumerableProp' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promisify.js(230,10): error TS2339: Property 'notEnumerableProp' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promisify.js(249,17): error TS2722: Cannot invoke an object which is possibly 'undefined'. node_modules/bluebird/js/release/promisify.js(252,24): error TS2722: Cannot invoke an object which is possibly 'undefined'. -node_modules/bluebird/js/release/promisify.js(255,18): error TS2339: Property 'notEnumerableProp' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promisify.js(259,10): error TS2339: Property 'toFastProperties' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promisify.js(264,12): error TS2722: Cannot invoke an object which is possibly 'undefined'. node_modules/bluebird/js/release/promisify.js(270,15): error TS2350: Only a void function can be called with the 'new' keyword. -node_modules/bluebird/js/release/promisify.js(270,68): error TS2339: Property 'classString' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promisify.js(279,10): error TS2339: Property 'copyDescriptors' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/promisify.js(285,15): error TS2350: Only a void function can be called with the 'new' keyword. -node_modules/bluebird/js/release/promisify.js(296,15): error TS2339: Property 'isIdentifier' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promisify.js(300,21): error TS2339: Property 'inheritedDataKeys' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/promisify.js(304,18): error TS2339: Property 'isClass' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/props.js(5,21): error TS2339: Property 'isObject' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/props.js(60,6): error TS2339: Property 'inherits' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/props.js(65,10): error TS2339: Property '_values' does not exist on type 'PropertiesPromiseArray'. node_modules/bluebird/js/release/props.js(66,32): error TS2339: Property '_totalResolved' does not exist on type 'PropertiesPromiseArray'. node_modules/bluebird/js/release/props.js(67,31): error TS2339: Property '_length' does not exist on type 'PropertiesPromiseArray'. @@ -238,23 +104,14 @@ node_modules/bluebird/js/release/props.js(75,26): error TS2339: Property '_value node_modules/bluebird/js/release/props.js(75,57): error TS2339: Property '_values' does not exist on type 'PropertiesPromiseArray'. node_modules/bluebird/js/release/props.js(78,14): error TS2339: Property '_resolve' does not exist on type 'PropertiesPromiseArray'. node_modules/bluebird/js/release/props.js(102,53): error TS2339: Property 'promise' does not exist on type 'PropertiesPromiseArray'. -node_modules/bluebird/js/release/race.js(18,25): error TS2339: Property 'asArray' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/race.js(20,92): error TS2339: Property 'classString' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/reduce.js(9,21): error TS2339: Property 'tryCatch' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/reduce.js(14,21): error TS2339: Property 'contextBind' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/reduce.js(31,6): error TS2339: Property 'inherits' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/reduce.js(43,9): error TS2532: Object is possibly 'undefined'. node_modules/bluebird/js/release/reduce.js(60,10): error TS2339: Property '_promise' does not exist on type 'ReductionPromiseArray'. node_modules/bluebird/js/release/reduce.js(65,52): error TS2339: Property '_cancel' does not exist on type 'ReductionPromiseArray'. node_modules/bluebird/js/release/reduce.js(66,14): error TS2339: Property '_isResolved' does not exist on type 'ReductionPromiseArray'. node_modules/bluebird/js/release/reduce.js(67,10): error TS2551: Property '_resultCancelled$' does not exist on type 'ReductionPromiseArray'. Did you mean '_resultCancelled'? -node_modules/bluebird/js/release/reduce.js(141,68): error TS2339: Property 'classString' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/reduce.js(144,18): error TS2339: Property 'promise' does not exist on type 'ReductionPromiseArray'. -node_modules/bluebird/js/release/schedule.js(7,26): error TS2339: Property 'getNativePromise' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/schedule.js(8,10): error TS2339: Property 'isNode' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/schedule.js(23,31): error TS2339: Property 'standalone' does not exist on type 'Navigator'. node_modules/bluebird/js/release/schedule.js(23,52): error TS2339: Property 'cordova' does not exist on type 'Window & typeof globalThis'. -node_modules/bluebird/js/release/settle.js(10,6): error TS2339: Property 'inherits' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/settle.js(13,10): error TS2339: Property '_values' does not exist on type 'SettledPromiseArray'. node_modules/bluebird/js/release/settle.js(14,32): error TS2339: Property '_totalResolved' does not exist on type 'SettledPromiseArray'. node_modules/bluebird/js/release/settle.js(15,31): error TS2339: Property '_length' does not exist on type 'SettledPromiseArray'. @@ -262,8 +119,6 @@ node_modules/bluebird/js/release/settle.js(16,14): error TS2339: Property '_reso node_modules/bluebird/js/release/settle.js(16,28): error TS2339: Property '_values' does not exist on type 'SettledPromiseArray'. node_modules/bluebird/js/release/settle.js(37,46): error TS2339: Property 'promise' does not exist on type 'SettledPromiseArray'. node_modules/bluebird/js/release/settle.js(41,46): error TS2339: Property 'promise' does not exist on type 'SettledPromiseArray'. -node_modules/bluebird/js/release/some.js(7,20): error TS2339: Property 'isArray' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/some.js(17,6): error TS2339: Property 'inherits' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/some.js(24,14): error TS2339: Property '_resolve' does not exist on type 'SomePromiseArray'. node_modules/bluebird/js/release/some.js(27,10): error TS2551: Property '_init$' does not exist on type 'SomePromiseArray'. Did you mean '_init'? node_modules/bluebird/js/release/some.js(28,40): error TS2339: Property '_values' does not exist on type 'SomePromiseArray'. @@ -294,29 +149,15 @@ node_modules/bluebird/js/release/some.js(115,17): error TS2339: Property 'length node_modules/bluebird/js/release/some.js(121,12): error TS2350: Only a void function can be called with the 'new' keyword. node_modules/bluebird/js/release/some.js(125,10): error TS2551: Property '_reject' does not exist on type 'SomePromiseArray'. Did you mean '_rejected'? node_modules/bluebird/js/release/some.js(133,23): error TS2339: Property 'promise' does not exist on type 'SomePromiseArray'. -node_modules/bluebird/js/release/thenables.js(4,21): error TS2339: Property 'errorObj' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/thenables.js(5,21): error TS2339: Property 'isObject' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/thenables.js(63,23): error TS2339: Property 'tryCatch' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/timers.js(51,10): error TS2339: Property 'markAsOriginatingFromRejection' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/using.js(6,38): error TS2339: Property 'inherits' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/using.js(7,25): error TS2339: Property 'errorObj' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/using.js(8,25): error TS2339: Property 'tryCatch' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/using.js(78,20): error TS2339: Property 'doDispose' does not exist on type 'Disposer'. node_modules/bluebird/js/release/using.js(97,23): error TS2339: Property 'data' does not exist on type 'FunctionDisposer'. -node_modules/bluebird/js/release/using.js(131,72): error TS2339: Property 'classString' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/using.js(223,15): error TS2350: Only a void function can be called with the 'new' keyword. node_modules/bluebird/js/release/util.js(279,45): error TS2345: Argument of type 'PropertyDescriptor | { value: any; } | undefined' is not assignable to parameter of type 'PropertyDescriptor & ThisType'. Type 'undefined' is not assignable to type 'PropertyDescriptor & ThisType'. Type 'undefined' is not assignable to type 'PropertyDescriptor'. -node_modules/bluebird/js/release/util.js(362,5): error TS2322: Type '{ setReflectHandler: (fn: any) => void; isClass: (fn: any) => boolean; isIdentifier: (str: any) => boolean; inheritedDataKeys: (obj: any) => string[]; getDataPropertyOrDefault: (obj: any, key: any, defaultValue: any) => any; ... 27 more ...; contextBind: (ctx: any, cb: any) => any; }' is not assignable to type 'typeof ret'. - Object literal may only specify known properties, and 'setReflectHandler' does not exist in type 'typeof ret'. -node_modules/bluebird/js/release/util.js(398,24): error TS2339: Property 'isNode' does not exist on type 'typeof ret'. node_modules/bluebird/js/release/util.js(405,13): error TS2532: Object is possibly 'undefined'. node_modules/bluebird/js/release/util.js(405,33): error TS2532: Object is possibly 'undefined'. node_modules/bluebird/js/release/util.js(405,54): error TS2532: Object is possibly 'undefined'. -node_modules/bluebird/js/release/util.js(407,37): error TS2339: Property 'isNode' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/util.js(418,9): error TS2339: Property 'isNode' does not exist on type 'typeof ret'. -node_modules/bluebird/js/release/util.js(418,21): error TS2339: Property 'toFastProperties' does not exist on type 'typeof ret'. diff --git a/tests/baselines/reference/user/chrome-devtools-frontend.log b/tests/baselines/reference/user/chrome-devtools-frontend.log index b0dabfddafc..b8d5f95285b 100644 --- a/tests/baselines/reference/user/chrome-devtools-frontend.log +++ b/tests/baselines/reference/user/chrome-devtools-frontend.log @@ -1,7 +1,7 @@ Exit Code: 1 Standard output: ../../../../built/local/lib.es5.d.ts(1433,11): error TS2300: Duplicate identifier 'ArrayLike'. -../../../../node_modules/@types/node/globals.d.ts(234,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'module' must be of type '{}', but here has type 'NodeModule'. +../../../../node_modules/@types/node/globals.d.ts(231,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'module' must be of type '{}', but here has type 'NodeModule'. node_modules/chrome-devtools-frontend/front_end/Runtime.js(43,8): error TS2339: Property '_importScriptPathPrefix' does not exist on type 'Window & typeof globalThis'. node_modules/chrome-devtools-frontend/front_end/Runtime.js(77,16): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. node_modules/chrome-devtools-frontend/front_end/Runtime.js(78,16): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. @@ -269,10 +269,16 @@ node_modules/chrome-devtools-frontend/front_end/animation/AnimationModel.js(751, node_modules/chrome-devtools-frontend/front_end/animation/AnimationModel.js(778,24): error TS2694: Namespace 'Protocol' has no exported member 'Page'. node_modules/chrome-devtools-frontend/front_end/animation/AnimationModel.js(811,11): error TS2339: Property 'AnimationModel' does not exist on type '{ new (effect?: AnimationEffect, timeline?: AnimationTimeline): Animation; prototype: Animation; }'. node_modules/chrome-devtools-frontend/front_end/animation/AnimationScreenshotPopover.js(7,11): error TS2339: Property 'AnimationScreenshotPopover' does not exist on type '{ new (effect?: AnimationEffect, timeline?: AnimationTimeline): Animation; prototype: Animation; }'. +node_modules/chrome-devtools-frontend/front_end/animation/AnimationScreenshotPopover.js(18,39): error TS2345: Argument of type 'new (width?: number, height?: number) => HTMLImageElement' is not assignable to parameter of type 'Node'. + Type 'new (width?: number, height?: number) => HTMLImageElement' is missing the following properties from type 'Node': baseURI, childNodes, firstChild, isConnected, and 47 more. +node_modules/chrome-devtools-frontend/front_end/animation/AnimationScreenshotPopover.js(19,13): error TS2339: Property 'style' does not exist on type 'new (width?: number, height?: number) => HTMLImageElement'. +node_modules/chrome-devtools-frontend/front_end/animation/AnimationScreenshotPopover.js(22,21): error TS2339: Property 'style' does not exist on type 'new (width?: number, height?: number) => HTMLImageElement'. node_modules/chrome-devtools-frontend/front_end/animation/AnimationScreenshotPopover.js(23,45): error TS2339: Property 'createChild' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/animation/AnimationScreenshotPopover.js(30,39): error TS2339: Property 'window' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/animation/AnimationScreenshotPopover.js(37,25): error TS2339: Property 'window' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/animation/AnimationScreenshotPopover.js(42,39): error TS2339: Property 'window' does not exist on type 'Element'. +node_modules/chrome-devtools-frontend/front_end/animation/AnimationScreenshotPopover.js(53,50): error TS2339: Property 'style' does not exist on type 'new (width?: number, height?: number) => HTMLImageElement'. +node_modules/chrome-devtools-frontend/front_end/animation/AnimationScreenshotPopover.js(55,52): error TS2339: Property 'style' does not exist on type 'new (width?: number, height?: number) => HTMLImageElement'. node_modules/chrome-devtools-frontend/front_end/animation/AnimationTimeline.js(8,11): error TS2339: Property 'AnimationTimeline' does not exist on type '{ new (effect?: AnimationEffect, timeline?: AnimationTimeline): Animation; prototype: Animation; }'. node_modules/chrome-devtools-frontend/front_end/animation/AnimationTimeline.js(14,38): error TS2339: Property 'createSVGChild' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/animation/AnimationTimeline.js(19,53): error TS2339: Property 'createChild' does not exist on type 'Element'. @@ -3863,7 +3869,7 @@ node_modules/chrome-devtools-frontend/front_end/console/ConsoleSidebar.js(119,47 node_modules/chrome-devtools-frontend/front_end/console/ConsoleSidebar.js(122,25): error TS2345: Argument of type 'Element' is not assignable to parameter of type 'Icon'. Type 'Element' is missing the following properties from type 'Icon': createdCallback, _descriptor, _spriteSheet, _iconType, and 117 more. node_modules/chrome-devtools-frontend/front_end/console/ConsoleSidebar.js(133,9): error TS2339: Property 'ConsoleSidebar' does not exist on type '{ new (): Console; prototype: Console; }'. -node_modules/chrome-devtools-frontend/front_end/console/ConsoleSidebar.js(147,27): error TS2740: Type 'Element' is missing the following properties from type 'Icon': createdCallback, _descriptor, _spriteSheet, _iconType, and 117 more. +node_modules/chrome-devtools-frontend/front_end/console/ConsoleSidebar.js(147,27): error TS2322: Type 'Element' is not assignable to type 'Icon'. node_modules/chrome-devtools-frontend/front_end/console/ConsoleSidebar.js(177,67): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/console/ConsoleSidebar.js(179,61): error TS2339: Property 'ConsoleSidebar' does not exist on type '{ new (): Console; prototype: Console; }'. node_modules/chrome-devtools-frontend/front_end/console/ConsoleSidebar.js(213,28): error TS2555: Expected at least 2 arguments, but got 1. @@ -5040,19 +5046,19 @@ node_modules/chrome-devtools-frontend/front_end/elements/ComputedStyleWidget.js( node_modules/chrome-devtools-frontend/front_end/elements/ComputedStyleWidget.js(73,12): error TS2339: Property '_filterRegex' does not exist on type 'ComputedStyleWidget'. node_modules/chrome-devtools-frontend/front_end/elements/ComputedStyleWidget.js(91,24): error TS2769: No overload matches this call. The last overload gave the following error. - Argument of type '(Promise | Promise)[]' is not assignable to parameter of type 'Iterable>'. + Argument of type '(Promise | Promise)[]' is not assignable to parameter of type 'Iterable>'. The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types. - Type 'IteratorResult | Promise, any>' is not assignable to type 'IteratorResult, any>'. - Type 'IteratorYieldResult | Promise>' is not assignable to type 'IteratorResult, any>'. - Type 'IteratorYieldResult | Promise>' is not assignable to type 'IteratorYieldResult>'. - Type 'Promise | Promise' is not assignable to type 'CSSMatchedStyles | PromiseLike'. - Type 'Promise' is not assignable to type 'CSSMatchedStyles | PromiseLike'. - Type 'Promise' is not assignable to type 'PromiseLike'. + Type 'IteratorResult | Promise, any>' is not assignable to type 'IteratorResult, any>'. + Type 'IteratorYieldResult | Promise>' is not assignable to type 'IteratorResult, any>'. + Type 'IteratorYieldResult | Promise>' is not assignable to type 'IteratorYieldResult>'. + Type 'Promise | Promise' is not assignable to type 'ComputedStyle | PromiseLike'. + Type 'Promise' is not assignable to type 'ComputedStyle | PromiseLike'. + Type 'Promise' is not assignable to type 'PromiseLike'. Types of property 'then' are incompatible. - Type '(onfulfilled?: (value: ComputedStyle) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike<...>) => Promise<...>' is not assignable to type '(onfulfilled?: (value: CSSMatchedStyles) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike<...>) => PromiseLike<...>'. + Type '(onfulfilled?: (value: CSSMatchedStyles) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike<...>) => Promise<...>' is not assignable to type '(onfulfilled?: (value: ComputedStyle) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike<...>) => PromiseLike<...>'. Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible. Types of parameters 'value' and 'value' are incompatible. - Type 'ComputedStyle' is missing the following properties from type 'CSSMatchedStyles': _cssModel, _node, _nodeStyles, _nodeForStyle, and 22 more. + Property 'computedStyle' is missing in type 'CSSMatchedStyles' but required in type 'ComputedStyle'. node_modules/chrome-devtools-frontend/front_end/elements/ComputedStyleWidget.js(147,52): error TS2339: Property 'keysArray' does not exist on type 'Map'. node_modules/chrome-devtools-frontend/front_end/elements/ComputedStyleWidget.js(179,50): error TS2339: Property 'createChild' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/elements/ComputedStyleWidget.js(200,74): error TS2339: Property 'consume' does not exist on type 'Event'. @@ -9613,8 +9619,6 @@ node_modules/chrome-devtools-frontend/front_end/sdk/RemoteObject.js(704,32): err node_modules/chrome-devtools-frontend/front_end/sdk/RemoteObject.js(727,14): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. node_modules/chrome-devtools-frontend/front_end/sdk/RemoteObject.js(728,32): error TS2694: Namespace 'Protocol' has no exported member 'Runtime'. node_modules/chrome-devtools-frontend/front_end/sdk/RemoteObject.js(729,14): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. -node_modules/chrome-devtools-frontend/front_end/sdk/RemoteObject.js(731,3): error TS2416: Property 'callFunctionJSON' in type 'RemoteObjectImpl' is not assignable to the same property in base type 'RemoteObject'. - Type '(functionDeclaration: (this: any) => any, args: any[], callback: (arg0: any) => any) => void' is not assignable to type '(functionDeclaration: (this: any, ...arg1: any[]) => T, args: any[], callback: (arg0: T) => any) => void'. node_modules/chrome-devtools-frontend/front_end/sdk/RemoteObject.js(731,3): error TS2416: Property 'callFunctionJSON' in type 'RemoteObjectImpl' is not assignable to the same property in base type 'RemoteObject'. Type '(functionDeclaration: (this: any) => any, args: any[], callback: (arg0: any) => any) => void' is not assignable to type '(functionDeclaration: (this: any, ...arg1: any[]) => T, args: any[], callback: (arg0: T) => any) => void'. Types of parameters 'functionDeclaration' and 'functionDeclaration' are incompatible. @@ -9635,8 +9639,6 @@ node_modules/chrome-devtools-frontend/front_end/sdk/RemoteObject.js(1153,31): er node_modules/chrome-devtools-frontend/front_end/sdk/RemoteObject.js(1175,14): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. node_modules/chrome-devtools-frontend/front_end/sdk/RemoteObject.js(1176,31): error TS2694: Namespace 'Protocol' has no exported member 'Runtime'. node_modules/chrome-devtools-frontend/front_end/sdk/RemoteObject.js(1177,14): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. -node_modules/chrome-devtools-frontend/front_end/sdk/RemoteObject.js(1179,3): error TS2416: Property 'callFunctionJSON' in type 'LocalJSONObject' is not assignable to the same property in base type 'RemoteObject'. - Type '(functionDeclaration: (this: any) => any, args: any[], callback: (arg0: any) => any) => void' is not assignable to type '(functionDeclaration: (this: any, ...arg1: any[]) => T, args: any[], callback: (arg0: T) => any) => void'. node_modules/chrome-devtools-frontend/front_end/sdk/RemoteObject.js(1179,3): error TS2416: Property 'callFunctionJSON' in type 'LocalJSONObject' is not assignable to the same property in base type 'RemoteObject'. Type '(functionDeclaration: (this: any) => any, args: any[], callback: (arg0: any) => any) => void' is not assignable to type '(functionDeclaration: (this: any, ...arg1: any[]) => T, args: any[], callback: (arg0: T) => any) => void'. Types of parameters 'functionDeclaration' and 'functionDeclaration' are incompatible. @@ -11022,24 +11024,16 @@ node_modules/chrome-devtools-frontend/front_end/text_editor/CodeMirrorTextEditor node_modules/chrome-devtools-frontend/front_end/text_editor/CodeMirrorTextEditor.js(1637,61): error TS2339: Property 'line' does not exist on type 'void'. node_modules/chrome-devtools-frontend/front_end/text_editor/CodeMirrorTextEditor.js(1637,71): error TS2339: Property 'ch' does not exist on type 'void'. node_modules/chrome-devtools-frontend/front_end/text_editor/CodeMirrorTextEditor.js(1647,14): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. -node_modules/chrome-devtools-frontend/front_end/text_editor/CodeMirrorUtils.js(57,53): error TS2345: Argument of type 'Pos' is not assignable to parameter of type 'Pos'. - Type 'Pos' is missing the following properties from type 'Pos': line, ch node_modules/chrome-devtools-frontend/front_end/text_editor/CodeMirrorUtils.js(146,15): error TS1345: An expression of type 'void' cannot be tested for truthiness node_modules/chrome-devtools-frontend/front_end/text_editor/CodeMirrorUtils.js(147,26): error TS2339: Property 'token' does not exist on type 'void'. node_modules/chrome-devtools-frontend/front_end/text_editor/CodeMirrorUtils.js(149,67): error TS2339: Property 'length' does not exist on type 'void'. node_modules/chrome-devtools-frontend/front_end/text_editor/TextEditorAutocompleteController.js(42,30): error TS2345: Argument of type 'void' is not assignable to parameter of type 'string'. -node_modules/chrome-devtools-frontend/front_end/text_editor/TextEditorAutocompleteController.js(66,36): error TS2339: Property 'line' does not exist on type 'Pos'. -node_modules/chrome-devtools-frontend/front_end/text_editor/TextEditorAutocompleteController.js(66,63): error TS2339: Property 'line' does not exist on type 'Pos'. node_modules/chrome-devtools-frontend/front_end/text_editor/TextEditorAutocompleteController.js(130,5): error TS2322: Type 'Promise<{ text: string; }[]>' is not assignable to type 'Promise<{ text: string; subtitle: string; iconType: string; priority: number; isSecondary: boolean; title: string; }[]>'. Type '{ text: string; }[]' is not assignable to type '{ text: string; subtitle: string; iconType: string; priority: number; isSecondary: boolean; title: string; }[]'. Type '{ text: string; }' is missing the following properties from type '{ text: string; subtitle: string; iconType: string; priority: number; isSecondary: boolean; title: string; }': subtitle, iconType, priority, isSecondary, title -node_modules/chrome-devtools-frontend/front_end/text_editor/TextEditorAutocompleteController.js(163,27): error TS2339: Property 'line' does not exist on type 'Pos'. node_modules/chrome-devtools-frontend/front_end/text_editor/TextEditorAutocompleteController.js(163,43): error TS2339: Property 'line' does not exist on type 'void'. -node_modules/chrome-devtools-frontend/front_end/text_editor/TextEditorAutocompleteController.js(163,67): error TS2339: Property 'ch' does not exist on type 'Pos'. node_modules/chrome-devtools-frontend/front_end/text_editor/TextEditorAutocompleteController.js(163,85): error TS2339: Property 'ch' does not exist on type 'void'. -node_modules/chrome-devtools-frontend/front_end/text_editor/TextEditorAutocompleteController.js(168,67): error TS2339: Property 'line' does not exist on type 'Pos'. node_modules/chrome-devtools-frontend/front_end/text_editor/TextEditorAutocompleteController.js(168,83): error TS2339: Property 'line' does not exist on type 'void'. -node_modules/chrome-devtools-frontend/front_end/text_editor/TextEditorAutocompleteController.js(169,27): error TS2339: Property 'ch' does not exist on type 'Pos'. node_modules/chrome-devtools-frontend/front_end/text_editor/TextEditorAutocompleteController.js(169,45): error TS2339: Property 'ch' does not exist on type 'void'. node_modules/chrome-devtools-frontend/front_end/text_editor/TextEditorAutocompleteController.js(199,20): error TS2339: Property 'length' does not exist on type 'void'. node_modules/chrome-devtools-frontend/front_end/text_editor/TextEditorAutocompleteController.js(202,36): error TS2339: Property 'length' does not exist on type 'void'. @@ -11187,6 +11181,9 @@ node_modules/chrome-devtools-frontend/front_end/timeline/TimelineEventOverview.j node_modules/chrome-devtools-frontend/front_end/timeline/TimelineEventOverview.js(204,36): error TS2339: Property '_overviewIndex' does not exist on type 'TimelineCategory'. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineEventOverview.js(246,68): error TS2339: Property 'peekLast' does not exist on type 'any[]'. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineEventOverview.js(248,81): error TS2339: Property '_overviewIndex' does not exist on type 'TimelineCategory'. +node_modules/chrome-devtools-frontend/front_end/timeline/TimelineEventOverview.js(384,7): error TS2322: Type 'Promise HTMLImageElement)>' is not assignable to type 'Promise'. + Type 'HTMLImageElement | (new (width?: number, height?: number) => HTMLImageElement)' is not assignable to type 'HTMLImageElement'. + Type 'new (width?: number, height?: number) => HTMLImageElement' is missing the following properties from type 'HTMLImageElement': align, alt, border, complete, and 261 more. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineEventOverview.js(457,17): error TS2339: Property 'createChild' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineEventOverview.js(483,31): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineEventOverview.js(524,28): error TS2339: Property 'peekLast' does not exist on type 'TimelineFrame[]'. @@ -11232,6 +11229,10 @@ node_modules/chrome-devtools-frontend/front_end/timeline/TimelineFlameChartDataP node_modules/chrome-devtools-frontend/front_end/timeline/TimelineFlameChartDataProvider.js(541,38): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineFlameChartDataProvider.js(548,25): error TS2339: Property 'createChild' does not exist on type 'DocumentFragment'. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineFlameChartDataProvider.js(621,36): error TS2339: Property 'preciseMillisToString' does not exist on type 'NumberConstructor'. +node_modules/chrome-devtools-frontend/front_end/timeline/TimelineFlameChartDataProvider.js(654,37): error TS2339: Property 'naturalHeight' does not exist on type 'new (width?: number, height?: number) => HTMLImageElement'. +node_modules/chrome-devtools-frontend/front_end/timeline/TimelineFlameChartDataProvider.js(655,39): error TS2339: Property 'naturalWidth' does not exist on type 'new (width?: number, height?: number) => HTMLImageElement'. +node_modules/chrome-devtools-frontend/front_end/timeline/TimelineFlameChartDataProvider.js(660,23): error TS2345: Argument of type 'new (width?: number, height?: number) => HTMLImageElement' is not assignable to parameter of type 'CanvasImageSource'. + Type 'new (width?: number, height?: number) => HTMLImageElement' is missing the following properties from type 'OffscreenCanvas': height, width, convertToBlob, getContext, and 4 more. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineFlameChartDataProvider.js(862,44): error TS2339: Property 'id' does not exist on type 'Event'. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineFlameChartDataProvider.js(865,63): error TS2339: Property 'id' does not exist on type 'Event'. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineFlameChartDataProvider.js(866,44): error TS2339: Property 'id' does not exist on type 'Event'. @@ -11675,6 +11676,7 @@ node_modules/chrome-devtools-frontend/front_end/timeline/TimelineUIUtils.js(1649 node_modules/chrome-devtools-frontend/front_end/timeline/TimelineUIUtils.js(1651,40): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineUIUtils.js(1652,40): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineUIUtils.js(1652,69): error TS2339: Property 'millisToString' does not exist on type 'NumberConstructor'. +node_modules/chrome-devtools-frontend/front_end/timeline/TimelineUIUtils.js(1657,64): error TS2345: Argument of type 'new (width?: number, height?: number) => HTMLImageElement' is not assignable to parameter of type 'Node'. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineUIUtils.js(1664,18): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineUIUtils.js(1665,74): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/timeline/TimelineUIUtils.js(1675,5): error TS2740: Type 'DocumentFragment' is missing the following properties from type 'Element': assignedSlot, attributes, classList, className, and 64 more. @@ -11958,7 +11960,6 @@ node_modules/chrome-devtools-frontend/front_end/ui/Geometry.js(272,13): error TS node_modules/chrome-devtools-frontend/front_end/ui/Geometry.js(316,13): error TS2304: Cannot find name 'CSSMatrix'. node_modules/chrome-devtools-frontend/front_end/ui/GlassPane.js(18,17): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. node_modules/chrome-devtools-frontend/front_end/ui/GlassPane.js(72,15): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. -node_modules/chrome-devtools-frontend/front_end/ui/GlassPane.js(82,5): error TS2739: Type 'Size' is missing the following properties from type 'Size': isEqual, widthToMax, addWidth, heightToMax, addHeight node_modules/chrome-devtools-frontend/front_end/ui/GlassPane.js(125,5): error TS2322: Type 'boolean' is not assignable to type 'symbol'. node_modules/chrome-devtools-frontend/front_end/ui/GlassPane.js(126,51): error TS2367: This condition will always return 'true' since the types 'boolean' and 'symbol' have no overlap. node_modules/chrome-devtools-frontend/front_end/ui/GlassPane.js(136,18): error TS2339: Property 'style' does not exist on type 'Element'. @@ -12329,18 +12330,6 @@ node_modules/chrome-devtools-frontend/front_end/ui/SplitWidget.js(590,25): error node_modules/chrome-devtools-frontend/front_end/ui/SplitWidget.js(593,27): error TS2339: Property 'window' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/ui/SplitWidget.js(647,21): error TS2339: Property 'constrain' does not exist on type 'NumberConstructor'. node_modules/chrome-devtools-frontend/front_end/ui/SplitWidget.js(654,21): error TS2339: Property 'constrain' does not exist on type 'NumberConstructor'. -node_modules/chrome-devtools-frontend/front_end/ui/SplitWidget.js(704,41): error TS2339: Property 'widthToMax' does not exist on type 'Constraints | Constraints'. - Property 'widthToMax' does not exist on type 'Constraints'. -node_modules/chrome-devtools-frontend/front_end/ui/SplitWidget.js(705,47): error TS2339: Property 'widthToMax' does not exist on type 'Constraints | Constraints'. - Property 'widthToMax' does not exist on type 'Constraints'. -node_modules/chrome-devtools-frontend/front_end/ui/SplitWidget.js(706,30): error TS2339: Property 'addWidth' does not exist on type 'Constraints | Constraints'. - Property 'addWidth' does not exist on type 'Constraints'. -node_modules/chrome-devtools-frontend/front_end/ui/SplitWidget.js(708,41): error TS2339: Property 'heightToMax' does not exist on type 'Constraints | Constraints'. - Property 'heightToMax' does not exist on type 'Constraints'. -node_modules/chrome-devtools-frontend/front_end/ui/SplitWidget.js(709,47): error TS2339: Property 'heightToMax' does not exist on type 'Constraints | Constraints'. - Property 'heightToMax' does not exist on type 'Constraints'. -node_modules/chrome-devtools-frontend/front_end/ui/SplitWidget.js(710,30): error TS2339: Property 'widthToMax' does not exist on type 'Constraints | Constraints'. - Property 'widthToMax' does not exist on type 'Constraints'. node_modules/chrome-devtools-frontend/front_end/ui/SplitWidget.js(872,47): error TS2555: Expected at least 2 arguments, but got 1. node_modules/chrome-devtools-frontend/front_end/ui/SuggestBox.js(72,50): error TS2345: Argument of type 'this' is not assignable to parameter of type 'ListDelegate<{ text: string; subtitle: string; iconType: string; priority: number; isSecondary: boolean; title: string; }>'. Type 'SuggestBox' is not assignable to type 'ListDelegate<{ text: string; subtitle: string; iconType: string; priority: number; isSecondary: boolean; title: string; }>'. @@ -12366,10 +12355,6 @@ node_modules/chrome-devtools-frontend/front_end/ui/TabbedPane.js(41,47): error T node_modules/chrome-devtools-frontend/front_end/ui/TabbedPane.js(47,48): error TS2339: Property 'createChild' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/ui/TabbedPane.js(159,27): error TS2339: Property 'focus' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/ui/TabbedPane.js(314,56): error TS2339: Property 'getComponentRoot' does not exist on type 'Element'. -node_modules/chrome-devtools-frontend/front_end/ui/TabbedPane.js(487,31): error TS2339: Property 'widthToMax' does not exist on type 'Constraints'. -node_modules/chrome-devtools-frontend/front_end/ui/TabbedPane.js(489,33): error TS2339: Property 'addWidth' does not exist on type 'Constraints'. -node_modules/chrome-devtools-frontend/front_end/ui/TabbedPane.js(491,33): error TS2339: Property 'addHeight' does not exist on type 'Constraints'. -node_modules/chrome-devtools-frontend/front_end/ui/TabbedPane.js(492,5): error TS2739: Type 'Constraints' is missing the following properties from type 'Constraints': isEqual, widthToMax, addWidth, heightToMax, addHeight node_modules/chrome-devtools-frontend/front_end/ui/TabbedPane.js(568,15): error TS2339: Property 'which' does not exist on type 'Event'. node_modules/chrome-devtools-frontend/front_end/ui/TabbedPane.js(671,27): error TS2339: Property '__tab' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/ui/TabbedPane.js(679,31): error TS2339: Property '__tab' does not exist on type 'Element'. @@ -12640,6 +12625,8 @@ node_modules/chrome-devtools-frontend/front_end/ui/UIUtils.js(1910,22): error TS node_modules/chrome-devtools-frontend/front_end/ui/UIUtils.js(1911,22): error TS2339: Property 'constrain' does not exist on type 'NumberConstructor'. node_modules/chrome-devtools-frontend/front_end/ui/UIUtils.js(1912,22): error TS2339: Property 'constrain' does not exist on type 'NumberConstructor'. node_modules/chrome-devtools-frontend/front_end/ui/UIUtils.js(1913,22): error TS2339: Property 'constrain' does not exist on type 'NumberConstructor'. +node_modules/chrome-devtools-frontend/front_end/ui/UIUtils.js(1943,50): error TS2345: Argument of type 'HTMLImageElement' is not assignable to parameter of type '(new (width?: number, height?: number) => HTMLImageElement) | PromiseLike HTMLImageElement>'. + Property 'then' is missing in type 'HTMLImageElement' but required in type 'PromiseLike HTMLImageElement>'. node_modules/chrome-devtools-frontend/front_end/ui/UIUtils.js(1961,12): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. node_modules/chrome-devtools-frontend/front_end/ui/UIUtils.js(1966,23): error TS2339: Property 'type' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/ui/UIUtils.js(1967,23): error TS2339: Property 'style' does not exist on type 'Element'. @@ -12718,16 +12705,7 @@ node_modules/chrome-devtools-frontend/front_end/ui/Widget.js(484,20): error TS23 node_modules/chrome-devtools-frontend/front_end/ui/Widget.js(485,17): error TS2339: Property 'focus' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/ui/Widget.js(498,39): error TS2339: Property 'traverseNextNode' does not exist on type 'Element'. node_modules/chrome-devtools-frontend/front_end/ui/Widget.js(513,25): error TS2339: Property 'hasFocus' does not exist on type 'Element'. -node_modules/chrome-devtools-frontend/front_end/ui/Widget.js(583,17): error TS2339: Property 'isEqual' does not exist on type 'Constraints'. node_modules/chrome-devtools-frontend/front_end/ui/Widget.js(593,55): error TS2339: Property 'removeChildren' does not exist on type 'Element'. -node_modules/chrome-devtools-frontend/front_end/ui/Widget.js(621,44): error TS2345: Argument of type 'Constraints' is not assignable to parameter of type 'number | Constraints'. - Type 'Constraints' is not assignable to type 'Constraints'. Two different types with this name exist, but they are unrelated. -node_modules/chrome-devtools-frontend/front_end/ui/Widget.js(622,43): error TS2345: Argument of type 'Constraints' is not assignable to parameter of type 'number | Constraints'. - Type 'Constraints' is not assignable to type 'Constraints'. Two different types with this name exist, but they are unrelated. -node_modules/chrome-devtools-frontend/front_end/ui/Widget.js(655,42): error TS2345: Argument of type 'Constraints' is not assignable to parameter of type 'number | Constraints'. - Type 'Constraints' is not assignable to type 'Constraints'. Two different types with this name exist, but they are unrelated. -node_modules/chrome-devtools-frontend/front_end/ui/Widget.js(656,45): error TS2345: Argument of type 'Constraints' is not assignable to parameter of type 'number | Constraints'. - Type 'Constraints' is not assignable to type 'Constraints'. Two different types with this name exist, but they are unrelated. node_modules/chrome-devtools-frontend/front_end/ui/Widget.js(669,14): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. node_modules/chrome-devtools-frontend/front_end/ui/Widget.js(693,51): error TS2339: Property 'deepActiveElement' does not exist on type 'Document'. node_modules/chrome-devtools-frontend/front_end/ui/Widget.js(713,1): error TS2322: Type '(child: Node) => Node' is not assignable to type '(newChild: T) => T'. diff --git a/tests/baselines/reference/user/graceful-fs.log b/tests/baselines/reference/user/graceful-fs.log index 2a02c52d08d..1f60574df06 100644 --- a/tests/baselines/reference/user/graceful-fs.log +++ b/tests/baselines/reference/user/graceful-fs.log @@ -15,12 +15,10 @@ node_modules/graceful-fs/graceful-fs.js(199,5): error TS2539: Cannot assign to ' node_modules/graceful-fs/graceful-fs.js(200,5): error TS2539: Cannot assign to 'WriteStream' because it is not a variable. node_modules/graceful-fs/graceful-fs.js(220,7): error TS2539: Cannot assign to 'ReadStream' because it is not a variable. node_modules/graceful-fs/graceful-fs.js(230,7): error TS2539: Cannot assign to 'WriteStream' because it is not a variable. -node_modules/graceful-fs/graceful-fs.js(242,7): error TS2539: Cannot assign to 'ReadStream' because it is not a variable. -node_modules/graceful-fs/graceful-fs.js(252,7): error TS2539: Cannot assign to 'WriteStream' because it is not a variable. -node_modules/graceful-fs/graceful-fs.js(262,68): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[any?, any?, ...any[]]'. -node_modules/graceful-fs/graceful-fs.js(285,70): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[any?, any?, ...any[]]'. -node_modules/graceful-fs/graceful-fs.js(334,9): error TS2554: Expected 0 arguments, but got 3. -node_modules/graceful-fs/graceful-fs.js(341,11): error TS2554: Expected 0 arguments, but got 3. +node_modules/graceful-fs/graceful-fs.js(264,68): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[any?, any?, ...any[]]'. +node_modules/graceful-fs/graceful-fs.js(287,70): error TS2345: Argument of type 'IArguments' is not assignable to parameter of type '[any?, any?, ...any[]]'. +node_modules/graceful-fs/graceful-fs.js(336,9): error TS2554: Expected 0 arguments, but got 3. +node_modules/graceful-fs/graceful-fs.js(343,11): error TS2554: Expected 0 arguments, but got 3. diff --git a/tests/baselines/reference/user/prettier.log b/tests/baselines/reference/user/prettier.log index 05342cae1e1..ac7d6fedeae 100644 --- a/tests/baselines/reference/user/prettier.log +++ b/tests/baselines/reference/user/prettier.log @@ -23,6 +23,7 @@ node_modules/@glimmer/util/dist/types/lib/destroy.d.ts(3,69): error TS2677: A ty Index signature is missing in type 'SymbolDestroyable'. node_modules/@glimmer/util/dist/types/lib/dom.d.ts(1,31): error TS2307: Cannot find module '@simple-dom/interface'. node_modules/@glimmer/util/dist/types/lib/is-serialization-first-node.d.ts(1,28): error TS2307: Cannot find module '@simple-dom/interface'. +node_modules/@typescript-eslint/typescript-estree/dist/create-program/createWatchProgram.d.ts(1,8): error TS1259: Module '"/prettier/prettier/node_modules/typescript/lib/typescript"' can only be default-imported using the 'esModuleInterop' flag src/cli/util.js(60,44): error TS2345: Argument of type 'null' is not assignable to parameter of type 'number | undefined'. src/cli/util.js(119,38): error TS2339: Property 'sync' does not exist on type '(...args: any[]) => any'. src/cli/util.js(413,36): error TS2345: Argument of type '{ dot: true; nodir: boolean; }' is not assignable to parameter of type 'GlobbyOptions'. @@ -36,6 +37,8 @@ src/cli/util.js(693,22): error TS2339: Property 'name' does not exist on type 'n src/cli/util.js(693,46): error TS2339: Property 'alias' does not exist on type 'never'. src/common/create-ignorer.js(34,19): error TS2349: This expression is not callable. Type 'typeof import("/prettier/prettier/node_modules/ignore/index")' has no call signatures. +src/common/get-file-info.js(36,27): error TS2339: Property 'resolveConfig' does not exist on type '{ ignorePath?: string | undefined; withNodeModules?: boolean | undefined; plugins: any; }'. +src/common/get-file-info.js(59,25): error TS2339: Property 'resolveConfig' does not exist on type '{ ignorePath?: string | undefined; withNodeModules?: boolean | undefined; plugins: any; }'. src/common/parser-create-error.js(8,9): error TS2339: Property 'loc' does not exist on type 'SyntaxError'. src/config/resolve-config.js(14,12): error TS2571: Object is of type 'unknown'. src/config/resolve-config.js(50,16): error TS2571: Object is of type 'unknown'. @@ -169,7 +172,7 @@ src/language-html/syntax-vue.js(14,27): error TS2339: Property 'right' does not src/language-html/utils.js(10,30): error TS2307: Cannot find module 'html-tag-names'. src/language-html/utils.js(11,39): error TS2307: Cannot find module 'html-element-attributes'. src/language-html/utils.js(444,17): error TS2554: Expected 0 arguments, but got 1. -src/language-js/comments.js(865,64): error TS2554: Expected 0 arguments, but got 1. +src/language-js/comments.js(867,64): error TS2554: Expected 0 arguments, but got 1. src/language-js/index.js(9,26): error TS2307: Cannot find module 'linguist-languages/data/JavaScript'. src/language-js/index.js(9,65): error TS2345: Argument of type '{ override: { since: string; parsers: string[]; vscodeLanguageIds: string[]; }; extend: { interpreters: string[]; }; }' is not assignable to parameter of type '{ extend: any; override: any; exclude: any; }'. Property 'exclude' is missing in type '{ override: { since: string; parsers: string[]; vscodeLanguageIds: string[]; }; extend: { interpreters: string[]; }; }' but required in type '{ extend: any; override: any; exclude: any; }'. @@ -197,7 +200,7 @@ src/language-js/index.js(71,73): error TS2345: Argument of type '{ override: { s src/language-js/index.js(81,26): error TS2307: Cannot find module 'linguist-languages/data/JSON5'. src/language-js/index.js(81,60): error TS2345: Argument of type '{ override: { since: string; parsers: string[]; vscodeLanguageIds: string[]; }; }' is not assignable to parameter of type '{ extend: any; override: any; exclude: any; }'. Type '{ override: { since: string; parsers: string[]; vscodeLanguageIds: string[]; }; }' is missing the following properties from type '{ extend: any; override: any; exclude: any; }': extend, exclude -src/language-js/needs-parens.js(880,14): error TS2769: No overload matches this call. +src/language-js/needs-parens.js(893,14): error TS2769: No overload matches this call. Overload 1 of 2, '(...items: ConcatArray<(childPath: any) => any>[]): ((childPath: any) => any)[]', gave the following error. Argument of type '(string | number)[]' is not assignable to parameter of type 'ConcatArray<(childPath: any) => any>'. The types returned by 'slice(...)' are incompatible between these types. @@ -211,36 +214,36 @@ src/language-js/printer-estree.js(263,36): error TS2304: Cannot find name 'Doc'. src/language-js/printer-estree.js(264,62): error TS2304: Cannot find name 'Doc'. src/language-js/printer-estree.js(271,12): error TS2304: Cannot find name 'FastPath'. src/language-js/printer-estree.js(272,12): error TS2304: Cannot find name 'Options'. -src/language-js/printer-estree.js(398,9): error TS2769: No overload matches this call. +src/language-js/printer-estree.js(401,9): error TS2769: No overload matches this call. Overload 1 of 2, '(...items: ConcatArray[]): never[]', gave the following error. Argument of type '{ type: string; parts: any; } | { type: string; contents: any; n: any; }' is not assignable to parameter of type 'ConcatArray'. Type '{ type: string; parts: any; }' is missing the following properties from type 'ConcatArray': length, join, slice Overload 2 of 2, '(...items: ConcatArray[]): never[]', gave the following error. Argument of type '{ type: string; parts: any; } | { type: string; contents: any; n: any; }' is not assignable to parameter of type 'ConcatArray'. Type '{ type: string; parts: any; }' is not assignable to type 'ConcatArray'. -src/language-js/printer-estree.js(1897,20): error TS2345: Argument of type '" "' is not assignable to parameter of type '{ type: string; id: any; contents: any; break: boolean; expandedStates: any; }'. -src/language-js/printer-estree.js(1899,20): error TS2345: Argument of type '{ type: string; parts: any; }' is not assignable to parameter of type '{ type: string; id: any; contents: any; break: boolean; expandedStates: any; }'. +src/language-js/printer-estree.js(1929,20): error TS2345: Argument of type '" "' is not assignable to parameter of type '{ type: string; id: any; contents: any; break: boolean; expandedStates: any; }'. +src/language-js/printer-estree.js(1931,20): error TS2345: Argument of type '{ type: string; parts: any; }' is not assignable to parameter of type '{ type: string; id: any; contents: any; break: boolean; expandedStates: any; }'. Type '{ type: string; parts: any; }' is missing the following properties from type '{ type: string; id: any; contents: any; break: boolean; expandedStates: any; }': id, contents, break, expandedStates -src/language-js/printer-estree.js(1901,18): error TS2345: Argument of type '"while ("' is not assignable to parameter of type '{ type: string; id: any; contents: any; break: boolean; expandedStates: any; }'. -src/language-js/printer-estree.js(1910,9): error TS2345: Argument of type '")"' is not assignable to parameter of type '{ type: string; id: any; contents: any; break: boolean; expandedStates: any; }'. -src/language-js/printer-estree.js(3430,11): error TS2769: No overload matches this call. +src/language-js/printer-estree.js(1933,18): error TS2345: Argument of type '"while ("' is not assignable to parameter of type '{ type: string; id: any; contents: any; break: boolean; expandedStates: any; }'. +src/language-js/printer-estree.js(1942,9): error TS2345: Argument of type '")"' is not assignable to parameter of type '{ type: string; id: any; contents: any; break: boolean; expandedStates: any; }'. +src/language-js/printer-estree.js(3467,11): error TS2769: No overload matches this call. Overload 1 of 2, '(...items: ConcatArray[]): never[]', gave the following error. Argument of type 'never[] | { type: string; parts: any; }' is not assignable to parameter of type 'ConcatArray'. Type '{ type: string; parts: any; }' is not assignable to type 'ConcatArray'. Overload 2 of 2, '(...items: ConcatArray[]): never[]', gave the following error. Argument of type 'never[] | { type: string; parts: any; }' is not assignable to parameter of type 'ConcatArray'. Type '{ type: string; parts: any; }' is not assignable to type 'ConcatArray'. -src/language-js/printer-estree.js(3782,22): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'. -src/language-js/printer-estree.js(3990,23): error TS2532: Object is possibly 'undefined'. -src/language-js/printer-estree.js(3991,24): error TS2532: Object is possibly 'undefined'. -src/language-js/printer-estree.js(4312,5): error TS2345: Argument of type '"" | { type: string; parts: any; } | { type: string; contents: any; }' is not assignable to parameter of type 'string'. +src/language-js/printer-estree.js(3817,22): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'. +src/language-js/printer-estree.js(4033,23): error TS2532: Object is possibly 'undefined'. +src/language-js/printer-estree.js(4034,24): error TS2532: Object is possibly 'undefined'. +src/language-js/printer-estree.js(4355,5): error TS2345: Argument of type '"" | { type: string; parts: any; } | { type: string; contents: any; }' is not assignable to parameter of type 'string'. Type '{ type: string; parts: any; }' is not assignable to type 'string'. -src/language-js/printer-estree.js(4316,16): error TS2345: Argument of type '{ type: string; parts: any; }' is not assignable to parameter of type 'string'. -src/language-js/printer-estree.js(4364,11): error TS2322: Type '{ type: string; id: any; contents: any; break: boolean; expandedStates: any; }' is not assignable to type 'string'. -src/language-js/printer-estree.js(4379,11): error TS2322: Type '{ type: string; parts: any; }' is not assignable to type 'string'. -src/language-js/printer-estree.js(4391,9): error TS2345: Argument of type '{ type: string; parts: any; }' is not assignable to parameter of type 'string'. -src/language-js/printer-estree.js(4664,9): error TS2554: Expected 0-2 arguments, but got 3. -src/language-js/printer-estree.js(5674,7): error TS2769: No overload matches this call. +src/language-js/printer-estree.js(4359,16): error TS2345: Argument of type '{ type: string; parts: any; }' is not assignable to parameter of type 'string'. +src/language-js/printer-estree.js(4407,11): error TS2322: Type '{ type: string; id: any; contents: any; break: boolean; expandedStates: any; }' is not assignable to type 'string'. +src/language-js/printer-estree.js(4422,11): error TS2322: Type '{ type: string; parts: any; }' is not assignable to type 'string'. +src/language-js/printer-estree.js(4434,9): error TS2345: Argument of type '{ type: string; parts: any; }' is not assignable to parameter of type 'string'. +src/language-js/printer-estree.js(4712,9): error TS2554: Expected 0-2 arguments, but got 3. +src/language-js/printer-estree.js(5728,7): error TS2769: No overload matches this call. Overload 1 of 2, '(...items: ConcatArray<(childPath: any) => any>[]): ((childPath: any) => any)[]', gave the following error. Argument of type '(string | number)[]' is not assignable to parameter of type 'ConcatArray<(childPath: any) => any>'. The types returned by 'slice(...)' are incompatible between these types. @@ -253,18 +256,22 @@ src/language-js/printer-estree.js(5674,7): error TS2769: No overload matches thi src/language-js/utils.js(118,55): error TS2554: Expected 0-1 arguments, but got 2. src/language-js/utils.js(417,14): error TS2339: Property 'comments' does not exist on type 'Expression'. Property 'comments' does not exist on type 'Identifier'. -src/language-js/utils.js(429,9): error TS2367: This condition will always return 'false' since the types '"FunctionExpression" | "ClassExpression" | "ObjectExpression" | "TaggedTemplateExpression" | "CallExpression" | "ConditionalExpression" | "UpdateExpression" | "SequenceExpression" | ... 11 more ... | "AwaitExpression"' and '"OptionalMemberExpression"' have no overlap. -src/language-js/utils.js(430,13): error TS2339: Property 'property' does not exist on type 'SimpleLiteral | RegExpLiteral | FunctionExpression | ArrowFunctionExpression | ArrayExpression | ... 16 more ... | AwaitExpression'. +src/language-js/utils.js(429,7): error TS2367: This condition will always return 'false' since the types '"FunctionExpression" | "ClassExpression" | "ObjectExpression" | "TaggedTemplateExpression" | "CallExpression" | "ConditionalExpression" | "UpdateExpression" | "SequenceExpression" | ... 11 more ... | "AwaitExpression"' and '"OptionalMemberExpression"' have no overlap. +src/language-js/utils.js(434,9): error TS2367: This condition will always return 'false' since the types '"FunctionExpression" | "ClassExpression" | "ObjectExpression" | "TaggedTemplateExpression" | "CallExpression" | "ConditionalExpression" | "UpdateExpression" | "SequenceExpression" | ... 11 more ... | "AwaitExpression"' and '"OptionalMemberExpression"' have no overlap. +src/language-js/utils.js(437,16): error TS2339: Property 'property' does not exist on type 'SimpleLiteral | RegExpLiteral | FunctionExpression | ArrowFunctionExpression | ArrayExpression | ... 16 more ... | AwaitExpression'. Property 'property' does not exist on type 'SimpleLiteral'. -src/language-js/utils.js(430,52): error TS2339: Property 'property' does not exist on type 'SimpleLiteral | RegExpLiteral | FunctionExpression | ArrowFunctionExpression | ArrayExpression | ... 16 more ... | AwaitExpression'. +src/language-js/utils.js(438,16): error TS2339: Property 'property' does not exist on type 'SimpleLiteral | RegExpLiteral | FunctionExpression | ArrowFunctionExpression | ArrayExpression | ... 16 more ... | AwaitExpression'. Property 'property' does not exist on type 'SimpleLiteral'. -src/language-js/utils.js(435,9): error TS2367: This condition will always return 'false' since the types '"FunctionExpression" | "ClassExpression" | "ObjectExpression" | "TaggedTemplateExpression" | "CallExpression" | "ConditionalExpression" | "UpdateExpression" | "SequenceExpression" | ... 11 more ... | "AwaitExpression"' and '"OptionalMemberExpression"' have no overlap. -src/language-js/utils.js(437,29): error TS2339: Property 'object' does not exist on type 'SimpleLiteral | RegExpLiteral | FunctionExpression | ArrowFunctionExpression | ArrayExpression | ... 16 more ... | AwaitExpression'. +src/language-js/utils.js(439,16): error TS2339: Property 'property' does not exist on type 'SimpleLiteral | RegExpLiteral | FunctionExpression | ArrowFunctionExpression | ArrayExpression | ... 16 more ... | AwaitExpression'. + Property 'property' does not exist on type 'SimpleLiteral'. +src/language-js/utils.js(440,16): error TS2339: Property 'property' does not exist on type 'SimpleLiteral | RegExpLiteral | FunctionExpression | ArrowFunctionExpression | ArrayExpression | ... 16 more ... | AwaitExpression'. + Property 'property' does not exist on type 'SimpleLiteral'. +src/language-js/utils.js(444,21): error TS2339: Property 'object' does not exist on type 'SimpleLiteral | RegExpLiteral | FunctionExpression | ArrowFunctionExpression | ArrayExpression | ... 16 more ... | AwaitExpression'. Property 'object' does not exist on type 'SimpleLiteral'. -src/language-js/utils.js(438,22): error TS2339: Property 'comments' does not exist on type 'SimpleLiteral | RegExpLiteral | FunctionExpression | ArrowFunctionExpression | ArrayExpression | ... 16 more ... | AwaitExpression'. +src/language-js/utils.js(445,18): error TS2339: Property 'comments' does not exist on type 'SimpleLiteral | RegExpLiteral | FunctionExpression | ArrowFunctionExpression | ArrayExpression | ... 16 more ... | AwaitExpression'. Property 'comments' does not exist on type 'SimpleLiteral'. -src/language-js/utils.js(444,9): error TS2367: This condition will always return 'false' since the types '"FunctionExpression" | "ClassExpression" | "ObjectExpression" | "TaggedTemplateExpression" | "CallExpression" | "ConditionalExpression" | "UpdateExpression" | "SequenceExpression" | ... 11 more ... | "AwaitExpression"' and '"Identifier"' have no overlap. -src/language-js/utils.js(445,9): error TS2367: This condition will always return 'false' since the types '"FunctionExpression" | "ClassExpression" | "ObjectExpression" | "TaggedTemplateExpression" | "CallExpression" | "ConditionalExpression" | "UpdateExpression" | "SequenceExpression" | ... 11 more ... | "AwaitExpression"' and '"ThisExpression"' have no overlap. +src/language-js/utils.js(450,11): error TS2367: This condition will always return 'false' since the types '"FunctionExpression" | "ClassExpression" | "ObjectExpression" | "TaggedTemplateExpression" | "CallExpression" | "ConditionalExpression" | "UpdateExpression" | "SequenceExpression" | ... 11 more ... | "AwaitExpression"' and '"Identifier"' have no overlap. +src/language-js/utils.js(450,41): error TS2367: This condition will always return 'false' since the types '"FunctionExpression" | "ClassExpression" | "ObjectExpression" | "TaggedTemplateExpression" | "CallExpression" | "ConditionalExpression" | "UpdateExpression" | "SequenceExpression" | ... 11 more ... | "AwaitExpression"' and '"ThisExpression"' have no overlap. src/language-markdown/index.js(8,26): error TS2307: Cannot find module 'linguist-languages/data/Markdown'. src/language-markdown/index.js(21,26): error TS2307: Cannot find module 'linguist-languages/data/Markdown'. src/language-markdown/index.js(21,63): error TS2345: Argument of type '{ override: { name: string; since: string; parsers: string[]; vscodeLanguageIds: string[]; filenames: never[]; extensions: string[]; }; }' is not assignable to parameter of type '{ extend: any; override: any; exclude: any; }'. @@ -284,39 +291,17 @@ src/language-yaml/printer-yaml.js(226,41): error TS2769: No overload matches thi Overload 2 of 2, '(...items: ConcatArray[]): never[]', gave the following error. Argument of type '"" | { type: string; parts: any; }' is not assignable to parameter of type 'ConcatArray'. Type '""' is not assignable to type 'ConcatArray'. -src/main/core-options.js(51,43): error TS1005: '}' expected. -src/main/core-options.js(63,5): error TS2322: Type '{ since: string; category: string; type: "int"; default: number; range: { start: number; end: number; step: number; }; description: any; cliCategory: string; }' is not assignable to type 'OptionInfo'. - Object literal may only specify known properties, and 'cliCategory' does not exist in type 'OptionInfo'. -src/main/core-options.js(71,5): error TS2740: Type '{ value: string; description: any; }[]' is missing the following properties from type 'OptionChoiceInfo': value, description, since, deprecated, and 4 more. -src/main/core-options.js(101,5): error TS2322: Type '{ since: string; category: string; type: "path"; description: string; cliName: string; cliCategory: string; cliDescription: string; }' is not assignable to type 'OptionInfo'. - Object literal may only specify known properties, and 'cliName' does not exist in type 'OptionInfo'. -src/main/core-options.js(111,5): error TS2322: Type '{ since: string; category: string; type: "boolean"; default: false; description: string; cliCategory: string; }' is not assignable to type 'OptionInfo'. - Object literal may only specify known properties, and 'cliCategory' does not exist in type 'OptionInfo'. -src/main/core-options.js(118,9): error TS2322: Type '[{ since: string; value: string; }, { since: string; value: undefined; }]' is not assignable to type 'string | number | boolean | { since: string; value: string | number | boolean; }[] | [{ value: (string | number | boolean)[]; }]'. +src/main/core-options.js(117,9): error TS2322: Type '[{ since: string; value: string; }, { since: string; value: undefined; }]' is not assignable to type 'string | number | boolean | { since: string; value: string | number | boolean; }[] | [{ value: (string | number | boolean)[]; }]'. Type '[{ since: string; value: string; }, { since: string; value: undefined; }]' is not assignable to type '[{ value: (string | number | boolean)[]; }]'. Types of property '0' are incompatible. Type '{ since: string; value: string; }' is not assignable to type '{ value: (string | number | boolean)[]; }'. Object literal may only specify known properties, and 'since' does not exist in type '{ value: (string | number | boolean)[]; }'. -src/main/core-options.js(124,5): error TS2740: Type '({ value: string; description: string; } | { value: string; description: string; deprecated: string; redirect: string; } | { value: string; since: string; description: string; } | { value: string; since: string; description: string; deprecated: string; redirect: string; } | { ...; })[]' is missing the following properties from type 'OptionChoiceInfo': value, description, since, deprecated, and 4 more. -src/main/core-options.js(176,5): error TS2322: Type '{ since: string; type: "path"; array: true; default: [{ value: never[]; }]; category: string; description: string; exception: (value: any) => boolean; cliName: string; cliCategory: string; }' is not assignable to type 'OptionInfo'. - Object literal may only specify known properties, and 'cliName' does not exist in type 'OptionInfo'. -src/main/core-options.js(191,5): error TS2322: Type '{ since: string; type: "path"; array: true; default: [{ value: never[]; }]; category: string; description: any; exception: (value: any) => boolean; cliName: string; cliCategory: string; }' is not assignable to type 'OptionInfo'. - Object literal may only specify known properties, and 'cliName' does not exist in type 'OptionInfo'. -src/main/core-options.js(194,3): error TS2740: Type '{ since: string; category: string; type: "int"; default: number; description: string; range: { start: number; end: number; step: number; }; }' is missing the following properties from type 'OptionInfo': array, deprecated, redirect, oppositeDescription, and 2 more. -src/main/core-options.js(213,5): error TS2322: Type '{ since: string; category: string; type: "int"; default: number; range: { start: number; end: number; step: number; }; description: any; cliCategory: string; }' is not assignable to type 'OptionInfo'. - Object literal may only specify known properties, and 'cliCategory' does not exist in type 'OptionInfo'. -src/main/core-options.js(226,5): error TS2322: Type '{ since: string; category: string; type: "int"; default: number; range: { start: number; end: number; step: number; }; description: any; cliCategory: string; }' is not assignable to type 'OptionInfo'. - Object literal may only specify known properties, and 'cliCategory' does not exist in type 'OptionInfo'. -src/main/core-options.js(237,5): error TS2322: Type '{ since: string; category: string; type: "boolean"; default: false; description: any; cliCategory: string; }' is not assignable to type 'OptionInfo'. - Object literal may only specify known properties, and 'cliCategory' does not exist in type 'OptionInfo'. -src/main/core-options.js(239,3): error TS2740: Type '{ type: "int"; category: string; default: number; description: string; range: { start: number; end: number; step: number; }; }' is missing the following properties from type 'OptionInfo': since, array, deprecated, redirect, and 3 more. -src/main/core-options.js(251,9): error TS2322: Type '[{ since: string; value: false; }, { since: string; value: undefined; }]' is not assignable to type 'string | number | boolean | { since: string; value: string | number | boolean; }[] | [{ value: (string | number | boolean)[]; }]'. +src/main/core-options.js(158,9): error TS2322: Type 'null' is not assignable to type 'string'. +src/main/core-options.js(250,9): error TS2322: Type '[{ since: string; value: false; }, { since: string; value: undefined; }]' is not assignable to type 'string | number | boolean | { since: string; value: string | number | boolean; }[] | [{ value: (string | number | boolean)[]; }]'. Type '[{ since: string; value: false; }, { since: string; value: undefined; }]' is not assignable to type '[{ value: (string | number | boolean)[]; }]'. Types of property '0' are incompatible. Type '{ since: string; value: false; }' is not assignable to type '{ value: (string | number | boolean)[]; }'. Object literal may only specify known properties, and 'since' does not exist in type '{ value: (string | number | boolean)[]; }'. -src/main/core-options.js(254,5): error TS2322: Type 'string' is not assignable to type 'boolean | null'. -src/main/core-options.js(259,3): error TS2740: Type '{ since: string; category: string; type: "boolean"; default: false; description: string; }' is missing the following properties from type 'OptionInfo': array, deprecated, redirect, oppositeDescription, and 3 more. src/main/core.js(303,34): error TS2538: Type 'false' cannot be used as an index type. src/main/core.js(303,47): error TS2538: Type 'false' cannot be used as an index type. src/main/core.js(308,28): error TS2538: Type 'false' cannot be used as an index type. diff --git a/tests/baselines/reference/user/puppeteer.log b/tests/baselines/reference/user/puppeteer.log index 06c9e50d505..f368b268259 100644 --- a/tests/baselines/reference/user/puppeteer.log +++ b/tests/baselines/reference/user/puppeteer.log @@ -1,17 +1,17 @@ Exit Code: 1 Standard output: lib/Accessibility.js(134,15): error TS2503: Cannot find namespace 'Protocol'. -lib/Accessibility.js(341,7): error TS2322: Type 'string | number | boolean' is not assignable to type 'never'. +lib/Accessibility.js(344,7): error TS2322: Type 'string | number | boolean' is not assignable to type 'never'. Type 'string' is not assignable to type 'never'. -lib/Accessibility.js(364,7): error TS2322: Type 'string | number | true' is not assignable to type 'never'. +lib/Accessibility.js(367,7): error TS2322: Type 'string | number | true' is not assignable to type 'never'. Type 'string' is not assignable to type 'never'. -lib/Accessibility.js(376,7): error TS2322: Type 'boolean | "mixed"' is not assignable to type 'never'. +lib/Accessibility.js(379,7): error TS2322: Type 'boolean | "mixed"' is not assignable to type 'never'. Type 'false' is not assignable to type 'never'. -lib/Accessibility.js(387,7): error TS2322: Type 'string | number | boolean' is not assignable to type 'never'. +lib/Accessibility.js(390,7): error TS2322: Type 'string | number | boolean' is not assignable to type 'never'. Type 'string' is not assignable to type 'never'. -lib/Accessibility.js(400,7): error TS2322: Type 'string | number | true' is not assignable to type 'never'. +lib/Accessibility.js(403,7): error TS2322: Type 'string | number | true' is not assignable to type 'never'. Type 'string' is not assignable to type 'never'. -lib/Accessibility.js(406,22): error TS2503: Cannot find namespace 'Protocol'. +lib/Accessibility.js(409,22): error TS2503: Cannot find namespace 'Protocol'. lib/Browser.js(109,15): error TS2503: Cannot find namespace 'Protocol'. lib/Browser.js(116,58): error TS2322: Type 'Promise' is not assignable to type 'Promise'. Type 'CDPSession' is not assignable to type 'Puppeteer.CDPSession'. @@ -42,7 +42,7 @@ lib/NetworkManager.js(295,15): error TS2503: Cannot find namespace 'Protocol'. lib/NetworkManager.js(319,15): error TS2503: Cannot find namespace 'Protocol'. lib/NetworkManager.js(529,15): error TS2503: Cannot find namespace 'Protocol'. lib/NetworkManager.js(668,15): error TS2503: Cannot find namespace 'Protocol'. -lib/Page.js(93,33): error TS2345: Argument of type 'CDPSession' is not assignable to parameter of type 'Puppeteer.CDPSession'. +lib/Page.js(94,33): error TS2345: Argument of type 'CDPSession' is not assignable to parameter of type 'Puppeteer.CDPSession'. Types of property 'on' are incompatible. Type '(event: string | symbol, listener: (...args: any[]) => void) => CDPSession' is not assignable to type '(event: T, listener: (arg: any) => void) => CDPSession'. Types of parameters 'event' and 'event' are incompatible. @@ -52,20 +52,20 @@ lib/Page.js(93,33): error TS2345: Argument of type 'CDPSession' is not assignabl Type 'T' is not assignable to type 'symbol'. Type 'string | number | symbol' is not assignable to type 'symbol'. Type 'string' is not assignable to type 'symbol'. -lib/Page.js(146,15): error TS2503: Cannot find namespace 'Protocol'. -lib/Page.js(219,15): error TS2503: Cannot find namespace 'Protocol'. -lib/Page.js(387,20): error TS2503: Cannot find namespace 'Protocol'. -lib/Page.js(450,7): error TS2740: Type '(...args: any[]) => Promise' is missing the following properties from type 'Window': applicationCache, caches, clientInformation, closed, and 227 more. -lib/Page.js(460,9): error TS2349: This expression is not callable. +lib/Page.js(147,15): error TS2503: Cannot find namespace 'Protocol'. +lib/Page.js(220,15): error TS2503: Cannot find namespace 'Protocol'. +lib/Page.js(388,20): error TS2503: Cannot find namespace 'Protocol'. +lib/Page.js(451,7): error TS2740: Type '(...args: any[]) => Promise' is missing the following properties from type 'Window': applicationCache, caches, clientInformation, closed, and 227 more. +lib/Page.js(461,9): error TS2349: This expression is not callable. Type 'Window' has no call signatures. -lib/Page.js(496,15): error TS2503: Cannot find namespace 'Protocol'. -lib/Page.js(506,22): error TS2503: Cannot find namespace 'Protocol'. -lib/Page.js(519,15): error TS2503: Cannot find namespace 'Protocol'. -lib/Page.js(529,15): error TS2503: Cannot find namespace 'Protocol'. -lib/Page.js(554,15): error TS2503: Cannot find namespace 'Protocol'. -lib/Page.js(607,14): error TS2503: Cannot find namespace 'Protocol'. -lib/Page.js(914,19): error TS2503: Cannot find namespace 'Protocol'. -lib/Page.js(1315,15): error TS2503: Cannot find namespace 'Protocol'. +lib/Page.js(497,15): error TS2503: Cannot find namespace 'Protocol'. +lib/Page.js(507,22): error TS2503: Cannot find namespace 'Protocol'. +lib/Page.js(520,15): error TS2503: Cannot find namespace 'Protocol'. +lib/Page.js(530,15): error TS2503: Cannot find namespace 'Protocol'. +lib/Page.js(555,15): error TS2503: Cannot find namespace 'Protocol'. +lib/Page.js(608,14): error TS2503: Cannot find namespace 'Protocol'. +lib/Page.js(944,19): error TS2503: Cannot find namespace 'Protocol'. +lib/Page.js(1354,15): error TS2503: Cannot find namespace 'Protocol'. lib/Target.js(23,15): error TS2503: Cannot find namespace 'Protocol'. lib/Target.js(87,7): error TS2322: Type 'Promise' is not assignable to type 'Promise'. Type 'Worker | Worker' is not assignable to type 'Worker'. diff --git a/tests/baselines/reference/user/uglify-js.log b/tests/baselines/reference/user/uglify-js.log index 79999aa8abd..2a892b5f50e 100644 --- a/tests/baselines/reference/user/uglify-js.log +++ b/tests/baselines/reference/user/uglify-js.log @@ -12,93 +12,92 @@ node_modules/uglify-js/lib/ast.js(989,29): error TS2339: Property 'parent' does node_modules/uglify-js/lib/compress.js(184,42): error TS2554: Expected 0 arguments, but got 1. node_modules/uglify-js/lib/compress.js(535,41): error TS2554: Expected 0 arguments, but got 1. node_modules/uglify-js/lib/compress.js(861,33): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(1121,38): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(1135,51): error TS2349: This expression is not callable. +node_modules/uglify-js/lib/compress.js(1122,38): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(1136,51): error TS2349: This expression is not callable. Not all constituents of type 'true | ((node: any) => any)' are callable. Type 'true' has no call signatures. -node_modules/uglify-js/lib/compress.js(1199,53): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(1240,112): error TS2454: Variable 'args' is used before being assigned. -node_modules/uglify-js/lib/compress.js(1241,29): error TS2532: Object is possibly 'undefined'. -node_modules/uglify-js/lib/compress.js(1250,87): error TS2322: Type 'false' is not assignable to type 'number'. -node_modules/uglify-js/lib/compress.js(1258,29): error TS2322: Type 'false' is not assignable to type 'never'. -node_modules/uglify-js/lib/compress.js(1367,53): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(1468,38): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(1578,42): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(1610,41): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(1722,49): error TS2345: Argument of type 'number[]' is not assignable to parameter of type '[number, number, ...never[]]'. +node_modules/uglify-js/lib/compress.js(1200,53): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(1241,112): error TS2454: Variable 'args' is used before being assigned. +node_modules/uglify-js/lib/compress.js(1242,29): error TS2532: Object is possibly 'undefined'. +node_modules/uglify-js/lib/compress.js(1251,87): error TS2322: Type 'false' is not assignable to type 'number'. +node_modules/uglify-js/lib/compress.js(1259,29): error TS2322: Type 'false' is not assignable to type 'never'. +node_modules/uglify-js/lib/compress.js(1368,53): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(1469,38): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(1549,42): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(1581,41): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(1693,49): error TS2345: Argument of type 'number[]' is not assignable to parameter of type '[number, number, ...never[]]'. Type 'number[]' is missing the following properties from type '[number, number, ...never[]]': 0, 1 -node_modules/uglify-js/lib/compress.js(2045,59): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(2083,53): error TS2345: Argument of type 'any[]' is not assignable to parameter of type '[number, number, ...never[]]'. +node_modules/uglify-js/lib/compress.js(2016,59): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(2054,53): error TS2345: Argument of type 'any[]' is not assignable to parameter of type '[number, number, ...never[]]'. Type 'any[]' is missing the following properties from type '[number, number, ...never[]]': 0, 1 -node_modules/uglify-js/lib/compress.js(2231,34): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(2950,42): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3404,38): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3428,33): error TS2322: Type '"f"' is not assignable to type 'boolean'. -node_modules/uglify-js/lib/compress.js(3562,33): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3615,29): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3632,29): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(3657,75): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3731,63): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3852,12): error TS2339: Property 'push' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(3927,38): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3948,24): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(3958,28): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(4183,17): error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. -node_modules/uglify-js/lib/compress.js(4246,45): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(4357,33): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(4655,17): error TS2403: Subsequent variable declarations must have the same type. Variable 'body' must be of type 'any[]', but here has type 'any'. -node_modules/uglify-js/lib/compress.js(4739,37): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(4947,57): error TS2345: Argument of type 'any[]' is not assignable to parameter of type '[string | RegExp, (string | undefined)?]'. +node_modules/uglify-js/lib/compress.js(2202,34): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(2928,42): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3382,38): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3406,33): error TS2322: Type '"f"' is not assignable to type 'boolean'. +node_modules/uglify-js/lib/compress.js(3540,33): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3593,29): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3611,29): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(3636,75): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3711,63): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3838,12): error TS2339: Property 'push' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(3917,38): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3938,24): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(3948,28): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(4182,17): error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. +node_modules/uglify-js/lib/compress.js(4245,45): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(4356,33): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(4654,17): error TS2403: Subsequent variable declarations must have the same type. Variable 'body' must be of type 'any[]', but here has type 'any'. +node_modules/uglify-js/lib/compress.js(4738,37): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(4946,57): error TS2345: Argument of type 'any[]' is not assignable to parameter of type '[string | RegExp, (string | undefined)?]'. Property '0' is missing in type 'any[]' but required in type '[string | RegExp, (string | undefined)?]'. -node_modules/uglify-js/lib/compress.js(5111,45): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(5118,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'code' must be of type 'string', but here has type '{ get: () => string; toString: () => string; indent: () => void; indentation: () => number; current_width: () => number; should_break: () => boolean; has_parens: () => boolean; newline: () => void; print: (str: any) => void; ... 23 more ...; parent: (n: any) => any; }'. -node_modules/uglify-js/lib/compress.js(5122,36): error TS2532: Object is possibly 'undefined'. -node_modules/uglify-js/lib/compress.js(5127,41): error TS2339: Property 'get' does not exist on type 'string'. -node_modules/uglify-js/lib/compress.js(5642,18): error TS2454: Variable 'is_strict_comparison' is used before being assigned. -node_modules/uglify-js/lib/compress.js(6149,25): error TS2367: This condition will always return 'false' since the types 'boolean' and 'string' have no overlap. -node_modules/uglify-js/lib/compress.js(6176,47): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(6249,39): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(6321,39): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(6327,41): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(6772,43): error TS2454: Variable 'property' is used before being assigned. -node_modules/uglify-js/lib/compress.js(6787,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'value' must be of type 'number', but here has type 'any'. -node_modules/uglify-js/lib/compress.js(6790,46): error TS2339: Property 'has_side_effects' does not exist on type 'number'. -node_modules/uglify-js/lib/compress.js(6796,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'value' must be of type 'number', but here has type 'any'. -node_modules/uglify-js/lib/compress.js(6834,34): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(5110,45): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(5117,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'code' must be of type 'string', but here has type '{ get: () => string; toString: () => string; indent: () => void; indentation: () => number; current_width: () => number; should_break: () => boolean; has_parens: () => boolean; newline: () => void; print: (str: any) => void; ... 23 more ...; parent: (n: any) => any; }'. +node_modules/uglify-js/lib/compress.js(5121,36): error TS2532: Object is possibly 'undefined'. +node_modules/uglify-js/lib/compress.js(5126,41): error TS2339: Property 'get' does not exist on type 'string'. +node_modules/uglify-js/lib/compress.js(5643,18): error TS2454: Variable 'is_strict_comparison' is used before being assigned. +node_modules/uglify-js/lib/compress.js(6150,25): error TS2367: This condition will always return 'false' since the types 'boolean' and 'string' have no overlap. +node_modules/uglify-js/lib/compress.js(6178,47): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(6253,39): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(6325,39): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(6331,41): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(6776,43): error TS2454: Variable 'property' is used before being assigned. +node_modules/uglify-js/lib/compress.js(6791,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'value' must be of type 'number', but here has type 'any'. +node_modules/uglify-js/lib/compress.js(6794,46): error TS2339: Property 'has_side_effects' does not exist on type 'number'. +node_modules/uglify-js/lib/compress.js(6800,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'value' must be of type 'number', but here has type 'any'. +node_modules/uglify-js/lib/compress.js(6838,34): error TS2554: Expected 0 arguments, but got 1. node_modules/uglify-js/lib/minify.js(186,75): error TS2339: Property 'compress' does not exist on type 'Compressor'. node_modules/uglify-js/lib/mozilla-ast.js(566,33): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/output.js(234,25): error TS2554: Expected 0 arguments, but got 2. -node_modules/uglify-js/lib/output.js(458,37): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/output.js(762,38): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/output.js(1158,44): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/output.js(1459,58): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -node_modules/uglify-js/lib/parse.js(361,20): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. +node_modules/uglify-js/lib/output.js(232,25): error TS2554: Expected 0 arguments, but got 2. +node_modules/uglify-js/lib/output.js(456,37): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/output.js(759,38): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/output.js(1153,44): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/output.js(1454,58): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. +node_modules/uglify-js/lib/parse.js(358,20): error TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'. Type 'undefined' is not assignable to type 'number'. -node_modules/uglify-js/lib/parse.js(443,32): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'. -node_modules/uglify-js/lib/parse.js(454,32): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'. -node_modules/uglify-js/lib/parse.js(505,20): error TS2339: Property 'raw_source' does not exist on type 'RegExp'. -node_modules/uglify-js/lib/parse.js(616,57): error TS2339: Property 'push' does not exist on type 'never'. -node_modules/uglify-js/lib/parse.js(626,32): error TS2345: Argument of type 'never[]' is not assignable to parameter of type 'never'. -node_modules/uglify-js/lib/parse.js(632,40): error TS2339: Property 'length' does not exist on type 'never'. -node_modules/uglify-js/lib/parse.js(733,13): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(769,69): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(769,83): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(813,31): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(819,17): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(823,21): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(828,43): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(847,21): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(866,21): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(981,23): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'. -node_modules/uglify-js/lib/parse.js(1095,9): error TS2322: Type 'any[]' is not assignable to type 'never[]'. +node_modules/uglify-js/lib/parse.js(437,32): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'. +node_modules/uglify-js/lib/parse.js(448,32): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'. +node_modules/uglify-js/lib/parse.js(498,20): error TS2339: Property 'raw_source' does not exist on type 'RegExp'. +node_modules/uglify-js/lib/parse.js(606,57): error TS2339: Property 'push' does not exist on type 'never'. +node_modules/uglify-js/lib/parse.js(612,32): error TS2345: Argument of type 'never[]' is not assignable to parameter of type 'never'. +node_modules/uglify-js/lib/parse.js(705,13): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(738,69): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(738,83): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(782,31): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(788,17): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(792,21): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(797,43): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(816,21): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(835,21): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(950,23): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'. +node_modules/uglify-js/lib/parse.js(1064,9): error TS2322: Type 'any[]' is not assignable to type 'never[]'. Type 'any' is not assignable to type 'never'. -node_modules/uglify-js/lib/parse.js(1152,17): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(1320,32): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(1420,20): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(1426,20): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(1512,48): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(1538,35): error TS2531: Object is possibly 'null'. -node_modules/uglify-js/lib/parse.js(1583,52): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(1121,17): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(1289,32): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(1389,20): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(1395,20): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(1481,48): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(1507,35): error TS2531: Object is possibly 'null'. +node_modules/uglify-js/lib/parse.js(1552,52): error TS2531: Object is possibly 'null'. node_modules/uglify-js/lib/propmangle.js(69,18): error TS2339: Property 'prototype' does not exist on type 'ObjectConstructor | FunctionConstructor | StringConstructor | BooleanConstructor | NumberConstructor | ... 4 more ... | ArrayConstructor'. Property 'prototype' does not exist on type 'Math'. node_modules/uglify-js/lib/propmangle.js(70,45): error TS2339: Property 'prototype' does not exist on type 'ObjectConstructor | FunctionConstructor | StringConstructor | BooleanConstructor | NumberConstructor | ... 4 more ... | ArrayConstructor'. @@ -106,14 +105,14 @@ node_modules/uglify-js/lib/propmangle.js(70,45): error TS2339: Property 'prototy node_modules/uglify-js/lib/propmangle.js(80,29): error TS2554: Expected 0 arguments, but got 1. node_modules/uglify-js/lib/propmangle.js(94,30): error TS2554: Expected 0 arguments, but got 1. node_modules/uglify-js/lib/propmangle.js(146,29): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/scope.js(88,21): error TS2339: Property 'defun' does not exist on type 'SymbolDef'. -node_modules/uglify-js/lib/scope.js(88,35): error TS2339: Property 'defun' does not exist on type 'SymbolDef'. -node_modules/uglify-js/lib/scope.js(102,29): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/scope.js(157,29): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/scope.js(192,47): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/scope.js(403,29): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/scope.js(460,30): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/scope.js(485,30): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/scope.js(89,21): error TS2339: Property 'defun' does not exist on type 'SymbolDef'. +node_modules/uglify-js/lib/scope.js(89,35): error TS2339: Property 'defun' does not exist on type 'SymbolDef'. +node_modules/uglify-js/lib/scope.js(103,29): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/scope.js(158,29): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/scope.js(193,47): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/scope.js(412,29): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/scope.js(475,30): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/scope.js(500,30): error TS2554: Expected 0 arguments, but got 1. node_modules/uglify-js/lib/sourcemap.js(55,25): error TS2304: Cannot find name 'MOZ_SourceMap'. node_modules/uglify-js/lib/sourcemap.js(61,23): error TS2304: Cannot find name 'MOZ_SourceMap'. node_modules/uglify-js/tools/exit.js(10,37): error TS2345: Argument of type 'any[]' is not assignable to parameter of type '[(number | undefined)?]'. diff --git a/tests/baselines/reference/user/webpack.log b/tests/baselines/reference/user/webpack.log index a660ffbad3f..d1af5e0c5f7 100644 --- a/tests/baselines/reference/user/webpack.log +++ b/tests/baselines/reference/user/webpack.log @@ -1,33 +1,44 @@ Exit Code: 1 Standard output: -lib/BannerPlugin.js(34,27): error TS2345: Argument of type 'BannerPluginArgument' is not assignable to parameter of type 'object | object[]'. - Type 'string' is not assignable to type 'object | object[]'. -lib/logging/Logger.js(49,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(53,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(57,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(61,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(65,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(70,21): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(75,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(79,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(83,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(87,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(91,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(95,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(99,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(103,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(117,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/logging/Logger.js(127,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "log" | "info" | "warn" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. -lib/util/registerExternalSerializer.js(253,14): error TS2339: Property 'line' does not exist on type 'Position'. -lib/util/registerExternalSerializer.js(254,14): error TS2339: Property 'column' does not exist on type 'Position'. -lib/validateSchema.js(15,11): error TS2339: Property 'children' does not exist on type 'ErrorObject'. -lib/validateSchema.js(16,11): error TS2339: Property 'children' does not exist on type 'ErrorObject'. -lib/validateSchema.js(26,22): error TS2339: Property 'additionalProperty' does not exist on type 'ErrorParameters'. - Property 'additionalProperty' does not exist on type 'RefParams'. -lib/validateSchema.js(40,22): error TS2339: Property 'additionalProperty' does not exist on type 'ErrorParameters'. - Property 'additionalProperty' does not exist on type 'RefParams'. -lib/validateSchema.js(51,31): error TS2339: Property 'additionalProperty' does not exist on type 'ErrorParameters'. - Property 'additionalProperty' does not exist on type 'RefParams'. +lib/MultiCompiler.js(15,65): error TS2300: Duplicate identifier 'AsyncSeriesHook'. +lib/MultiCompiler.js(16,77): error TS2300: Duplicate identifier 'SyncBailHook'. +lib/MultiCompiler.js(17,70): error TS2300: Duplicate identifier 'WatchOptions'. +lib/MultiCompiler.js(18,37): error TS2300: Duplicate identifier 'Compiler'. +lib/MultiCompiler.js(19,34): error TS2300: Duplicate identifier 'Stats'. +lib/MultiCompiler.js(20,37): error TS2300: Duplicate identifier 'Watching'. +lib/MultiCompiler.js(21,52): error TS2300: Duplicate identifier 'InputFileSystem'. +lib/MultiCompiler.js(22,59): error TS2300: Duplicate identifier 'IntermediateFileSystem'. +lib/MultiCompiler.js(23,53): error TS2300: Duplicate identifier 'OutputFileSystem'. +lib/MultiCompiler.js(25,23): error TS2300: Duplicate identifier 'CompilerStatus'. +lib/MultiCompiler.js(33,14): error TS2300: Duplicate identifier 'Callback'. +lib/MultiCompiler.js(39,14): error TS2300: Duplicate identifier 'RunWithDependenciesHandler'. +lib/MultiCompiler.js(105,6): error TS2300: Duplicate identifier 'outputPath'. +lib/MultiCompiler.js(120,6): error TS2300: Duplicate identifier 'inputFileSystem'. +lib/MultiCompiler.js(124,6): error TS2300: Duplicate identifier 'outputFileSystem'. +lib/MultiCompiler.js(128,6): error TS2300: Duplicate identifier 'intermediateFileSystem'. +lib/MultiCompiler.js(135,6): error TS2300: Duplicate identifier 'inputFileSystem'. +lib/MultiCompiler.js(144,6): error TS2300: Duplicate identifier 'outputFileSystem'. +lib/MultiCompiler.js(153,6): error TS2300: Duplicate identifier 'intermediateFileSystem'. +lib/logging/Logger.js(49,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(53,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(57,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(61,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(65,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(70,21): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(75,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(79,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(83,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(87,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(91,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(95,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(99,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(103,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(117,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/logging/Logger.js(127,20): error TS2345: Argument of type 'string' is not assignable to parameter of type '"error" | "time" | "group" | "debug" | "info" | "warn" | "log" | "trace" | "groupCollapsed" | "groupEnd" | "profile" | "profileEnd" | "clear" | "status"'. +lib/util/registerExternalSerializer.js(218,14): error TS2339: Property 'start' does not exist on type 'typeof SourceLocation'. +lib/util/registerExternalSerializer.js(219,14): error TS2339: Property 'start' does not exist on type 'typeof SourceLocation'. +lib/util/registerExternalSerializer.js(220,14): error TS2339: Property 'end' does not exist on type 'typeof SourceLocation'. +lib/util/registerExternalSerializer.js(221,14): error TS2339: Property 'end' does not exist on type 'typeof SourceLocation'. From 763588422445402ef38ca8b882ace806a597dc83 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 29 Oct 2019 14:56:33 -0700 Subject: [PATCH 61/63] JSDoc type reference understands require with entity name (#34804) * resolve require with entity name postfix For example, `require("x").c`. This is the value equivalent of `import("x").a.b.c`, but the syntax tree is not as nicely designed for this purpose. Fixes #34802 * Add bug number to test * Add optional chain test --- src/compiler/checker.ts | 14 +++-- .../jsdocTypeReferenceToImport.symbols | 58 +++++++++++++++++ .../jsdocTypeReferenceToImport.types | 62 +++++++++++++++++++ .../jsdoc/jsdocTypeReferenceToImport.ts | 23 +++++++ 4 files changed, 152 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/jsdocTypeReferenceToImport.symbols create mode 100644 tests/baselines/reference/jsdocTypeReferenceToImport.types create mode 100644 tests/cases/conformance/jsdoc/jsdocTypeReferenceToImport.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 145e3351754..3a88ddd3f07 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10765,11 +10765,15 @@ namespace ts { let typeType = valueType; if (symbol.valueDeclaration) { const decl = getRootDeclaration(symbol.valueDeclaration); - const isRequireAlias = isVariableDeclaration(decl) - && decl.initializer - && isCallExpression(decl.initializer) - && isRequireCall(decl.initializer, /*requireStringLiteralLikeArgument*/ true) - && valueType.symbol; + let isRequireAlias = false; + if (isVariableDeclaration(decl) && decl.initializer) { + let expr = decl.initializer; + // skip past entity names, eg `require("x").a.b.c` + while (isPropertyAccessExpression(expr)) { + expr = expr.expression; + } + isRequireAlias = isCallExpression(expr) && isRequireCall(expr, /*requireStringLiteralLikeArgument*/ true) && !!valueType.symbol; + } if (isRequireAlias || node.kind === SyntaxKind.ImportType) { typeType = getTypeReferenceType(node, valueType.symbol); } diff --git a/tests/baselines/reference/jsdocTypeReferenceToImport.symbols b/tests/baselines/reference/jsdocTypeReferenceToImport.symbols new file mode 100644 index 00000000000..c7d04ff5a16 --- /dev/null +++ b/tests/baselines/reference/jsdocTypeReferenceToImport.symbols @@ -0,0 +1,58 @@ +=== tests/cases/conformance/jsdoc/jsdocTypeReferenceToImport.js === +// #34802 + +const C = require('./ex').C; +>C : Symbol(C, Decl(jsdocTypeReferenceToImport.js, 2, 5)) +>require('./ex').C : Symbol(C, Decl(ex.d.ts, 0, 0)) +>require : Symbol(require) +>'./ex' : Symbol("tests/cases/conformance/jsdoc/ex", Decl(ex.d.ts, 0, 0)) +>C : Symbol(C, Decl(ex.d.ts, 0, 0)) + +const D = require('./ex')?.C; +>D : Symbol(D, Decl(jsdocTypeReferenceToImport.js, 3, 5)) +>require('./ex')?.C : Symbol(C, Decl(ex.d.ts, 0, 0)) +>require : Symbol(require) +>'./ex' : Symbol("tests/cases/conformance/jsdoc/ex", Decl(ex.d.ts, 0, 0)) +>C : Symbol(C, Decl(ex.d.ts, 0, 0)) + +/** @type {C} c */ +var c = new C() +>c : Symbol(c, Decl(jsdocTypeReferenceToImport.js, 5, 3)) +>C : Symbol(C, Decl(jsdocTypeReferenceToImport.js, 2, 5)) + +c.start +>c.start : Symbol(C.start, Decl(ex.d.ts, 0, 16)) +>c : Symbol(c, Decl(jsdocTypeReferenceToImport.js, 5, 3)) +>start : Symbol(C.start, Decl(ex.d.ts, 0, 16)) + +c.end +>c.end : Symbol(C.end, Decl(ex.d.ts, 1, 17)) +>c : Symbol(c, Decl(jsdocTypeReferenceToImport.js, 5, 3)) +>end : Symbol(C.end, Decl(ex.d.ts, 1, 17)) + +/** @type {D} c */ +var d = new D() +>d : Symbol(d, Decl(jsdocTypeReferenceToImport.js, 10, 3)) +>D : Symbol(D, Decl(jsdocTypeReferenceToImport.js, 3, 5)) + +d.start +>d.start : Symbol(C.start, Decl(ex.d.ts, 0, 16)) +>d : Symbol(d, Decl(jsdocTypeReferenceToImport.js, 10, 3)) +>start : Symbol(C.start, Decl(ex.d.ts, 0, 16)) + +d.end +>d.end : Symbol(C.end, Decl(ex.d.ts, 1, 17)) +>d : Symbol(d, Decl(jsdocTypeReferenceToImport.js, 10, 3)) +>end : Symbol(C.end, Decl(ex.d.ts, 1, 17)) + +=== tests/cases/conformance/jsdoc/ex.d.ts === +export class C { +>C : Symbol(C, Decl(ex.d.ts, 0, 0)) + + start: number +>start : Symbol(C.start, Decl(ex.d.ts, 0, 16)) + + end: number +>end : Symbol(C.end, Decl(ex.d.ts, 1, 17)) +} + diff --git a/tests/baselines/reference/jsdocTypeReferenceToImport.types b/tests/baselines/reference/jsdocTypeReferenceToImport.types new file mode 100644 index 00000000000..4d4fe89ae02 --- /dev/null +++ b/tests/baselines/reference/jsdocTypeReferenceToImport.types @@ -0,0 +1,62 @@ +=== tests/cases/conformance/jsdoc/jsdocTypeReferenceToImport.js === +// #34802 + +const C = require('./ex').C; +>C : typeof import("tests/cases/conformance/jsdoc/ex").C +>require('./ex').C : typeof import("tests/cases/conformance/jsdoc/ex").C +>require('./ex') : typeof import("tests/cases/conformance/jsdoc/ex") +>require : any +>'./ex' : "./ex" +>C : typeof import("tests/cases/conformance/jsdoc/ex").C + +const D = require('./ex')?.C; +>D : typeof import("tests/cases/conformance/jsdoc/ex").C +>require('./ex')?.C : typeof import("tests/cases/conformance/jsdoc/ex").C +>require('./ex') : typeof import("tests/cases/conformance/jsdoc/ex") +>require : any +>'./ex' : "./ex" +>C : typeof import("tests/cases/conformance/jsdoc/ex").C + +/** @type {C} c */ +var c = new C() +>c : import("tests/cases/conformance/jsdoc/ex").C +>new C() : import("tests/cases/conformance/jsdoc/ex").C +>C : typeof import("tests/cases/conformance/jsdoc/ex").C + +c.start +>c.start : number +>c : import("tests/cases/conformance/jsdoc/ex").C +>start : number + +c.end +>c.end : number +>c : import("tests/cases/conformance/jsdoc/ex").C +>end : number + +/** @type {D} c */ +var d = new D() +>d : import("tests/cases/conformance/jsdoc/ex").C +>new D() : import("tests/cases/conformance/jsdoc/ex").C +>D : typeof import("tests/cases/conformance/jsdoc/ex").C + +d.start +>d.start : number +>d : import("tests/cases/conformance/jsdoc/ex").C +>start : number + +d.end +>d.end : number +>d : import("tests/cases/conformance/jsdoc/ex").C +>end : number + +=== tests/cases/conformance/jsdoc/ex.d.ts === +export class C { +>C : C + + start: number +>start : number + + end: number +>end : number +} + diff --git a/tests/cases/conformance/jsdoc/jsdocTypeReferenceToImport.ts b/tests/cases/conformance/jsdoc/jsdocTypeReferenceToImport.ts new file mode 100644 index 00000000000..8163988fc0c --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocTypeReferenceToImport.ts @@ -0,0 +1,23 @@ +// #34802 +// @Filename: jsdocTypeReferenceToImport.js +// @noEmit: true +// @allowJs: true +// @checkJs: true + +const C = require('./ex').C; +const D = require('./ex')?.C; +/** @type {C} c */ +var c = new C() +c.start +c.end + +/** @type {D} c */ +var d = new D() +d.start +d.end + +// @Filename: ex.d.ts +export class C { + start: number + end: number +} From 00dd1f0609a65b6854b6b68e41c35f315c91f310 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 29 Oct 2019 15:08:59 -0700 Subject: [PATCH 62/63] Add isIntersectionConstituent to relation key (#34789) * Add isIntersectionConstituent to relation key isIntersectionConstituent controls whether relation checking performs excess property and common property checks. It is possible to fail a relation check with excess property checks turned on, cache the result, and then skip a relation check with excess property checks that would have succeeded. #33133 provides an example of such a program. Fixes #33133 the right way, so I reverted the fix at #33213 Fixes #34762 (by reverting #33213) Fixes #33944 -- I added the test from #34646 * Update comments in test --- src/compiler/checker.ts | 19 +++--- .../commonTypeIntersection.errors.txt | 26 ++++++++ .../reference/commonTypeIntersection.js | 10 +++ .../reference/commonTypeIntersection.symbols | 21 +++++++ .../reference/commonTypeIntersection.types | 21 +++++++ ...yofReliesOnKeyofNeverUpperBound.errors.txt | 62 ++++++++++--------- .../intersectionAndUnionTypes.errors.txt | 10 +-- ...tersectionMemberOfUnionNarrowsCorrectly.js | 11 ++++ ...ctionMemberOfUnionNarrowsCorrectly.symbols | 27 ++++++++ ...sectionMemberOfUnionNarrowsCorrectly.types | 20 ++++++ ...sertionsWithIntersectionTypes01.errors.txt | 3 + .../unionThisTypeInFunctions.errors.txt | 16 +++-- .../intersection/commonTypeIntersection.ts | 4 ++ ...tersectionMemberOfUnionNarrowsCorrectly.ts | 4 ++ 14 files changed, 209 insertions(+), 45 deletions(-) create mode 100644 tests/baselines/reference/commonTypeIntersection.errors.txt create mode 100644 tests/baselines/reference/commonTypeIntersection.js create mode 100644 tests/baselines/reference/commonTypeIntersection.symbols create mode 100644 tests/baselines/reference/commonTypeIntersection.types create mode 100644 tests/baselines/reference/intersectionMemberOfUnionNarrowsCorrectly.js create mode 100644 tests/baselines/reference/intersectionMemberOfUnionNarrowsCorrectly.symbols create mode 100644 tests/baselines/reference/intersectionMemberOfUnionNarrowsCorrectly.types create mode 100644 tests/cases/conformance/types/intersection/commonTypeIntersection.ts create mode 100644 tests/cases/conformance/types/intersection/intersectionMemberOfUnionNarrowsCorrectly.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3a88ddd3f07..e278a96a841 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14165,7 +14165,7 @@ namespace ts { return true; } if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Object) { - const related = relation.get(getRelationKey(source, target, relation)); + const related = relation.get(getRelationKey(source, target, /*isIntersectionConstituent*/ false, relation)); if (related !== undefined) { return !!(related & RelationComparisonResult.Succeeded); } @@ -14571,7 +14571,7 @@ namespace ts { // and we need to handle "each" relations before "some" relations for the same kind of type. if (source.flags & TypeFlags.Union) { result = relation === comparableRelation ? - someTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive), isIntersectionConstituent) : + someTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive)) : eachTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive)); } else { @@ -14609,7 +14609,7 @@ namespace ts { // // - For a primitive type or type parameter (such as 'number = A & B') there is no point in // breaking the intersection apart. - result = someTypeRelatedToType(source, target, /*reportErrors*/ false, /*isIntersectionConstituent*/ true); + result = someTypeRelatedToType(source, target, /*reportErrors*/ false); } if (!result && (source.flags & TypeFlags.StructuredOrInstantiable || target.flags & TypeFlags.StructuredOrInstantiable)) { if (result = recursiveTypeRelatedTo(source, target, reportErrors, isIntersectionConstituent)) { @@ -14903,14 +14903,14 @@ namespace ts { return result; } - function someTypeRelatedToType(source: UnionOrIntersectionType, target: Type, reportErrors: boolean, isIntersectionConstituent: boolean): Ternary { + function someTypeRelatedToType(source: UnionOrIntersectionType, target: Type, reportErrors: boolean): Ternary { const sourceTypes = source.types; if (source.flags & TypeFlags.Union && containsType(sourceTypes, target)) { return Ternary.True; } const len = sourceTypes.length; for (let i = 0; i < len; i++) { - const related = isRelatedTo(sourceTypes[i], target, reportErrors && i === len - 1, /*headMessage*/ undefined, isIntersectionConstituent); + const related = isRelatedTo(sourceTypes[i], target, reportErrors && i === len - 1); if (related) { return related; } @@ -14997,7 +14997,7 @@ namespace ts { if (overflow) { return Ternary.False; } - const id = getRelationKey(source, target, relation); + const id = getRelationKey(source, target, isIntersectionConstituent, relation); const entry = relation.get(id); if (entry !== undefined) { if (reportErrors && entry & RelationComparisonResult.Failed && !(entry & RelationComparisonResult.Reported)) { @@ -16211,17 +16211,18 @@ namespace ts { * To improve caching, the relation key for two generic types uses the target's id plus ids of the type parameters. * For other cases, the types ids are used. */ - function getRelationKey(source: Type, target: Type, relation: Map) { + function getRelationKey(source: Type, target: Type, isIntersectionConstituent: boolean, relation: Map) { if (relation === identityRelation && source.id > target.id) { const temp = source; source = target; target = temp; } + const intersection = isIntersectionConstituent ? "&" : ""; if (isTypeReferenceWithGenericArguments(source) && isTypeReferenceWithGenericArguments(target)) { const typeParameters: Type[] = []; - return getTypeReferenceId(source, typeParameters) + "," + getTypeReferenceId(target, typeParameters); + return getTypeReferenceId(source, typeParameters) + "," + getTypeReferenceId(target, typeParameters) + intersection; } - return source.id + "," + target.id; + return source.id + "," + target.id + intersection; } // Invoke the callback for each underlying property symbol of the given symbol and return the first diff --git a/tests/baselines/reference/commonTypeIntersection.errors.txt b/tests/baselines/reference/commonTypeIntersection.errors.txt new file mode 100644 index 00000000000..c10f8e2cfec --- /dev/null +++ b/tests/baselines/reference/commonTypeIntersection.errors.txt @@ -0,0 +1,26 @@ +tests/cases/conformance/types/intersection/commonTypeIntersection.ts(2,5): error TS2322: Type '{ __typename?: "TypeTwo"; } & { a: boolean; }' is not assignable to type '{ __typename?: "TypeOne"; } & { a: boolean; }'. + Type '{ __typename?: "TypeTwo"; } & { a: boolean; }' is not assignable to type '{ __typename?: "TypeOne"; }'. + Types of property '__typename' are incompatible. + Type '"TypeTwo"' is not assignable to type '"TypeOne"'. +tests/cases/conformance/types/intersection/commonTypeIntersection.ts(4,5): error TS2322: Type '{ __typename?: "TypeTwo"; } & string' is not assignable to type '{ __typename?: "TypeOne"; } & string'. + Type '{ __typename?: "TypeTwo"; } & string' is not assignable to type '{ __typename?: "TypeOne"; }'. + Types of property '__typename' are incompatible. + Type '"TypeTwo"' is not assignable to type '"TypeOne"'. + + +==== tests/cases/conformance/types/intersection/commonTypeIntersection.ts (2 errors) ==== + declare let x1: { __typename?: 'TypeTwo' } & { a: boolean }; + let y1: { __typename?: 'TypeOne' } & { a: boolean} = x1; // should error here + ~~ +!!! error TS2322: Type '{ __typename?: "TypeTwo"; } & { a: boolean; }' is not assignable to type '{ __typename?: "TypeOne"; } & { a: boolean; }'. +!!! error TS2322: Type '{ __typename?: "TypeTwo"; } & { a: boolean; }' is not assignable to type '{ __typename?: "TypeOne"; }'. +!!! error TS2322: Types of property '__typename' are incompatible. +!!! error TS2322: Type '"TypeTwo"' is not assignable to type '"TypeOne"'. + declare let x2: { __typename?: 'TypeTwo' } & string; + let y2: { __typename?: 'TypeOne' } & string = x2; // should error here + ~~ +!!! error TS2322: Type '{ __typename?: "TypeTwo"; } & string' is not assignable to type '{ __typename?: "TypeOne"; } & string'. +!!! error TS2322: Type '{ __typename?: "TypeTwo"; } & string' is not assignable to type '{ __typename?: "TypeOne"; }'. +!!! error TS2322: Types of property '__typename' are incompatible. +!!! error TS2322: Type '"TypeTwo"' is not assignable to type '"TypeOne"'. + \ No newline at end of file diff --git a/tests/baselines/reference/commonTypeIntersection.js b/tests/baselines/reference/commonTypeIntersection.js new file mode 100644 index 00000000000..1bef2b3b06c --- /dev/null +++ b/tests/baselines/reference/commonTypeIntersection.js @@ -0,0 +1,10 @@ +//// [commonTypeIntersection.ts] +declare let x1: { __typename?: 'TypeTwo' } & { a: boolean }; +let y1: { __typename?: 'TypeOne' } & { a: boolean} = x1; // should error here +declare let x2: { __typename?: 'TypeTwo' } & string; +let y2: { __typename?: 'TypeOne' } & string = x2; // should error here + + +//// [commonTypeIntersection.js] +var y1 = x1; // should error here +var y2 = x2; // should error here diff --git a/tests/baselines/reference/commonTypeIntersection.symbols b/tests/baselines/reference/commonTypeIntersection.symbols new file mode 100644 index 00000000000..3c81f5f4508 --- /dev/null +++ b/tests/baselines/reference/commonTypeIntersection.symbols @@ -0,0 +1,21 @@ +=== tests/cases/conformance/types/intersection/commonTypeIntersection.ts === +declare let x1: { __typename?: 'TypeTwo' } & { a: boolean }; +>x1 : Symbol(x1, Decl(commonTypeIntersection.ts, 0, 11)) +>__typename : Symbol(__typename, Decl(commonTypeIntersection.ts, 0, 17)) +>a : Symbol(a, Decl(commonTypeIntersection.ts, 0, 46)) + +let y1: { __typename?: 'TypeOne' } & { a: boolean} = x1; // should error here +>y1 : Symbol(y1, Decl(commonTypeIntersection.ts, 1, 3)) +>__typename : Symbol(__typename, Decl(commonTypeIntersection.ts, 1, 9)) +>a : Symbol(a, Decl(commonTypeIntersection.ts, 1, 38)) +>x1 : Symbol(x1, Decl(commonTypeIntersection.ts, 0, 11)) + +declare let x2: { __typename?: 'TypeTwo' } & string; +>x2 : Symbol(x2, Decl(commonTypeIntersection.ts, 2, 11)) +>__typename : Symbol(__typename, Decl(commonTypeIntersection.ts, 2, 17)) + +let y2: { __typename?: 'TypeOne' } & string = x2; // should error here +>y2 : Symbol(y2, Decl(commonTypeIntersection.ts, 3, 3)) +>__typename : Symbol(__typename, Decl(commonTypeIntersection.ts, 3, 9)) +>x2 : Symbol(x2, Decl(commonTypeIntersection.ts, 2, 11)) + diff --git a/tests/baselines/reference/commonTypeIntersection.types b/tests/baselines/reference/commonTypeIntersection.types new file mode 100644 index 00000000000..aa14b244bb0 --- /dev/null +++ b/tests/baselines/reference/commonTypeIntersection.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/types/intersection/commonTypeIntersection.ts === +declare let x1: { __typename?: 'TypeTwo' } & { a: boolean }; +>x1 : { __typename?: "TypeTwo"; } & { a: boolean; } +>__typename : "TypeTwo" +>a : boolean + +let y1: { __typename?: 'TypeOne' } & { a: boolean} = x1; // should error here +>y1 : { __typename?: "TypeOne"; } & { a: boolean; } +>__typename : "TypeOne" +>a : boolean +>x1 : { __typename?: "TypeTwo"; } & { a: boolean; } + +declare let x2: { __typename?: 'TypeTwo' } & string; +>x2 : { __typename?: "TypeTwo"; } & string +>__typename : "TypeTwo" + +let y2: { __typename?: 'TypeOne' } & string = x2; // should error here +>y2 : { __typename?: "TypeOne"; } & string +>__typename : "TypeOne" +>x2 : { __typename?: "TypeTwo"; } & string + diff --git a/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt b/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt index af63c18523d..9abaa6db803 100644 --- a/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt +++ b/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt @@ -5,20 +5,23 @@ tests/cases/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.t Type '"text" | "email"' is not assignable to type 'ChannelOfType["type"] & ChannelOfType["type"]'. Type '"text"' is not assignable to type 'ChannelOfType["type"] & ChannelOfType["type"]'. Type '"text"' is not assignable to type 'ChannelOfType["type"]'. - Type 'T' is not assignable to type 'ChannelOfType["type"]'. - Type '"text" | "email"' is not assignable to type 'ChannelOfType["type"]'. - Type '"text"' is not assignable to type 'ChannelOfType["type"]'. - Type '"text"' is not assignable to type 'T & "text"'. - Type '"text"' is not assignable to type 'T'. - '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'. - Type 'T' is not assignable to type 'T & "text"'. - Type '"text" | "email"' is not assignable to type 'T & "text"'. - Type '"text"' is not assignable to type 'T & "text"'. - Type '"text"' is not assignable to type 'T'. - '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'. - Type 'T' is not assignable to type '"text"'. - Type '"text" | "email"' is not assignable to type '"text"'. - Type '"email"' is not assignable to type '"text"'. + Type '"text"' is not assignable to type 'T & "text"'. + Type '"text"' is not assignable to type 'T'. + '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'. + Type 'T' is not assignable to type 'ChannelOfType["type"]'. + Type '"text" | "email"' is not assignable to type 'ChannelOfType["type"]'. + Type '"text"' is not assignable to type 'ChannelOfType["type"]'. + Type '"text"' is not assignable to type 'T & "text"'. + Type '"text"' is not assignable to type 'T'. + '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'. + Type 'T' is not assignable to type 'T & "text"'. + Type '"text" | "email"' is not assignable to type 'T & "text"'. + Type '"text"' is not assignable to type 'T & "text"'. + Type '"text"' is not assignable to type 'T'. + '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'. + Type 'T' is not assignable to type '"text"'. + Type '"text" | "email"' is not assignable to type '"text"'. + Type '"email"' is not assignable to type '"text"'. ==== tests/cases/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.ts (1 errors) ==== @@ -63,20 +66,23 @@ tests/cases/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.t !!! error TS2322: Type '"text" | "email"' is not assignable to type 'ChannelOfType["type"] & ChannelOfType["type"]'. !!! error TS2322: Type '"text"' is not assignable to type 'ChannelOfType["type"] & ChannelOfType["type"]'. !!! error TS2322: Type '"text"' is not assignable to type 'ChannelOfType["type"]'. -!!! error TS2322: Type 'T' is not assignable to type 'ChannelOfType["type"]'. -!!! error TS2322: Type '"text" | "email"' is not assignable to type 'ChannelOfType["type"]'. -!!! error TS2322: Type '"text"' is not assignable to type 'ChannelOfType["type"]'. -!!! error TS2322: Type '"text"' is not assignable to type 'T & "text"'. -!!! error TS2322: Type '"text"' is not assignable to type 'T'. -!!! error TS2322: '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'. -!!! error TS2322: Type 'T' is not assignable to type 'T & "text"'. -!!! error TS2322: Type '"text" | "email"' is not assignable to type 'T & "text"'. -!!! error TS2322: Type '"text"' is not assignable to type 'T & "text"'. -!!! error TS2322: Type '"text"' is not assignable to type 'T'. -!!! error TS2322: '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'. -!!! error TS2322: Type 'T' is not assignable to type '"text"'. -!!! error TS2322: Type '"text" | "email"' is not assignable to type '"text"'. -!!! error TS2322: Type '"email"' is not assignable to type '"text"'. +!!! error TS2322: Type '"text"' is not assignable to type 'T & "text"'. +!!! error TS2322: Type '"text"' is not assignable to type 'T'. +!!! error TS2322: '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'. +!!! error TS2322: Type 'T' is not assignable to type 'ChannelOfType["type"]'. +!!! error TS2322: Type '"text" | "email"' is not assignable to type 'ChannelOfType["type"]'. +!!! error TS2322: Type '"text"' is not assignable to type 'ChannelOfType["type"]'. +!!! error TS2322: Type '"text"' is not assignable to type 'T & "text"'. +!!! error TS2322: Type '"text"' is not assignable to type 'T'. +!!! error TS2322: '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'. +!!! error TS2322: Type 'T' is not assignable to type 'T & "text"'. +!!! error TS2322: Type '"text" | "email"' is not assignable to type 'T & "text"'. +!!! error TS2322: Type '"text"' is not assignable to type 'T & "text"'. +!!! error TS2322: Type '"text"' is not assignable to type 'T'. +!!! error TS2322: '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'. +!!! error TS2322: Type 'T' is not assignable to type '"text"'. +!!! error TS2322: Type '"text" | "email"' is not assignable to type '"text"'. +!!! error TS2322: Type '"email"' is not assignable to type '"text"'. } const newTextChannel = makeNewChannel('text'); diff --git a/tests/baselines/reference/intersectionAndUnionTypes.errors.txt b/tests/baselines/reference/intersectionAndUnionTypes.errors.txt index 4f3b1db01e3..7de8735f640 100644 --- a/tests/baselines/reference/intersectionAndUnionTypes.errors.txt +++ b/tests/baselines/reference/intersectionAndUnionTypes.errors.txt @@ -24,14 +24,14 @@ tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(29,1): e Property 'd' is missing in type 'A & B' but required in type 'D'. tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(31,1): error TS2322: Type 'A & B' is not assignable to type '(A & C) | (A & D) | (B & C) | (B & D)'. Type 'A & B' is not assignable to type 'B & D'. - Type 'A & B' is not assignable to type 'D'. + Property 'd' is missing in type 'A & B' but required in type 'D'. tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(32,1): error TS2322: Type 'A | B' is not assignable to type '(A & C) | (A & D) | (B & C) | (B & D)'. Type 'A' is not assignable to type '(A & C) | (A & D) | (B & C) | (B & D)'. Type 'A' is not assignable to type 'A & D'. Property 'd' is missing in type 'A' but required in type 'D'. tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(33,1): error TS2322: Type 'C & D' is not assignable to type '(A & C) | (A & D) | (B & C) | (B & D)'. Type 'C & D' is not assignable to type 'B & D'. - Type 'C & D' is not assignable to type 'B'. + Property 'b' is missing in type 'C & D' but required in type 'B'. tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(34,1): error TS2322: Type 'C | D' is not assignable to type '(A & C) | (A & D) | (B & C) | (B & D)'. Type 'C' is not assignable to type '(A & C) | (A & D) | (B & C) | (B & D)'. Type 'C' is not assignable to type 'B & C'. @@ -118,7 +118,8 @@ tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(37,1): e ~ !!! error TS2322: Type 'A & B' is not assignable to type '(A & C) | (A & D) | (B & C) | (B & D)'. !!! error TS2322: Type 'A & B' is not assignable to type 'B & D'. -!!! error TS2322: Type 'A & B' is not assignable to type 'D'. +!!! error TS2322: Property 'd' is missing in type 'A & B' but required in type 'D'. +!!! related TS2728 tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts:4:15: 'd' is declared here. y = aob; ~ !!! error TS2322: Type 'A | B' is not assignable to type '(A & C) | (A & D) | (B & C) | (B & D)'. @@ -130,7 +131,8 @@ tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(37,1): e ~ !!! error TS2322: Type 'C & D' is not assignable to type '(A & C) | (A & D) | (B & C) | (B & D)'. !!! error TS2322: Type 'C & D' is not assignable to type 'B & D'. -!!! error TS2322: Type 'C & D' is not assignable to type 'B'. +!!! error TS2322: Property 'b' is missing in type 'C & D' but required in type 'B'. +!!! related TS2728 tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts:2:15: 'b' is declared here. y = cod; ~ !!! error TS2322: Type 'C | D' is not assignable to type '(A & C) | (A & D) | (B & C) | (B & D)'. diff --git a/tests/baselines/reference/intersectionMemberOfUnionNarrowsCorrectly.js b/tests/baselines/reference/intersectionMemberOfUnionNarrowsCorrectly.js new file mode 100644 index 00000000000..059d182b1b2 --- /dev/null +++ b/tests/baselines/reference/intersectionMemberOfUnionNarrowsCorrectly.js @@ -0,0 +1,11 @@ +//// [intersectionMemberOfUnionNarrowsCorrectly.ts] +export type U = { kind?: 'A', a: string } | { kind?: 'B' } & { b: string }; +type Ex = T extends U ? T : never; +declare let x: Ex +x.a + + +//// [intersectionMemberOfUnionNarrowsCorrectly.js] +"use strict"; +exports.__esModule = true; +x.a; diff --git a/tests/baselines/reference/intersectionMemberOfUnionNarrowsCorrectly.symbols b/tests/baselines/reference/intersectionMemberOfUnionNarrowsCorrectly.symbols new file mode 100644 index 00000000000..d10772a93f5 --- /dev/null +++ b/tests/baselines/reference/intersectionMemberOfUnionNarrowsCorrectly.symbols @@ -0,0 +1,27 @@ +=== tests/cases/conformance/types/intersection/intersectionMemberOfUnionNarrowsCorrectly.ts === +export type U = { kind?: 'A', a: string } | { kind?: 'B' } & { b: string }; +>U : Symbol(U, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 0, 0)) +>kind : Symbol(kind, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 0, 17)) +>a : Symbol(a, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 0, 29)) +>kind : Symbol(kind, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 0, 45)) +>b : Symbol(b, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 0, 62)) + +type Ex = T extends U ? T : never; +>Ex : Symbol(Ex, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 0, 75)) +>T : Symbol(T, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 1, 8)) +>U : Symbol(U, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 1, 10)) +>T : Symbol(T, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 1, 8)) +>U : Symbol(U, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 1, 10)) +>T : Symbol(T, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 1, 8)) + +declare let x: Ex +>x : Symbol(x, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 2, 11)) +>Ex : Symbol(Ex, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 0, 75)) +>U : Symbol(U, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 0, 0)) +>kind : Symbol(kind, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 2, 22)) + +x.a +>x.a : Symbol(a, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 0, 29)) +>x : Symbol(x, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 2, 11)) +>a : Symbol(a, Decl(intersectionMemberOfUnionNarrowsCorrectly.ts, 0, 29)) + diff --git a/tests/baselines/reference/intersectionMemberOfUnionNarrowsCorrectly.types b/tests/baselines/reference/intersectionMemberOfUnionNarrowsCorrectly.types new file mode 100644 index 00000000000..77805ece13b --- /dev/null +++ b/tests/baselines/reference/intersectionMemberOfUnionNarrowsCorrectly.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/types/intersection/intersectionMemberOfUnionNarrowsCorrectly.ts === +export type U = { kind?: 'A', a: string } | { kind?: 'B' } & { b: string }; +>U : U +>kind : "A" +>a : string +>kind : "B" +>b : string + +type Ex = T extends U ? T : never; +>Ex : Ex + +declare let x: Ex +>x : { kind?: "A"; a: string; } +>kind : "A" + +x.a +>x.a : string +>x : { kind?: "A"; a: string; } +>a : string + diff --git a/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt b/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt index 29a7f49d2db..d7df5037490 100644 --- a/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt +++ b/tests/baselines/reference/typeAssertionsWithIntersectionTypes01.errors.txt @@ -1,6 +1,7 @@ tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(17,9): error TS2352: Conversion of type 'I2' to type 'I1 & I3' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. Property 'p3' is missing in type 'I2' but required in type 'I3'. tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts(18,9): error TS2352: Conversion of type 'I2' to type 'I3' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. + Property 'p3' is missing in type 'I2' but required in type 'I3'. ==== tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts (2 errors) ==== @@ -28,6 +29,8 @@ tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithInt var b = z; ~~~~~ !!! error TS2352: Conversion of type 'I2' to type 'I3' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. +!!! error TS2352: Property 'p3' is missing in type 'I2' but required in type 'I3'. +!!! related TS2728 tests/cases/conformance/types/typeRelationships/comparable/typeAssertionsWithIntersectionTypes01.ts:10:5: 'p3' is declared here. var c = z; var d = y; \ No newline at end of file diff --git a/tests/baselines/reference/unionThisTypeInFunctions.errors.txt b/tests/baselines/reference/unionThisTypeInFunctions.errors.txt index db03a5426fb..f4f0377a087 100644 --- a/tests/baselines/reference/unionThisTypeInFunctions.errors.txt +++ b/tests/baselines/reference/unionThisTypeInFunctions.errors.txt @@ -5,8 +5,12 @@ tests/cases/conformance/types/thisType/unionThisTypeInFunctions.ts(10,5): error Type '(this: Real, n: number) => void' is not assignable to type '(this: Fake, n: number) => void'. The 'this' types of each signature are incompatible. Type 'Fake' is not assignable to type 'Real'. - Types of property 'data' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of property 'method' are incompatible. + Type '(this: Fake, n: number) => void' is not assignable to type '(this: Real, n: number) => void'. + The 'this' types of each signature are incompatible. + Type 'Real' is not assignable to type 'Fake'. + Types of property 'data' are incompatible. + Type 'string' is not assignable to type 'number'. ==== tests/cases/conformance/types/thisType/unionThisTypeInFunctions.ts (1 errors) ==== @@ -28,7 +32,11 @@ tests/cases/conformance/types/thisType/unionThisTypeInFunctions.ts(10,5): error !!! error TS2684: Type '(this: Real, n: number) => void' is not assignable to type '(this: Fake, n: number) => void'. !!! error TS2684: The 'this' types of each signature are incompatible. !!! error TS2684: Type 'Fake' is not assignable to type 'Real'. -!!! error TS2684: Types of property 'data' are incompatible. -!!! error TS2684: Type 'number' is not assignable to type 'string'. +!!! error TS2684: Types of property 'method' are incompatible. +!!! error TS2684: Type '(this: Fake, n: number) => void' is not assignable to type '(this: Real, n: number) => void'. +!!! error TS2684: The 'this' types of each signature are incompatible. +!!! error TS2684: Type 'Real' is not assignable to type 'Fake'. +!!! error TS2684: Types of property 'data' are incompatible. +!!! error TS2684: Type 'string' is not assignable to type 'number'. } \ No newline at end of file diff --git a/tests/cases/conformance/types/intersection/commonTypeIntersection.ts b/tests/cases/conformance/types/intersection/commonTypeIntersection.ts new file mode 100644 index 00000000000..1b4ce3746bc --- /dev/null +++ b/tests/cases/conformance/types/intersection/commonTypeIntersection.ts @@ -0,0 +1,4 @@ +declare let x1: { __typename?: 'TypeTwo' } & { a: boolean }; +let y1: { __typename?: 'TypeOne' } & { a: boolean} = x1; // should error here +declare let x2: { __typename?: 'TypeTwo' } & string; +let y2: { __typename?: 'TypeOne' } & string = x2; // should error here diff --git a/tests/cases/conformance/types/intersection/intersectionMemberOfUnionNarrowsCorrectly.ts b/tests/cases/conformance/types/intersection/intersectionMemberOfUnionNarrowsCorrectly.ts new file mode 100644 index 00000000000..d2657011dae --- /dev/null +++ b/tests/cases/conformance/types/intersection/intersectionMemberOfUnionNarrowsCorrectly.ts @@ -0,0 +1,4 @@ +export type U = { kind?: 'A', a: string } | { kind?: 'B' } & { b: string }; +type Ex = T extends U ? T : never; +declare let x: Ex +x.a From 87cc8c4af8fb2adcde0dfe92cb6f4703236b3291 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 29 Oct 2019 17:42:30 -0700 Subject: [PATCH 63/63] Evaluate RHS of binding/assignment pattern first (#34806) --- src/compiler/factory.ts | 8 ++++-- src/compiler/transformers/destructuring.ts | 19 ++++++++++++-- .../blockScopedBindingUsedBeforeDef.js | 4 +-- .../computedPropertiesInDestructuring1.js | 26 +++++++++---------- .../computedPropertiesInDestructuring2.js | 2 +- .../crashInGetTextOfComputedPropertyName.js | 4 +-- .../reference/destructureComputedProperty.js | 4 +-- ...structuredMaappedTypeIsNotImplicitlyAny.js | 2 +- .../destructuringAssignment_private.js | 6 ++--- .../reference/destructuringControlFlow.js | 4 +-- .../baselines/reference/genericObjectRest.js | 8 +++--- .../lateBoundDestructuringImplicitAnyError.js | 18 ++++++------- 12 files changed, 62 insertions(+), 43 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 7ec85bd94c1..c09736a5c3c 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -5389,6 +5389,12 @@ namespace ts { * Gets the property name of a BindingOrAssignmentElement */ export function getPropertyNameOfBindingOrAssignmentElement(bindingElement: BindingOrAssignmentElement): PropertyName | undefined { + const propertyName = tryGetPropertyNameOfBindingOrAssignmentElement(bindingElement); + Debug.assert(!!propertyName || isSpreadAssignment(bindingElement), "Invalid property name for binding element."); + return propertyName; + } + + export function tryGetPropertyNameOfBindingOrAssignmentElement(bindingElement: BindingOrAssignmentElement): PropertyName | undefined { switch (bindingElement.kind) { case SyntaxKind.BindingElement: // `a` in `let { a: b } = ...` @@ -5429,8 +5435,6 @@ namespace ts { ? target.expression : target; } - - Debug.fail("Invalid property name for binding element."); } function isStringOrNumericLiteral(node: Node): node is StringLiteral | NumericLiteral { diff --git a/src/compiler/transformers/destructuring.ts b/src/compiler/transformers/destructuring.ts index 10d090a152e..23f19ef9da8 100644 --- a/src/compiler/transformers/destructuring.ts +++ b/src/compiler/transformers/destructuring.ts @@ -68,7 +68,8 @@ namespace ts { if (value) { value = visitNode(value, visitor, isExpression); - if (isIdentifier(value) && bindingOrAssignmentElementAssignsToName(node, value.escapedText)) { + if (isIdentifier(value) && bindingOrAssignmentElementAssignsToName(node, value.escapedText) || + bindingOrAssignmentElementContainsNonLiteralComputedName(node)) { // If the right-hand value of the assignment is also an assignment target then // we need to cache the right-hand value. value = ensureIdentifier(flattenContext, value, /*reuseIdentifierExpressions*/ false, location); @@ -147,6 +148,19 @@ namespace ts { return false; } + function bindingOrAssignmentElementContainsNonLiteralComputedName(element: BindingOrAssignmentElement): boolean { + const propertyName = tryGetPropertyNameOfBindingOrAssignmentElement(element); + if (propertyName && isComputedPropertyName(propertyName) && !isLiteralExpression(propertyName.expression)) { + return true; + } + const target = getTargetOfBindingOrAssignmentElement(element); + return !!target && isBindingOrAssignmentPattern(target) && bindingOrAssignmentPatternContainsNonLiteralComputedName(target); + } + + function bindingOrAssignmentPatternContainsNonLiteralComputedName(pattern: BindingOrAssignmentPattern): boolean { + return !!forEach(getElementsOfBindingOrAssignmentPattern(pattern), bindingOrAssignmentElementContainsNonLiteralComputedName); + } + /** * Flattens a VariableDeclaration or ParameterDeclaration to one or more variable declarations. * @@ -184,7 +198,8 @@ namespace ts { if (isVariableDeclaration(node)) { let initializer = getInitializerOfBindingOrAssignmentElement(node); - if (initializer && isIdentifier(initializer) && bindingOrAssignmentElementAssignsToName(node, initializer.escapedText)) { + if (initializer && (isIdentifier(initializer) && bindingOrAssignmentElementAssignsToName(node, initializer.escapedText) || + bindingOrAssignmentElementContainsNonLiteralComputedName(node))) { // If the right-hand value of the assignment is also an assignment target then // we need to cache the right-hand value. initializer = ensureIdentifier(flattenContext, initializer, /*reuseIdentifierExpressions*/ false, initializer); diff --git a/tests/baselines/reference/blockScopedBindingUsedBeforeDef.js b/tests/baselines/reference/blockScopedBindingUsedBeforeDef.js index cc9ad56be88..adbba8ee8ae 100644 --- a/tests/baselines/reference/blockScopedBindingUsedBeforeDef.js +++ b/tests/baselines/reference/blockScopedBindingUsedBeforeDef.js @@ -15,7 +15,7 @@ for (var _i = 0, _a = [{}]; _i < _a.length; _i++) { continue; } // 2: -for (var _c = a, a = {}[_c]; false;) +for (var _c = {}, _d = a, a = _c[_d]; false;) continue; // 3: -var _d = b, b = {}[_d]; +var _e = {}, _f = b, b = _e[_f]; diff --git a/tests/baselines/reference/computedPropertiesInDestructuring1.js b/tests/baselines/reference/computedPropertiesInDestructuring1.js index 4a0d6db3c1d..7dea81590c7 100644 --- a/tests/baselines/reference/computedPropertiesInDestructuring1.js +++ b/tests/baselines/reference/computedPropertiesInDestructuring1.js @@ -38,15 +38,15 @@ let [{[foo.toExponential()]: bar7}] = [{bar: "bar"}]; //// [computedPropertiesInDestructuring1.js] -var _a, _b, _c, _d, _e, _f; +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; // destructuring in variable declarations var foo = "bar"; -var _g = foo, bar = { bar: "bar" }[_g]; +var _o = { bar: "bar" }, _p = foo, bar = _o[_p]; var bar2 = { bar: "bar" }["bar"]; var foo2 = function () { return "bar"; }; -var _h = foo2(), bar3 = { bar: "bar" }[_h]; -var _j = foo, bar4 = [{ bar: "bar" }][0][_j]; -var _k = foo2(), bar5 = [{ bar: "bar" }][0][_k]; +var _q = { bar: "bar" }, _r = foo2(), bar3 = _q[_r]; +var _s = [{ bar: "bar" }], _t = foo, bar4 = _s[0][_t]; +var _u = [{ bar: "bar" }], _v = foo2(), bar5 = _u[0][_v]; function f1(_a) { var x = _a["bar"]; } @@ -63,13 +63,13 @@ function f5(_a) { var _b = foo2(), x = _a[0][_b]; } // report errors on type errors in computed properties used in destructuring -var _l = foo(), bar6 = [{ bar: "bar" }][0][_l]; -var _m = foo.toExponential(), bar7 = [{ bar: "bar" }][0][_m]; +var _w = [{ bar: "bar" }], _x = foo(), bar6 = _w[0][_x]; +var _y = [{ bar: "bar" }], _z = foo.toExponential(), bar7 = _y[0][_z]; // destructuring assignment -(_a = foo, bar = { bar: "bar" }[_a]); +(_a = { bar: "bar" }, _b = foo, bar = _a[_b]); (bar2 = { bar: "bar" }["bar"]); -(_b = foo2(), bar3 = { bar: "bar" }[_b]); -_c = foo, bar4 = [{ bar: "bar" }][0][_c]; -_d = foo2(), bar5 = [{ bar: "bar" }][0][_d]; -_e = foo(), bar4 = [{ bar: "bar" }][0][_e]; -_f = (1 + {}), bar4 = [{ bar: "bar" }][0][_f]; +(_c = { bar: "bar" }, _d = foo2(), bar3 = _c[_d]); +_e = [{ bar: "bar" }], _f = foo, bar4 = _e[0][_f]; +_g = [{ bar: "bar" }], _h = foo2(), bar5 = _g[0][_h]; +_j = [{ bar: "bar" }], _k = foo(), bar4 = _j[0][_k]; +_l = [{ bar: "bar" }], _m = (1 + {}), bar4 = _l[0][_m]; diff --git a/tests/baselines/reference/computedPropertiesInDestructuring2.js b/tests/baselines/reference/computedPropertiesInDestructuring2.js index 8579881b775..e52acafcf49 100644 --- a/tests/baselines/reference/computedPropertiesInDestructuring2.js +++ b/tests/baselines/reference/computedPropertiesInDestructuring2.js @@ -4,4 +4,4 @@ let {[foo2()]: bar3} = {}; //// [computedPropertiesInDestructuring2.js] var foo2 = function () { return "bar"; }; -var _a = foo2(), bar3 = {}[_a]; +var _a = {}, _b = foo2(), bar3 = _a[_b]; diff --git a/tests/baselines/reference/crashInGetTextOfComputedPropertyName.js b/tests/baselines/reference/crashInGetTextOfComputedPropertyName.js index 71d5df00e2a..15dd773c58d 100644 --- a/tests/baselines/reference/crashInGetTextOfComputedPropertyName.js +++ b/tests/baselines/reference/crashInGetTextOfComputedPropertyName.js @@ -36,12 +36,12 @@ exports.__esModule = true; var itemId = 'some-id'; // --- test on first level --- var items = {}; -var _a = itemId, itemOk1 = items[_a]; +var _a = items, _b = itemId, itemOk1 = _a[_b]; typeof itemOk1; // pass var objWithItems = { items: {} }; var itemOk2 = objWithItems.items[itemId]; typeof itemOk2; // pass -var _b = objWithItems.items /*happens when default value is provided*/, _c = itemId, itemWithTSError = (_b === void 0 ? {} /*happens when default value is provided*/ : _b)[_c]; +var _c = objWithItems, _d = _c.items /*happens when default value is provided*/, _e = itemId, itemWithTSError = (_d === void 0 ? {} /*happens when default value is provided*/ : _d)[_e]; // in order to re-produce the error, uncomment next line: typeof itemWithTSError; // :( // will result in: diff --git a/tests/baselines/reference/destructureComputedProperty.js b/tests/baselines/reference/destructureComputedProperty.js index 290f3f8119e..768684f90b6 100644 --- a/tests/baselines/reference/destructureComputedProperty.js +++ b/tests/baselines/reference/destructureComputedProperty.js @@ -13,7 +13,7 @@ const { p: p3 } = new C(); //// [destructureComputedProperty.js] var nameN = "n"; -var _a = nameN, n = ab[_a]; +var _a = ab, _b = nameN, n = _a[_b]; var C = /** @class */ (function () { function C() { } @@ -22,5 +22,5 @@ var C = /** @class */ (function () { var nameP = "p"; var p0 = new C()["p"]; var p1 = new C()["p"]; -var _b = nameP, p2 = new C()[_b]; +var _c = new C(), _d = nameP, p2 = _c[_d]; var p3 = new C().p; diff --git a/tests/baselines/reference/destructuredMaappedTypeIsNotImplicitlyAny.js b/tests/baselines/reference/destructuredMaappedTypeIsNotImplicitlyAny.js index 3fe1f2febcc..b4f784eadb8 100644 --- a/tests/baselines/reference/destructuredMaappedTypeIsNotImplicitlyAny.js +++ b/tests/baselines/reference/destructuredMaappedTypeIsNotImplicitlyAny.js @@ -9,7 +9,7 @@ function foo(key: T, obj: { [_ in T]: number }) { //// [destructuredMaappedTypeIsNotImplicitlyAny.js] function foo(key, obj) { - var _a = key, bar = obj[_a]; // Element implicitly has an 'any' type because type '{ [_ in T]: number; }' has no index signature. + var _a = obj, _b = key, bar = _a[_b]; // Element implicitly has an 'any' type because type '{ [_ in T]: number; }' has no index signature. bar; // bar : any // Note: this does work: var lorem = obj[key]; diff --git a/tests/baselines/reference/destructuringAssignment_private.js b/tests/baselines/reference/destructuringAssignment_private.js index b8f4130761b..cbf52ba202e 100644 --- a/tests/baselines/reference/destructuringAssignment_private.js +++ b/tests/baselines/reference/destructuringAssignment_private.js @@ -15,7 +15,7 @@ const nameO = "o"; //// [destructuringAssignment_private.js] -var _a, _b; +var _a, _b, _c, _d; var C = /** @class */ (function () { function C() { this.x = 0; @@ -27,6 +27,6 @@ var x; (x = [{ a: new C() }][0].a.x); (x = new C().o[0].a); var nameX = "x"; -(_a = nameX, x = [{ a: new C() }][0].a[_a]); +(_a = [{ a: new C() }], _b = nameX, x = _a[0].a[_b]); var nameO = "o"; -(_b = nameO, x = new C()[_b][0].a); +(_c = new C(), _d = nameO, x = _c[_d][0].a); diff --git a/tests/baselines/reference/destructuringControlFlow.js b/tests/baselines/reference/destructuringControlFlow.js index f3b5a8e0dd9..600cddc8bb2 100644 --- a/tests/baselines/reference/destructuringControlFlow.js +++ b/tests/baselines/reference/destructuringControlFlow.js @@ -69,11 +69,11 @@ function f3(obj) { } } function f4() { - var _a; + var _a, _b; var x; (x = 0..x); // Error (x = 0["x"]); // Error - (_a = "x" + "", x = 0[_a]); // Errpr + (_a = 0, _b = "x" + "", x = _a[_b]); // Errpr } var _a = ["foo"], key = _a[0], value = _a[1]; value.toUpperCase(); // Error diff --git a/tests/baselines/reference/genericObjectRest.js b/tests/baselines/reference/genericObjectRest.js index 33815e1bb98..0ef4859d341 100644 --- a/tests/baselines/reference/genericObjectRest.js +++ b/tests/baselines/reference/genericObjectRest.js @@ -48,16 +48,16 @@ function f1(obj) { let { a: a2, b: b2 } = obj, r2 = __rest(obj, ["a", "b"]); let { 'a': a3 } = obj, r3 = __rest(obj, ['a']); let { ['a']: a4 } = obj, r4 = __rest(obj, ['a']); - let _a = a, a5 = obj[_a], r5 = __rest(obj, [typeof _a === "symbol" ? _a : _a + ""]); + let _a = obj, _b = a, a5 = _a[_b], r5 = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]); } const sa = Symbol(); const sb = Symbol(); function f2(obj) { - let _a = sa, a1 = obj[_a], _b = sb, b1 = obj[_b], r1 = __rest(obj, [typeof _a === "symbol" ? _a : _a + "", typeof _b === "symbol" ? _b : _b + ""]); + let _a = obj, _b = sa, a1 = _a[_b], _c = sb, b1 = _a[_c], r1 = __rest(_a, [typeof _b === "symbol" ? _b : _b + "", typeof _c === "symbol" ? _c : _c + ""]); } function f3(obj, k1, k2) { - let _a = k1, a1 = obj[_a], _b = k2, a2 = obj[_b], r1 = __rest(obj, [typeof _a === "symbol" ? _a : _a + "", typeof _b === "symbol" ? _b : _b + ""]); + let _a = obj, _b = k1, a1 = _a[_b], _c = k2, a2 = _a[_c], r1 = __rest(_a, [typeof _b === "symbol" ? _b : _b + "", typeof _c === "symbol" ? _c : _c + ""]); } function f4(obj, k1, k2) { - let _a = k1, a1 = obj[_a], _b = k2, a2 = obj[_b], r1 = __rest(obj, [typeof _a === "symbol" ? _a : _a + "", typeof _b === "symbol" ? _b : _b + ""]); + let _a = obj, _b = k1, a1 = _a[_b], _c = k2, a2 = _a[_c], r1 = __rest(_a, [typeof _b === "symbol" ? _b : _b + "", typeof _c === "symbol" ? _c : _c + ""]); } diff --git a/tests/baselines/reference/lateBoundDestructuringImplicitAnyError.js b/tests/baselines/reference/lateBoundDestructuringImplicitAnyError.js index 61331a13564..0dac53806b8 100644 --- a/tests/baselines/reference/lateBoundDestructuringImplicitAnyError.js +++ b/tests/baselines/reference/lateBoundDestructuringImplicitAnyError.js @@ -30,26 +30,26 @@ void prop9; //// [lateBoundDestructuringImplicitAnyError.js] var named = "foo"; -var _a = named, prop = { prop: "foo" }[_a]; +var _a = { prop: "foo" }, _b = named, prop = _a[_b]; void prop; var numIndexed = null; var strIndexed = null; var numed = 6; var symed = Symbol(); var symed2 = Symbol(); -var _b = named, prop2 = numIndexed[_b]; +var _c = numIndexed, _d = named, prop2 = _c[_d]; void prop2; -var _c = numed, prop3 = numIndexed[_c]; +var _e = numIndexed, _f = numed, prop3 = _e[_f]; void prop3; -var _d = named, prop4 = strIndexed[_d]; +var _g = strIndexed, _h = named, prop4 = _g[_h]; void prop4; -var _e = numed, prop5 = strIndexed[_e]; +var _j = strIndexed, _k = numed, prop5 = _j[_k]; void prop5; -var _f = symed, prop6 = numIndexed[_f]; +var _l = numIndexed, _m = symed, prop6 = _l[_m]; void prop6; -var _g = symed, prop7 = strIndexed[_g]; +var _o = strIndexed, _p = symed, prop7 = _o[_p]; void prop7; -var _h = symed2, prop8 = numIndexed[_h]; +var _q = numIndexed, _r = symed2, prop8 = _q[_r]; void prop8; -var _j = symed2, prop9 = strIndexed[_j]; +var _s = strIndexed, _t = symed2, prop9 = _s[_t]; void prop9;