-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Expose more node checking / type guard API functions for developers #52727
Comments
On a slight side note: |
Many helpers including isExpression were made public in #52284, if you're missing it, I would look at a build of 5.0 to look for what's missing. (Pretend the lib folder in main doesn't exist; it's just a pinned compiler we use to build the compiler itself.) I'm general the filenames are a lie; they were correct for a while but functions were added and moved and so it doesn't really align with anything right now. I believe @rbuckton expressed some interest in moving these around. Some helpers are problematic in that they use parent pointers, which may not always work. But, none of those are currently public (on purpose), but probably do need some public variant. |
Seems this was just addressed, I guess this issue can be closed then. @JoshuaKGoldberg I was already think this, but no I'm even more sure, we should set TS@5 as the minimum supported version of the library. I don't think it's really worth back supported older TS version for such a new library; v5 is also nice clean version to start from. |
Not all of them were made public; I think I only exposed ones that would be useful with the new visitor API as of #49929. In particular I remember only exposing some of the token functions. You might need more than just what would be in a transform, though. (I didn't remove any so I'm pretty sure you could get away with 4.x too) |
@JoshuaKGoldberg good to close this one or are there more functions that should be exposed? |
Sorry for the delay @RyanCavanaugh, I was out last week - and then this took a little while to write up.
Yes, quite a few candidates. The following table's functions all exist in
Emoji key:
Types
Nodes
Note: there are likely a few mistakes in this chart; it was boring and tedious to generate. Please use it as a rough lay-of-the-land rather than precise technical documentation. |
RE: methods on Type and such, these are all declared here (and truthfully, I spend so little time in services that I forgot they existed!): https://github.com/microsoft/TypeScript/blob/main/src/services/types.ts Notably, I haven't looked closely, but my impression from having exported a bunch of stuff in 5.0 is that anything to do with nodes that turn out to be simple kind checks are very safe for us to export, although I'm very surprised that so many of there are marked β. I think I mentioned this above, but, I think there's some intent to try and move all of these helpers to a file and make them complete, which would solve some of this at least. (If only |
Aha, thanks, I've updated the table.
Is there a tracking issue? If not, is that statement enough to count as accepting PRs? π
Is there a tracking issue for this? @bradzacher and I have mentioned this to each other a few times, that it'd be great to make that change at some point. +1 |
No, I don't there is; I'm going off some commentary from @rbuckton in my strictFunctionTypes PR.
Also no; I think that this was prohibitively slow. So much so that a version of the compiler with Node as a union is a benchmark (Compiler-Unions, if you've ever seen the perf runner output). |
Do you mind if I restructure your comment a little to stick However, for |
Go ahead, thanks for asking! |
Could |
The notes don't seem to be out yet, but we had a long discussion about this in a design meeting and it seems like we're landing at only de-internalizing the So, that'd roughly translate to anything with a red X above not being created, but everything else is fair game, whatever dropping As for Type, I don't think any of those were going to be exported. Type helpers are a little more challenging because they have to be exported on the TypeChecker object. |
In the interim, is |
@Rich-Harris |
@jakebailey could Edit: and/or, |
Suggestion
π Search Terms
type guard internal api functions tsutils ts-api-utils
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
The
typescript
package contains many node checking / type guard API functions for developers (isAccessor
,isArrayBindingPattern
, etc.). Many of them are exported for public use. Some are not. Could we expose many more of them?A bit of history: the
tsutils
package has existed for many years to fill in those missing type guards & other API pieces. It hasn't been maintained in a couple of years so I'm filling out a successor,ts-api-utils
with a lot of help from @RebeccaStevens. We're now discussing which parts of the TypeScript API -internal and public- the package should provide.π Motivating Example
Two categories of
@internal
functions come to mind:/src/compiler/factory/nodeTests.ts
contains 21:isCommaToken
,isExclamationToken
,isQuestionToken
, etc.isExpression
,isExpressionNode
,isUnaryExpression
, etc.π» Use Cases
Developers writing logic to work with the TypeScript AST often want these functions as they're handy utilities. Many of them exist in
tsutils
for that reason.Request: which of those internal / not-exported functions would you be open to a PR exposing to the public?
Related:
zeroType
emptyStringType
andisTypeAssignableTo
on the TS TypeCheckerΒ #50694The text was updated successfully, but these errors were encountered: