标签: reactjs use-state
我试图将useState数组声明为任何类型,但不确定如何?这就是我尝试过的
const [files, setFiles] = useState(any[])
答案 0 :(得分:2)
像这样:const [files, setFiles] = useState<any[]>([])
const [files, setFiles] = useState<any[]>([])
答案 1 :(得分:1)
useState需要一个generic。你可以做到
useState
有关更多信息,请参见:https://github.com/DefinitelyTyped/DefinitelyTyped/blob/8a1b68be3a64e5d2aa1070f68cc935d668a976ad/types/react/index.d.ts#L844