Repository: TypeScript
Issue: inferFromUsage JSDoc Quick fix breaks return function pattern
Labels: Bug,Help Wanted

<!-- 🚨 STOP 🚨 STOP 🚨 STOP 🚨

Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common "Bugs" That Aren't Bugs section!

Please help us by doing the following steps before logging an issue:
  * Search: https://github.com/Microsoft/TypeScript/search?type=Issues
  * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ

Please fill in the *entire* template below.
-->

<!--
Please try to reproduce the issue with the latest published version. It may have already been fixed.
For npm: `typescript@next`
This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly
-->
**TypeScript Version:**  4.0.0-dev.20200712 and 3.9.6
**Visual Studio Code Version:** 1.47.0

<!-- Search terms you tried before logging this (so others can find this issue more easily) -->
**Search Terms:** https://github.com/microsoft/TypeScript/issues?q=is%3Aissue+is%3Aopen+"Quick+fix"+"return+function"

When clicking "Quick Fix..." in vscode for the anonymous function in `reduceUntil` leads to broken behaviour and `reduceUntil` returns `undefined`.

You can play with the code at [repl.it](https://repl.it/@dotnetCarpenter/ThirstyGruesomeComputing#index.js)

**Code**

```js
/**
 * @param {{(): boolean; (arg0: any): any}} predicate
 */
function reduceUntil (predicate) {
    let stop = false
    return function(accu, x) {
        if (accu.length === 0) stop = false // reset if new accu
        if (predicate(x)) stop = true // stop when true
        if (stop) return accu // return the accumulated
        return accu + x	// append next value to accu
    }
}
```

**Expected behavior:**

```js
/**
 * @param {{ (): boolean; (arg0: any): any; }} predicate
 */
function reduceUntil (predicate) {
	let stop = false
	return /** @type {(accu: string, x: string) => string} */ function (accu, x) {
		if (accu.length === 0) stop = false // reset if new accu
		if (predicate(x)) stop = true // stop when true
		if (stop) return accu // return the accumulated
		return accu + x	// append next value to accu
	}
}
```

**Actual behavior:**

```js
/**
 * @param {{ (): boolean; (arg0: any): any; }} predicate
 */
function reduceUntil (predicate) {
	let stop = false
	return /**
		* @param {string | any[]} accu
		* @param {any} x
		*/
function (accu, x) {
			if (accu.length === 0) stop = false // reset if new accu
			if (predicate(x)) stop = true // stop when true
			if (stop) return accu // return the accumulated
			return accu + x	// append next value to accu
		}
}
```
_The above refactoring is b0rken and `reduceUntil` will now return `undefined`._

**Playground Link:** <!-- A link to a TypeScript Playground "Share" link which demonstrates this behavior -->
Another accepted documentation refactoring would be to move the type definition to the @return section of the outer function as shown here:
https://www.staging-typescript.org/play?useJavaScript=true#code/PQKhCgAIUgBAHAhgJ0QW0gb0wCgJQBckARgPakA2ApogHYDckOKA5gAxF0Cehk3Avv0jxkVACYBLAMaIALlSgxYo2QFdktAM5ZmUqaqKbZyCbRYAaSAA9Dx0yzyQAvAD5IRk2aGixqqVWRFYHAAM1VaKVkJUlpIHz8qAFVaKIocEXFpOSpHTChIAupZd1lSeGdIEMQKTQUCgpV1WLCIqJjdfUsrXPz6+okQpkQ9VQA6ajNZAAtnJydINkcjMoqqmqpIYGA4qlrigchaKgB3PhHevsgD9J8s+RxupdLy+eNVDa2SleOpqli3uqXArXZbwRyNDRnfSbbYQ-6-KGqNCqCjZMQXPpwxGQADU1gAkJ9EPB4H8xIcqFZigA3arvSClREXfjgfhAA

**Related Issues:** <!-- Did you find other bugs that looked similar? -->
https://github.com/microsoft/vscode/issues/102399
https://github.com/microsoft/TypeScript/issues/31836