-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
3.4 regression for type argument inference #30390
Comments
Error is
|
Ah, yes, the common bug of us inferring literal types where we really shouldn't. |
(thanks, I had to run to catch a bus) |
We now make inferences from generic return type positions (#29478), so the A simpler example of the same issue: declare function capture<T>(f: () => [T]): [T];
let x1: [{ success: boolean }] = capture(() => {
return Math.random() ? [{ success: true }] : [{ success: false }];
}) Interestingly, this very similar example doesn't have an issue: let x2: [{ success: number }] = capture(() => {
return Math.random() ? [{ success: 0 }] : [{ success: 1 }];
}) The reason is that a contextual type We could attempt to track whether all occurrences of |
I'm not sure if this is the same issue or not: class Base {}
class Foo<T> extends Base {
constructor(value: T, fn: (value: Foo<T>) => void) { super(); }
}
const foo = new Foo(5, (f: Foo<number>) => {});
// foo has type Foo<5>
const bar = new Foo(5, (f: Foo<number> & Base) => {});
// bar has type Foo<number> |
Found trying to compile VS Code at https://github.com/Microsoft/vscode/blob/1ce2b64abb08ed7998a5a6697ba0248a51934605/src/vs/workbench/services/textfile/common/textFileService.ts#L294-L338
Isolated repro:
The text was updated successfully, but these errors were encountered: