question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Symbol missing from generated types

See original GitHub issue

Codegen will create typescript definitions that do not include the MESSAGE_TYPE symbol, even though it will be present in all response messages.

Following the example in the manual for this definition:

message Person {
    string name = 1;
    uint64 id = 2;
    int32 years = 3 [json_name = "baz"];
    optional bytes data = 5;
}

I would expect that the typescript interface is something like:

import { MessageType, MESSAGE_TYPE } from '@protobuf-ts/runtime';

export interface Person {
    /**
     * @generated from protobuf field: string name = 1;
     */
    name: string;
    /**
     * @generated from protobuf field: uint64 id = 2;
     */
    id: bigint;
    /**
     * @generated from protobuf field: int32 years = 3 [json_name = "baz"];
     */
    years: number;
    /**
     * maybe a jpeg?
     *
     * @generated from protobuf field: optional bytes data = 5;
     */
    data?: Uint8Array;


    // This what's missing
    [MESSAGE_TYPE]: MessageType<Person>
}

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
timostammcommented, Jun 6, 2022

Ah, WeakMap is definitely a nice idea. I’ve been using it back in the days in ActionScript and didn’t realize JavaScript implementations finally caught up 😃

Can’t think of any drawbacks. We export both symbols, so it is a breaking change, but it seems worth it for a new major.

0reactions
jcreadycommented, May 19, 2022

@timostamm I wonder if we could avoid the whole mess of extra properties on the objects by using a WeakMap to store the message type (and possibly the unknown fields). Something to consider for v3.

// runtime/src/message-type-contract.ts
const MessageTypeMap = new WeakMap<object, IMessageType<any>>();
export const getMessageType = <T extends object>(ref: T): IMessageType<T> | undefined => MessageTypeMap.get(ref);

// runtime/src/binary-format-contract.ts
const UnknownFieldMap = new WeakMap<object, UnknownField[]>();
export const getUnknownFields = (ref: object): UnknownField[] | undefined => UnknownFieldMap.get(ref);
// Usage
import { getMessageType, getUnknownFields, IMessageType, UnknownField } from '@protobuf-ts/runtime';

const MessageType: IMessageType<typeof someReference> | undefined = getMessageType(someReference);
if (MessageType) {
    console.log(MessageType.toJson(someReference));
}

const UnknownFields: UnknownField[] | undefined = getUnknownFields(someReference);
if (UnknownFields) {
    console.log(UnknownFields.map((uf) => uf.no));
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Missing import in generated declaration file #49065 - GitHub
Missing import in generated declaration file #49065 ; Bug A bug in TypeScript ; Domain: Declaration Emit The issue relates to the emission...
Read more >
QGIS 3 missing symbols - GIS Stack Exchange
If you recently updated your version of QGIS and the default symbol styles were missing, you probably had something go wrong when you ......
Read more >
AWS Tutorials: GraphQL build fails on missing symbols and ...
AWS Tutorials: GraphQL build fails on missing symbols and too many ... This is an auto generated class representing the NoteData type in ......
Read more >
How to Resolve The Cannot Find Symbol Error in Java - Rollbar
The most common triggers for the cannot find symbol compile-time error include: missing variable and method declarations;; out-of-scope ...
Read more >
Compilation error with Clover enabled - missing type, cannot ...
Errors related with a missing symbol might occur when: ... sources are being generated after Clover's instrumentation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found