sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Include TypeScript definitions in bundle

Open rexxars opened this issue 1 year ago • 1 comments

Treat this as a work-in-progress that we can use to base our discussions from. Addresses #3369

In essence, this lifts the types from the @types/sharp module into the official package, along with the tests that were in that package as well.

Because the types reference node.js types such as Buffer, we also need to add a new dependency: @types/node. The DefinitelyTyped modules uses the wildcard version range (*) in order to prevent multiple copies of the package in the module tree, which often leads to hard to diagnose problems. An alternative would be for us to use >=14.0.0 or similar. Open to suggestions.

As @lovell pointed out in #3369, this should be considered a minor breaking change, so should likely be released as 0.32.0. When that happens, we can also deprecate @types/sharp using the official process.

Some thoughts:

  • While I don't know of any errors in the typings, there is always a chance that there are. I wouldn't be surprised to see a few more PRs popping up to address issues.
  • There is starting to be a bit of duplication in documenting things - there is a chance that the jsdoc and the tsdoc is slightly out of sync. Ideally we'd find a better process here, or even consider doing "typescript first" and compiling to js (this is probably controversial - just thinking aloud).
  • The "type tests" are somewhat spotty in coverage, and very unstructured. Unless there are plans to migrate to TypeScript fully, I would probably want to restructure these tests a bit over time - splitting them into logical, "sorted" sections of some kind. I'm not sure if it's worth waiting for this work to be completed before a release however - open to suggestions.

rexxars avatar Sep 17 '22 05:09 rexxars

Let me know if you want any more changes done to this!

rexxars avatar Sep 21 '22 01:09 rexxars