mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 06:41:59 -06:00
Merge pull request #6699 from RyanCavanaugh/fix6663
Use union types in the return type of functions in the error case
This commit is contained in:
commit
2ef6f13532
@ -10421,7 +10421,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
25
tests/cases/fourslash/getJavaScriptCompletions19.ts
Normal file
25
tests/cases/fourslash/getJavaScriptCompletions19.ts
Normal 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');
|
||||
Loading…
x
Reference in New Issue
Block a user