_Pear
_Pear7mo ago

Help with TypeScript namespaces - is this pattern supported?

Hi! I am attempting to model some classes in a Namespace for organization purposes. I would expect this pattern to work, the linter doesn't complain at least, but when I run deno test it fails with the error in the README. Is this not supported in Deno? I tried using triple slash directives as well but no luck. Thanks! https://github.com/CobyPear/deno-namespace-reproduction
GitHub
GitHub - CobyPear/deno-namespace-reproduction
Contribute to CobyPear/deno-namespace-reproduction development by creating an account on GitHub.
5 Replies
Deno AI Helper
Deno AI Helper7mo ago
I apologize, but I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided, I can offer some general advice regarding TypeScript namespaces. TypeScript namespaces are a legacy way to organize code and are not recommended for new projects. Instead, ES modules are the standard in Deno for code organization and module management. If you're using namespaces and encountering issues, it might be due to Deno's focus on ES modules, which could be causing compatibility issues with the namespace pattern. Without seeing the specific code and error message, it's difficult to provide a precise solution. However, if you're using triple-slash directives and they're not resolving the issue, it's possible that there's a mismatch between the way Deno handles modules and the way your code is structured with namespaces. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice. If you continue to experience issues, you might want to consider refactoring your code to use ES modules instead of namespaces for better compatibility with Deno.
_Pear
_Pear7mo ago
When using namespaces in a .d.ts file, the deno linter does not complain. When using it in a .ts file, it will warn you to use ESmodules instead of namespaces. Could the linter be enhanced to give the same warning in d.ts files?
ry
ry7mo ago
@_Pear it'd be helpful if you opened an issue in the deno repo, we can take a closer look
_Pear
_Pear7mo ago
sure, I'll open one this evening. I have a reproduction attached at the link in the OP if you're able to take a look in the meantime.
_Pear
_Pear7mo ago
GitHub
Linter does not warn about namespaces in .d.ts file · Issue #2310...
Version: Deno 1.40.3 The following lint warning appears in a .ts file when trying to use a namespace, but not a .d.ts file: TypeScript's module and namespace are discouraged to use Use ES2015 m...