Another project cannot import the library that was constructed

I am in the process of creating a library that acts as a wrapper for a soap API. The layout of the library is structured like this:

|-node_modules
|
|-src
|  |-soapWrapperLibrary.ts
|  |-soapLibraryClient.ts
|
|-types
|  |-soapResponseType.d.ts

The library utilizes the client, which generates an object called soapResponseType that I have defined.

This library will be employed in another internal project, with no intention of pushing anything to npm or similar platforms. After attempting to compile it using tsc, I encountered an issue where the compilation ignored the custom type I had specified (soapResponseType.d.ts). Consequently, an error arose while importing my library due to the absence of the definition file.

I experimented with various approaches related to compiled types and utilized typeRoots without success.

My expectation from tsc is for all my files to be compiled into a single bundle or something cohesive that can be imported as a complete entity, incorporating both types and classes.

Despite applying specific settings, the resulting structure only reflects the following, devoid of any trace of soapResponseType.d.ts:

|-dist
|  |-lib
|  |  |-soapWrapperLibrary.js
|  |  |-soapWrapperLibrary.js.map
|  |  |soapLibraryClient.js
|  |  |soapLibraryClient.js.map
|  |-types
|  |  |-soapWrapperLibrary.d.ts
|  |  |soapLibraryClient.d.ts

Upon running the command tsc --listFiles, it displays the three files I created: two .ts files and one .d.ts file

A repository demonstrating the issue can be found here: https://github.com/TheoSl93/buildLibraryTest

Here are my tsconfig.json and package.json:

tsconfig

{
  "compilerOptions": {
    "target": "es5",
    "module":"es2015",
    "strict": true,
    "declaration": true,
    "outDir": "dist/lib",
    "declarationDir": "dist/types",
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "removeComments": true,
    "sourceMap": true,
    "baseUrl": ".",
    "paths": {
      "@/*": [
        "./types"
      ]
    },
    "lib": ["es2015", "es2016", "es2017", "dom"],
    "emitDecoratorMetadata": true,
    "typeRoots": [
      "node_modules/@types",
      "types/*"
    ]
  },
  "typedocOptions": {
    "mode": "modules",
    "out": "docs",
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "test/**/*.ts",
    "test/**/*.tsx"
  ],
  "exclude": [
    "node_modules",
    "test"
  ],
}


package

{
  "name": "soap-library",
  "version": "0.0.1",
  "description": "reproduction for stackoverflow",
  "main": "dist/lib/soapLibraryClient.js",
  "repository": "https://github.com/TheoSl93/buildLibraryTest.git",
  "author": "Theo Sloot",
  "license": "MIT",
  "scripts": {
    "prebuild": "rm -rf dist",
    "build": "tsc --module commonjs"
  },
  "sideEffects": false,
}

At this stage, I have the following questions:

  • Is there a method to include custom definitions during compilation solely using tsc?
  • Is this step necessary? Can the library be imported using just the .ts files rather than the compiled .js files?

Answer №1

If you want TypeScript to recognize your type definition file named soapResponseType.d.ts, simply rename it as soapResponseType.ts and place it in your types folder. This will automatically generate a new soapResponseType.d.ts with the same content as soapResponseType.ts, without requiring any transpilation. Additionally, remember to relocate your types folder into the src directory since your tsconfig is set up to compile only the files within the src folder.

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

Is there a way for me to modify the formatting of the text that I

Can you help me transform a text that looks like this: '?category=1,2&brand=1' into something like this: '?categories[]=1&categories[]=2&brands[]=1'? I'm not quite sure how to make this change. ...

Update text using jQuery without deleting child elements

I need to modify this particular text content: <body> <p class="server_info"> GT 64 ms <b>|</b> Time: <span id="serverTime">4:21:26</span> <span id="serverDate">11/03/2014</span> ...

What are the disadvantages of using getBoundingClientRect() in ReactJS?

I recently incorporated the getBoundingClientRect() method into my project. However, a fellow React developer expressed concerns about its browser compatibility. In theory, shouldn't Webpack or Babel handle such compatibility issues? ...

Error with the type of CanvasGradient in the NPM package for converting text to image

I attempted to generate an image using a specific text by utilizing npm's text-to-image package, but encountered an error during typescript compilation. The errors I encountered upon running the typescript compilation command are related to files with ...

Determining where to implement the API display logic - on the server side or

Currently, I am in the process of restructuring an API that deals with user profiles stored in one table and profile images in another. The current setup involves querying the profiles table first and then looping through the images table to gather the ass ...

"Attempting to dynamically include Components for SSR bundle in React can result in the error message 'Functions are invalid as a React child'. Be cautious of this

When working with my express route, I encountered an issue trying to pass a component for use in a render function that handles Server-Side Rendering (SSR). Express Route: import SettingsConnected from '../../../client/components/settings/settings-c ...

Error: The function being called in <class> is not recognized as a function

I have a unique situation with my component setup export class Component1Component implements OnInit { public greetings: string =""; constructor(private greeter: Greeter) { } ngOnInit() { this.greetings = this.greeter.sayHello(); } } The structur ...

React - Render an element to display two neighboring <tr> tags

I'm in the process of creating a table where each row is immediately followed by an "expander" row that is initially hidden. The goal is to have clicking on any row toggle the visibility of the next row. To me, it makes sense to consider these row pa ...

Utilize datetime values in chartjs ajax for data visualization

I'm currently working on creating a chart using chart.js. I have php code that retrieves datetime data through an ajax call. However, the chart is not displaying any data and there are no visible errors. I've checked the php code using console.lo ...

The rule 'import/no-cycle' definition could not be located

After removing my npm package along with the package.lock.json file, I proceeded to run 'npm install' and followed up with 'npm update'. However, upon starting my application using 'npm run start', an error occurred. Upon lau ...

Having trouble removing the npm package spotifydl from my system

After running the command npm install -g spotifydl, I discovered that the package was obsolete and no longer functioning properly. Subsequently, I attempted to remove it using npm uninstall -g spotifydl, but instead of completely uninstalling, it kept re ...

Bringing in data from <script> to use in <script setup>

To ensure unique ids for instances of a Vue component, I am using a simple generator to enumerate them. Typically, I would initialize the generator outside of the setup function like this: const idGen = generateIds("component:my-component"); export defaul ...

Guiding motion of a parental container using a button

This seems like a fairly straightforward task, but I'm getting a bit frustrated with it. Is there a way to move an entire div by simply holding down the mouse button on a particular button? let container = document.getElementById('abo ...

The click functionality is not functioning properly within the .each() loop

For my event handler, I am trying to use click() but it doesn't seem to be working. Here is the code snippet: $('.ajax-close').click(function( event ){ event.preventDefault(); alert('hi'); $( ' ...

Ways to customize the border color on a Card component using React Material UI

Is there a way to change the border color of a Card component in React Material UI? I attempted using the style property with borderColor: "red" but it did not work. Any suggestions on how to achieve this? ...

Adjust the width of the TinyMCE Editor to automatically resize based on the content being

Is it possible for TinyMCE to adjust the content within an absolutely positioned container and update the width while editing? <div class="container"> <textarea>This is my very long text that should not break. This is my very long text tha ...

Utilize Google Drive and scripts to incorporate map images into a React application

I'm currently working on setting up an album feature on my react website for a friend, and I would like the images in the album to be linked to a Google Drive so that he can easily upload new images whenever he wants. After successfully inserting the ...

Incorporating ngrx/Store into a current Angular application

Currently, I am working on an Angular 7 project that consists of numerous components communicating with an API to update data. The constant refreshing of the data using setTimeout has made it quite overwhelming as all the components are pulling data from t ...

Dealing with bulkWrites in Mongoose and MongoDB: how to handle cast errors with finesse

When importing data into my app's database using MongoDB's bulkWrite operation, I encounter a challenge. The data may contain errors as it comes from an external source. To maintain the integrity of my data, I need to update my collection while s ...

TS-2304 Error - 'Iterable' not found in TypeScript when trying to import 'jquery' into a '.ts' file

Currently, I am utilizing TypeScript version 2.4 in Visual Studio Code for development. My approach involved installing jQuery via NPM using the given command: npm install --save @types/jquery Subsequently, I obtained the source code for the jquery modul ...