Skip to content

Typing for getRedirectionURL should allow synchronous methods #907

@daedalus28

Description

@daedalus28

The typing for getRedirectionURL requires the method to be async, but it doesn't need to be (case in point - one of the official examples defines it synchronously.

When trying to do this in a typescript project, it errors out:

Image

Marking it as async anyway leads to a ts-lint violation for require-await which is part of tslint's recommendedTypeChecked. It's also technically worse for performance because it creates an extra promise (albeit negligible). Right now, it means all users of this library that use typescript with the recommended settings for ts lint have to suppress this with a comment, disable the rule, or add an extraneous code like an extra Promise.resolve. None of these are great options.

I'm not super familiar with this codebase, but after poking around, I think all that's necessary is to change the code here https://github.com/supertokens/supertokens-auth-react/blob/master/lib/ts/recipe/recipeModule/utils.ts#L15

from

getRedirectionURL = async (_: unknown): Promise<string | undefined | null> => undefined;

to

getRedirectionURL = (_: unknown): string | undefined | null | Promise<string | undefined | null> => undefined;

You can also use a utility type like type-fest's Promiseable to make it more concise:

getRedirectionURL = (_: unknown): Promiseable<string | undefined | null> => undefined;

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