pixijs / layers

Separate the z-hierarchy of your scene tree from its canonical structure.
https://pixijs.io/layers/docs/
MIT License
224 stars 57 forks source link

TS error: Can't assign Layer to Container #72

Closed tustin2121 closed 3 years ago

tustin2121 commented 3 years ago

I'm getting a lot of annoying TypeScript errors in my project when I attempt to use the @pixi/layers package with Pixi.js 6.0.4. This seems to be the root cause in https://github.com/pixijs/pixi-layers/blob/master/index.d.ts#L79

Property 'renderCanvas' in type 'Layer' is not assignable to the same property in base type 'Container'.
  Type '(renderer: ILayeredRenderer) => void' is not assignable to type '(renderer: CanvasRenderer) => void'.
    Types of parameters 'renderer' and 'renderer' are incompatible.
      Type 'CanvasRenderer' is missing the following properties from type 'ILayeredRenderer': _lastDisplayOrder, _activeLayer, incDisplayOrder, _oldRenderts(2416)

I'm unsure how to fix this problem as I'm new to TypeScript (and am ready to abandon it shortly with how much of a pain it's been over normal js so far, tbh...).

EDIT: Commenting out the line makes the error go away. I'm sure that's not how this is supposed to be fixed, but that's a workaround I guess for now...

NotAmaan commented 3 years ago

I keep getting that error too. Its not really typescript's fault, just a type incompatibility between PIXI's default stage (PIXI.Container) and the Stage offered by pixi-layers.

Instead of commenting out something in a dependency (your change would be gone on next npm install), you could add // @ts-ignore one line before error (there would be a few more)

ivanpopelyshev commented 3 years ago

Oh, that's a new bug I have introduced :) gonna fix it

ivanpopelyshev commented 3 years ago

published 1.0.6 , plesae try again

tustin2121 commented 3 years ago

That did indeed fix the problem. Thanks!

Instead of commenting out something in a dependency (your change would be gone on next npm install), you could add // @ts-ignore one line before error (there would be a few more)

Oh I'm fully aware of how dependancies work. I'm not new to the NPM game, just TS specifically. And I was irritated that I would have had to put a @ts-ignore on like five consecutive lines because every time I added another Layer to the Stage, ts was throwing the error. (And it was nearly midnight and I was cranky, and I've already had quite a few more annoyances with ts than this.)

But anyway, thanks for the fast response.