Skip to content

Instantly share code, notes, and snippets.

@micmro
Last active November 22, 2021 09:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micmro/24f0a7d61a7f4de597b0512aff656c73 to your computer and use it in GitHub Desktop.
Save micmro/24f0a7d61a7f4de597b0512aff656c73 to your computer and use it in GitHub Desktop.
Add a custom type definition file for an existing (non-typed) npm module, while automatically pick up the typing (for both Typescript or Javascript in case of VS Code). Typings are contained in the `typings/` directory
//real file is in: `typings/swagger-express-mw/index.d.ts` (relative to tsconfig.json)
import {Config, ConnectMiddleware} from "../swagger-node-runner"
/**
* Create a new instance of Connect specific SwaggerNodeRunner
*/
export function create(config: Config, cb: {(err: Error | undefined, runner: ConnectMiddleware): void}): void
{
"compilerOptions": {
"baseUrl": ".", // needed for custom mapping of typing
"module": "commonjs",
"moduleResolution": "node",
"target": "es6",
// custom mapping of typing
"paths": {
"*" : [ "typings/*"] //generic version
// "swagger-express-mw": ["typings/swagger-express-mw"] //specific module version
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment