I'm trying to add a new function to an existing class Node
defined inside the namespace cc
. The namespace is declared as follows:
creator.d.ts
declare namespace cc {
...
export class Node extends _BaseNode {
...
}
...
}
And my extension function attempt looks like:
NodeExtension.ts
interface cc {
Node: {
getWorldPosition(): cc.Vec2;
}
}
cc.Node.prototype.getWorldPosition = function (this: cc.Node) {
return this.parent.convertToWorldSpaceAR(this.getPosition());
};
But I'm getting the error "Property 'getWorldPosition' does not exist on type 'Node'" when trying to set the function.
The creator.d.ts declaration file belongs to the game development framework Cocos Creator.