Skip to content

Generated TypeScript message definition not compatible with message$Properties definition #826

@bhouser

Description

@bhouser

protobuf.js version: 6.7.3
Protobuf version: 3

Generated TypeScript message definition not compatible with message$Properties definition. It's not possible to (for example) pass a Token object as a parameter to Token.encode(token), since the types are incompatible.

Protobuf definition

message Token {
    google.protobuf.Any message = 1;
}

Generated Typescript definitions

type Token$Properties = {
    message?: google.protobuf.Any$Properties;
};

class Token {
    constructor(properties?: core.Token$Properties);
    public message: (google.protobuf.Any$Properties|null);
    public static encode(message: core.Token$Properties, writer?: $protobuf.Writer): $protobuf.Writer;
    public static encodeDelimited(message: core.Token$Properties, writer?: $protobuf.Writer): $protobuf.Writer;
    public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): core.Token;
    public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): core.Token;
    public static verify(message: { [k: string]: any }): string;
}

Typescript error:

Error:(42, 37) TS2345:Argument of type 'Token' is not assignable to parameter of type 'Token$Properties'.
  Types of property 'message' are incompatible.
    Type 'Any$Properties | null' is not assignable to type 'Any$Properties | undefined'.
      Type 'null' is not assignable to type 'Any$Properties | undefined'.

I'm pretty sure it should be possible to assign an object of Type Token to an object of type Token$Properties. This is however impossible, since public message: (google.protobuf.Any$Properties|null); is incompatible with message?: google.protobuf.Any$Properties;. An optional field does not accept types which could be null.

I believe this is the same issue as described here:
#808

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions