Home / Companies / LogRocket / Blog / Post Details
Content Deep Dive

Make sharing TypeScript code and types quick and easy

Blog post from LogRocket

Post Details
Company
Date Published
Author
Ashley Davis
Word Count
3,955
Language
-
Hacker News Points
-
Summary

The blog post explores various methods for sharing TypeScript code libraries effectively across different projects and components within a larger application. Initially, it highlights the challenges of sharing code in TypeScript as compared to C++ or C#, emphasizing the importance of not duplicating code for new projects. Traditional methods such as publishing code to npm or a Git repository, while common, are often seen as cumbersome, especially for internal use within microservices or when reusing models across REST APIs. The post introduces TypeScript project references, available since TypeScript v3.0, as a solution for structuring programs into smaller pieces, improving build times, and organizing code efficiently. It then provides detailed examples, including sharing code libraries between microservices using Docker and integrating them into a frontend built with React and Parcel. The author also introduces a custom tool, ts-project-bundle, to facilitate the bundling process, offering a scalable approach to project structure that accommodates multiple shared libraries and microservices. The narrative concludes by advocating for the TypeScript compiler to eventually incorporate built-in support for bundling or exporting compiled JavaScript code, which would streamline the process further.