I've been working on generating d.ts files for my library, and below is the content of my tsconfig.json
.
{
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"declarationDir": "dist/typings",
"target": "es5",
"diagnostics": true,
"lib": [
"es5",
"es6",
"dom"
],
"noEmitOnError": true,
"noImplicitAny": true,
"noImplicitThis": false,
"noUnusedParameters": false,
"noUnusedLocals": false,
"experimentalDecorators": true
},
"include": [
"src/**/*",
"typings/**/*.d.ts"
],
"exclude": [
"node_modules"
]
}
Additionally, here's a snippet of the source code:
// script.ts
import { Application } from "../application";
export class ScriptType { }
export function createScript(ScriptConstructor: typeof ScriptType) {
return (app: Application) => {
// do something;
return ScriptConstructor;
}
}
// orbitCamera.ts
import { createScript, ScriptType } from "../script";
class OrbitCamera extends ScriptType { }
export default createScript(OrbitCamera);
After running tsc
to generate d.ts
, I encountered the following output:
$ cat dist/typings/scripts/camera/orbitCamera.d.ts
import { ScriptType } from "../script";
export declare class OrbitCamera extends ScriptType {
...
}
declare const _default: (app: import("../../../../../../../Users/u/Projects/p/src/application").Application) => typeof ScriptType;
export default _default;
However, this result seems to be problematic as referencing this generated d.ts
file in another project could lead to a Cannot find name 'import'
error.
How can this issue be resolved? Any suggestions or solutions would be greatly appreciated. Thank you.