GamerTS Posted September 17, 2021 Share Posted September 17, 2021 Hi all, How does one add custom features to Pixi.JS in typescript with it complaining? Example: DisplayObject.prototype.myFunction = (){ //do stuff}; const c = new Container(); c.myFunction() //Does stuff TS complains about myFunction not existing on DisplayObject, but it DOES work, as if I litter my code with //@ts-ignore it complies fine. Obviously having //@ts-ignore isn't really a solution, but if it works in JS it should work in TS, but I'm not sure how. TIA. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted September 17, 2021 Share Posted September 17, 2021 (edited) /// <reference path="./global.d.ts"> then create global.d.ts nearby, with something like that: https://github.com/pixijs/layers/blob/master/global.d.ts Pixi exposes a number of interfaces in GlobalMixins for extending. Not all of them, but several that are usually used in plugins. It wasnt possible to move pixijs and plugins to TS+imports without this hack. Edited September 17, 2021 by ivan.popelyshev Quote Link to comment Share on other sites More sharing options...
GamerTS Posted September 17, 2021 Author Share Posted September 17, 2021 Outstanding! Thank you! ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.