Microsoft/TypeScript

`export let` variable doesn't require the variable to be assigned within current file

Open

#61,994 建立於 2025年7月3日

在 GitHub 查看
 (4 留言) (1 反應) (0 負責人)TypeScript (6,726 fork)batch import
Domain: check: Control FlowHelp WantedPossible Improvement

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

🔎 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

貢獻者指南