Skip to content
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

Consistent field nullability in the constructor and fromObject method #163

Closed
wants to merge 16 commits into from

Conversation

Santalov
Copy link

The fromObject and constructor arguments became consistent in terms of nullability. To determine, if a field is nullable, the following function is used:

export function canBeCreatedWithoutValue(
  rootDescriptor: descriptor.FileDescriptorProto,
  fieldDescriptor: descriptor.FieldDescriptorProto,
) {
  return (
    isOptional(rootDescriptor, fieldDescriptor) ||
    // Both proto2 and proto3 don't track presence for maps and repeated fields.
    // https://github.com/protocolbuffers/protobuf/blob/main/docs/field_presence.md#presence-in-proto2-apis
    isMap(fieldDescriptor) ||
    isRepeated(fieldDescriptor)
  );
}

This also makes repeated and map fields nullable in constructor (they weren't).

Santalov added 16 commits July 29, 2022 11:20
Removed RecursivePartial<T>, instead introduced AsObjectPartial, which is used as fromObject method argument. Make getters, setters and AsObject typed according to canHaveNullValue predicate. Brought AsObjectPartial into line with constructor's declaration.
Change method access in RPC from property access to element access.
Add non-null assertion operators in places where an indexed access occurs.
return data && message when fromObject has no field assignments.
@thesayyn
Copy link
Owner

thesayyn commented Sep 1, 2023

Closing as there's been no activity on this.

@thesayyn thesayyn closed this Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants