Skip to content

Use undefined instead of void #26

@davewasmer

Description

@davewasmer

It looks like the loading utility hook types the value property as void. This makes it difficult to work around potential edge cases in the code:

  let [ user, userIsLoading, userError ] = useAuthState(firebase.auth());
  if (userIsLoading) {
    return null;
  }
  // do something with user ...
  user.someProperty; // <- errors with "someProperty doesn't exist on type void | User"

The problem here is that, because user is typed as possibly being void (which is different from undefined), I can't even do something like user!.someProperty to assure TS that the variable will have a value.

I think the fix here is to switch to undefined as the fallback type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions