Skip to content

flatten accepts null/undefined type #187

@jonathanmhcai

Description

@jonathanmhcai

The signature flatten<T, R>(target: T, ...): R leaves T unconstrained, so TypeScript lets you pass null | undefined. However, at runtime the function expects an object and crashes.

Reproduction: https://playcode.io/2592924

Ideally this is prevented at compile time, by constraining T:

export function flatten<T extends object, R = Record<string, unknown>>(
  target: T,
  options?: FlattenOptions
): R;

Related: #185

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions