Creating an npm library using TypeScript model classes: A step-by-step guide

Currently, I am working on a large-scale web application that consists of multiple modules and repositories. Each module is being developed as an individual Angular project.

These Angular projects have some shared UI components, services, and models which I publish to our company's private npm repository (Sinopia) and then install them where needed.

While I've used Angular libraries for the UI components and services, I find it excessive to create an entirely new Angular library project for models since they only contain class definitions and no logic.

I'm looking for recommendations on frameworks or best practices for developing these kinds of libraries. Any guidance or a link to a similar Git repository would be greatly appreciated.

Answer №1

A few days ago, I found myself in a similar situation where I needed to reference classes and interfaces across multiple projects. The solution was to create a node module that could be utilized by all other projects.

For more information, please visit my repository on GitHub: https://github.com/Plochie/pacify.

Within this repository, you will find all the classes written in TypeScript. After building the project, you will obtain JavaScript files in the 'dist' folder. Don't forget to review the tsconfig.json file in each directory.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Reusing Angular routes across different modules for backbutton functionality

Insights on my Application (Angular 12): Comprises of 3 Modules, each containing an overview page with a list and specific detail pages Each route is assigned an area tag to identify the user's navigation within the module Goal for Angular´s RouteR ...

Angular 2: Another service is unable to find the custom service

I have a situation where I am using an HttpInterceptor and trying to integrate a NotificationService within it. However, I encountered an issue where the NotificationService appears to be undefined in the httpInterceptor. Is there something that I missed o ...

The Angular selector is unrecognized: double-check that it belongs to the current module if it is an Angular component

After creating a component, I attempted to utilize it in another component by specifying its selector in the display segment. <app-component1></app-component1> However, I encountered a compile error. Upon reviewing the imports in the modules, ...

Help with Material-UI: Passing unique props to a custom TreeItem component

I am trying to pass an argument category to the component CustomTreeItem which uses TreeItemContent. Documentation: https://mui.com/ru/api/tree-item/ import TreeItem, { TreeItemProps, useTreeItem, TreeItemContentProps, } from '@material-ui/lab ...

Are there any specific technical reasons for steering clear of using a self-reliant local dependency (file reference) within npm?

Is it possible to use local import paths for my Node.js package (self-reference) in the same way I am using local import paths for other local packages, rather than relying on relative paths? Here is an example of a package.json configuration: { "na ...

Utilize React to transform PDF files into PNG images and seamlessly upload them to Cloudinary

Currently, I am utilizing react typescript and looking to select a PDF file, transform the PDF into an image, and then upload the final image onto Cloudinary. Although I have a service set up for uploading images in my Cloudinary media library, I am unsu ...

Icon Searchbar Feature in Ionic 2

I am currently working with Ionic2 and have integrated the ion-searchbar component into my project: https://i.sstatic.net/CqmF4.png Question Would it be possible to customize the search icon? The default icon is a magnifying glass, but I would like to r ...

Creating a TypeScript type or interface that represents an object with one of many keys or simply a string

I am tasked with creating an interface that can either be a string or an object with one of three specific keys. The function I have takes care of different errors and returns the appropriate message: export const determineError = (error: ServerAlerts): ...

How can you utilize Angular 2's http.post method to interact with a web API2 controller method from a component?

ClassComponent.ts fetchTableHeaders(Id: any) { let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); let body = JSON.stringify(Id); var request = this. ...

What is the method for utilizing a class variable without assigning a value to it initially

class testClass { student: { name: string, age: number } constructor(options?: any) { this.student = { name: '', age: 0 }; } setStudent(name:string, age:number) { this.student.name ...

Error message: "Mismatched data types in Formik errors when utilizing TypeScript"

I have a customized input component for formik which includes an error label if one exists. When I print it like this: {errors[field.name]}, it works. However, {t(errors[field.name]?.toLocaleString())} does not work. import { FieldProps, FormikErrors } ...

Styling Angular2 Material Dialog: the perfect fit

The Angular2 material team recently unveiled the MDDialog module at https://github.com/angular/material2/blob/master/src/lib/dialog/README.md I am interested in customizing the appearance of Angular2 material's dialog. Specifically, I want to adjust ...

The error "modules[moduleId] is undefined" occurs when running `ng build --watch

Currently, I am experimenting with the ng build --watch feature in Angular to make changes to my views without manually rebuilding each time. Although I encountered no errors when initiating it, upon accessing my website, I faced different console errors ...

Is it possible to invoke JavaScript code from TypeScript?

I'm struggling with calling a JavaScript file from TypeScript. After resolving one import issue and adjusting the base function for tsc recognition, I'm now stuck on recognizing a declared function prototype in the JavaScript file. Although I ha ...

Guide to incorporating ThreeJS Collada loader with TypeScript / Angular CLI

I currently have three plugins installed: node_modules/three My Collada loader was also successfully installed in: node_modules/three-collada-loader It seems that the typings already include definitions for the Collada loader as well: node_modules/@ty ...

Using CSS to create hover effects for specific classes of elements

Is there a way to make the button change color on hover when hovering over anywhere in the navigation bar (.topNav) instead of just when hovering over the individual button elements (.top, .middle, .bottom classes)? I tried using span to achieve this, but ...

When importing Next.js but failing to call the function, an error is thrown: "Module not found: Error: Unable to resolve 'dns'"

Everything was running smoothly with my NextJS project until I suddenly encountered a ModuleNotFoundError issue, specifically related to dynamic routing in NextJs. The error message I am seeing is: Module not found: Error: Can't resolve 'dns&apo ...

Struggling to reach the same level of bundle optimization with webpack + angular when compared to angular-cli

I am currently facing an issue with two Angular projects that I have. One is developed using angular-cli, while the other one is built with Webpack and utilizes @ngtools/webpack. Both projects are based on Angular 7.1.4 and @angular-devkit 0.13.5. The code ...

Having trouble getting my specialized pipe (filter) to function properly in Angular 2

I have implemented a custom pipe for filtering data in my table. Oddly, when I enter a search string into the input box, it correctly prints 'found' in the console but no rows are displayed in the table. However, if I remove the pipe altogether, ...

Angular Bootstrap Datepicker provides us with a date object, but I need it in the Date format

My desired date format is "Wed Aug 07 2019 16:42:07 GMT+0530 (India Standard Time)", but instead I am receiving { year: 1789, month: 7, day: 14 } from ngbDatepicker. Any assistance on resolving this issue would be greatly appreciated. ...