Skip to content

Update the typescript example in README.md#744

Closed
winksaville wants to merge 1 commit intoprotobufjs:masterfrom
winksaville:update-typescript-example
Closed

Update the typescript example in README.md#744
winksaville wants to merge 1 commit intoprotobufjs:masterfrom
winksaville:update-typescript-example

Conversation

@winksaville
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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