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

Update the typescript example in README.md #744

Closed

Conversation

winksaville
Copy link

The update makes the example execute using typescript 2.2.2. The
following changes were made.

  • Changed lookupType parameter to "awesomepackage.AwesomeMessage"
  • Use let instead of var as its consider a better style
  • Add type : any for message
  • Add printing of message.awesomeField
  • Add example of decoding of buffer and printing result
  • Commented out redundant or non-executable lines

The update makes the example execute using typescript 2.2.2. The
following changes were made.

 - Changed lookupType parameter to `"awesomepackage.AwesomeMessage"`
 - Use `let` instead of `var` as its consider a better style
 - Add type `: any` for message
 - Add printing of message.awesomeField
 - Add example of decoding of buffer and printing result
 - Commented out redundant or non-executable lines
@winksaville
Copy link
Author

I had trouble getting the example working so I thought I provide this PR to help others. I was surprised I needed to explicitly type message and decodedMessage to : any. Is there something I did incorrectly to require the : any?

@dcodeIO
Copy link
Member

dcodeIO commented Apr 4, 2017

I was surprised I needed to explicitly type message and decodedMessage to : any

This might be the case because you are accessing its properties with dot syntax (message.awesomeField) but messages dynamically created at runtime technically have no typings and are just instanceof protobuf.Message. Does it work when using message["awesomeField"]?

If you'd like to have proper typings for dynamic messages, too, you could still use pbts-generated typings for its static counterpart with your dynamic code.

@winksaville
Copy link
Author

Thanks for the feed back and updating README.md

@winksaville winksaville closed this Apr 4, 2017
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

Successfully merging this pull request may close these issues.

2 participants