Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于React+TS项目中使用npm包遇到的问题 #21

Open
Mioayaya opened this issue Dec 4, 2023 · 0 comments
Open

关于React+TS项目中使用npm包遇到的问题 #21

Mioayaya opened this issue Dec 4, 2023 · 0 comments

Comments

@Mioayaya
Copy link

Mioayaya commented Dec 4, 2023

文档里给出的是 const jinrishici = require('jinrishici');
如果使用 import { jinrishici } from 'jinrishici'; 则会报错。
这里有两个坑,1个是目前没有ts的类型包,另外一个是包里导出的是 load 函数。
对于第一个问题,在项目根目录里创建 jinrishici.d.ts 文件,简单内容为 declare module 'jinrishici'; 并在 tsconfig.json 中的 "include":[],数组中添加 "jinrishici.d.ts", 如 "include": ["src","jinrishici.d.ts"] ,即可。
对于第二个问题,修改为 import { load } from 'jinrishici'; 就可以使用了。

@Mioayaya Mioayaya closed this as completed Dec 4, 2023
@Mioayaya Mioayaya reopened this Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant