-
-
Notifications
You must be signed in to change notification settings - Fork 544
feat: generate immutable types #522
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
Conversation
src/transform/headers.ts
Outdated
let output = ""; | ||
|
||
Object.entries(headerMap).forEach(([k, v]) => { | ||
if (!v.schema) return; | ||
|
||
if (v.description) output += comment(v.description); | ||
|
||
const readonly = immutableTypes ? "readonly " : ""; |
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.
👍🏻
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.
I personally am also a fan of readonly string[]
over ReadonlyArray<string>
. AFAIK this looks easier to implement, and has no downsides. I’m in favor of this approach.
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.
the "downside" - if you want to call it such - would be a minimum requirement of TypeScript v3.4, which I think should be fine considering v4.2 is currently latest.
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.
TS 4 was such an easy update I don’t know of any reason why people would still be on an old version. But given that this is opt-in too, this is more than fine.
Awesome! Love the direction of this PR; I would have done it the same way. My only suggestion would be to add at least 1 test for this. But the nice part of adding a new feature is that we’re not breaking behavior for anybody. So even if we missed a type, we could add it after-the-fact. |
6ac95dd
to
a43ce6b
Compare
Codecov Report
@@ Coverage Diff @@
## main #522 +/- ##
==========================================
+ Coverage 84.87% 84.91% +0.03%
==========================================
Files 9 9
Lines 324 338 +14
Branches 105 108 +3
==========================================
+ Hits 275 287 +12
- Misses 46 47 +1
- Partials 3 4 +1
Continue to review full report at Codecov.
|
Thank you! 😊
yeah, I'll add some tests. just wanted to see the current tests passing.
I agree. |
@drwpow the PR is pretty much good to go. I just want to merge some duplicate interfaces I created for passing around options: { immutableTypes }. gonna try to get to it tomorrow. I tried the branch against our company schemas and it works great. |
Awesome. I’ll take a look tomorrow. It’s looking good to me already. |
}; | ||
}; | ||
};`) | ||
); |
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.
💯
expect(generated).toBe(expected); | ||
}); | ||
|
||
it(`reads ${schema} spec (v3) from file (immutable types)`, () => { |
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.
Love all the immutable tests!
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 PR is looking good! I have no changes requested. Ping me when you feel you’re happy with it and I can merge.
I can also either release an RC if you’d like to do more testing, or we can just cut a minor release. Your call. Again, since this is a new flag, I’m not as concerned with just releasing because we won’t be breaking anyone.
0b31fa6
to
02f98e5
Compare
should be good to go! 👍 minor release should be fine 🤞 |
@drwpow just wanted to point out a couple things: 1: 2: execSync(
`../../bin/cli.js specs/${schema} -o generated/${output} --prettier-config .prettierrc --immutable-types`,
{
cwd: __dirname,
}
); and therefore also removed the folders from 3: I added an that makes it possible to install this module directly from the repository, as the build automatically runs after the install, which is great for development. |
Thanks so much! Agree with all of these changes. Thanks again for contributing |
@all-contributors please add @dnalborczyk for code, test |
I've put up a pull request to add @dnalborczyk! 🎉 |
@drwpow thank you for this great project and thank you for accepting the PR! |
@drwpow @dnalborczyk Thanks for implementing & reviewing this feature! I really appreciate your time & efforts. 🎉 (I just wanted to join the "thanks" party! 😁) |
fixes: #501