-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Why TypeScript ReturnType returned sequence is unstable in vscode #51517
Comments
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! |
It still exist in |
I know they are same when used as union type. I wonder why the result is unstable? Different time display different sequence. |
Yes, it occur when all extensions are disabled. And it occur in my friends. |
@Eve-Sama you didn't provide your TS version, and it's 3.x? |
|
TypeScript version is |
try type A = () => 'a';
type B = () => 'b';
type C = () => 'c';
type D = () => 'd';
type x = [
// ^?
ReturnType<A | B>,
ReturnType<B | A>,
ReturnType<D | C>,
ReturnType<C | D>,
] It seems that I can't make an array with different ones, but the order depends on which one was instantiated earlier |
export type TestFn = <T extends ReadonlyArray<() => string>>(request: T, thenCallback: (data: ReturnType<T[number]>) => void) => void;
const fnA: () => 'a' = () => 'a';
const fnB: () => 'b' = () => 'b';
const fnC: () => 'c' = () => 'c';
const fnD: () => 'd' = () => 'd';
const fn: TestFn = (requestList, thenCallback) => {
console.log(requestList, `requestList`);
console.log(thenCallback, `thenCallback`);
};
fn([fnA, fnB, fnC, fnD], data => {
console.log(data, `data`);
}); This bug lead to this trouble. |
TS doesn't provide any guarantees about union members order. Always been this way. Basically duplicate of #17944 |
But why random? |
@Eve-Sama not "random", but "instantiation order" |
If it's ts's feature, Why it works fine in IDEA? |
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 - |
const fnA: () => 'a' = () => 'a';
const fnB: () => 'b' = () => 'b';
const fnC: () => 'c' = () => 'c';
const fnD: () => 'd' = () => 'd';
const fn: TestFn = (requestList, thenCallback) => {
console.log(requestList, `requestList`);
console.log(thenCallback, `thenCallback`);
};
fn([fnA, fnB, fnC, fnD] as const, data => {
console.log(data, `data`); // data: "a" | "b" | "c" | "d"
}); I have found how to make it works. Just need to add |
Does this issue occur when all extensions are disabled?: Yes/No
Steps to Reproduce:
It's weird that above code run in vscode. I think the
Res1
andRes2
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?The text was updated successfully, but these errors were encountered: