Skip to content

Commit 1625a6c

Browse files
committed
Merge pull request microsoft#2982 from Microsoft/fixPromiseDeclaration
Updated ES6 declarations for Promise, updated baselines
2 parents 689c09c + 0982a9e commit 1625a6c

File tree

104 files changed

+683
-555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+683
-555
lines changed

bin/lib.core.es6.d.ts

+52-18
Original file line numberDiff line numberDiff line change
@@ -1237,11 +1237,41 @@ interface SymbolConstructor {
12371237
isConcatSpreadable: symbol;
12381238

12391239
/**
1240-
* A method that returns the default iterator for an object.Called by the semantics of the
1240+
* A method that returns the default iterator for an object. Called by the semantics of the
12411241
* for-of statement.
12421242
*/
12431243
iterator: symbol;
12441244

1245+
/**
1246+
* A regular expression method that matches the regular expression against a string. Called
1247+
* by the String.prototype.match method.
1248+
*/
1249+
match: symbol;
1250+
1251+
/**
1252+
* A regular expression method that replaces matched substrings of a string. Called by the
1253+
* String.prototype.replace method.
1254+
*/
1255+
replace: symbol;
1256+
1257+
/**
1258+
* A regular expression method that returns the index within a string that matches the
1259+
* regular expression. Called by the String.prototype.search method.
1260+
*/
1261+
search: symbol;
1262+
1263+
/**
1264+
* A function valued property that is the constructor function that is used to create
1265+
* derived objects.
1266+
*/
1267+
species: symbol;
1268+
1269+
/**
1270+
* A regular expression method that splits a string at the indices that match the regular
1271+
* expression. Called by the String.prototype.split method.
1272+
*/
1273+
split: symbol;
1274+
12451275
/**
12461276
* A method that converts an object to a corresponding primitive value.Called by the ToPrimitive
12471277
* abstract operation.
@@ -4728,6 +4758,16 @@ declare module Reflect {
47284758
function setPrototypeOf(target: any, proto: any): boolean;
47294759
}
47304760

4761+
interface PromiseLike<T> {
4762+
/**
4763+
* Attaches callbacks for the resolution and/or rejection of the Promise.
4764+
* @param onfulfilled The callback to execute when the Promise is resolved.
4765+
* @param onrejected The callback to execute when the Promise is rejected.
4766+
* @returns A Promise for the completion of which ever callback is executed.
4767+
*/
4768+
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>;
4769+
}
4770+
47314771
/**
47324772
* Represents the completion of an asynchronous operation
47334773
*/
@@ -4738,14 +4778,16 @@ interface Promise<T> {
47384778
* @param onrejected The callback to execute when the Promise is rejected.
47394779
* @returns A Promise for the completion of which ever callback is executed.
47404780
*/
4741-
then<TResult>(onfulfilled?: (value: T) => TResult | Promise<TResult>, onrejected?: (reason: any) => TResult | Promise<TResult>): Promise<TResult>;
4781+
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>;
47424782

47434783
/**
47444784
* Attaches a callback for only the rejection of the Promise.
47454785
* @param onrejected The callback to execute when the Promise is rejected.
47464786
* @returns A Promise for the completion of the callback.
47474787
*/
4748-
catch(onrejected?: (reason: any) => T | Promise<T>): Promise<T>;
4788+
catch(onrejected?: (reason: any) => T | PromiseLike<T>): Promise<T>;
4789+
4790+
[Symbol.toStringTag]: string;
47494791
}
47504792

