coopernurse / node-pool

Generic resource pooling for node.js
2.38k stars 259 forks source link

Add updated type definitions #260

Closed t3hmrman closed 3 years ago

t3hmrman commented 5 years ago

I've done the bare minimum:

I would love some help checking the published artifact however -- locally I'm using r2g and the build package looks fine (includes index.d.ts in the package root).

Resolves #259

t3hmrman commented 5 years ago

I could also add a basic r2g-based test to this PR and hook that into the project testing, but figured I'd at least get the regular PR up first.

[EDIT] - Quick & dirty local testing procedures:

First, Create a new small test project (npm init), with this index.ts:

import { createPool } from "generic-pool";
const pool = createPool({
  create: () => Promise.resolve(1),
  destroy: () => Promise.resolve(1),
});

pool
    .drain()
    // Expect Typescript to complain on the line below since PromiseLike has no .catch()
    .catch((err: Error) => {}); 

After creating the new project I did two things:

Confirming old (broken) functionality

Checking the new index.d.ts

Again, this can be made more easily automatable with r2g (this is what it's for, you just need to add a folder called .r2g in the project and add tests in it. But the method above was doable for quick & dirty testing.