Strange "Cannot use namespace 'Foo' as a type" error with dummy `declare module "foo";` declaration
See original GitHub issueMaybe 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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:14
- Comments:12 (1 by maintainers)
Top Results From Across the Web
How to fix 'Cannot use namespace as a type ts(2709)' in ...
I was struggling to figure out how I could write a type definition for passing an external/3rd party module around.
Read more >List of the armcc error and warning messages - Arm Developer
When the compiler is not in C99 mode, this error is produced by a function declaration f(V) where V is a void type....
Read more >The starting point for learning TypeScript
Declaration Files. Learn how to write declaration files to describe existing JavaScript. Important for DefinitelyTyped contributions.
Read more >Defining Your Own Python Function
This means that when you write code within a function, you can use variable names ... C:\Users\john\Documents\Python\doc>python foo.py Before calling f() ...
Read more >Python Tutorial - Getting Started with Python and Python Basics
You do NOT need to declare variables (name and type) before using them. ... In Python, you need to include a dummy statement...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This error was happening to me when I accidentally had
declare module "mymodule"
but then actually was usingimport {MyInterface} from 'mymodule'
and this caused any usage of MyInterface after that to result in the errors “Cannot use namespace ‘MyInterface’ as a type” and “Property ‘myprop’ of exported interface has or is using private name ‘MyInterface’.” on the same lineI had to delete the
declare module "mymodule"
line and then it worked. This was very confusing to me so I’d add a +1 for a better error message if possible@cmdcolin having your module declared is necessary when using typescript and having
noImplicitAny
turned on in thets.config
. To solve this namespace error while keeping your declaration you can puttypeof
in front of the place where you are using the namespace.