rezi99
rezi995mo ago

How to publish global types with JSR?

I was trying to republish my npm package with JSR via npm jsr package. It all went well with one exception. I did not find a way how to publish global types (declare namespace). In npm I can declare in package.json what file is responsible for types and then I can pack all generated types + the global definitions. But as JSR does this automatically I haven't find a way how to pass those global types. Is there a way around it now?
2 Replies
Deno AI Helper
Deno AI Helper5mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided, it seems like you're trying to work with global type declarations when republishing a package with JSR (which I assume refers to a JavaScript Registry). In the context of Deno, which typically uses TypeScript for type definitions, global types are usually declared in .d.ts files. If you're trying to include global type declarations in your package, you would typically include a declare namespace or declare global block in a .d.ts file. Here's a generic example of how you might declare a global type in a .d.ts file:
// types.d.ts
declare namespace MyGlobalNamespace {
interface MyGlobalInterface {
// ...
}
}

// Or for global variables
declare global {
var myGlobalVar: MyGlobalType;
}
// types.d.ts
declare namespace MyGlobalNamespace {
interface MyGlobalInterface {
// ...
}
}

// Or for global variables
declare global {
var myGlobalVar: MyGlobalType;
}
In a Deno context, you would then import this .d.ts file in your code to use the declared types. However, since you're mentioning JSR and npm, it's possible that you're referring to a different workflow or tool that I'm not aware of. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of the advice given. If you're using a specific tool or workflow that is not part of the Deno ecosystem, it would be best to consult the documentation or support resources for that tool to find the best way to include global type declarations.
rezi99
rezi995mo ago
It does not work if I export namespace from index.ts the namespace is emptied once the package is published