【发布时间】:2018-01-29 23:44:39
【问题描述】:
我们为 material-ui@next 创建了类型,并希望将它们与库一起提供,我们在上一个测试版中就这样做了。
这是index.d.ts的链接。
但是这些类型不能以其当前形式使用。在开发中,它们在本地使用并且运行良好,但在使用库 TypeScript 传送文件时似乎使用了不同的发现策略。
所有引用子文件夹的类型(例如declare 'material-ui/Button/Button')都不会被 TypeScript 找到。导入组件时会出现错误:
[ts]
Could not find a declaration file for module 'material-ui/Button/Button'. '<project path>/node_modules/material-ui/Button/Button.js' implicitly has an 'any' type.
Try `npm install @types/material-ui/Button/Button` if it exists or add a new declaration (.d.ts) file containing `declare module 'material-ui/Button/Button';`
在npm_modules 文件夹中使用时,TypeScript 不接受声明其他导入吗?因为如前所述,在本地使用它们甚至将它们移动到@types/material-ui 将使它们起作用。
此外,TypeScript 似乎找到了 index.d.ts,因为从“根”导入有效 (import { Button} from 'material-ui')。
【问题讨论】:
-
Typescript 自动搜索
@types中的类型,我相信,在package.json中带有typings键的节点包。你的包清单或其他地方有任何指向index.d.ts的东西吗? -
是的,TS 也能找到类型。像
{ Button } from ' material-ui'一样导入有效。
标签: typescript material-ui definitelytyped