I have a package with tons of generated modules that all export the same type (eg. icon library).
I want to avoid creating a .d.ts
file for each module as they would all be the same.
Instead, I would like to create an index.d.ts
file at the root of the package with something like this:
// pkg-with-many-assets/index.d.ts
declare module 'pkg-with-many-assets/*' {
const svgPath: string;
export default svgPath;
}
I'm finding that this doesn't register with consuming apps. However, this works when I place the file within the consuming app.
Is it possible to create a package with an ambient module declaration?
Edit:
Seems this is actually possible because @types/simple-icons does it. However, if I were to copy and paste the @types/simple-icons/index.d.ts
file to simple-icons/index.d.ts
in my node_modules
directory, it no longer works.
Perhaps the issue is with TypeScript not reading the index.d.ts
file at the root of the simple-icons
package (despite the "types": "index.d.ts"
specification in package.json
).
I managed to get the above to work by specifying the package name in tsconfig.json
compilerOptions.types
, but obviously I would like this detection to be automatic without manual configuration.