-
Notifications
You must be signed in to change notification settings - Fork 10
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
fix(types): Fixes array over union sub-return-types. #31
Conversation
Wraps the ${first} return type in parentheses so that array type augments the whole sub-type e.g., in case the sub-type is a union. E.g., ``` From: mget(...keys: string[]): Promise<string | null[]>; // string | Array<null> to: mget(...keys: string[]): Promise<(string | null)[]>; // Array<string | null> From: hmget(key: string, ...fields: string[]): Promise<string | null[]>; // string | Array<null> to: hmget(key: string, ...fields: string[]): Promise<(string | null)[]>; // Array<string | null> ```
All of the CI tests pass but it's failing on a check for |
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.
Thanks for this, good catch! The git status --porcelain
is there because since #24 the generated code is checked in, so we need to make sure that the code in git matches what the scripts generate.
If you run npm run ci
locally on your branch, the generated file will be updated and the script will fail like on Travis. You can then commit that file (you should see the effect of your changes in the diff), and run npm run ci
again. The second time it should succeed after detecting no more changes.
Let me know if this works for you. I'll add some docs around this to the readme.
scripts/generate-usages.ts
Outdated
@@ -249,7 +249,7 @@ const getReturnType = (sampleValues: any[] | undefined): string => { | |||
const itemReturnTypes = new Set(sampleValues.map(getReturnType)); | |||
if (itemReturnTypes.size === 1) { | |||
const first = itemReturnTypes.values().next().value; | |||
return `${first}[]`; | |||
return `(${first})[]`; |
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.
return `(${first})[]`; | |
return `Array<${first}>`; |
Adds generated code for CI guard Reduces noise in generated types via extra check for pipe character so that parens are only added when the generated array sub-type is actually a union type. This seems to work fine for the current data types. Hopefully we won't ever need a parser to actually check for balanced parens various expressions before adding more.
Okay, I think I've got things straightened out after giving GitHub and Travis a workout. Might want to squash the commits in this PR if you can. Thanks for the lib! |
@nl-brett-stime pushed a change only using the |
🎉 This PR is included in version 1.5.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Wraps the ${first} return type in parentheses so that array type augments the whole sub-type e.g., in case the sub-type is a union.
E.g.,