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

Naming collisions with message named Object #161

Closed
timostamm opened this issue Sep 18, 2021 Discussed in #160 · 1 comment
Closed

Naming collisions with message named Object #161

timostamm opened this issue Sep 18, 2021 Discussed in #160 · 1 comment
Labels
bug Something isn't working

Comments

@timostamm
Copy link
Owner

Discussed in #160

Originally posted by joeflatt September 18, 2021
Hi,

I'm new to this so not sure if it's a bug or a known issue that has a workaround.

I compile against a large set of proto files that contain a message named Object. I don't have any control over the proto files themselves. The generated typescript code won't compile because it makes use of static methods on JavaScript's Object class (i.e. Object.defineProperty).

Here's how I'm using protobuf-ts:
npx protoc --ts_out src/ --ts_opt generate_dependencies --proto_path apis/ find apis -name '*.proto'

Thanks!

The easiest fix seems to be an adding Object to the list of reserved type names here:

const reservedTypeNames = 'Long,Uint8Array,array,Array,string,String,number,Number,boolean,Boolean,bigint,BigInt'.split(',');

Alternatively, change our access on Object to globalThis.Object.

@timostamm timostamm added the bug Something isn't working label Sep 18, 2021
@timostamm
Copy link
Owner Author

Keywords are much less likely to change than objects in the global scope, so we should only escape keywords, and use globalThis for objects in global scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant