Discussion: Consider making a "shortcut" API around TypeScript for node types #6013
Replies: 3 comments
-
I would say we could probably go one step further and just offer all of this off of the parser serivces! For example: type ParserServices = {
getTypeAtLocation(node: TSESTree.Node): ReturnType<ts.TypeChecker['getTypeAtLocation']>;
};
const parserServices = util.getParserServices(context);
parserServices.getTypeAtLocation(node); That would make it even more straight-forward for people to use the tooling! |
Beta Was this translation helpful? Give feedback.
-
Oh interesting. I like putting this as a member of |
Beta Was this translation helpful? Give feedback.
-
the reason I like it as a direct sibling is it's one less step. const {program} = util.getParserServices(context);
const checker = program.getTypeChecker(); Adding it as a separate property would make it more likely there's a clash if the consumer needs a more advanced API than what we offer. const {checker, program} = util.getParserServices(context);
const checker2 = program.getTypeChecker(); If we build it right then most usecases shouldn't really need to ever manually touch |
Beta Was this translation helpful? Give feedback.
-
Suggestion
We write code like this very frequently:
It's a little burdensome.
@bradzacher and I were chatting in a pairing about how it might be convenient to make a wrapper around this, for convenience. Vague first draft:
We'd probably want to export this as a publicly available & documented API, so it's not confusing to consumers why our source code doesn't look like examples.
One downside would be that we're obfuscating how to use TypeScript APIs. I hate to add to complexity of understanding these already hard-to-understand things...
Beta Was this translation helpful? Give feedback.
All reactions