Jump to content

Extending Objects [Typescript]


Recommended Posts

Hi all,

How does one add custom features to Pixi.JS in typescript with it complaining?




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.



Link to comment
Share on other sites

/// <reference path="./global.d.ts">

then create global.d.ts nearby, with something like that:


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 by ivan.popelyshev
Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...