Skip to content

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

Open
@weswigham

Description

@weswigham

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:

Code

const w: void = "";

const x: () => void = () => "";

const y: () => Promise<void> = async () => "";

function a(): void {
    return "";
}

async function b(): Promise<void> {
    return "";
}

const y2: () => Promise<() => void> =  async () => () => "";

function a2(): () => void {
    return () => "";
}

function b2(): 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