When I use intellisense with the following code snippet, everything works perfectly:
test.d.ts
:
export interface ITest {
foo: string;
setFoo(foo: string): ITest;
}
export as namespace JSDoc;
test.js
:
/** @typeof {import("./test")} JSDoc */
/**
* @returns {JSDoc.ITest}
*/
function test() {
return {
foo: "",
setFoo: function (foo) {
this.foo = foo;
return this;
}
};
}
exports.test = test;
However, when I uncomment the //this.foo = this.foo;
line, a warning is generated on the object returned by the test
function:
Type 'typeof setFoo' is not assignable to type '(foo: string) => ITest'. Property 'setFoo' is missing in type 'setFoo' but required in type 'ITest'.ts(2322) test.d.ts(3, 5): 'setFoo' is declared here. test.d.ts(3, 5): The expected type comes from property 'setFoo' which is declared here on type 'ITest'
Additionally, a screenshot of the issue can be viewed below:
https://i.sstatic.net/iHe7N.png
Any thoughts on why this occurs and how I may resolve it?