Open wildfire810 opened 4 years ago
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.
@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')); }
Github has been working horribly in the last few days. I can't edit the broken markup in the previous message 😕
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 @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>;
According to https://github.com/protobufjs/protobuf.js/issues/1306 downgrading to Node 10.x is a workarround.
I use the library in cocos creator,a typescript game framework. It's not running in node. Browser or game engine.
protobuf.js version: 6.8.8
message MessageList { repeated Message messageList = 1; }
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.