Repository navigation
Change two recently added classes to strict typing - #415
Merged
Merged
Conversation
New code may as well go all in on type hints. I'll be interested to see if this helps with maintainability over time.
Owner
Author
|
I wonder if I could fail the build if a new ruby file added since sorbet was introduced was missing strict typing? Maybe something based on this git command that lists files added since the relevant commit: |
paracycle
reviewed
Dec 29, 2021
| end | ||
| def initialize(x, y); end | ||
| def initialize(x, y) | ||
| @x = T.let(0, Numeric) |
There was a problem hiding this comment.
You don't need the actual value of the variable in RBI files, you should be able to just do:
@x = T.let(T.unsafe(nil), Numeric)instead. Here T.unsafe(nil) creates a dummy value that is T.untyped and T.let declares the type of it.
This way, your internal implementation details will not leak into RBI files, you can just declare the types instead.
yob
added a commit
that referenced
this pull request
Dec 29, 2021
These type hints were added in #415 while changing some files to `typed: strict`. It felt weird providing an initial value that I knew wasn't used, and in a follow up comment on the PR it was suggested that I can use this form to be clear that I'm annotating the ivar type without setting a value. `T.unsafe(nil)` also feels a bit weird. So much syntax for so little value. It'd be nice if sorbet had a way to only specificy the ivar type in an RBI files, without the value argument at all 🤷♂️
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
New code may as well go all in on type hints. I'll be interested to see if this helps with maintainability over time.
Thanks to this answer on stackoverflow for pointing me in the right direction: https://stackoverflow.com/questions/70515191/how-can-i-resolve-sorbet-error-use-of-undeclared-variable/70519194#70519194