Skip to content

export let variable doesn't require the variable to be assigned within current fileΒ #61994

Open
@lionel-rowe

Description

@lionel-rowe

πŸ”Ž Search Terms

export let, undefined, assignment, assigned

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about export let

⏯ Playground Link

No response

πŸ’» Code

// a.ts
export let x: { foo(): void }

if (!!false) {
    // @ts-expect-error Variable 'x' is used before being assigned.
    x.foo()
}

// b.ts
import { x } from './a.ts'

// TS compiles, throws at runtime
x.foo()

πŸ™ Actual behavior

TS compiles, only throws at runtime.

πŸ™‚ Expected behavior

TS refuses to compile without ! non-null assertion, with error probably being reported in the exporting module a.ts rather than the importing module b.ts.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions