npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rtk-to-endpoints

v0.2.3

Published

A TypeScript Language Service Plugin that enhances IDE experience for RTK Query by enabling 'Go to Definition' from hooks to endpoint definitions.

Downloads

395

Readme

rtk-to-endpoints

English | 简体中文

一个 TypeScript 语言服务插件,通过实现从 RTK Query hook 到 endpoint 定义的"跳转到定义"功能,增强 IDE 开发体验。

问题

使用 RTK Query 时,hook 名称(如 useGetUserQuery)是由 endpoint 名称(如 getUser)动态派生而来的。TypeScript 原生的"跳转到定义"只能指向类型体操代码,无法直接跳转到 createApi 中的 endpoint 定义处。

解决方案

该插件拦截"跳转到定义"请求,识别 RTK Query hook 命名模式,直接导航到对应的 endpoint 定义。

安装

npm install --save-dev rtk-to-endpoints

配置

1. 在 tsconfig.json 中添加插件

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "rtk-to-endpoints"
      }
    ]
  }
}

2. 切换 VSCode 使用工作区 TypeScript

此插件需要 VSCode 使用工作区的 TypeScript 版本而非内置版本。

操作步骤:

  1. 打开命令面板:

    • Windows/Linux: Ctrl+Shift+P
    • macOS: Cmd+Shift+P
  2. 执行指令:TypeScript: 选择 TypeScript 版本... (或 "TypeScript: Select TypeScript Version")

  3. 选择使用工作区版本 (或 "Use Workspace Version")

  4. 重新加载 VSCode 窗口Ctrl+Shift+P / Cmd+Shift+P开发人员: 重新加载窗口 / "Developer: Reload Window")使配置生效。

使用

配置完成后,在任何 RTK Query hook 上使用"跳转到定义"(F12 / Cmd+点击):

// 点击 useGetUserQuery 将跳转到 getUser endpoint 定义处
const { data } = useGetUserQuery();

解构场景下的多次跳转

本插件不递归解析赋值操作。如果 hook 名称是从其他地方赋值而来(例如通过解构),可能需要多次跳转:

export const userApi = createApi({
  endpoints: (builder) => ({
    getUsers: builder.query<string, void>({
      // <- 2. 第二次跳转到达此处(endpoint 定义)
      query: () => ''
    }),
  })
})

export const { useGetUsersQuery } = userApi
//               ^
//               |
// 1. 第一次跳转到达此处(解构位置)
//    再次跳转即可到达 endpoint 定义

支持的 hook 模式:

  • use{Endpoint}Query
  • useLazy{Endpoint}Query
  • use{Endpoint}Mutation
  • use{Endpoint}QueryState
  • use{Endpoint}InfiniteQuery
  • use{Endpoint}InfiniteQueryState

要求

  • TypeScript >= 4.0.0

许可证

MIT