-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Function param with generic type are not recognized correctly #23705
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
Comments
You need an explicit type argument here, because |
@Andy-MS shouldn't |
1 similar comment
@Andy-MS shouldn't |
I don't see a compile error in any of |
function test<T>(value1: T, value2: T) {
return value2
}
test({ a: 1 }, {}); @Andy-MS Just see this.
And it's strange that it works well if it is this: function test<T>(value1: T, value2: T) {
return value2
}
test(<{ a: number }>{ a: 1 }, {}); |
class Protocol<T>{ }
interface ReqTest {
abcde: string;
}
const PtlTest: Protocol<ReqTest> = new Protocol<ReqTest>();
function request<T>(ptl: Protocol<T>, req: T): T { return req; }
request(PtlTest, {}) @Andy-MS And even if I give |
I'll tentatively mark this as a bug due to the inconsistency in: declare function equal<T>(a: T, b: T): boolean;
equal("", 0); // Error
equal({ a: 1 }, { b: 2 }); // No error |
See more about the rationals here in https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#improved-type-inference-for-object-literals |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.7.0-dev.201xxxxx
2.8.3
Search Terms:
Code
Expected behavior:
Compile error.
Because
request(PtlTest, {})
, param 2{}
not matchReqTest
Actual behavior:
Compile success
Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered: