It appears that the type definition for the return value of useApplication is not really correct.
It returns ApplicationState which looks like this:
interface ApplicationState
{
app: Application;
// more stuff...
}
The problem is that the default value for the Application Context is set to an empty object ({}) and then cast to ApplicationState:
|
export const Context = createContext<ApplicationState>({} as ApplicationState); |
In my project, I have at many times seen an error thrown because I attempt to access app from the useApplication() call, but it is undefined at that time, despite the typings saying this is always set.
Please consider making changes so the typings are accurate. It's ok with me if I have to do an additional check to make sure I have an Application instance after my call to useApplication, but with the typings requiring me to do so. The empty object {} does not adhere to the interface.
Thanks!
It appears that the type definition for the return value of
useApplicationis not really correct.It returns
ApplicationStatewhich looks like this:The problem is that the default value for the Application Context is set to an empty object (
{}) and then cast toApplicationState:pixi-react/src/components/Context.ts
Line 4 in 30cf1f8
In my project, I have at many times seen an error thrown because I attempt to access
appfrom theuseApplication()call, but it isundefinedat that time, despite the typings saying this is always set.Please consider making changes so the typings are accurate. It's ok with me if I have to do an additional check to make sure I have an
Applicationinstance after my call touseApplication, but with the typings requiring me to do so. The empty object{}does not adhere to the interface.Thanks!