From c5a81edfb1515c694ffd1fcc2639c288d5f71695 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 3 May 2016 14:51:30 -0700 Subject: [PATCH] Fix #8423: Remove undefined while getting the type of the first argument of then signature --- src/compiler/checker.ts | 2 +- .../asyncFunctionsAndStrictNullChecks.js | 33 ++++++ .../asyncFunctionsAndStrictNullChecks.symbols | 102 +++++++++++++++++ .../asyncFunctionsAndStrictNullChecks.types | 103 ++++++++++++++++++ .../asyncFunctionsAndStrictNullChecks.ts | 18 +++ 5 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/asyncFunctionsAndStrictNullChecks.js create mode 100644 tests/baselines/reference/asyncFunctionsAndStrictNullChecks.symbols create mode 100644 tests/baselines/reference/asyncFunctionsAndStrictNullChecks.types create mode 100644 tests/cases/compiler/asyncFunctionsAndStrictNullChecks.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bf0ba6beb25..68a0c23a301 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13443,7 +13443,7 @@ namespace ts { } function getTypeOfFirstParameterOfSignature(signature: Signature) { - return getTypeAtPosition(signature, 0); + return getTypeWithFacts(getTypeAtPosition(signature, 0), TypeFacts.NEUndefined); } /** diff --git a/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.js b/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.js new file mode 100644 index 00000000000..32fc769e4f3 --- /dev/null +++ b/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.js @@ -0,0 +1,33 @@ +//// [asyncFunctionsAndStrictNullChecks.ts] + +declare namespace Windows.Foundation { + interface IPromise { + then(success?: (value: TResult) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; + then(success?: (value: TResult) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; + then(success?: (value: TResult) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; + then(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; + done(success?: (value: TResult) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + + cancel(): void; + } +} + +async function sample(promise: Windows.Foundation.IPromise) { + var number = await promise; +} + + +//// [asyncFunctionsAndStrictNullChecks.js] +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments)).next()); + }); +}; +function sample(promise) { + return __awaiter(this, void 0, void 0, function* () { + var number = yield promise; + }); +} diff --git a/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.symbols b/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.symbols new file mode 100644 index 00000000000..593702a35fd --- /dev/null +++ b/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.symbols @@ -0,0 +1,102 @@ +=== tests/cases/compiler/asyncFunctionsAndStrictNullChecks.ts === + +declare namespace Windows.Foundation { +>Windows : Symbol(Windows, Decl(asyncFunctionsAndStrictNullChecks.ts, 0, 0)) +>Foundation : Symbol(Foundation, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 26)) + + interface IPromise { +>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38)) +>TResult : Symbol(TResult, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 23)) + + then(success?: (value: TResult) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; +>then : Symbol(IPromise.then, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 33), Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 145), Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 135), Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 135)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 13)) +>success : Symbol(success, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 16)) +>value : Symbol(value, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 27)) +>TResult : Symbol(TResult, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 23)) +>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 13)) +>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 58)) +>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 68)) +>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 13)) +>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 95)) +>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 108)) +>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 13)) + + then(success?: (value: TResult) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; +>then : Symbol(IPromise.then, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 33), Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 145), Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 135), Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 135)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 13)) +>success : Symbol(success, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 16)) +>value : Symbol(value, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 27)) +>TResult : Symbol(TResult, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 23)) +>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 13)) +>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 58)) +>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 68)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 13)) +>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 85)) +>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 98)) +>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 13)) + + then(success?: (value: TResult) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; +>then : Symbol(IPromise.then, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 33), Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 145), Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 135), Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 135)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 13)) +>success : Symbol(success, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 16)) +>value : Symbol(value, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 27)) +>TResult : Symbol(TResult, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 23)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 13)) +>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 48)) +>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 58)) +>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 13)) +>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 85)) +>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 98)) +>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 13)) + + then(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; +>then : Symbol(IPromise.then, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 33), Decl(asyncFunctionsAndStrictNullChecks.ts, 3, 145), Decl(asyncFunctionsAndStrictNullChecks.ts, 4, 135), Decl(asyncFunctionsAndStrictNullChecks.ts, 5, 135)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 13)) +>success : Symbol(success, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 16)) +>value : Symbol(value, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 27)) +>TResult : Symbol(TResult, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 23)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 13)) +>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 48)) +>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 58)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 13)) +>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 75)) +>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 88)) +>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 13)) + + done(success?: (value: TResult) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; +>done : Symbol(IPromise.done, Decl(asyncFunctionsAndStrictNullChecks.ts, 6, 125)) +>U : Symbol(U, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 13)) +>success : Symbol(success, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 16)) +>value : Symbol(value, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 27)) +>TResult : Symbol(TResult, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 23)) +>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 50)) +>error : Symbol(error, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 60)) +>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 79)) +>progress : Symbol(progress, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 92)) + + cancel(): void; +>cancel : Symbol(IPromise.cancel, Decl(asyncFunctionsAndStrictNullChecks.ts, 7, 122)) + } +} + +async function sample(promise: Windows.Foundation.IPromise) { +>sample : Symbol(sample, Decl(asyncFunctionsAndStrictNullChecks.ts, 11, 1)) +>promise : Symbol(promise, Decl(asyncFunctionsAndStrictNullChecks.ts, 13, 22)) +>Windows : Symbol(Windows, Decl(asyncFunctionsAndStrictNullChecks.ts, 0, 0)) +>Foundation : Symbol(Windows.Foundation, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 26)) +>IPromise : Symbol(Windows.Foundation.IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38)) + + var number = await promise; +>number : Symbol(number, Decl(asyncFunctionsAndStrictNullChecks.ts, 14, 7)) +>promise : Symbol(promise, Decl(asyncFunctionsAndStrictNullChecks.ts, 13, 22)) +} + diff --git a/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.types b/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.types new file mode 100644 index 00000000000..4d3424b730c --- /dev/null +++ b/tests/baselines/reference/asyncFunctionsAndStrictNullChecks.types @@ -0,0 +1,103 @@ +=== tests/cases/compiler/asyncFunctionsAndStrictNullChecks.ts === + +declare namespace Windows.Foundation { +>Windows : any +>Foundation : any + + interface IPromise { +>IPromise : IPromise +>TResult : TResult + + then(success?: (value: TResult) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; +>then : { (success?: ((value: TResult) => IPromise) | undefined, error?: ((error: any) => IPromise) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; (success?: ((value: TResult) => IPromise) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; (success?: ((value: TResult) => U) | undefined, error?: ((error: any) => IPromise) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; (success?: ((value: TResult) => U) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; } +>U : U +>success : ((value: TResult) => IPromise) | undefined +>value : TResult +>TResult : TResult +>IPromise : IPromise +>U : U +>error : ((error: any) => IPromise) | undefined +>error : any +>IPromise : IPromise +>U : U +>progress : ((progress: any) => void) | undefined +>progress : any +>IPromise : IPromise +>U : U + + then(success?: (value: TResult) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; +>then : { (success?: ((value: TResult) => IPromise) | undefined, error?: ((error: any) => IPromise) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; (success?: ((value: TResult) => IPromise) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; (success?: ((value: TResult) => U) | undefined, error?: ((error: any) => IPromise) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; (success?: ((value: TResult) => U) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; } +>U : U +>success : ((value: TResult) => IPromise) | undefined +>value : TResult +>TResult : TResult +>IPromise : IPromise +>U : U +>error : ((error: any) => U) | undefined +>error : any +>U : U +>progress : ((progress: any) => void) | undefined +>progress : any +>IPromise : IPromise +>U : U + + then(success?: (value: TResult) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; +>then : { (success?: ((value: TResult) => IPromise) | undefined, error?: ((error: any) => IPromise) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; (success?: ((value: TResult) => IPromise) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; (success?: ((value: TResult) => U) | undefined, error?: ((error: any) => IPromise) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; (success?: ((value: TResult) => U) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; } +>U : U +>success : ((value: TResult) => U) | undefined +>value : TResult +>TResult : TResult +>U : U +>error : ((error: any) => IPromise) | undefined +>error : any +>IPromise : IPromise +>U : U +>progress : ((progress: any) => void) | undefined +>progress : any +>IPromise : IPromise +>U : U + + then(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; +>then : { (success?: ((value: TResult) => IPromise) | undefined, error?: ((error: any) => IPromise) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; (success?: ((value: TResult) => IPromise) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; (success?: ((value: TResult) => U) | undefined, error?: ((error: any) => IPromise) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; (success?: ((value: TResult) => U) | undefined, error?: ((error: any) => U) | undefined, progress?: ((progress: any) => void) | undefined): IPromise; } +>U : U +>success : ((value: TResult) => U) | undefined +>value : TResult +>TResult : TResult +>U : U +>error : ((error: any) => U) | undefined +>error : any +>U : U +>progress : ((progress: any) => void) | undefined +>progress : any +>IPromise : IPromise +>U : U + + done(success?: (value: TResult) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; +>done : (success?: ((value: TResult) => any) | undefined, error?: ((error: any) => any) | undefined, progress?: ((progress: any) => void) | undefined) => void +>U : U +>success : ((value: TResult) => any) | undefined +>value : TResult +>TResult : TResult +>error : ((error: any) => any) | undefined +>error : any +>progress : ((progress: any) => void) | undefined +>progress : any + + cancel(): void; +>cancel : () => void + } +} + +async function sample(promise: Windows.Foundation.IPromise) { +>sample : (promise: Windows.Foundation.IPromise) => Promise +>promise : Windows.Foundation.IPromise +>Windows : any +>Foundation : any +>IPromise : Windows.Foundation.IPromise + + var number = await promise; +>number : number +>await promise : number +>promise : Windows.Foundation.IPromise +} + diff --git a/tests/cases/compiler/asyncFunctionsAndStrictNullChecks.ts b/tests/cases/compiler/asyncFunctionsAndStrictNullChecks.ts new file mode 100644 index 00000000000..f9a751314e9 --- /dev/null +++ b/tests/cases/compiler/asyncFunctionsAndStrictNullChecks.ts @@ -0,0 +1,18 @@ +// @target: es6 +// @strictNullChecks: true + +declare namespace Windows.Foundation { + interface IPromise { + then(success?: (value: TResult) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; + then(success?: (value: TResult) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; + then(success?: (value: TResult) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; + then(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; + done(success?: (value: TResult) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + + cancel(): void; + } +} + +async function sample(promise: Windows.Foundation.IPromise) { + var number = await promise; +}