microsoft / microsoft/TypeScript

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

Open
#61,994 4 comments 1 reaction 0 assignees View on GitHub
Domain: check: Control Flow Help Wanted Possible Improvement
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

### 🔎 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

```ts
// 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_

Contributor guide

Open the contributing guide

Research direction

Start with the cross-file example in a.ts and b.ts and reproduce the current compilation and runtime behavior. Trace the definite-assignment check for the exported x and its use after import; done means the compiler reports the missing assignment rather than allowing the runtime failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.