-
-
Notifications
You must be signed in to change notification settings - Fork 530
fix(openapi-typescript): prevent type error when items is boolean #2260
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
base: main
Are you sure you want to change the base?
fix(openapi-typescript): prevent type error when items is boolean #2260
Conversation
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
|
@kerwanp I'm not sure if I need to add a changeset or not, I only saw a handful currently there so I'm assuming it's either new or not used. Please let me know, happy to add one if needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Please just add a patch
changeset (see comment) so we can credit you for this fix, and also push a release after merge.
* @param key - The key to check for | ||
* @returns True if the object has the key, false otherwise | ||
*/ | ||
function hasKey<K extends string>(possibleObject: unknown, key: K): possibleObject is { [key in K]: unknown } { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great idea, thank you!
@@ -18,6 +18,14 @@ describe("transformSchemaObject > array", () => { | |||
// options: DEFAULT_OPTIONS, | |||
}, | |||
], | |||
// Prevents: "TypeError: Cannot use 'in' operator to search for 'type' in true" | |||
[ | |||
"boolean items", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test!
Changes
Prevents a
TypeError
due to a badin
operator fortype: "array"
.Example: https://json-schema.org/understanding-json-schema/reference/array
How to Review
Take it as it is :)
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)