So, in my TypeScript library, I import a module and return a type from it in an exported function:
// myLib/src/index.ts
import * as SAT from 'sat';
export function getCollisionResponse(a: SAT.Polygon, b: SAT.Polygon): SAT.Response {
const res = new SAT.Response();
SAT.testPolygonPolygon(a, b, res);
return res;
}
SAT is included as a vendored ambient type definition in myLib/types/sat.d.ts
:
// myLib/types/sat.d.ts
declare module "sat" {
// ...
}
Now, I compile my TypeScript lib to JS when I publish to NPM, along with generated type definitions. So my declaration ends up looking like:
// myLib/dist/declarations/index.d.ts
import * as SAT from 'sat';
export declare function getCollisionResponse(a: SAT.Polygon, b: SAT.Polygon): SAT.Response;
All good, right? Except when I import myLib
from my application, I get a weird error:
(1,22): error TS2307: Cannot find module 'sat'.
I don't know how to include this ambient definition in the output such that code that imports myLib
can properly refernce it.