Skip to content

Application Context typings are inaccurate and can cause errors #645

@zenblender

Description

@zenblender

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions