Skip to content

Types for async functions do not handle void assignments like normal ones #33420

Description

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:

Code

constw: void="";constx: ()=>void=()=>"";consty: ()=>Promise<void>=async()=>"";functiona(): void{return"";}asyncfunctionb(): Promise<void>{return"";}consty2: ()=>Promise<()=>void>=async()=>()=>"";functiona2(): ()=>void{return()=>"";}functionb2(): Promise<()=>void>{return()=>"";}

Expected behavior:
Generally speaking, all of them should be an error, or all of them shouldn't be.

Actual behavior:
We have a special "function returning void" rule that allows () => "" to be assignable to () => void, but this doesn't carry thru to async scenarios, so a async () => "" is not assignable to a () => Promise<void>.

Playground Link

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions