Skip to content

Async function not type checking correctly #15830

Closed
@OliverJAsh

Description

@OliverJAsh

TypeScript Version: 2.3.2

Code

{
    const fn = (): Promise<number> => {
        const innerFn = async () => {
            if (1 === 1) {
                return Promise.resolve('wrong type');
            } else {
                return Promise.resolve(1);
            }
        };

        // should error with `Type 'string' is not assignable to type 'number'.`
        return innerFn();
    };

    fn();
}

Expected behavior:
return innerFn() should error with Type 'string' is not assignable to type 'number'.

Actual behavior:
return innerFn() does not error.

If you remove the async keyword from the async function, the program type checks as expected:

{
    const fn = (): Promise<number> => {
        const innerFn = () => {
            if (1 === 1) {
                return Promise.resolve('wrong type');
            } else {
                return Promise.resolve(1);
            }
        };

        return innerFn();
    };

    fn();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions