-
Notifications
You must be signed in to change notification settings - Fork 349
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
feat: Add static-only variant to to outputTypeAnnotations option #858
Conversation
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.
Hi @bouk ! This sounds like a good idea...
Two asks:
-
do you mind renaming this to
outputTypeAnnotations=staticOnly
? The "const-only" at first made me think of the TypeScriptconst
feature, like the output would become readonly oras const
or what not--but makes senses, you just want only the "static"$type
field, and not one added to the actual message interface. -
Can you create a new
integration/*
directory with aparameters.txt
that uses thestaticOnly
param, just to get some regression coverage of this feature?
Thanks!
src/main.ts
Outdated
@@ -616,7 +619,9 @@ function makeDeepPartial(options: Options, longs: ReturnType<typeof makeLongUtil | |||
|
|||
// Based on the type from ts-essentials | |||
const keys = | |||
options.outputTypeAnnotations || options.outputTypeRegistry ? code`Exclude<keyof T, '$type'>` : code`keyof T`; | |||
(options.outputTypeAnnotations || options.outputTypeRegistry) && options.outputTypeAnnotations !== "const-only" |
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.
Hm, this logic is doing in enough places, can you create like a addTypeToMessages(options)
helper function?
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.
Done
I've renamed it to |
Cool, thanks @bouk ! Looks like there is a build failure; could you 👀 , but otherwise is great, and I'll merge once that's passing. |
* Add integration test * Add helper for adding type to message
7d91df6
to
dc1acf2
Compare
@stephenh forgot to add a parameter file! |
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.
👍
# [1.151.0](v1.150.1...v1.151.0) (2023-07-04) ### Features * Add static-only variant to to outputTypeAnnotations option ([#858](#858)) ([d7c4af7](d7c4af7))
🎉 This PR is included in version 1.151.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hi, I want to write a generic function like such:
So I need to have type annotations emitted but also still have the interfaces generated without the
$type
field. In this PR I'm adding a const-only variant tooutputTypeAnnotations
that does this.