Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repeated message error #1307

Open
wildfire810 opened this issue Oct 4, 2019 · 7 comments
Open

repeated message error #1307

wildfire810 opened this issue Oct 4, 2019 · 7 comments

Comments

@wildfire810
Copy link

wildfire810 commented Oct 4, 2019

protobuf.js version: 6.8.8

message MessageList {
repeated Message messageList = 1;
}

/** Represents a MessageList. */
export class MessageList implements IMessageList {

    /**
     * Constructs a new MessageList.
     * @param [properties] Properties to set
     */
    constructor(properties?: IMessageList);

    /** MessageList messageList. */
    public messageList: [ 'Array' ].<IMessage>;

    /**
     * Creates a new MessageList instance using the specified properties.
     * @param [properties] Properties to set
     * @returns MessageList instance
     */
    public static create(properties?: IMessageList): MessageList;

    /**
     * Encodes the specified MessageList message. Does not implicitly {@link MessageList.verify|verify} messages.
     * @param message MessageList message or plain object to encode
     * @param [writer] Writer to encode to
     * @returns Writer
     */
    public static encode(message: IMessageList, writer?: $protobuf.Writer): $protobuf.Writer;

    /**
     * Decodes a MessageList message from the specified reader or buffer.
     * @param reader Reader or buffer to decode from
     * @param [length] Message length if known beforehand
     * @returns MessageList
     * @throws {Error} If the payload is not a reader or valid buffer
     * @throws {$protobuf.util.ProtocolError} If required fields are missing
     */
    public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): MessageList;
}

D:\Project\skybox\Engine\Monju\Protocol\ProtoBuf\Protocol.d.ts
Error:Error:line (70)TS2416: Property 'messageList' in type 'MessageList' is not assignable to the same property in base type 'IMessageList'.
Type '["Array"]' is not assignable to type 'IMessage[]'.
Type '"Array"' has no properties in common with type 'IMessage'.
Error:Error:line (77)TS2304: Cannot find name 'create'.
Error:Error:line (77)TS2304: Cannot find name 'properties'.
Error:Error:line (77)TS2693: 'IMessageList' only refers to a type, but is being used as a value here.
Error:Error:line (85)TS2552: Cannot find name 'encode'. Did you mean 'Node'?
Error:Error:line (85)TS2552: Cannot find name 'message'. Did you mean 'Message'?
Error:Error:line (85)TS2693: 'IMessageList' only refers to a type, but is being used as a value here.
Error:Error:line (85)TS2304: Cannot find name 'writer'.
Error:Error:line (95)TS2304: Cannot find name 'decode'.
Error:Error:line (95)TS2304: Cannot find name 'reader'.
Error:Error:line (95)TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
Error:Error:line (95)TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
Error:Error:line (95)TS2693: 'number' only refers to a type, but is being used as a value here.
Error:Error:line (70)TS1005: ';' expected.
Error:Error:line (70)TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
Error:Error:line (70)TS1109: Expression expected.
Error:Error:line (77)TS1128: Declaration or statement expected.
Error:Error:line (77)TS1128: Declaration or statement expected.
Error:Error:line (77)TS1109: Expression expected.
Error:Error:line (77)TS1005: ';' expected.
Error:Error:line (85)TS1128: Declaration or statement expected.
Error:Error:line (85)TS1128: Declaration or statement expected.
Error:Error:line (85)TS1005: ',' expected.
Error:Error:line (85)TS1109: Expression expected.
Error:Error:line (85)TS1005: ';' expected.
Error:Error:line (95)TS1128: Declaration or statement expected.
Error:Error:line (95)TS1128: Declaration or statement expected.
Error:Error:line (95)TS1005: ',' expected.
Error:Error:line (95)TS1109: Expression expected.
Error:Error:line (95)TS1005: ';' expected.
Error:Error:line (96)TS1128: Declaration or statement expected.

@mreiche
Copy link

mreiche commented Oct 16, 2019

Same here. Problem is, that it transpiles
public messageList:IMessage[] to public messageList: [ 'Array' ].<IMessage> which results in Syntax errors.

This has something to do with the TypeScript Compiler I guess, because in my Env nothing else changed. This is bad, because I dont know the version that worked before.

@Taraflex
Copy link

@mreiche @wildfire810
You can patch files generated by something like
typescript```
import { sync as glob } from 'fast-glob';
import { readFileSync, writeFileSync } from 'fs';

for (let file of glob('*.d.ts', { cwd: __dirname + '/../src/generated' })) {
file = __dirname + '/../src/generated/' + file;
const jsFile = file.replace(/.d.ts$/i, '.js');
writeFileSync(file, readFileSync(file, 'utf-8').replace(/[ 'Array' ]./g, 'Array'));
writeFileSync(jsFile, '//@ts-nocheck\n' + readFileSync(jsFile, 'utf-8'));
}

@Taraflex
Copy link

Github has been working horribly in the last few days. I can't edit the broken markup in the previous message 😕

@mreiche
Copy link

mreiche commented Oct 16, 2019

I probably get this fixed. But I really want to know the reason for that. Do you know a working Typescript Version?

I compile my proto files like:

node ./node_modules/protobufjs/bin/pbjs --no-create --no-verify --no-convert --no-delimited -t static-module --es6 -w commonjs -o src/model/protobuf/bundle_pb.js ../../proto/src/main/*.proto

and

node ./node_modules/protobufjs/bin/pbts -o src/model/protobuf/bundle_pb.d.ts src/model/protobuf/bundle_pb.js

It installes one of these extensions

installing jsdoc@^3.5.5
installing minimist@^1.2.0
installing tmp@0.0.33
installing uglify-js@^3.3.25
installing espree@^3.5.4
installing escodegen@^1.9.1
installing estraverse@^4.2.0

which may also cause the issue.

@mreiche
Copy link

mreiche commented Oct 16, 2019

@mreiche @wildfire810
You can patch files generated by something like

import { sync as glob } from 'fast-glob';
import { readFileSync, writeFileSync } from 'fs';

for (let file of glob('*.d.ts', { cwd: __dirname + '/../src/generated' })) {
   file = __dirname + '/../src/generated/' + file;
   const jsFile = file.replace(/.d.ts$/i, '.js');
   writeFileSync(file, readFileSync(file, 'utf-8').replace(/[ 'Array' ]./g, 'Array'));
   writeFileSync(jsFile, '//@ts-nocheck\n' + readFileSync(jsFile, 'utf-8'));
}

Im not sure if this works in general, because it also compiles

/**
  * File meta.
  * @member {Object.<string,string>} meta
  * @memberof data.File
  * @instance
*/
File.prototype.meta = $util.emptyObject;

to

/** File meta. */
public meta: [ 'object' ].<string, string>;

@mreiche
Copy link

mreiche commented Nov 5, 2019

According to #1306 downgrading to Node 10.x is a workarround.

@wildfire810
Copy link
Author

I use the library in cocos creator,a typescript game framework.
It's not running in node.
Browser or game engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants