Skip to content

Commit c5a81ed

Browse files
committed
Fix #8423: Remove undefined while getting the type of the first argument of then signature
1 parent f28d535 commit c5a81ed

File tree

5 files changed

+257
-1
lines changed

5 files changed

+257
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13443,7 +13443,7 @@ namespace ts {
1344313443
}
1344413444

1344513445
function getTypeOfFirstParameterOfSignature(signature: Signature) {
13446-
return getTypeAtPosition(signature, 0);
13446+
return getTypeWithFacts(getTypeAtPosition(signature, 0), TypeFacts.NEUndefined);
1344713447
}
1344813448

1344913449
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
//// [asyncFunctionsAndStrictNullChecks.js]
21+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22+
return new (P || (P = Promise))(function (resolve, reject) {
23+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
24+
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
25+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
26+
step((generator = generator.apply(thisArg, _arguments)).next());
27+
});
28+
};
29+
function sample(promise) {
30+
return __awaiter(this, void 0, void 0, function* () {
31+
var number = yield promise;
32+
});
33+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
=== tests/cases/compiler/asyncFunctionsAndStrictNullChecks.ts ===
2+
3+
declare namespace Windows.Foundation {
4+
>Windows : any
5+
>Foundation : any
6+
7+
interface IPromise<TResult> {
8+
>IPromise : IPromise<TResult>
9+
>TResult : TResult
10+
11+
then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
12+
>then : { <U>(success?: ((value: TResult) => IPromise<U>) | undefined, error?: ((error: any) => IPromise<U>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U>(success?: ((value: TResult) => IPromise<U>) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U>(success?: ((value: TResult) => U) | undefined, error?: ((error: any) => IPromise<U>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U>(success?: ((value: TResult) => U) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; }
13+
>U : U
14+
>success : ((value: TResult) => IPromise<U>) | undefined
15+
>value : TResult
16+
>TResult : TResult
17+
>IPromise : IPromise<TResult>
18+
>U : U
19+
>error : ((error: any) => IPromise<U>) | undefined
20+
>error : any
21+
>IPromise : IPromise<TResult>
22+
>U : U
23+
>progress : ((progress: any) => void) | undefined
24+
>progress : any
25+
>IPromise : IPromise<TResult>
26+
>U : U
27+
28+
then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
29+
>then : { <U>(success?: ((value: TResult) => IPromise<U>) | undefined, error?: ((error: any) => IPromise<U>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U>(success?: ((value: TResult) => IPromise<U>) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U>(success?: ((value: TResult) => U) | undefined, error?: ((error: any) => IPromise<U>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U>(success?: ((value: TResult) => U) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; }
30+
>U : U
31+
>success : ((value: TResult) => IPromise<U>) | undefined
32+
>value : TResult
33+
>TResult : TResult
34+
>IPromise : IPromise<TResult>
35+
>U : U
36+
>error : ((error: any) => U) | undefined
37+
>error : any
38+
>U : U
39+
>progress : ((progress: any) => void) | undefined
40+
>progress : any
41+
>IPromise : IPromise<TResult>
42+
>U : U
43+
44+
then<U>(success?: (value: TResult) => U, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
45+
>then : { <U>(success?: ((value: TResult) => IPromise<U>) | undefined, error?: ((error: any) => IPromise<U>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U>(success?: ((value: TResult) => IPromise<U>) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U>(success?: ((value: TResult) => U) | undefined, error?: ((error: any) => IPromise<U>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U>(success?: ((value: TResult) => U) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; }
46+
>U : U
47+
>success : ((value: TResult) => U) | undefined
48+
>value : TResult
49+
>TResult : TResult
50+
>U : U
51+
>error : ((error: any) => IPromise<U>) | undefined
52+
>error : any
53+
>IPromise : IPromise<TResult>
54+
>U : U
55+
>progress : ((progress: any) => void) | undefined
56+
>progress : any
57+
>IPromise : IPromise<TResult>
58+
>U : U
59+
60+
then<U>(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
61+
>then : { <U>(success?: ((value: TResult) => IPromise<U>) | undefined, error?: ((error: any) => IPromise<U>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U>(success?: ((value: TResult) => IPromise<U>) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U>(success?: ((value: TResult) => U) | undefined, error?: ((error: any) => IPromise<U>) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; <U>(success?: ((value: TResult) => U) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise<U>; }
62+
>U : U
63+
>success : ((value: TResult) => U) | undefined
64+
>value : TResult
65+
>TResult : TResult
66+
>U : U
67+
>error : ((error: any) => U) | undefined
68+
>error : any
69+
>U : U
70+
>progress : ((progress: any) => void) | undefined
71+
>progress : any
72+
>IPromise : IPromise<TResult>
73+
>U : U
74+
75+
done<U>(success?: (value: TResult) => any, error?: (error: any) => any, progress?: (progress: any) => void): void;
76+
>done : <U>(success?: ((value: TResult) => any) | undefined, error?: ((error: any) => any) | undefined, progress?: ((progress: any) => void) | undefined) => void
77+
>U : U
78+
>success : ((value: TResult) => any) | undefined
79+
>value : TResult
80+
>TResult : TResult
81+
>error : ((error: any) => any) | undefined
82+
>error : any
83+
>progress : ((progress: any) => void) | undefined
84+
>progress : any
85+
86+
cancel(): void;
87+
>cancel : () => void
88+
}
89+
}
90+
91+
async function sample(promise: Windows.Foundation.IPromise<number>) {
92+
>sample : (promise: Windows.Foundation.IPromise<number>) => Promise<void>
93+
>promise : Windows.Foundation.IPromise<number>
94+
>Windows : any
95+
>Foundation : any
96+
>IPromise : Windows.Foundation.IPromise<TResult>
97+
98+
var number = await promise;
99+
>number : number
100+
>await promise : number
101+
>promise : Windows.Foundation.IPromise<number>
102+
}
103+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @target: es6
2+
// @strictNullChecks: true
3+
4+
declare namespace Windows.Foundation {
5+
interface IPromise<TResult> {
6+
then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
7+
then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
8+
then<U>(success?: (value: TResult) => U, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
9+
then<U>(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
10+
done<U>(success?: (value: TResult) => any, error?: (error: any) => any, progress?: (progress: any) => void): void;
11+
12+
cancel(): void;
13+
}
14+
}
15+
16+
async function sample(promise: Windows.Foundation.IPromise<number>) {
17+
var number = await promise;
18+
}

0 commit comments

Comments
 (0)