[英]create index.d.ts for read-more-react npm package
I have a typescript project,我有一个 typescript 项目,
I am trying to import read-more-react but beacuse it doesn't have a @type defined for it, I need to write the index.d.ts file myself (place it under @type/read-more-react),我正在尝试导入read-more-react但因为它没有为它定义@type,我需要自己编写 index.d.ts 文件(将其放在@type/read-more-react 下),
I have tried this:我试过这个:
declare module 'read-more-react' {
import React from 'react';
declare const ReadMoreReact: React.FunctionComponent<ReadMoreReactProps>;
}
interface ReadMoreReactProps {
text: string
min: number
ideal: number
max: number
readMoreText: string
}
but it doesn't seems to work,但它似乎不起作用,
can anyone help me in how to successfully implement the index.d.ts file, what am I missing?谁能帮助我如何成功实现 index.d.ts 文件,我错过了什么?
Inside your tsconfig.json file, you need to include your index.d.ts
file.在您的 tsconfig.json 文件中,您需要包含您的
index.d.ts
文件。 You can do so by adding the following:您可以通过添加以下内容来做到这一点:
{
"include": [
"path/to/your/index.d.ts",
]
}
Also use this code instead:也使用此代码:
declare module 'read-more-react' {
import React from 'react';
interface ReadMoreReactProps {
text: string
min: number
ideal: number
max: number
readMoreText: string
}
const ReadMoreReact: React.FC<ReadMoreReactProps>;
export default ReadMoreReact;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.