Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

[JS] Add `fromObject` method to take an AsObject type and return a T.

Aberta
#11 5 comentários 12 reações 1 responsável Ver no GitHub

@lukesandberg já está trabalhando nisso.

Desde 11/3/2022.

Avaliação

Esta issue ainda não foi avaliada.

Descrição

bug javascript triaged

What language does this apply to?
JS/TS

Describe the problem you are trying to solve.
In JS, many different libraries expect to work with dictionaries, basically Record<A, B> or lists of these, to do things like state management in single page apps, list operations like find, slice, zip, etc. and more. Having the ability to freely move between a Message and a JSON object would make it MUCH easier to interoperate with different tools.

Currently, my message types get compiled to something like the following:

export class Polygon extends jspb.Message {
  // getters and setters here

  serializeBinary(): Uint8Array;
  toObject(includeInstance?: boolean): Polygon.AsObject;
  static toObject(includeInstance: boolean, msg: Polygon): Polygon.AsObject;
  static serializeBinaryToWriter(message: Polygon, writer: jspb.BinaryWriter): void;
  static deserializeBinary(bytes: Uint8Array): Polygon;
  static deserializeBinaryFromReader(message: Polygon, reader: jspb.BinaryReader): Polygon;
}

Describe the solution you'd like

  static fromObject(from: Polygon.AsObject): Polygon;

Describe alternatives you've considered
Writing a generic function to parse the field descriptors, but I don't know enough to make it work correctly, PLUS, it seems like a much better thing to be provided out of the box.

Additional context

Linguagem predominante
JavaScript
Estrelas
471
Forks
91
Merge médio
1d 12h
PRs com merge (30d)
6

Preparar o ambiente

Ainda não verificamos os arquivos de configuração deste projeto. Comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de protocolbuffers/protobuf-javascript

Todas as issues de protocolbuffers/protobuf-javascript

Issues semelhantes

Mais issues de JavaScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.