I've been working on setting up .d.ts definitions for a JavaScript project in order to enable auto-completion in Intellij IDEA.
Here is an example of the JavaScript code I'm currently defining:
var testObj = {
tests: function (it) {
it("Should...", function (screen) {
})
}
};
The goal is to have auto-completion for the 'screen' callback parameter.
I managed to achieve this by adding JSDoc comments that reference the .d.ts interfaces:
var testObj = {
/** @param {function(*,function(TestNamespace.IScreen))} it */
tests: function (it) {
it("Should...", function (screen) {
})
}
};
and
var testObj = {
tests: function (it) {
it("Should...",
/** @param {TestNamespace.IIt} it */
function (screen) {
})
}
};
The issue with the first approach is that it feels overly complex and can possibly be simplified using something like
/** @param {TestNamespace.IIt} it */
, but linking to this interface causes the 'screen' object to lose its relevant auto-completion capabilities.
The problem with the second method is that the comment needs to be repeated for every 'it' block created.
Therefore, my aim is to utilize the first method without the lengthy JSDoc comment, opting instead for a shorter comment linking directly to the TestNamespace.IIt
interface. I suspect there may be an error in how I defined the IIt interface, but I am struggling to identify it. I hope there is a way to achieve what I desire. Any assistance would be greatly appreciated!
A condensed version of my current .d.ts file looks like this:
export = TestNamespace;
declare namespace TestNamespace {
export interface IIt {
(description: string, callback: (screen: IScreen) => void): void
}
export interface IScreen {
doSomething(): void
}
}