Skip to content
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

Fix #8423: Remove undefined while getting the type of the first argument of then signature #8449

Merged
merged 3 commits into from
May 4, 2016
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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13428,7 +13428,7 @@ namespace ts {
return undefined;
}

const onfulfilledParameterType = getUnionType(map(thenSignatures, getTypeOfFirstParameterOfSignature));
const onfulfilledParameterType = getTypeWithFacts(getUnionType(map(thenSignatures, getTypeOfFirstParameterOfSignature)), TypeFacts.NEUndefined);
if (onfulfilledParameterType.flags & TypeFlags.Any) {
return undefined;
}
Expand Down
14 changes: 9 additions & 5 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace ts {
name: "out",
type: "string",
isFilePath: false, // This is intentionally broken to support compatability with existing tsconfig files
// for correct behaviour, please use outFile
// for correct behaviour, please use outFile
paramType: Diagnostics.FILE,
},
{
Expand Down Expand Up @@ -464,7 +464,7 @@ namespace ts {

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

/* @internal */
export function parseListTypeOption(opt: CommandLineOptionOfListType, value: string, errors: Diagnostic[]): (string | number)[] {
const values = (value || "").trim().split(",");
const values = trimString((value || "")).split(",");
switch (opt.element.type) {
case "number":
return ts.map(values, parseInt);
Expand Down Expand Up @@ -601,7 +601,7 @@ namespace ts {
* Read tsconfig.json file
* @param fileName The path to the config file
*/
export function readConfigFile(fileName: string, readFile: (path: string) => string): { config?: any; error?: Diagnostic } {
export function readConfigFile(fileName: string, readFile: (path: string) => string): { config?: any; error?: Diagnostic } {
let text = "";
try {
text = readFile(fileName);
Expand Down Expand Up @@ -775,7 +775,7 @@ namespace ts {
defaultOptions: CompilerOptions | TypingOptions, diagnosticMessage: DiagnosticMessage, errors: Diagnostic[]) {

if (!jsonOptions) {
return ;
return;
}

const optionNameMap = arrayToMap(optionDeclarations, opt => opt.name);
Expand Down Expand Up @@ -829,4 +829,8 @@ namespace ts {
function convertJsonOptionOfListType(option: CommandLineOptionOfListType, values: any[], basePath: string, errors: Diagnostic[]): any[] {
return filter(map(values, v => convertJsonOption(option.element, v, basePath, errors)), v => !!v);
}

function trimString(s: string) {
return typeof s.trim === "function" ? s.trim() : s.replace(/^[\s]+|[\s]+$/g, "");
}
}
48 changes: 48 additions & 0 deletions tests/baselines/reference/asyncFunctionsAndStrictNullChecks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//// [asyncFunctionsAndStrictNullChecks.ts]

declare namespace Windows.Foundation {
interface IPromise<TResult> {
then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
then<U>(success?: (value: TResult) => U, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
then<U>(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
done<U>(success?: (value: TResult) => any, error?: (error: any) => any, progress?: (progress: any) => void): void;

cancel(): void;
}
}

async function sample(promise: Windows.Foundation.IPromise<number>) {
var number = await promise;
}


declare function resolve1<T>(value: T): Promise<T>;
declare function resolve2<T>(value: T): Windows.Foundation.IPromise<T>;

async function sample2(x?: number) {
let x1 = await resolve1(x);
let x2 = await resolve2(x);
}


//// [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;
});
}
function sample2(x) {
return __awaiter(this, void 0, void 0, function* () {
let x1 = yield resolve1(x);
let x2 = yield resolve2(x);
});
}
136 changes: 136 additions & 0 deletions tests/baselines/reference/asyncFunctionsAndStrictNullChecks.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
=== 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<TResult> {
>IPromise : Symbol(IPromise, Decl(asyncFunctionsAndStrictNullChecks.ts, 1, 38))
>TResult : Symbol(TResult, Decl(asyncFunctionsAndStrictNullChecks.ts, 2, 23))

then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
>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<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
>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<U>(success?: (value: TResult) => U, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
>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<U>(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
>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<U>(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<number>) {
>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))
}


declare function resolve1<T>(value: T): Promise<T>;
>resolve1 : Symbol(resolve1, Decl(asyncFunctionsAndStrictNullChecks.ts, 15, 1))
>T : Symbol(T, Decl(asyncFunctionsAndStrictNullChecks.ts, 18, 26))
>value : Symbol(value, Decl(asyncFunctionsAndStrictNullChecks.ts, 18, 29))
>T : Symbol(T, Decl(asyncFunctionsAndStrictNullChecks.ts, 18, 26))
>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, --, --))
>T : Symbol(T, Decl(asyncFunctionsAndStrictNullChecks.ts, 18, 26))

declare function resolve2<T>(value: T): Windows.Foundation.IPromise<T>;
>resolve2 : Symbol(resolve2, Decl(asyncFunctionsAndStrictNullChecks.ts, 18, 51))
>T : Symbol(T, Decl(asyncFunctionsAndStrictNullChecks.ts, 19, 26))
>value : Symbol(value, Decl(asyncFunctionsAndStrictNullChecks.ts, 19, 29))
>T : Symbol(T, Decl(asyncFunctionsAndStrictNullChecks.ts, 19, 26))
>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))
>T : Symbol(T, Decl(asyncFunctionsAndStrictNullChecks.ts, 19, 26))

async function sample2(x?: number) {
>sample2 : Symbol(sample2, Decl(asyncFunctionsAndStrictNullChecks.ts, 19, 71))
>x : Symbol(x, Decl(asyncFunctionsAndStrictNullChecks.ts, 21, 23))

let x1 = await resolve1(x);
>x1 : Symbol(x1, Decl(asyncFunctionsAndStrictNullChecks.ts, 22, 7))
>resolve1 : Symbol(resolve1, Decl(asyncFunctionsAndStrictNullChecks.ts, 15, 1))
>x : Symbol(x, Decl(asyncFunctionsAndStrictNullChecks.ts, 21, 23))

let x2 = await resolve2(x);
>x2 : Symbol(x2, Decl(asyncFunctionsAndStrictNullChecks.ts, 23, 7))
>resolve2 : Symbol(resolve2, Decl(asyncFunctionsAndStrictNullChecks.ts, 18, 51))
>x : Symbol(x, Decl(asyncFunctionsAndStrictNullChecks.ts, 21, 23))
}

Loading