Skip to content

Union type member order switches #33605

Closed
@cain-wang

Description

@cain-wang

We noticed TypeScript switches the order of the union type members in the error message. And we hope someone can shine a light on this. The error is for React Ref type.

The error message used to be:

"Type 'Ref<unknown>' is not assignable to type 'string | RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void) | null | undefined'."

Now it becomes: (RefObject and ((instance: HTMLDivElement | null) => void) switches)

Type 'Ref<unknown>' is not assignable to type 'string | ((instance: HTMLDivElement | null) => void) | RefObject<HTMLDivElement> | null | undefined

We did not change relevant code, but did add react-transition-group dependency.

What puzzles me is in @types/react, the ref type is defined as:

type Ref<T> = { bivarianceHack(instance: T | null): void }["bivarianceHack"] | RefObject<T> | null;

Why the order of the bivarianceHack and RefObject would switch all of sudden?

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