-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Inconsistent TS2345 error when using function generics #50818
Comments
The correct behavior is for there to be no error here: excess property checks arenβt intended to apply to generic constraints. |
@fatcerberus you are right, I've updated the issue description. |
This looks similar to some other bugs we've seen reported where weird errors show up while typing |
I also encounter the similar situation when passing function paramter in different ways.(typescipt version 4.1.3) interface AAA {
hyYears: Array<any>;
}
function func(process: AAA) {
console.log(process);
}
const unresolveParams = {
hyYears: [],
periodDataId: 1,
};
func(unresolveParams); // why this line can't detect the extra parameter
func({
hyYears: [],
periodDataId: 1, // ts(2345) detect the extra parameter. Argument of type '{ hyYears: undefined[]; periodDataId: number; func(unresolveParams: any): any; }' is not assignable to parameter of type 'AAA'
}); |
If only I bisected this correctly, the regression has been introduced by #36747 |
@JonathonChen your case is not a bug, you can learn more about this here |
@Andarist How did you happen to reproduce this? Just using the editor or did you manage to get a test working? (I so far have not...) |
I was using the editor with TS built from different commits. I was doing that within the TS repo itself so I could pretty easily jump between commits/builds |
Darn π I haven't yet found the right fourslash calls to get this reproducing, so into the server RPC logs I go... |
Got it: ////declare function func<T extends { foo: 1 }>(arg: T): void;
////
////func({ foo: 1, bar/*1*/: 1 });
goTo.marker("1");
edit.insert("2");
verify.completions({ exact: undefined });
verify.noErrors(); (I spent all that time figuring out how to assert in fourslash that there are no completions so I could perform the request.) |
You may interested in a similar issue I filed in the realm of "errors that only show up while typing": #51661 I don't know if it's the same underlying cause, or if my brief investigation into it was way off the mark or not, but food for thought. |
Amazing! π |
I ran into similar issue, initially with generics, but the simplified to even without generics. I am still not sure what was causing inconsistencies in different situations, but I did find that having a property with the name "name" seemed to cause the error reporting, I dont know if word is reserved or something, either way thought would share if its useful at all https://www.typescriptlang.org/play?#code/FAFwngDgpgBAsmA8gIwFZQMYhgXhgb2GBhgCcoBDAEwHsA7AGzBgDcKGBXKAZwC4DiJMpVqNmdCgFso-biFIBLOgHMA3IIC+6rUQz05MACIBBACrH+CFOiy4BJNpx79CQmBOn8ARI65eANJqBOrr62NxQIADCFNg4ggAUvjLwSGiYIADaPuxc3F4AugCUuAB8iRR0CpLsfKnWGUWWaTZxpTAJrkIAdL2V1bWBbsl1yUMwGkXqwHp0BgDuNKQA1tx2EdGxnR4yXnRQ8zAYsV6ToXPhABY0HAxUABIULFAAoqSkS+uRMSAJCSU4dr-ModAFA-DuKQpPYHGAANVyUC8EyKRQSJnMUyIQA |
I see no error in the above snippet, so if you're having a problem and can reproduce it without generics, I would suggest making a new issue as that's very likely different. |
Great thank you, before I create an issue I would appreciate if you could take a glance at It's a little clearer than the above one but same thing. The fact there is no error is the issue as I understand, it should not accept function, but seems to when field is called 'name', just to make sure its not something already known. Thanks |
Nice, thanks for clarifying, feel free to hide or delete my posts if useful, cheers. |
Bug Report
π Search Terms
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
bar
property sometimes displayed as valid and sometimes produce an error:When playing with the code live and change
bar
tobar222
orba
sometimes the error shown and sometimes not.Refreshing the playground link with the changes always remove the error.
Screen.Recording.2022-09-17.at.20.20.57.mov
π Expected behavior
Always display as valid without any error.
{ foo: 1, bar: 1 }
is a valid subtype of{ foo: 1 }
and so can legally be used to instantiateT
.Maybe related to #49490
The text was updated successfully, but these errors were encountered: