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?