microsoft / microsoft/TypeScript
Unexpected "used before its declaration" error when implementing a exported type of a merged namespace
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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