Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Make a "shortcut" API around TypeScript for node types #6244

Closed
Assignees
JoshuaKGoldberg
Labels
accepting prsGo ahead, send a pull request that resolves this issuerepo maintenancethings to do with maintenance of the repo, and not with code/docs
Milestone
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Discussed in#6013

Originally posted byJoshuaKGoldberg November 7, 2022

Suggestion

We write code like this very frequently:

constparserServices=util.getParserServices(context);constchecker=parserServices.program.getTypeChecker();consttsNode=parserServices.esTreeNodeToTSNodeMap.get(node);consttype=checker.getTypeAtLocation(node);

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:

declareconsttypeUtils:{[Kinkeyofts.TypeChecker]:(services:ParserServices,node:TSESTree.Node)=>ReturnType<ts.TypeChecker[K]>;};consttype=typeUtils.getTypeAtLocation(parserServices,node);

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...


We ended up with#6013 (comment): putting the types right on the parser services.

I would say we could probably go one step further and just offer all of this off of the parser serivces!

For example:

typeParserServices={getTypeAtLocation(node:TSESTree.Node):ReturnType<ts.TypeChecker['getTypeAtLocation']>;};constparserServices=util.getParserServices(context);parserServices.getTypeAtLocation(node);

That would make it even more straight-forward for people to use the tooling!

Metadata

Metadata

Labels

accepting prsGo ahead, send a pull request that resolves this issuerepo maintenancethings to do with maintenance of the repo, and not with code/docs

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp