-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Do not report excess property errors on spread #19775
Comments
Why is this a bug? I'm using this to get excess property checking to work when assigning an object of one type to another.
Are there any other workarounds to get EPC when you aren't using object literals? |
cause the error here is not correct really. types are open in TS, so you can easily defeat the check here, and you do not get the error elsewhere either.. e.g. const x = { a: 0 , b: 0 } ;
const y : { a: number } = x; // no error
const z: { a : number } = { ...x } // error.. why? |
Makes sense that this inconsistency should be fixed. Is there any workaround to force excess property checking in the case when you do want it? |
This is tracked by #12936 |
We're running into this issue. I'm confused by your original comment though.
Did you mean it does error on x? |
the contents of |
* Unify JSX Call Checking Codepaths * Add tests for fixed issues * Fix lint, move all error checking into the only-run-once resolveSignature call * Remove unused (unreachable?) code path * Consolidate a little more duplicated logic into signature checking * Fix #19775 a bit more * Cosmetic changes from CR
@mhegazy I have a question/concern about this. If using the spread operator is not going to report excessive property checks, this makes the new object dangerous do use. For example, you can have a |
@ktalebian this behavior is not unique to the spread operator. If you changed your example to just As mentioned above, types are open in TypeScript. This is a design decision. But there’s a proposal (#12936) for the behavior you’re looking for. |
The result of a spread operator should not contribute to the excess property checks. only the properties listed in the object literal should be checked. i.e.:
The text was updated successfully, but these errors were encountered: