How can a TypeScript sub-module be incorporated into a module that is not written in TypeScript?

I have a private typescript module that serves as a dependency for a larger project. This dependency is established by including the typescript repository as a submodule and then installing it using npm into a local sub-folder. The typescript module compiles into JavaScript in its dist folder, allowing the major project to utilize it seamlessly. However, there's an issue - the dist folder is not included in the typescript repository.

What would be the most efficient workflow for consuming this typescript module from a JavaScript-only major project? Currently, my best solution involves manually running the $ tsc command before using the major project, which can be seen as cumbersome since it's not a transparent process. If there is a better approach out there, please share your insights. Thank you!

Answer №1

If you're faced with this decision, there are a few routes you can take.

  1. One straightforward option is to include the dist folder in your repository unless you plan on setting up a private npm registry like Verdaccio. While not uncommon, it's an easy solution that may work best for your needs.
  2. An unconventional yet effective approach involves adding a postinstall script in your TypeScript package's package.json file to trigger the tsc compiler after installation. This method does require adding typescript as a dependency, which may not be ideal since it should typically be a dev dependency, but it could still be a viable choice for some scenarios.

  3. Alternatively, instead of installing the package directly, you could utilize npm link and include a compilation script in your main project to handle compiling when changes occur. You might consider integrating it into your existing scripts like

    "start": "npm compile-package && webpack"
    , although this method may not be scalable in the long run.

  4. For projects using Babel, especially larger ones, adjusting the configuration to transpile TypeScript using

    @babel/plugin-transform-typescript
    is another option. Keep in mind that certain setups such as projects created with create-react-app might have limitations regarding recompiling code from node_modules.

While there may be other solutions out there, weighing options 1 or 2 could be the way to go.

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

React Native automatically triggers the onPress event when using withNavigation

It seems that onPress should only be triggered by a touch event. Initially, this was the case, but when using withNavigation in a screen outside of the StackNavigator, onPress appears to render automatically. HomeScreen.js function mapStateToProps(state) ...

Angular: Comparing the Performance of Switch Statements and Dictionary Lookups

Having trouble deciding between two options for parsing URL parameters? Both seem suboptimal, but is there a better way to handle this situation? If you have any suggestions for a plausible Option #3, please share. Let's assume we are dealing with up ...

Showing the number of guilds as an action displayed on the screen

I'm trying to make my bot say "Watching (number of servers it's in) servers!" with this code: const activities_list = [ "with the &help command.", "with the developers console", "with some code", "with JavaScript", client.guilds. ...

Managing DOM Elements After Loading

Recently, I've been experimenting with Rainbow.js for syntax highlighting. One issue I encountered is that when I load a page using pagination navigation (#page2) into the body, Rainbow.color() fails to color the syntax inside pre-defined pre tags. In ...

Experiencing CORS issue on the frontend while using Django backend

I am currently accessing a Django REST POST API http://127.0.0.1:8000/api from my frontend located at http://127.0.0.1:5500/index.html. I have set up django-cors-headers and ensured that the frontend's image_upload.js, backend's settings.py, view ...

Using XmlHttpRequest to send a zipped file created with JSZip in JavaScript

I'm currently working on a web application where I need to generate a set of files based on user input, zip them using the JSZip library, and then post these files to a server using XHR. The code snippet for this functionality is as follows: var cont ...

Example of sending a POST request using Ajax

Can someone assist me in understanding ajax requests better with a simple example? I attempted to test an ajax request to search the word "rails" on GitHub, and my code looks like this: $.ajax({ url: 'www.github.com', type: 'post', con ...

issue with displaying content with useEffect hook

Displaying a list of coupons based on the selected category using useEffect and saga. const initialState = { is_loading: true, coupon_data: [], error_msg: '', } This is the initial state. is_loading is set to true by default so that ...

Cost calculation algorithm in javascript

Currently struggling with creating a code that my friend and I were assigned. The task is to calculate and return the average of all values in an array called customerBalance. This array represents the amount customers owe my fictional business, with each ...

Enhance the type declarations in Angular using TypeScript

I have been working on creating a TypeScript definition file for the angular-q-extras library You can view the full definition file I have written here This definition file includes a few methods added to the IQService interface: declare var _: string; ...

Exporting Datatables to excel does not remove HTML tags as expected

I recently implemented a data tables export button on my data table. Some of the columns in this table contain HTML tags, such as: <button data-toggle="dropdown" class="btn btn-primary dropdown-toggle btn-xs">BUTTON NAME</butto ...

What is the best way to retrieve a list of unchecked checkboxes in a Razor Page model?

Currently, I am working on a razor page using .NET Core 7. I have encountered an issue where I am unable to pass values of 1, 2, and 3 for unchecked checkboxes from the HTML page to the page model in the post method. When the user clicks the submit button ...

AngularJS Facebook Events is a platform that combines the power

Looking to incorporate AngularJS to showcase public Facebook events on a website. Discovered this helpful resource while searching online:- Followed the steps precisely, but I am unsure about how to obtain an "access token". Despite registering as a devel ...

Modify select options using JavaScript without losing the selected choice

I am attempting to update the options list of a select element using JavaScript and jQuery while retaining previously selected values. Below is the code I am using: var temp = $('#SelectName').chosen().val(); select = document.getEleme ...

`Trouble with javascript, ajax, and PHP - insert onSubmit is not functioning properly and POST is

Currently, I am attempting to perform an insertion into my MySQL database using an onSubmit() function. The main part of my function works as expected. However, there is a persistent issue where a '1' is being inserted into the field of logbook_i ...

Protractor - How to Locate Ui-Sref Links

I am encountering an issue while trying to detect the links in the following HTML code. Despite installing linkUiSref through npm, I continue to receive an error stating "object has no method linkUisref." Any suggestions on how to resolve this? element(by ...

Utilize the circliful jQuery plugin within an Angular project

I am currently working on incorporating the jQuery plugin "circliful" into my Angular application. In order to make the circliful graph function properly, I need to define data attributes like: <div id="chart" data-text="30%" data-percent="30">< ...

Issue #2032: AJAX causing OpenFlashChart error; solution found with PHP

Greetings! I've been experimenting with OpenFlash-Chart, and while some PHP graphs are showing up correctly, I encountered an error in my latest JavaScript code: Open Flash Chart IO ERROR Loading test data Error #2032 The URL I attempted to access: . ...

minimize the size of the image within a popup window

I encountered an issue with the react-popup component I am using. When I add an image to the popup, it stretches to full width and length. How can I resize the image? export default () => ( <Popup trigger={<Button className="button" ...

JS form submission problem

Seeking advice on developing a functional contact form using HTML, CSS, and JavaScript. All conditions currently validate properly, but encountering an issue with error messages persisting after re-entering the required fields. Additionally, looking to red ...