-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Expose getStringLiteralType and getNumberLiteralType on the TypeChecker, plus remove /** @internal */ from several useful methods. #52473
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
Merged
andrewbranch
merged 4 commits into
microsoft:main
from
sstchur:sstchur/expose-various-helpers-on-checker
Mar 7, 2023
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aab7cb9
Expose getStringType, getStringLiteralType, getNumberType, getNumberL…
sstchur-msft 59650df
Merge branch 'main' into sstchur/expose-various-helpers-on-checker
andrewbranch 7d6158f
Update API baseline
andrewbranch d3cdc58
Don’t expose `fresh` parameter, add `getBigIntType`, add JSDoc warnings
andrewbranch 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 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
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
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
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
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.
Rereading this again, do we want to expose the fresh parameter? Or should we maybe overload it and only expose one without parameters publicly?
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 does the fresh param do? In my personal needs using this, I'm just invoking
getFalseType()
. How likely is it that people using this would need/want to pass in the fresh arg?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.
Literal types have fresh and regular variants. When assigning from a fresh literal to a mutable location, the resulting type is widened to the base type:
from an API perspective, this means it’s important to note that
but that a
false
type will always be one of these. Within the checker, we would probably never do an equality comparison to determine if a type isfalse
; we’d callgetTypeFacts
and look at those, but that’s not exported. Soooo, whether to expose it, 🤷♂️?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.
Lots of places appear to do things like
foo === falseType || foo === freshFalseType
too. I guess it depends, but it might be important if you are trying to do something with these functions...Alternatively what people want externally is "is this assignable to false" but obviously that API is a different issue so...
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.
Interesting. So in my case, I have
checker.getFalseType(false)
(since I don't pass anything in). And I'm later using that, but not with===
. Rather, I'm using it withisTypeAssignableTo
, because what I desire to know is if some type I have could accept the valuefalse
.For example:
Later, I want to know if
foo
would acceptfalse
. I don't want or need to know iffoo
would acceptboolean
, only if it will acceptfalse
.But I have to admit that I don't know which of the two:
checker.getFalseType(true)
orchecker.getFalseType(false)
I want in this case, or if it even matters?And the whole reason I mention my use-case at all is to try to add insight that might help decide if we need to expose the
freshType
arg or not? I can't purport to know what others might be doing withgetFalseType
or if their use-cases are at all like mine.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.
Fresh/regular shouldn’t matter for assignability, so it sounds like in your case it doesn’t matter.
Noticing that a couple of our codefixes grab a type, check its flags for
BooleanLiteral
, and then compare tochecker.getFalseType(true)
andchecker.getFalseType(false)
, I’m inclined to say it’s fine to leave it exposed. Codemods are a good example of a reasonable usage of our API.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.
Obviously the value of my input is limited, since I don't have the same depth on knowledge about TS that you guys have, but my intuition would be to leave it exposed. As a developer, I prefer having flexibility available to me, even if I don't use it, so long as that flexibility doesn't make my life difficult. And in this case, it doesn't seem to, so I say leave it.