-
Notifications
You must be signed in to change notification settings - Fork 31
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
Config option for disabling shield errors on obsolete fields #81
Comments
Is there a TypeScript config to make this invalid? const userObj = { name: "foo", bar: 1}
myTelefunc(userObj) I wonder what TypeScript's rationale is for differentiating this from As for Telefunc, how can Telefunc tell the difference? |
I'm pretty sure that there is no config option to make this invalid. This behaviour was a conscious decision in the language design of typescript and is fundamental to a lot of the stuff build upon it. In general typescript types behave more like interfaces from languages like Go. The big surprise to me was that passing an object literal with an obsolete field is invalid. Maybe their rational was: If you are so explicit in passing it as a literal you most probably want to fully adhere to the type definition. Still feels weird to me though. I consider this an edge case as most of the objects you pass into a function are not literals. |
Makes sense.
To be honest, it seems quite an edge case. So I'm leaning towards making this lower priority. |
I agree that usecase is edge case'y but my proposed solution would help for all other cases also. My other three bugs had no localstorage involved just straight parameter passing and for these I also wished I had the proposed config option. |
I don't know if I find the time to do this but would you be open for a PR on this? |
Yes, I can see it to be fairly simple. (If it ends up being complex, keep in mind that I may reject if it's too time consuming for me to review.) |
Problem
Would solve #78.
The shields for telefunc's will throw validation errors when request parameters have fields defined that are not in the type definition. What makes this behaviour problematic is the fact that typescript is structurally typed, meaning it won't help you to find these bugs in the IDE. (if there is at least 1 level of indirection) See Example:
See TS playground.
Solution
I propose a new config option which makes the shields not throw validation errors for objects containing fields which are not part of the type definition. This would actually align the shields type validation behaviour with typescripts validation behaviour.
The text was updated successfully, but these errors were encountered: