ts-proto
ts-proto copied to clipboard
Encode crashes on `null` object values
If i try to encode an object that has null values, instead of undefined, the encode()
fails. These null values are sometimes nested objects as well.
I used v1.171 and it still crashes.
@gabrielOttopia can you include the snippet of code from encode
that stack traces?
Are you using the useNullAsOptional
flag introduced in #1017 ? Historically we've not supported null
, so unless you're using useNullAsOptional
that behavior is probably expected.
@stephenh I tried that flag and got this error:
`src/autogenerated/X/X_management.ts:241:96 - error TS2345: Argument of type '{ clientId?: { id?: string | undefined; } | null | undefined; stationId?: { id?: { id?: string | undefined; } | null | undefined; address?: { ipv4?: number | null | undefined; ipv6?: Uint8Array | null | undefined; } | null | undefined; } | null | undefined; }' is not assignable to parameter of type '{ clientId?: { id?: string | undefined; } | null | undefined; stationId?: { id?: { id?: string | undefined; } | null | undefined; address?: { ipv4?: number | null | undefined; ipv6?: Uint8Array | null | undefined; } | null | undefined; } | null | undefined; } & { ...; } & {}'.
Type '{ clientId?: { id?: string | undefined; } | null | undefined; stationId?: { id?: { id?: string | undefined; } | null | undefined; address?: { ipv4?: number | null | undefined; ipv6?: Uint8Array | null | undefined; } | null | undefined; } | null | undefined; }' is not assignable to type '{ clientId?: ({ id?: string | undefined; } & { id?: string | undefined; } & {}) | undefined; stationId?: ({ id?: { id?: string | undefined; } | null | undefined; address?: { ipv4?: number | null | undefined; ipv6?: Uint8Array | ... 1 more ... | undefined; } | null | undefined; } & { ...; } & {}) | undefined; }'.
Types of property 'clientId' are incompatible.
Type '{ id?: string | undefined; } | null | undefined' is not assignable to type '({ id?: string | undefined; } & { id?: string | undefined; } & {}) | undefined'.
Type 'null' is not assignable to type '({ id?: string | undefined; } & { id?: string | undefined; } & {}) | undefined'.
241 message.connectedClients = object.connectedClients?.map((e) => ConnectedClient.fromPartial(e)) || [];
`
` Type '{ id?: string | undefined; } | null | undefined' is not assignable to type '({ id?: string | undefined; } & { id?: string | undefined; } & {}) | undefined'.
Type 'null' is not assignable to type '({ id?: string | undefined; } & { id?: string | undefined; } & {}) | undefined'.ts(2345)
`
the error snipped i get probably wont be too helpful