From 57661607e9ba28abb7d2284f88858c8f1f972d83 Mon Sep 17 00:00:00 2001 From: Vincent Boivin Date: Mon, 5 Oct 2020 19:38:12 -0400 Subject: [PATCH] fix(40929) PromiseConstructor error message for newer versions of ECMAScript (#40931) * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Fixes #40929 Co-authored-by: TypeScript Bot --- src/compiler/utilities.ts | 7 ++++--- ...hangeYourTargetLibraryES2016Plus.errors.txt | 16 ++++++++-------- ...uNeedToChangeYourTargetLibraryES2016Plus.js | 8 ++++---- ...ToChangeYourTargetLibraryES2016Plus.symbols | 4 ++-- ...edToChangeYourTargetLibraryES2016Plus.types | 18 ++++++++---------- ...uNeedToChangeYourTargetLibraryES2016Plus.ts | 4 ++-- 6 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index e56356afbce..ec0b768a1ad 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -556,7 +556,8 @@ namespace ts { Math: ["clz32", "imul", "sign", "log10", "log2", "log1p", "expm1", "cosh", "sinh", "tanh", "acosh", "asinh", "atanh", "hypot", "trunc", "fround", "cbrt"], Map: ["entries", "keys", "values"], Set: ["entries", "keys", "values"], - Promise: ["all", "race", "reject", "resolve"], + Promise: emptyArray, + PromiseConstructor: ["all", "race", "reject", "resolve"], Symbol: ["for", "keyFor"], WeakMap: ["entries", "keys", "values"], WeakSet: ["entries", "keys", "values"], @@ -596,14 +597,14 @@ namespace ts { BigInt: emptyArray, BigInt64Array: emptyArray, BigUint64Array: emptyArray, - Promise: ["allSettled"], + PromiseConstructor: ["allSettled"], SymbolConstructor: ["matchAll"], String: ["matchAll"], DataView: ["setBigInt64", "setBigUint64", "getBigInt64", "getBigUint64"], RelativeTimeFormat: ["format", "formatToParts", "resolvedOptions"] }, esnext: { - Promise: ["any"], + PromiseConstructor: ["any"], String: ["replaceAll"], NumberFormat: ["formatToParts"] } diff --git a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.errors.txt b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.errors.txt index 24388413b3c..404b95152c7 100644 --- a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.errors.txt +++ b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.errors.txt @@ -24,11 +24,11 @@ tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(30,30): err tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(31,31): error TS2550: Property 'trimLeft' does not exist on type '""'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2019' or later. tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(32,32): error TS2550: Property 'trimRight' does not exist on type '""'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2019' or later. tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(33,45): error TS2550: Property 'description' does not exist on type 'symbol'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2019' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(36,53): error TS2550: Property 'allSettled' does not exist on type 'Promise'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2020' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(36,39): error TS2550: Property 'allSettled' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2020' or later. tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(37,31): error TS2550: Property 'matchAll' does not exist on type '""'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2020' or later. tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(38,47): error TS2550: Property 'matchAll' does not exist on type 'SymbolConstructor'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2020' or later. tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(39,20): error TS2583: Cannot find name 'BigInt'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2020' or later. -tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(42,46): error TS2550: Property 'any' does not exist on type 'Promise'. Do you need to change your target library? Try changing the `lib` compiler option to 'esnext' or later. +tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(42,32): error TS2550: Property 'any' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the `lib` compiler option to 'esnext' or later. tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(43,33): error TS2550: Property 'replaceAll' does not exist on type '""'. Do you need to change your target library? Try changing the `lib` compiler option to 'esnext' or later. tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(44,70): error TS2550: Property 'formatToParts' does not exist on type 'NumberFormat'. Do you need to change your target library? Try changing the `lib` compiler option to 'esnext' or later. @@ -122,9 +122,9 @@ tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(44,70): err !!! error TS2550: Property 'description' does not exist on type 'symbol'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2019' or later. // es2020 - const testPromiseAllSettled = new Promise(() => {}).allSettled(); - ~~~~~~~~~~ -!!! error TS2550: Property 'allSettled' does not exist on type 'Promise'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2020' or later. + const testPromiseAllSettled = Promise.allSettled([]); + ~~~~~~~~~~ +!!! error TS2550: Property 'allSettled' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2020' or later. const testStringMatchAll = "".matchAll(); ~~~~~~~~ !!! error TS2550: Property 'matchAll' does not exist on type '""'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2020' or later. @@ -136,9 +136,9 @@ tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts(44,70): err !!! error TS2583: Cannot find name 'BigInt'. Do you need to change your target library? Try changing the `lib` compiler option to 'es2020' or later. // esnext - const testPromiseAny = new Promise(() => {}).any(); - ~~~ -!!! error TS2550: Property 'any' does not exist on type 'Promise'. Do you need to change your target library? Try changing the `lib` compiler option to 'esnext' or later. + const testPromiseAny = Promise.any([]); + ~~~ +!!! error TS2550: Property 'any' does not exist on type 'PromiseConstructor'. Do you need to change your target library? Try changing the `lib` compiler option to 'esnext' or later. const testStringReplaceAll = "".replaceAll(); ~~~~~~~~~~ !!! error TS2550: Property 'replaceAll' does not exist on type '""'. Do you need to change your target library? Try changing the `lib` compiler option to 'esnext' or later. diff --git a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.js b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.js index 9dd50e73b6a..3acfb2e08f4 100644 --- a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.js +++ b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.js @@ -34,13 +34,13 @@ const testStringTrimRight = "".trimRight(); const testSymbolDescription = Symbol("foo").description; // es2020 -const testPromiseAllSettled = new Promise(() => {}).allSettled(); +const testPromiseAllSettled = Promise.allSettled([]); const testStringMatchAll = "".matchAll(); const testRegExpMatchAll = /matchAll/g[Symbol.matchAll]("matchAll"); const testBigInt = BigInt(123); // esnext -const testPromiseAny = new Promise(() => {}).any(); +const testPromiseAny = Promise.any([]); const testStringReplaceAll = "".replaceAll(); const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); @@ -76,11 +76,11 @@ var testStringTrimLeft = "".trimLeft(); var testStringTrimRight = "".trimRight(); var testSymbolDescription = Symbol("foo").description; // es2020 -var testPromiseAllSettled = new Promise(function () { }).allSettled(); +var testPromiseAllSettled = Promise.allSettled([]); var testStringMatchAll = "".matchAll(); var testRegExpMatchAll = /matchAll/g[Symbol.matchAll]("matchAll"); var testBigInt = BigInt(123); // esnext -var testPromiseAny = new Promise(function () { }).any(); +var testPromiseAny = Promise.any([]); var testStringReplaceAll = "".replaceAll(); var testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); diff --git a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.symbols b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.symbols index 3ebf4065550..228d943e224 100644 --- a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.symbols +++ b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.symbols @@ -97,7 +97,7 @@ const testSymbolDescription = Symbol("foo").description; >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) // es2020 -const testPromiseAllSettled = new Promise(() => {}).allSettled(); +const testPromiseAllSettled = Promise.allSettled([]); >testPromiseAllSettled : Symbol(testPromiseAllSettled, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 35, 5)) >Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) @@ -112,7 +112,7 @@ const testBigInt = BigInt(123); >testBigInt : Symbol(testBigInt, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 38, 5)) // esnext -const testPromiseAny = new Promise(() => {}).any(); +const testPromiseAny = Promise.any([]); >testPromiseAny : Symbol(testPromiseAny, Decl(doYouNeedToChangeYourTargetLibraryES2016Plus.ts, 41, 5)) >Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) diff --git a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.types b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.types index 6248a1e6b09..fb0578caf23 100644 --- a/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.types +++ b/tests/baselines/reference/doYouNeedToChangeYourTargetLibraryES2016Plus.types @@ -207,14 +207,13 @@ const testSymbolDescription = Symbol("foo").description; >description : any // es2020 -const testPromiseAllSettled = new Promise(() => {}).allSettled(); +const testPromiseAllSettled = Promise.allSettled([]); >testPromiseAllSettled : any ->new Promise(() => {}).allSettled() : any ->new Promise(() => {}).allSettled : any ->new Promise(() => {}) : Promise +>Promise.allSettled([]) : any +>Promise.allSettled : any >Promise : PromiseConstructor ->() => {} : () => void >allSettled : any +>[] : undefined[] const testStringMatchAll = "".matchAll(); >testStringMatchAll : any @@ -240,14 +239,13 @@ const testBigInt = BigInt(123); >123 : 123 // esnext -const testPromiseAny = new Promise(() => {}).any(); +const testPromiseAny = Promise.any([]); >testPromiseAny : any ->new Promise(() => {}).any() : any ->new Promise(() => {}).any : any ->new Promise(() => {}) : Promise +>Promise.any([]) : any +>Promise.any : any >Promise : PromiseConstructor ->() => {} : () => void >any : any +>[] : undefined[] const testStringReplaceAll = "".replaceAll(); >testStringReplaceAll : any diff --git a/tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts b/tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts index 901d53c021a..897c4e8e5dc 100644 --- a/tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts +++ b/tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2016Plus.ts @@ -35,12 +35,12 @@ const testStringTrimRight = "".trimRight(); const testSymbolDescription = Symbol("foo").description; // es2020 -const testPromiseAllSettled = new Promise(() => {}).allSettled(); +const testPromiseAllSettled = Promise.allSettled([]); const testStringMatchAll = "".matchAll(); const testRegExpMatchAll = /matchAll/g[Symbol.matchAll]("matchAll"); const testBigInt = BigInt(123); // esnext -const testPromiseAny = new Promise(() => {}).any(); +const testPromiseAny = Promise.any([]); const testStringReplaceAll = "".replaceAll(); const testNumberFormatFormatToParts = new Intl.NumberFormat("en-US").formatToParts(); \ No newline at end of file