Skip to content

Commit 24aabec

Browse files
committed
Merge pull request #8449 from Microsoft/Fix8423
Fix #8423: Remove undefined while getting the type of the first argument of then signature
2 parents cb9be66 + 9ff66fb commit 24aabec

6 files changed

+362
-6
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13434,7 +13434,7 @@ namespace ts {
1343413434
return undefined;
1343513435
}
1343613436

13437-
const onfulfilledParameterType = getUnionType(map(thenSignatures, getTypeOfFirstParameterOfSignature));
13437+
const onfulfilledParameterType = getTypeWithFacts(getUnionType(map(thenSignatures, getTypeOfFirstParameterOfSignature)), TypeFacts.NEUndefined);
1343813438
if (onfulfilledParameterType.flags & TypeFlags.Any) {
1343913439
return undefined;
1344013440
}

src/compiler/commandLineParser.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ namespace ts {
143143
name: "out",
144144
type: "string",
145145
isFilePath: false, // This is intentionally broken to support compatability with existing tsconfig files
146-
// for correct behaviour, please use outFile
146+
// for correct behaviour, please use outFile
147147
paramType: Diagnostics.FILE,
148148
},
149149
{
@@ -464,7 +464,7 @@ namespace ts {
464464

465465
/* @internal */
466466
export function parseCustomTypeOption(opt: CommandLineOptionOfCustomType, value: string, errors: Diagnostic[]) {
467-
const key = (value || "").trim().toLowerCase();
467+
const key = trimString((value || "")).toLowerCase();
468468
const map = opt.type;
469469
if (hasProperty(map, key)) {
470470
return map[key];
@@ -476,7 +476,7 @@ namespace ts {
476476

477477
/* @internal */
478478
export function parseListTypeOption(opt: CommandLineOptionOfListType, value: string, errors: Diagnostic[]): (string | number)[] {
479-
const values = (value || "").trim().split(",");
479+
const values = trimString((value || "")).split(",");
480480
switch (opt.element.type) {
481481
case "number":
482482
return ts.map(values, parseInt);
@@ -601,7 +601,7 @@ namespace ts {
601601
* Read tsconfig.json file
602602
* @param fileName The path to the config file
603603
*/
604-
export function readConfigFile(fileName: string, readFile: (path: string) => string): { config?: any; error?: Diagnostic } {
604+
export function readConfigFile(fileName: string, readFile: (path: string) => string): { config?: any; error?: Diagnostic } {
605605
let text = "";
606606
try {
607607
text = readFile(fileName);
@@ -775,7 +775,7 @@ namespace ts {
775775
defaultOptions: CompilerOptions | TypingOptions, diagnosticMessage: DiagnosticMessage, errors: Diagnostic[]) {
776776

777777
if (!jsonOptions) {
778-
return ;
778+
return;
779779
}
780780

781781
const optionNameMap = arrayToMap(optionDeclarations, opt => opt.name);
@@ -829,4 +829,8 @@ namespace ts {
829829
function convertJsonOptionOfListType(option: CommandLineOptionOfListType, values: any[], basePath: string, errors: Diagnostic[]): any[] {
830830
return filter(map(values, v => convertJsonOption(option.element, v, basePath, errors)), v => !!v);
831831
}
832+
833+
function trimString(s: string) {
834+
return typeof s.trim === "function" ? s.trim() : s.replace(/^[\s]+|[\s]+$/g, "");
835+
}
832836
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//// [asyncFunctionsAndStrictNullChecks.ts]
2+
3+
declare namespace Windows.Foundation {
4+
interface IPromise<TResult> {
5+
then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
6+
then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
7+
then<U>(success?: (value: TResult) => U, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
8+
then<U>(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
9+
done<U>(success?: (value: TResult) => any, error?: (error: any) => any, progress?: (progress: any) => void): void;
10+
11+
cancel(): void;
12+
}
13+
}
14+
15+
async function sample(promise: Windows.Foundation.IPromise<number>) {
16+
var number = await promise;
17+
}
18+
19+
20+
declare function resolve1<T>(value: T): Promise<T>;
21+
declare function resolve2<T>(value: T): Windows.Foundation.IPromise<T>;
22+
23+
async function sample2(x?: number) {
24+
let x1 = await resolve1(x);
25+
let x2 = await resolve2(x);
26+
}
27+
28+
29+
//// [asyncFunctionsAndStrictNullChecks.js]
30+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
31+
return new (P || (P = Promise))(function (resolve, reject) {
32+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
33+
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
34+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
35+
step((generator = generator.apply(thisArg, _arguments)).next());
36+
});
37+
};
38+
function sample(promise) {
39+
return __awaiter(this, void 0, void 0, function* () {
40+
var number = yield promise;
41+
});
42+
}
43+
function sample2(x) {
44+
return __awaiter(this, void 0, void 0, function* () {
45+
let x1 = yield resolve1(x);
46+
let x2 = yield resolve2(x);
47+
});
48+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
=== tests/cases/compiler/asyncFunctionsAndStrictNullChecks.ts ===
2+
3+
declare namespace Windows.Foundation {
4+
>Windows : Symbol(Windows, Decl(asyncFunctionsAndStrictNullChecks.ts, 0, 0))
5+
>Foundation : Symbol(Foundation, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 26))
6+
7+
interface IPromise<TResult> {
8+
>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38))
9+
>TResult : Symbol(TResult, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 23))
10+
11+
then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
12+
>then : Symbol(IPromise.then, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 33), Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 145), Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 135), Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 135))
13+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 13))
14+
>success : Symbol(success, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 16))
15+
>value : Symbol(value, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 27))
16+
>TResult : Symbol(TResult, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 23))
17+
>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38))
18+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 13))
19+
>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 58))
20+
>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 68))
21+
>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38))
22+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 13))
23+
>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 95))
24+
>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 108))
25+
>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38))
26+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 13))
27+
28+
then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
29+
>then : Symbol(IPromise.then, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 33), Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 145), Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 135), Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 135))
30+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 13))
31+
>success : Symbol(success, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 16))
32+
>value : Symbol(value, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 27))
33+
>TResult : Symbol(TResult, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 23))
34+
>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38))
35+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 13))
36+
>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 58))
37+
>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 68))
38+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 13))
39+
>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 85))
40+
>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 98))
41+
>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38))
42+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 13))
43+
44+
then<U>(success?: (value: TResult) => U, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
45+
>then : Symbol(IPromise.then, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 33), Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 145), Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 135), Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 135))
46+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 13))
47+
>success : Symbol(success, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 16))
48+
>value : Symbol(value, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 27))
49+
>TResult : Symbol(TResult, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 23))
50+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 13))
51+
>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 48))
52+
>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 58))
53+
>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38))
54+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 13))
55+
>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 85))
56+
>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 98))
57+
>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38))
58+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 13))
59+
60+
then<U>(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
61+
>then : Symbol(IPromise.then, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 33), Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 145), Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 135), Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 135))
62+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 13))
63+
>success : Symbol(success, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 16))
64+
>value : Symbol(value, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 27))
65+
>TResult : Symbol(TResult, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 23))
66+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 13))
67+
>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 48))
68+
>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 58))
69+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 13))
70+
>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 75))
71+
>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 88))
72+
>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38))
73+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 13))
74+
75+
done<U>(success?: (value: TResult) => any, error?: (error: any) => any, progress?: (progress: any) => void): void;
76+
>done : Symbol(IPromise.done, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 125))
77+
>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 13))
78+
>success : Symbol(success, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 16))
79+
>value : Symbol(value, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 27))
80+
>TResult : Symbol(TResult, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 23))
81+
>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 50))
82+
>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 60))
83+
>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 79))
84+
>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 92))
85+
86+
cancel(): void;
87+
>cancel : Symbol(IPromise.cancel, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 122))
88+
}
89+
}
90+
91+
async function sample(promise: Windows.Foundation.IPromise<number>) {
92+
>sample : Symbol(sample, Decl(asyncFunctionsAndStrictNullChecks.ts, 11, 1))
93+
>promise : Symbol(promise, Decl(asyncFunctionsAndStrictNullChecks.ts, 13, 22))
94+
>Windows : Symbol(Windows, Decl(asyncFunctionsAndStrictNullChecks.ts, 0, 0))
95+
>Foundation : Symbol(Windows.Foundation, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 26))
96+
>IPromise : Symbol(Windows.Foundation.IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38))
97+
98+
var number = await promise;
99+
>number : Symbol(number, Decl(asyncFunctionsAndStrictNullChecks.ts, 14, 7))
100+
>promise : Symbol(promise, Decl(asyncFunctionsAndStrictNullChecks.ts, 13, 22))
101+
}
102+
103+
104+
declare function resolve1<T>(value: T): Promise<T>;
105+
>resolve1 : Symbol(resolve1, Decl(asyncFunctionsAndStrictNullChecks.ts, 15, 1))
106+
>T : Symbol(T, Decl(asyncFunctionsAndStrictNullChecks.ts, 18, 26))
107+
>value : Symbol(value, Decl(asyncFunctionsAndStrictNullChecks.ts, 18, 29))
108+
>T : Symbol(T, Decl(asyncFunctionsAndStrictNullChecks.ts, 18, 26))
109+
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
110+
>T : Symbol(T, Decl(asyncFunctionsAndStrictNullChecks.ts, 18, 26))
111+
112+
declare function resolve2<T>(value: T): Windows.Foundation.IPromise<T>;
113+
>resolve2 : Symbol(resolve2, Decl(asyncFunctionsAndStrictNullChecks.ts, 18, 51))
114+
>T : Symbol(T, Decl(asyncFunctionsAndStrictNullChecks.ts, 19, 26))
115+
>value : Symbol(value, Decl(asyncFunctionsAndStrictNullChecks.ts, 19, 29))
116+
>T : Symbol(T, Decl(asyncFunctionsAndStrictNullChecks.ts, 19, 26))
117+
>Windows : Symbol(Windows, Decl(asyncFunctionsAndStrictNullChecks.ts, 0, 0))
118+
>Foundation : Symbol(Windows.Foundation, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 26))
119+
>IPromise : Symbol(Windows.Foundation.IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38))
120+
>T : Symbol(T, Decl(asyncFunctionsAndStrictNullChecks.ts, 19, 26))
121+
122+
async function sample2(x?: number) {
123+
>sample2 : Symbol(sample2, Decl(asyncFunctionsAndStrictNullChecks.ts, 19, 71))
124+
>x : Symbol(x, Decl(asyncFunctionsAndStrictNullChecks.ts, 21, 23))
125+
126+
let x1 = await resolve1(x);
127+
>x1 : Symbol(x1, Decl(asyncFunctionsAndStrictNullChecks.ts, 22, 7))
128+
>resolve1 : Symbol(resolve1, Decl(asyncFunctionsAndStrictNullChecks.ts, 15, 1))
129+
>x : Symbol(x, Decl(asyncFunctionsAndStrictNullChecks.ts, 21, 23))
130+
131+
let x2 = await resolve2(x);
132+
>x2 : Symbol(x2, Decl(asyncFunctionsAndStrictNullChecks.ts, 23, 7))
133+
>resolve2 : Symbol(resolve2, Decl(asyncFunctionsAndStrictNullChecks.ts, 18, 51))
134+
>x : Symbol(x, Decl(asyncFunctionsAndStrictNullChecks.ts, 21, 23))
135+
}
136+

0 commit comments

Comments
 (0)