47514793
interface PromiseConstructor {
@@ -4756,37 +4798,27 @@ interface PromiseConstructor {
47564798

47574799
/**
47584800
* Creates a new Promise.
4759-
* @param init A callback used to initialize the promise. This callback is passed two arguments:
4801+
* @param executor A callback used to initialize the promise. This callback is passed two arguments:
47604802
* a resolve callback used resolve the promise with a value or the result of another promise,
47614803
* and a reject callback used to reject the promise with a provided reason or error.
47624804
*/
4763-
new <T>(init: (resolve: (value?: T | Promise<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
4764-
4765-
<T>(init: (resolve: (value?: T | Promise<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
4805+
new <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
47664806

47674807
/**
47684808
* Creates a Promise that is resolved with an array of results when all of the provided Promises
47694809
* resolve, or rejected when any Promise is rejected.
47704810
* @param values An array of Promises.
47714811
* @returns A new Promise.
47724812
*/
4773-
all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
4774-
4775-
/**
4776-
* Creates a Promise that is resolved with an array of results when all of the provided Promises
4777-
* resolve, or rejected when any Promise is rejected.
4778-
* @param values An array of values.
4779-
* @returns A new Promise.
4780-
*/
4781-
all(values: Promise<void>[]): Promise<void>;
4813+
all<T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>;
47824814

47834815
/**
47844816
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
47854817
* or rejected.
47864818
* @param values An array of Promises.
47874819
* @returns A new Promise.
47884820
*/
4789-
race<T>(values: (T | Promise<T>)[]): Promise<T>;
4821+
race<T>(values: Iterable<T | PromiseLike<T>>): Promise<T>;
47904822

47914823
/**
47924824
* Creates a new rejected promise for the provided reason.
@@ -4807,13 +4839,15 @@ interface PromiseConstructor {
48074839
* @param value A promise.
48084840
* @returns A promise whose internal state matches the provided promise.
48094841
*/
4810-
resolve<T>(value: T | Promise<T>): Promise<T>;
4842+
resolve<T>(value: T | PromiseLike<T>): Promise<T>;
48114843

48124844
/**
48134845
* Creates a new resolved promise .
48144846
* @returns A resolved promise.
48154847
*/
48164848
resolve(): Promise<void>;
4849+
4850+
[Symbol.species]: Function;
48174851
}
48184852

48194853
declare var Promise: PromiseConstructor;

bin/lib.es6.d.ts

+52-18
Original file line numberDiff line numberDiff line change
@@ -1237,11 +1237,41 @@ interface SymbolConstructor {
12371237
isConcatSpreadable: symbol;
12381238

12391239
/**
1240-
* A method that returns the default iterator for an object.Called by the semantics of the
1240+
* A method that returns the default iterator for an object. Called by the semantics of the
12411241
* for-of statement.
12421242
*/
12431243
iterator: symbol;
12441244

1245+
/**
1246+
* A regular expression method that matches the regular expression against a string. Called
1247+
* by the String.prototype.match method.
1248+
*/
1249+
match: symbol;
1250+
1251+
/**
1252+
* A regular expression method that replaces matched substrings of a string. Called by the
1253+
* String.prototype.replace method.
1254+
*/
1255+
replace: symbol;
1256+
1257+
/**
1258+
* A regular expression method that returns the index within a string that matches the
1259+
* regular expression. Called by the String.prototype.search method.
1260+
*/
1261+
search: symbol;
1262+
1263+
/**
1264+
* A function valued property that is the constructor function that is used to create
1265+
* derived objects.
1266+
*/
1267+
species: symbol;
1268+
1269+
/**
1270+
* A regular expression method that splits a string at the indices that match the regular
1271+
* expression. Called by the String.prototype.split method.
1272+
*/
1273+
split: symbol;
1274+
12451275
/**
12461276
* A method that converts an object to a corresponding primitive value.Called by the ToPrimitive
12471277
* abstract operation.
@@ -4728,6 +4758,16 @@ declare module Reflect {
47284758
function setPrototypeOf(target: any, proto: any): boolean;
47294759
}
47304760

4761+
interface PromiseLike<T> {
4762+
/**
4763+
* Attaches callbacks for the resolution and/or rejection of the Promise.
4764+
* @param onfulfilled The callback to execute when the Promise is resolved.
4765+
* @param onrejected The callback to execute when the Promise is rejected.
4766+
* @returns A Promise for the completion of which ever callback is executed.
4767+
*/
4768+
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>;
4769+
}
4770+
47314771
/**
47324772
* Represents the completion of an asynchronous operation
47334773
*/
@@ -4738,14 +4778,16 @@ interface Promise<T> {
47384778
* @param onrejected The callback to execute when the Promise is rejected.
47394779
* @returns A Promise for the completion of which ever callback is executed.
47404780
*/
4741-
then<TResult>(onfulfilled?: (value: T) => TResult | Promise<TResult>, onrejected?: (reason: any) => TResult | Promise<TResult>): Promise<TResult>;
4781+
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>;
47424782

47434783
/**
47444784
* Attaches a callback for only the rejection of the Promise.
47454785
* @param onrejected The callback to execute when the Promise is rejected.
47464786
* @returns A Promise for the completion of the callback.
47474787
*/
4748-
catch(onrejected?: (reason: any) => T | Promise<T>): Promise<T>;
4788+
catch(onrejected?: (reason: any) => T | PromiseLike<T>): Promise<T>;
4789+
4790+
[Symbol.toStringTag]: string;
47494791
}
47504792

47514793
interface PromiseConstructor {
@@ -4756,37 +4798,27 @@ interface PromiseConstructor {
47564798

47574799
/**
47584800
* Creates a new Promise.
4759-
* @param init A callback used to initialize the promise. This callback is passed two arguments:
4801+
* @param executor A callback used to initialize the promise. This callback is passed two arguments:
47604802
* a resolve callback used resolve the promise with a value or the result of another promise,
47614803
* and a reject callback used to reject the promise with a provided reason or error.
47624804
*/
4763-
new <T>(init: (resolve: (value?: T | Promise<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
4764-
4765-
<T>(init: (resolve: (value?: T | Promise<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
4805+
new <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
47664806

47674807
/**
47684808
* Creates a Promise that is resolved with an array of results when all of the provided Promises
47694809
* resolve, or rejected when any Promise is rejected.
47704810
* @param values An array of Promises.
47714811
* @returns A new Promise.
47724812
*/
4773-
all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
4774-
4775-
/**
4776-
* Creates a Promise that is resolved with an array of results when all of the provided Promises
4777-
* resolve, or rejected when any Promise is rejected.
4778-
* @param values An array of values.
4779-
* @returns A new Promise.
4780-
*/
4781-
all(values: Promise<void>[]): Promise<void>;
4813+
all<T>(values: Iterable<T | PromiseLike<T>>): Promise<T[]>;
47824814

47834815
/**
47844816
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
47854817
* or rejected.
47864818
* @param values An array of Promises.
47874819
* @returns A new Promise.
47884820
*/
4789-
race<T>(values: (T | Promise<T>)[]): Promise<T>;
4821+
race<T>(values: Iterable<T | PromiseLike<T>>): Promise<T>;
47904822

47914823
/**
47924824
* Creates a new rejected promise for the provided reason.
@@ -4807,13 +4839,15 @@ interface PromiseConstructor {
48074839
* @param value A promise.
48084840
* @returns A promise whose internal state matches the provided promise.
48094841
*/
4810-
resolve<T>(value: T | Promise<T>): Promise<T>;
4842+
resolve<T>(value: T | PromiseLike<T>): Promise<T>;
48114843

48124844
/**
48134845
* Creates a new resolved promise .
48144846
* @returns A resolved promise.
48154847
*/
48164848
resolve(): Promise<void>;
4849+
4850+
[Symbol.species]: Function;
48174851
}
48184852

48194853
declare var Promise: PromiseConstructor;

bin/tsc.js

+23-17
Original file line numberDiff line numberDiff line change
@@ -20229,10 +20229,10 @@ var ts;
2022920229
}
2023020230
ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile;
2023120231
function emitFiles(resolver, host, targetSourceFile) {
20232-
var extendsHelper = "\nvar __extends = this.__extends || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n __.prototype = b.prototype;\n d.prototype = new __();\n};";
20233-
var decorateHelper = "\nif (typeof __decorate !== \"function\") __decorate = function (decorators, target, key, desc) {\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") return Reflect.decorate(decorators, target, key, desc);\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};";
20234-
var metadataHelper = "\nif (typeof __metadata !== \"function\") __metadata = function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};";
20235-
var paramHelper = "\nif (typeof __param !== \"function\") __param = function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};";
20232+
var extendsHelper = "\nvar __extends = (this && this.__extends) || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n __.prototype = b.prototype;\n d.prototype = new __();\n};";
20233+
var decorateHelper = "\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") return Reflect.decorate(decorators, target, key, desc);\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};";
20234+
var metadataHelper = "\nvar __metadata = (this && this.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};";
20235+
var paramHelper = "\nvar __param = (this && this.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};";
2023620236
var compilerOptions = host.getCompilerOptions();
2023720237
var languageVersion = compilerOptions.target || 0;
2023820238
var sourceMapDataList = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined;
@@ -24590,20 +24590,22 @@ var ts;
2459024590
writeLine();
2459124591
emitDetachedComments(node);
2459224592
var startIndex = emitDirectivePrologues(node.statements, false);
24593-
if ((languageVersion < 2) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8)) {
24594-
writeLines(extendsHelper);
24595-
extendsEmitted = true;
24596-
}
24597-
if (!decorateEmitted && resolver.getNodeCheckFlags(node) & 512) {
24598-
writeLines(decorateHelper);
24599-
if (compilerOptions.emitDecoratorMetadata) {
24600-
writeLines(metadataHelper);
24593+
if (!compilerOptions.noEmitHelpers) {
24594+
if ((languageVersion < 2) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & 8)) {
24595+
writeLines(extendsHelper);
24596+
extendsEmitted = true;
24597+
}
24598+
if (!decorateEmitted && resolver.getNodeCheckFlags(node) & 512) {
24599+
writeLines(decorateHelper);
24600+
if (compilerOptions.emitDecoratorMetadata) {
24601+
writeLines(metadataHelper);
24602+
}
24603+
decorateEmitted = true;
24604+
}
24605+
if (!paramEmitted && resolver.getNodeCheckFlags(node) & 1024) {
24606+
writeLines(paramHelper);
24607+
paramEmitted = true;
2460124608
}
24602-
decorateEmitted = true;
24603-
}
24604-
if (!paramEmitted && resolver.getNodeCheckFlags(node) & 1024) {
24605-
writeLines(paramHelper);
24606-
paramEmitted = true;
2460724609
}
2460824610
if (ts.isExternalModule(node) || compilerOptions.separateCompilation) {
2460924611
if (languageVersion >= 2) {
@@ -25529,6 +25531,10 @@ var ts;
2552925531
type: "boolean",
2553025532
description: ts.Diagnostics.Do_not_emit_outputs
2553125533
},
25534+
{
25535+
name: "noEmitHelpers",
25536+
type: "boolean"
25537+
},
2553225538
{
2553325539
name: "noEmitOnError",
2553425540
type: "boolean",

0 commit comments

Comments
 (0)