Skip to content

Missing error 'initializer of parameter 'foo' cannot reference identifier 'bas' declared after it' within IIFE #29139

Closed
@ajafff

Description

@ajafff

TypeScript Version: 3.2.1

Search Terms:

Code

function test(
    foo = (() => bas)(), // missing error
    bar = bas, // ok, already has error
    baz = () => bas, // ok, accessing 'bas' is deferred
    bas: string,
) {}

Expected behavior:

Referencing bas in the initializer of foo should be an error.
Control flow analysis inlines IIFEs, but this check doesn't seem to do that.

Actual behavior:

No compile error, resulting in a runtime error.

Playground Link: https://agentcooper.github.io/typescript-play/#code/GYVwdgxgLglg9mABFApgZygCgFCL44OORAXkU0wEpSA+RAIwEM1KqAaRAek8QFsY0aGGADmiFACcJcCbnxMJpBsw7dEcANYdGAGwkpGAEwCeiABbNxUmXLxMAXkqq1laVT03aIEdENGIAciY0AMQBREMUYEl9Q1tXAC5EDAlhETZsagBvAF8gA

Related Issues:

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