Skip to content

Instantly share code, notes, and snippets.

@thomasboyt
Created August 5, 2016 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasboyt/bdf164e1a58b4832ef3f43ed8d655857 to your computer and use it in GitHub Desktop.
Save thomasboyt/bdf164e1a58b4832ef3f43ed8d655857 to your computer and use it in GitHub Desktop.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment