microsoft / microsoft/TypeScript
Strange "Cannot use namespace 'Foo' as a type" error with dummy `declare module "foo";` declaration
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Maybe this is a question, but it has come up multiple times on Stack Overflow (most recently here) without a good answer, so I'm asking it here.
TypeScript Version: master (03af107)
Search Terms: "cannot use namespace" "as a type" TS2709 "declare module"
Code
declare module "foo";
declare module "bar" {
import { Foo } from "foo";
let x: Foo;
}
Expected behavior: An error that makes sense, or no error?
Actual behavior: error TS2709: Cannot use namespace 'Foo' as a type.
Playground Link: link
Related Issues: None found
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 by reproducing the TS2709 error in the linked TypeScript Playground using the dummy declare module "foo"; and nested declare module "bar" example. Trace the compiler's handling of the imported Foo in the type position, then verify that the result is either a sensible diagnostic or no error for the reported case.
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