loading...

re: TypeScript: how do you share type definitions across multiple projects? VIEW POST

FULL DISCUSSION
 

Hi there,

You may want to look into the new 'Project References' feature.

typescriptlang.org/docs/handbook/p...

I can't say for sure exactly how it works, but based on the documentation you would be able to use dependencies (or 'references'), from typescript projects that are in sub-directories, or parent directories.

This means that either a multi-repo or mono-repo approach would work, provided the required dependencies exist where the config says they will.

The code is then compiled with the --build(-b) flag, which will compile all dependencies for use in the project.

This could be super useful, and I'm currently looking to implement it myself in an upcoming project where I'll have lots of shared types across about 5 TS projects.

Hope I could be of at least some help, in pointing out Project References, even if I'm not an expert.

 

Hi! That's a nice one, thanks for sharing it! I think it might be useful in some cases, but what concerns me here is that you have to reproduce the exact folder's structure every time in order to make it work. And moreover, you have to keep all of your projects consuming the types within the same File System, which is not the case for most of the modern apps taking place on different "machines" in the cloud.

 

Both are good points. My intuition had told me that when deploying the applications, the adjacent projects wouldn't need to be copied alongside, as they would be compiled into the current project. I may be incorrect though.
Maybe in a few weeks when I'm dozens of hours deep into a project using Project References, I'll know a little more.

Yeah, definitely. It's always difficult to be sure of something before you spent hours on it. Please feel free to share the results of your journey!

code of conduct - report abuse