-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Support "+ system clipboard register (#780) #782
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
55582a1
Support "+ system clipboard register
bdchauvette d3bae99
Merge branch 'master' into register-quoteplus
bdchauvette e3e6d58
Merge branch 'master' into register-quoteplus
bdchauvette ae5f010
Add isClipboardRegister? to IRegisterContent
bdchauvette d6e1352
Merge branch 'master' into register-quoteplus
bdchauvette 6d46247
Make IRegisterContent.isClipboardRegister required
bdchauvette 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.
Can you just do
return register && register.isClipboardRegister
?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 actually tried that initially, but tsc doesn't like it very much:
It works fine if I change the signature to
isClipboardRegister(string): boolean | undefined
, but I wasn't sure if that was preferable to having a messier function body.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.
Can you show me the exact line(s) of code that you're using to get that error?
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 it's being caused by the
isClipboardRegister
property being optional: the property has a type signature ofboolean | undefined
, but theRegister.isClipboardRegister
method expects to only return booleans.If we try to return the property without first converting it to a
boolean
, it's possible for the value toundefined
(b/c it's optional), which violates the signature for the checking method.(I think) this would also explain why it works if I change the allowed return type to
boolean | undefined
.I'm pretty new to typescript, so I'm not sure what the idiomatic way to handle this kind of thing is 😕
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.
Each of these allow the code to compile without a hitch:
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.
Ohhhhh. It's because it's an optional property, which has type
boolean | undefined
, which we are returning directly. That makes sense... in a weird way. :)I guess TypeScript is pointing out that we did a dumb thing by saying the type was
isClipboardRegister?: boolean
since now we can't distinguishundefined
fromfalse
in an easy way.Best is probably to change the type to
isClipboardRegister: boolean
, and add it to all registers. Then this code will work and also ourundefined
vsfalse
case will go away.TypeScript caught a (minor) bug! Yay, TypeScript!
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.
Yay, TypeScript! 🙌
Looks like I just broke Travis, though. Any ideas what's going on there? 😕
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.
¯_(ツ)_/¯ restarted the Travis build.