我正在尝试使用流行的反应-电话号码输入包,但是,在使用with country选项时,我发现了各种类型记录错误,目前为止所做的一切都是找到的:
npm install --save react-phone-number-input
npm install --save @types/react-phone-number-input
import PhoneInput from 'react-phone-number-input'
<PhoneInput/>但是,对于without country,我们必须这样做,就像他们在网站上指出的那样:
import PhoneInput from 'react-phone-number-input/input'
function Example() {
// `value` will be the parsed phone number in E.164 format.
// Example: "+12133734253".
const [value, setValue] = useState()
// If `country` property is not passed
// then "International" format is used.
// Otherwise, "National" format is used.
return (
<PhoneInput
country="US"
value={value}
onChange={setValue} />
)
}但是,`react-phone-number-input/input.的问题在于类型记录的抱怨,而且他们似乎忘了提到@的问题
这是我得到的具体错误:
TS7016: Could not find a declaration file for module 'react-phone-number-input/input'.
'/home/liz/prj/node_modules/react-phone-number-input/input/index.commonjs.js' implicitly has an 'any' type.
Try `npm install @types/react-phone-number-input-input-min` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-phone-number-input/input';我该如何解决这个问题?文档中提到的任何解决方案或安装?
发布于 2021-06-29 16:59:49
创建自定义类型declaration.Steps:
在这里,我只提供了一小部分类型,这些类型按照我的需求是足够的,但是它足以在此基础上构建:
/// <reference types="react">
declare module 'react-phone-number-input/input' {
interface CustomPhoneInputProps {
onChange: (value: string) => void;
value: string;
placeholder: string;
className: string;
}
export default class PhoneInput extends React.Component<CustomPhoneInputProps, object> {}
}发布于 2022-01-31 20:54:33
我认为这是他们的指示中的一个错误。从他们的演示来看,应该是
import Input from 'react-phone-number-input/input'
<Input
placeholder="Enter phone number"
value={value}
onChange={setValue} />注意,它是输入,而不是PhoneInput。
https://stackoverflow.com/questions/68173421
复制相似问题