You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React+TypeScript中react-scrollable-picker类型声明缺失问题解决

解决react-scrollable-picker类型声明缺失问题

当你遇到以下错误:

Could not find a declaration file for module 'react-scrollable-picker'. '/directory/node_modules/react-scrollable-picker/lib/react-scrollable-picker.js' implicitly has an 'any' type. Try npm i --save-dev @types/react-scrollable-picker if it exists or add a new declaration (.d.ts) file containing declare module 'react-scrollable-picker';

且执行npm i --save-dev @types/react-scrollable-picker提示找不到资源时,本质是这个库没有官方维护的TypeScript类型声明包,直接手动创建声明文件即可解决:

  • 在项目中新建types目录(已有则跳过)
  • 在types目录下创建react-scrollable-picker.d.ts文件
  • 在该文件中写入代码:
    declare module 'react-scrollable-picker';
    
  • 打开tsconfig.json,确保include配置包含types目录,示例配置:
    {
      "compilerOptions": { /* 你的现有配置 */ },
      "include": ["src", "types"]
    }
    

完成后TypeScript的类型报错会自动消除,若后续需要更精准的类型提示,可以根据库的API用法自行补充声明文件里的类型定义。

内容的提问来源于stack exchange,提问作者Satish Sharma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 11:42:06