Use union types in the return type of functions in the error case

Fixes #6663

(cherry picked from commit da6e82f639)
This commit is contained in:
Ryan Cavanaugh
2016-01-28 11:39:19 -08:00
committed by Bill Ticehurst
parent 671d83e81a
commit de2ef72d4f
2 changed files with 27 additions and 1 deletions

View File

@@ -10433,7 +10433,8 @@ namespace ts {
}
else {
error(func, Diagnostics.No_best_common_type_exists_among_return_expressions);
return unknownType;
// Defer to unioning the return types so we get a) downstream errors earlier and b) better Salsa experience
return getUnionType(types);
}
}

View File

@@ -0,0 +1,25 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: file.js
//// function fn() {
//// if (foo) {
//// return 0;
//// } else {
//// return '0';
//// }
//// }
//// let x = fn();
//// if(typeof x === 'string') {
//// x/*str*/
//// } else {
//// x/*num*/
//// }
goTo.marker('str');
edit.insert('.');
verify.completionListContains('substr', undefined, undefined, 'method');
goTo.marker('num');
edit.insert('.');
verify.completionListContains('toFixed', undefined, undefined, 'method');