Skip to content

Using typechecked typescript-eslint trips unbound-method lint on react-stately functions #8663

@jvliwanag

Description

@jvliwanag

Provide a general summary of the issue here

Consider the following use of react-stately useOverlayTriggerState:

function MyDialog(): React.ReactNode {
  let { open } = useOverlayTriggerState({}); // lint error here

  return (<div><button onPress={open}/></div>);
}

Typescript-eslint when configured with recommended typechecked config detects a potential error - unbound -method.

🤔 Expected Behavior?

No lint error.

😯 Current Behavior

Lint error unbound-method.

💁 Possible Solution

This is because the way the interface is written is akin to a class method:

export interface OverlayTriggerState {
    readonly isOpen: boolean;
    setOpen(isOpen: boolean): void;
    open(): void;
    close(): void;
    toggle(): void;
}

In fact, if we imagine that useOverlayTriggerState indeed return some class instance, say: new OverlayTriggerStateImpl, destructuring the result in let { open } = useOverlayTriggerState({}) would indeed be erroneous as this wouldn't be properly bound.

Granted, the actual implementation isn't a class and this doesn't really matter. To correct this however, we should be writing the interface as:

export interface OverlayTriggerState {
    readonly isOpen: boolean;
    setOpen: (isOpen: boolean) => void;
    open: () => void;
    close: () => void;
    toggle: () => void;
}

If it were written that way, then the unbound-method lint correctly passes.

🔦 Context

No response

🖥️ Steps to Reproduce

see summary

Version

@react-stately/overlays 3.6.18

What browsers are you seeing the problem on?

Other

If other, please specify.

No response

What operating system are you using?

n/a

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

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