I am trying to write a declaration file for h3. Please see the function reference.
First, I am not sure how typescript detects the definition files.
It detects my definition, if placed on a folder /src/@types/<any filename>.d.ts
, with the below content
declare module 'h3-js' {
export type h3ToGeoBoundary = any;
...
}
But, I also read you can create a folder like /src/@types/h3-js/index.d.ts
, but it won't detect definition if write like
export = h3;
export as namespace h3;
declare namespace h3 {
export type h3ToGeoBoundary = () => void; // TODO: correct types
}
It doesn't matter which one works, but I am not sure how to export a namespace with first approach. With that, I get error Property 'h3ToGeoBoundary' does not exist on type 'typeof import("h3-js")'.
Please help with a minimal file, with a working export for h3ToGeoBoundary
, so I can expand further.
Since module just exports a bunch of functions you can define them as individual exports (using your first approach):
declare module "h3-js" {
export function h3ToGeoBoundary(): void;
}