Skip to content

Union type member order switches #33605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cain-wang opened this issue Sep 26, 2019 · 3 comments
Closed

Union type member order switches #33605

cain-wang opened this issue Sep 26, 2019 · 3 comments

Comments

@cain-wang
Copy link

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?

@AnyhowStep
Copy link
Contributor

AnyhowStep commented Sep 26, 2019

It's just a thing that happens.

#29255

#29146

@cain-wang
Copy link
Author

Thanks a lot for the pointers! I've been searching a lot on the internet and even digging up TS code base to find an answer!!

@AnyhowStep
Copy link
Contributor

One more,
#32224

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants