Home > Mobile >  adding a property in a class inside d.ts file inside node_modules typescript
adding a property in a class inside d.ts file inside node_modules typescript

Time:04-05

There is a class called 'Game' inside phaser.d.ts file inside node_modules/phaser.

I want to add an extra property 'GLOBAL' to the class 'Game' without touching node_modules.

how can I achieve it?

CodePudding user response:

You could use whats called augmentation which would look to something along the lines of :

https://codesandbox.io/embed/typescript-playground-export-forked-55dnzo?fontsize=14&hidenavigation=1&theme=dark

// global.d.ts
declare module 'phaser' {
    interface Game {
       GLOBAL: any;
    }
}

Hope that will help you

  • Related