Export custom types for third-party library in published NPM package

Viewed 155

I'm developing an npm package that uses a third-party library without types. I have types for it defined in a folder outside /src, as such:

/dist
/src
/types
  /third-party-library
    index.d.ts

index.d.ts looks something like this:

declare module 'third-party-library' {
  export interface INeedThis { ... }
}

And it's used in the code as such:

// src/index.ts for example
import { INeedThis } from 'third-party-library'
export interface SomeModel {
  config: INeedThis
}

When I use this package in another project, SomeModel.config shows up as any, which is confusing for the end user. This external type is not part of /dist so that makes sense, but where would I put it in /dist, or how should I go about packaging it properly? Or is this bad practise and I should go about it another way?

0 Answers
Related