How to share Typescript declarations across Server & Client side projects?

265 Views Asked by At

I've created a server-side library to consume Yelp Fusion API in TypeScript. the library references a bunch of types/interfaces which I would like to expose to client-side applications, but in a way that is not requiring the npm install of the server-side library.

I am thinking to separate the types to their own published package and reference that in both the server and client applications but this seems hard to maintain and I am wondering if there is a built-in or otherwise more efficient way to approach this?

1

There are 1 best solutions below

0
On

You could separate the types to a different module which you could then reference from both the client and server package.json.

You can add it as a local dependency like so:

{
  "dependencies": {
    "myTypes": "file:../path/to/module"
  }
}

The only downside is that you need to reinstall the node_modules every time you recompile the types.