Skip to content

Handle null/undefined in keys -> getFn #800

Closed as not planned
Closed as not planned

Description

@codewitchio

Is there an existing issue or pull request for this?

  • I have searched the existing issues and pull requests

Feature description

When providing a getFn inside of the keys option, it requires a function that never returns null or undefined. It is defined as:

getFn?: (obj: T) => ReadonlyArray<string> | string

This is notably different from how getFn is defined inside the options object, which is as follows:

type FuseGetFunction<T> = (
  obj: T,
  path: string | string[]
) => ReadonlyArray<string> | string | undefined | null

Notice the addition of undefined | null in the return type, which is not present in the former example.

I've ended up having to add ?? "" in a lot of places using nested searches which gets annoying quickly. An example options object:

{
  keys: [
    { name: "name", weight: 1, getFn: (m) => m.user.name ?? "" },
    { name: "email", weight: 0.5, getFn: (m) => m.user.email ?? "" },
  ],
}

Desired solution

It would be nice if I could instead provide the following options object:

{
  keys: [
    { name: "name", weight: 1, getFn: (m) => m.user.name },
    { name: "email", weight: 0.5, getFn: (m) => m.user.email },
  ],
}

Alternatives considered

I've tried to make a helper function inside my project that solves it, but it turned out very inelegant to iterate through the options object and modify the functions.

Additional context

No response

Activity

  1. changed the title [-]Support null/undefined in `keys` -> `getFn`[/-] [+]Handle null/undefined in `keys` -> `getFn`[/+] on Apr 30, 2025
  2. github-actions commented on Aug 29, 2025

    @github-actions

    This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 30 days

  3. added a commit that references this issue on Apr 2, 2026
    d33b735
  4. krisk commented on Apr 2, 2026

    @krisk
    Owner

    Fixed in d33b735. Key-level getFn can now return null or undefined — no more need for ?? "" workarounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions