Skip to content

fix(40929) PromiseConstructor error message for newer versions of ECMAScript #40931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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"]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>'. 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<unknown>'. 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.

Expand Down Expand Up @@ -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<unknown>'. 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.
Expand All @@ -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<unknown>'. 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Original file line number Diff line number Diff line change
Expand Up @@ -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, --, --))

Expand All @@ -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, --, --))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>
>Promise.allSettled([]) : any
>Promise.allSettled : any
>Promise : PromiseConstructor
>() => {} : () => void
>allSettled : any
>[] : undefined[]

const testStringMatchAll = "".matchAll();
>testStringMatchAll : any
Expand All @@ -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<unknown>
>Promise.any([]) : any
>Promise.any : any
>Promise : PromiseConstructor
>() => {} : () => void
>any : any
>[] : undefined[]

const testStringReplaceAll = "".replaceAll();
>testStringReplaceAll : any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();