-
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
Typescript: Pass an extra parameter #6963
Comments
I'd say the documentation is wrong / out of date. The error you are seeing is an example of #3823. It would have worked before that PR, which landed in v1.6. |
This is in the spec, not the docs, just for tagging clarification. |
As pointed by the Stackoverflow answer below code fixes the problem
This is not given in spec. Is this a feature or the implementation has been changed as a part of progression. |
It's a cast - casting is in the spec, and it's a feature. Just remember that a cast is basically you overriding the compiler and saying "this is the type of this thing at this position", and so its mostly your responsibility to make sure it's valid to cast in a given situation. |
A "nicer" way to "fix" the types and allow passing an argument with extra members would be modifying the signature of function getX<T extends Point>(p: T) {
return p.x;
} Though it may not be immediately obvious how this is any different, this alters inference to allow for any subtype of Point to be passed as an argument, bypassing the "strictness" check added in 1.6. |
for future references, more information about strict object literal checking can be found at https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#strict-object-literal-assignment-checking |
I was trying the below code from the documentation
As per the code comment says below line should be ok.
getX({ x: 0, y: 0, color: "red" }); // Extra fields Ok
But i am getting error as below:
But the below code works well which i re-wrote in which i made params as optional:
Please can somebody help me out if the documentation is wrong or am i missing something here
FYI i am using:
Same is been asked in stackoverflow:
I have attached the screenshot FYI.
The text was updated successfully, but these errors were encountered: