Closed
Description
Does this issue occur when all extensions are disabled?: Yes/No
- VS Code Version: 1.73.0 (Universal)
- OS Version: Mac 12.5.1
Steps to Reproduce:
type A = () => 'a';
type B = () => 'b';
type Res1 = ReturnType<A | B>;
type Res2 = ReturnType<B | A>;
It's weird that above code run in vscode. I think the Res1
and Res2
is different. But they always keep same output. Sometimes they are 'a' | 'b'
, sometimes they are 'b' | 'a'
. I have to restart vscode window or restart ts server trying to get right output. Is this a vscode bug?
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
vscodenpa commentedon Nov 12, 2022
Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.73.1. Please try upgrading to the latest version and checking whether this issue remains.
Happy Coding!
Eve-Sama commentedon Nov 12, 2022
It still exist in
1.73.1
Eve-Sama commentedon Nov 12, 2022
I know they are same when used as union type. I wonder why the result is unstable? Different time display different sequence.
Okaretkina7 commentedon Nov 12, 2022
Eve-Sama commentedon Nov 12, 2022
Yes, it occur when all extensions are disabled. And it occur in my friends.
Eve-Sama commentedon Nov 12, 2022
It works fine in
IDEA
Dimava commentedon Nov 12, 2022
@Eve-Sama you didn't provide your TS version, and it's 3.x?
Eve-Sama commentedon Nov 12, 2022
"typescript": "^4.8.3"
Eve-Sama commentedon Nov 12, 2022
TypeScript version is
4.8.4
via package.json from node_modulesDimava commentedon Nov 12, 2022
try
It seems that I can't make an array with different ones, but the order depends on which one was instantiated earlier
Eve-Sama commentedon Nov 13, 2022
This bug lead to this trouble.
IllusionMH commentedon Nov 14, 2022
TS doesn't provide any guarantees about union members order. Always been this way.
Basically duplicate of #17944
Eve-Sama commentedon Nov 14, 2022
But why random?
Dimava commentedon Nov 14, 2022
@Eve-Sama not "random", but "instantiation order"
It's not sorted, and the first result is considered to be correct
Eve-Sama commentedon Nov 15, 2022
If it's ts's feature, Why it works fine in IDEA?
fatcerberus commentedon Nov 16, 2022
I think IDEA uses its own language service that's based on the official one but with enhancements/customizations so it doesn't always behave the same. Even so, this is just about display order -
A | B
andB | A
are exactly the same type to the compiler.Eve-Sama commentedon Nov 28, 2022
I have found how to make it works. Just need to add
as const
.