-
Notifications
You must be signed in to change notification settings - Fork 17
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
Protocol: Add undocumented message types #9
Merged
scheibo
merged 11 commits into
pkmn:master
from
taylorhansen:8-protocol-add-undocumented-args
Jun 2, 2021
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
28bf0ff
Add arg typigns
taylorhansen c09e276
Fix Protocol.key()
taylorhansen 5320c6d
Fix verifier
taylorhansen 3554a1b
Unsplit |noinit| and |hidelines| messages
taylorhansen 64609df
Add CSS selector type
taylorhansen d0f3483
Fix typigns for |tempnotify| and |tempnotifyoff|
taylorhansen dea6d3a
Fix typings for |hidelines| messages
taylorhansen 38eb583
Remove unused |modaction| message
taylorhansen 8b6cf09
Fix typings for |askreg| message
taylorhansen 3ff5a57
Tighten verifier
taylorhansen f35c17b
Simplify tuple typings
taylorhansen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's going on with this type? The
...[]
is kind of confusing to me, as it the array nesting. Can this be simplified?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's parsed as
...([] | [Message] | [Message, string])
due to operator precedence and tuple spreading, though some style guides enforce the parentheses anyway for clarity. Could do that or manually split it into a 3-array union, your call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the parens will help at the bare minimum.
['tempnotify', TempNotifyName, Message] | ['tempnotify', TempNotifyName, Message, Message] | ['tempnotify', TempNotifyName, Message, Message, string]
seems the most clear (unless I'm mistaking what this type actually is?).['tempnotify', TempNotifyName, Message, Message?, string?]
seems less precise but possibly how I might type this if I were doing it, as I'm not positive the extra precision really matters. Up to you which route you want to go, but please add parens if you want to keep the current approach :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
?
suffix allows forundefined
and/or skipping the tuple element, so that might not be ideal. Probably best to expand it into the type union then.Will do this for
|expire|
as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's less accurate, but we're also trying to put super rigorous types on top of something which is basically just raw strings on the PS side, so I'm usually not to bothered about dropping an
?
for convenience because PS is more likely to break things in the protocol than theundefined
is going to cause problems for people :).Technically its also the case that for like
['expire']
you can still index at 1 and getundefined
, so really the main difference with?
is that you're basically implying the array should be length 2 with the second element occasionallyundefined
, though if I really wanted to be explicit about that I'd probably goMessage | undefined
(its also the case that nothing in the protocol can beundefined
because we can't translateundefined
over the wire).tl;dr pedantically yes, the
?
implies some things different than the union, but in practice I'm not too hot and bothered by it in the context of the PS protocol :)