-
Notifications
You must be signed in to change notification settings - Fork 337
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 usePrototypeForDefaults option #484
Conversation
chore: update options test
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.
Looks great!
import { Child_Type, Simple, StateEnum } from './simple'; | ||
|
||
describe('simple', () => { | ||
it('generates types correctly', () => { |
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.
Maybe add a test that does a Simple.decode
that shows a from-default value like age: 0
has Object.keys().includes("age") === false
or what not?
let createBase = code`createBase${fullName}()`; | ||
if (options.usePrototypeForDefaults) { | ||
createBase = code`Object.create(${createBase}) as ${fullName}`; | ||
} |
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.
Ah wow, nice how small this change is.
@stephenh I added some more appropriate tests. I hope that is what you meant. |
Yep, that's what I meant. Thanks! |
})).finish()); | ||
|
||
expect(Object.keys(decodedWithZero).includes('age')).toBeFalsy(); | ||
expect(decodedWithZero.hasOwnProperty('age')).toBeFalsy(); |
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.
Ah right right, I'd expected this to be truthy, but it's the whole proto3 thing that optionals are not encoded, so presence is broken. But this will work for proto2, which is what the descriptors comein as.
# [1.103.0](v1.102.2...v1.103.0) (2022-01-20) ### Features * add usePrototypeForDefaults option ([#484](#484)) ([8e8c810](8e8c810))
🎉 This PR is included in version 1.103.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This adds a feature flag
usePrototypeForDefaults
as discussed in #479I have tested this by building
ts-proto
with this change, rebuilding thets-proto-descriptors
lib using the rebuiltts-proto
, then linking to the newts-proto-descriptors
fromts-proto
and re-building all integrations and testing them.