-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: LS: Refactoringse.g. extract to constant or function, rename symbole.g. extract to constant or function, rename symbol
Milestone
Description
TypeScript Version: 3.9.2, 4.0.0-beta, 4.1.0-dev.20200820
Search Terms:
Convert to async function, quick fix, 80006, This may be converted to an async function
Code
const wait = (delay: number): Promise<(msg: string) => void> =>
new Promise(resolve =>
setTimeout(() => {
const f = (msg: string) => console.log(msg)
resolve(f)
}, delay)
)
const f = () => {
return wait(1000).then(res => res('hello'))
}Expected behavior:
Running 'Convert to async function' on f should generate code like below.
const wait = (delay: number): Promise<(msg: string) => void> =>
new Promise(resolve =>
setTimeout(() => {
const f = (msg: string) => console.log(msg)
resolve(f)
}, delay)
)
const f = async () => {
const res = await wait(1000)
return res('hello')
}Actual behavior:
Running 'Convert to async function' on f generates code like below.
const wait = (delay: number): Promise<(msg: string) => void> =>
new Promise(resolve =>
setTimeout(() => {
const f = (msg: string) => console.log(msg)
resolve(f)
}, delay)
)
const f = async () => {
const msg=await wait(1000)
return res('hello')
}Related Issues:
with imported functions #39858
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: LS: Refactoringse.g. extract to constant or function, rename symbole.g. extract to constant or function, rename symbol