Skip to content

[Bug]: Type of loader should not allow to return undefined #10239

@jer-sen

Description

@jer-sen

What version of React Router are you using?

6.8.2

Steps to Reproduce

Write a function that return undefined or nothing in a loader of a route.

Expected Behavior

Type Script error.

This type

/**
 * Route loader function signature
 */
export interface LoaderFunction {
    (args: LoaderFunctionArgs): Promise<Response> | Response | Promise<any> | any;
}

should be rewritten

/**
 * Route loader function signature
 */
export interface LoaderFunction {
    (args: LoaderFunctionArgs): Promise<Response> | Response | Promise<string | number | boolean | symbol | object | null> | string | number | boolean | symbol | object | null;
}

Actual Behavior

No TS error, and so there will be an error at runtime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions