-
-
Notifications
You must be signed in to change notification settings - Fork 487
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
Undefined properties on body object are not flagged if required fields are filled in #1769
Comments
This comment was marked as spam.
This comment was marked as spam.
First option: Using object spread can help catch extra properties!
Second option: Applying explicit type annotations forces TypeScript to perform a strict check!
|
Thanks, but it appears these workarounds still don't catch the issue. For example:
The |
@Elgueromiranda That defeats the purpose of |
Bitten by this today. I had a typo in an optional body parameter name that went completely unchecked. |
This is a great catch, and would welcome a PR for this. One suggestion is to move all type tests into a |
I spent several hours trying to figure this one out because I really want it fixed. The problem I've decided is that TypeScript does not have good tooling for debugging complex types like this. I can't, for example, set a breakpoint in a debugger and step through how types are propagating through generics (if such a tool exists, let me know). So it's just a lot of trial and error and it's a nightmarish debugging experience I got so frustrated that over the weekend I made an alternate implementation of openapi-fetch that uses code generation instead of generics like I alluded to in #1779 - I'm calling it typed-fetch. Should be API compatible with openapi-fetch minus some of the extra stuff openapi-fetch has that native fetch does not have (like middlewares). I'm sure it's missing a lot of corner cases, but so far it's pretty solid with swagger petstore and doesn't seem to suffer from weird issues like this library does. Wanted to throw it out there because I think if you were to copy the architecture (swapping out golang for TypeScript), the simplicity of it would make openapi-fetch much easier to contribute to, debug, test, and maintain because you can use a real debugger. |
Description
If I have something like this:
then tsc correctly flags
ASDfadsfasdf
as being superfluous:However, as soon as all required fields are in:
it is no longer flagged:
This is a problem because it means you can introduce typos on optional fields, and tsc won't catch it.
Reproduction
Seems to happen no matter what I try. tsconfig is set to esnext module with bundler resolution.
Expected result
Superfluous fields should be flagged regardless of if required ones are filled in or not.
Checklist
The text was updated successfully, but these errors were encountered: