dts-generator
dts-generator copied to clipboard
generated bundle is empty
I'm attempting to build definition files for the following external modules:
// ClassA.ts
export class ClassA {
public method() {
return true;
}
}
// ModuleB.ts
import {ClassA} from './ClassA';
export interface IModuleB {
ClassA: typeof ClassA
}
export var moduleB: IModuleB = {
ClassA: ClassA
};
// ModuleA.ts
import {moduleB, IModuleB} from './ModuleB';
export interface IModuleA {
moduleB: IModuleB
};
export var moduleA: IModuleA = {
moduleB: moduleB
};
With the following dts-generator config:
grunt.registerTask('default', ['copy:main', 'ts', 'dts']);
grunt.task.registerTask('dts', 'dts', function() {
require('dts-generator').default({
name: 'package-name',
project: 'src',
out: 'package-name.d.ts',
//src: [ 'build/**/*.ts' ], // I've tried both src & files options
files: grunt.file.expand(['./build/**/*.ts'])
});
});
As you can see above, I've tried using both src, and files, as well as providing my files via my tsconfig (which resides in src/
).
I can't spot anything that I'm doing incorrectly - does anyone have any idea what I'm missing?
Is your tsconfig.json in the src directory? if it is in the root, then try project='.'. If you don't want to use the tsconfig.json then don't supply a project property. Let me take a look at my modified file to see if you have that option to not include one.
Ok, if you supply the project then it will try to load everything from the project file and uses the typescript parseJsonConfigFileContent to populate the files property of the options. If not it uses 'files' property.
Yeah, my tsconfig.json
is in src. I tried adding files to my tsconfig.json
as follows:
{
"compilerOptions": {
...
},
"files": [
"./ClassA.ts",
"./ModuleA.ts",
"./ModuleB.ts"
]
}
And my dts-generator config as follows:
require('dts-generator').default({
name: 'package-name',
project: 'src',
out: 'package-name.d.ts',
src: [ 'build/**/*.ts' ]
});
And I'm getting an empty package-name.d.ts
.
I've also tried specifying files as you mentioned and I'm still having no luck:
require('dts-generator').default({
name: 'package-name',
out: 'package-name.d.ts',
baseDir: '.',
files: [
'src/ModuleA.ts',
'src/ModuleB.ts',
'src/ClassA.ts'
]
});
Note that my Gruntfile.js
sits in the project root, I'm setting the baseDir
to my project root, and I'm providing file paths relative to my project root - all as documented (as far as I can tell!). I'll try to download a node deugger to see if I can find out what's going wrong.
In all tools similar to dts-generator seems to have the problem with interfaces :(