Skip to content

Support default instances on singular/required fields #1064

@oliveryasuna

Description

@oliveryasuna

I feel like this option should already exists, but I read through the README and could not find it. Please let me know if I am missing something.

Given a message:

message ErrorResponse {
  uint32 code = 1;
  string message = 2;
  optional string details = 3;
}

It generates:

export interface ErrorResponse {
  code: number;
  message: string;
  details?: string | undefined;
}

That is expected behavior.

However, if I have the following message:

message Test {
  message Inner {
    string value = 1;
  }
  message A {
    string value = 1;
  }
  message B {
    string value = 1;
  }

  Inner inner = 1;
  oneof value {
    A a = 2;
    B b = 3;
  }
}

It generates:

export interface Test {
  inner: TestInner | undefined;
  value?: { $case: "a"; a: TestA } | { $case: "b"; b: TestB } | undefined;
}

export interface TestInner {
  value: string;
}

export interface TestA {
  value: string;
}

export interface TestB {
  value: string;
}

Why is Test.inner defined with | undefined and why is Test.value optional and also defined with | undefined?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions