After executing the tsc
command to compile my project into the dist
directory, I noticed that typescript is generating an incorrect or empty d.ts file.
Here is a snippet of my tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es2020",
"moduleResolution": "Node",
"noImplicitAny": true,
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"outDir": "dist",
"strict": true,
"declaration": true,
"declarationMap": true
},
"lib": ["es2020"],
"compileOnSave": true,
"include": [
"src"
]
}
This code snippet represents my src/index.ts
:
class Test {
method = (string: string) => {
console.log(string)
}
}
module.exports = Test
Upon running the $ tsc
command, the resulting content in my dist/index.d.ts
file is as follows:
export {};
//# sourceMappingURL=Test.d.ts.map
Although importing the package into another project as an npm dependency works without issues, when attempting to import Test
and calling
const test = new Test; test.method('hello world')
, it's evident that there is an issue with the .d.ts file generated.
I'm currently utilizing typescript v4.0.5