I am writing a library in TypeScript: @cjol/core
. It has a JavaScript dependency dep
, which does not have an @types
package available. Instead, I have written a custom dep.d.ts
file, which makes all the typings work nicely as I develop the library. Everything compiles fine but my dep.d.ts
does not appear anywhere in the output.
When I try to include my library in another client project @cjol/client
, the client project will not compile. I get an error like this one:
../core/build/index.d.ts:2:24 - error TS7016: Could not find a declaration file for module 'dep'. '/home/cjol/.../dep/index.js' implicitly has an 'any' type.
Try `npm install @types/dep` if it exists or add a new declaration (.d.ts) file containing `declare module 'dep';`
2 > import { Foo } from "dep";
I am also using Yarn workspaces (@cjol/core
and @cjol/client
are both packages in the same workspace, under ./core
and ./client
), but I don't think that's relevant here. I need @cjol/client
to output my custom definition file, but I can't figure out how to make it happen!
Edit 1: Again, I'm not sure the details are relevant, but here's what index.d.ts
looks like. As mentioned, it's been generated by TypeScript.
import { Stuff } from "a-typescript-library";
import { Foo } from "dep";
export * from "./my-app-types";
declare type APIResponse<T> = {
/* ... */
};
export declare class API {
/* ... */
}
Edit 2: Here's what dep.d.ts
looks like:
declare module "dep" {
import Something from "something.js";
export class DepClass {
/* loads of stuff */
}
}
Edit 4: Perhaps another way of thinking about my question. If I have written a custom .d.ts
file, how can I distribute it? Do I need to create a whole new package containing the type definition?