打字稿在正确输入的参数上引发错误
Typescript raising an error on a correctly typed parameter
我正在使用 NextJs 和打字稿,当我传递一个正确输入的道具时,我得到的错误是:
./pages/jobs.tsx:100:15
Type error: Type '{ job: jobType; key: number; handleTagClick: (tag: string) => void; }' is not assignable to type 'IntrinsicAttributes & jobType'.
Property 'job' does not exist on type 'IntrinsicAttributes & jobType'.
98 | filteredJobs.map((job) => (
99 | <JobComponent
> 100 | job={job}
| ^
101 | key={job.id}
102 | handleTagClick={handleTagClick}
103 | />
error Command failed with exit code 1.
JobComponent
的类型就像它接收多个参数一样,但你可能意味着这是一个道具对象。
目前:
const JobComponent = (job: jobType, handleTagClick: Function) => {}
应该是什么:
type Props = { job: jobType, handleTagClick: Function };
const JobComponent = ({job, handleTagClick}: Props) => {}
我正在使用 NextJs 和打字稿,当我传递一个正确输入的道具时,我得到的错误是:
./pages/jobs.tsx:100:15
Type error: Type '{ job: jobType; key: number; handleTagClick: (tag: string) => void; }' is not assignable to type 'IntrinsicAttributes & jobType'.
Property 'job' does not exist on type 'IntrinsicAttributes & jobType'.
98 | filteredJobs.map((job) => (
99 | <JobComponent
> 100 | job={job}
| ^
101 | key={job.id}
102 | handleTagClick={handleTagClick}
103 | />
error Command failed with exit code 1.
JobComponent
的类型就像它接收多个参数一样,但你可能意味着这是一个道具对象。
目前:
const JobComponent = (job: jobType, handleTagClick: Function) => {}
应该是什么:
type Props = { job: jobType, handleTagClick: Function };
const JobComponent = ({job, handleTagClick}: Props) => {}