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

Always use Map for int64 keys #708

Closed
zhuscat opened this issue Nov 22, 2022 · 2 comments
Closed

Always use Map for int64 keys #708

zhuscat opened this issue Nov 22, 2022 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@zhuscat
Copy link

zhuscat commented Nov 22, 2022

message Foo {
  map<int64, int64> bar = 1;
}

is generated to

export interface Foo {
  bar: { [key: Long]: Long }
}

when --ts_proto_opt=forceLong=long

This is a type error:

An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
@stephenh
Copy link
Owner

Hey @zhuscat ; thanks for the report. That's a good find.

We already have some code that will use a JS map, which is enabled with:

--ts_proto_opt=useMapType=true

It would probably be a good idea to always use the map type for longs, even if useMapType=false.

If you'd like to submit a PR for that fix, that'd be great!

Otherwise just using useMapType=true should unblock you for now, I think.

@stephenh stephenh changed the title map<int64, int64> generated to { [key: Long]: Long }, which is a type error Always use Map for int64 keys Nov 25, 2022
@stephenh stephenh added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Nov 25, 2022
buzap added a commit to buzap/ts-proto that referenced this issue Aug 17, 2023
stephenh pushed a commit that referenced this issue Aug 18, 2023
* fix: always use Map for int64 keys (#708)

* build: change prettier trailingComma to all
@stephenh
Copy link
Owner

This should be fixed by #905 in the next release, thanks @buzap !

stephenh pushed a commit that referenced this issue Aug 18, 2023
## [1.156.7](v1.156.6...v1.156.7) (2023-08-18)

### Bug Fixes

* always use Map for int64 keys ([#708](#708)) ([#905](#905)) ([cf2fb59](cf2fb59))
eladhaim pushed a commit to eladhaim/ts-proto that referenced this issue Sep 2, 2023
* fix: always use Map for int64 keys (stephenh#708)

* build: change prettier trailingComma to all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants