Improve debug failure for failed node cast (#21539)

This commit is contained in:
Andy 2018-02-01 10:51:28 -08:00 committed by GitHub
parent 1fb3593e61
commit 477cba539b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1454,7 +1454,13 @@ namespace ts {
export function cast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut {
if (value !== undefined && test(value)) return value;
Debug.fail(`Invalid cast. The supplied value did not pass the test '${Debug.getFunctionName(test)}'.`);
if (value && typeof (value as any).kind === "number") {
Debug.fail(`Invalid cast. The supplied ${(ts as any).SyntaxKind[(value as any).kind]} did not pass the test '${Debug.getFunctionName(test)}'.`);
}
else {
Debug.fail(`Invalid cast. The supplied value did not pass the test '${Debug.getFunctionName(test)}'.`);
}
}
/** Does nothing. */