pixijs / pixi-react

Write PIXI apps using React declarative style
https://pixijs.io/pixi-react/
MIT License
2.33k stars 177 forks source link

Incorrect TypeScript Type for `oldProps` in CustomComponent#applyProps #348

Closed mutewinter closed 5 months ago

mutewinter commented 2 years ago

Description

oldProps is defined here as oldProps: Readonly<P>,, however on first render it is an empty object. This can cause errors when attempting to access oldProps values on first render.

Steps to reproduce

  1. Create a custom component
  2. Define applyProps
  3. See invalid type for oldProps

Additional info

inlet commented 2 years ago

This is correctly, on initial render it doesn't have any old props on it.. we might set the type to something like Readonly<P> | undefined?

mutewinter commented 2 years ago

Currently it’s an empty object, which means it doesn’t throw when accessing one level deep props. But I agree with changing it to undefined is more clear. It would be a breaking change.