I'm loading a third-party library called sorted-array and using it like this: However, I get this error: Cannot use namespace 'SortedArray' as a type.ts(2709). How do you explicitly set a new property on `window` in TypeScript? Can state or city police officers enforce the FCC regulations? Namespaces are a TypeScript-specific way to organize code. To create namespaces, you will use the namespace keyword followed by the name of the namespace and then a {} block. See the Namespaces documentation for more information about TypeScript namespaces. I thought omitting the extension didn't matter, but I guess sometimes it does. This new IIFE matches the second declaration of your DatabaseEntity namespace. However, this is not always the case, and sometimes youll have to deal with a library that does not bundle its own type module declaration. Cannot use namespace 'FilterProps' as a type. Conversely, the variables lettersRegexp and numberRegexp are implementation details, so they are left unexported and will not be visible to code outside the namespace. To illustrate this create a new User instance and store it in the newUser variable: namespace DatabaseEntity { Cette erreur m'arrivait lorsque j'avais accidentellement declare module "mymodule" mais que j'utilisais en fait import {MyInterface} from 'mymodule' et que toute utilisation de typescript - You should not be able to have both an import and a namespace of the same name. "target": "es5", For the most part, any TypeScript or JavaScript code will work in Office Scripts. Search Terms: "cannot use namespace" "as a type" TS2709 "declare module". Do not hesitate to share your thoughts here to help others. This IIFE receives a single parameter DatabaseEntity || (DatabaseEntity = {}), which is the current value of the DatabaseEntity variable. I am doing this, because this way I have a consistent namespace. Find centralized, trusted content and collaborate around the technologies you use most. Do not hesitate to share your response here to help other visitors like you. Instead of putting lots of different names into the global namespace, lets wrap up our objects into a namespace. For the TypeScript: "Cannot use namespace as a type". Why are there two different pronunciations for the word Tee? Note: In very old versions of TypeScript namespaces were called Internal Modules, these pre-date JavaScript module systems. the in import x from "";, import x = require("");, etc.) If youve enjoyed this tutorial and our broader community, consider checking out our DigitalOcean products which can also help you achieve your development goals. This is only possible because you exported those in the previous namespace declaration. For deeply nested namespaces, the namespace alias comes in handy to keep things clean. Microsoft Azure joins Collectives on Stack Overflow. This was very confusing to me so I'd add a +1 for a better error message if possible, I had to delete the declare module "mymodule" line and then it worked. This makes it easier to customize the module declaration down the road or to even make the type declaration available to all developers by submitting it to the DefinetelyTyped repository. See how TypeScript improves day to day working with JavaScript with minimal additional syntax.