microsoft / microsoft/TypeScript

Unexpected "used before its declaration" error when implementing a exported type of a merged namespace

Open
#54,429 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: Binder Help Wanted Needs Human Review Needs More Info
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Bug Report

🔎 Search Terms

used before its declaration vscode

🕗 Version & Regression Information
  • tested in 4.7.3, 5.0.4 and nightly
⏯ Playground Link

Playground link with relevant code

💻 Code
namespace Foo {
    export interface Bar { }
}

class X implements Foo.Bar {

}

const Foo = 1;
🙁 Actual behavior

In VSCode it reports:

namespace Foo
Block-scoped variable 'Foo' used before its declaration.ts(2448)
Untitled-1(9, 7): 'Foo' is declared here.
Variable 'Foo' is used before being assigned.ts(2454)

You may not see the error immediately if you paste the code into a new file. It will appear when you start typing something.

Note that the error cannot be reproduced in the playground.

🙂 Expected behavior

No error.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided TypeScript example and Playground link, then compare the editor diagnostic with the Playground behavior for the merged namespace and exported type. Trace the type-checking path that reports the "used before its declaration" and "used before being assigned" errors, and add a regression test showing that this code produces no error.

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
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.