Skip to content

Erroneous "unreachable code" with async IIFE? #11738

Closed
@aseemk

Description

@aseemk

TypeScript Version: 2.0.3

Code:

const sleep = async (ms) => {
    return new Promise((resolve, reject) => {
        setTimeout(resolve, ms);
    });
};

console.log('Kicking off async task...');

(async () => {
    console.log('Sleeping for 10ms...');
    await sleep(10);
    console.log('Going to fail now. What happens?');
    throw new Error();
})();

console.log('Kicked off.');

Expected behavior: compilation succeeds, and runs with the following output:

Kicking off async task...
Sleeping for 10ms...
Kicked off.
Going to fail now. What happens?

Actual behavior: compilation fails:

async.ts(16,1): error TS7027: Unreachable code detected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions