What is the correct way to extend a namespace/module with babylon in TS?

well on first look it does look like it should work, but in typescript it’s sometimes the little nuances :slight_smile:

This is happening because of the way we export out declarations. This will work:

import { UniversalCamera } from "babylonjs";


declare module "babylonjs/Cameras/universalCamera" {
    export interface UniversalCamera {
        moveTo: (...args: any[]) => any;
    }
}

UniversalCamera.prototype.moveTo = (...args: any[]) => {
    console.log(args);
};

And this will work as well:

import { UniversalCamera } from "babylonjs";

declare module "babylonjs" {
    interface TouchCamera {
        moveTo: (...args: any[]) => any;
    }
}

UniversalCamera.prototype.moveTo = (...args: any[]) => {
    console.log(args);
};
2 Likes