#How do you declare the type of an arrow function ?

6 messages · Page 1 of 1 (latest)

hexed lichen
#

My type definition is

type ProjectArrType = {
    title: string,
    description: string,
    tools: { [index: number]: string }
}[];

interface ProjectType<P = {}> {
    (props: P): React.ReactNode
}

My usage in the function

const Project: ProjectType<ProjectArrType> = ({ title, description, tools }) => {
//Code 
}

I'm getting the error
Property 'title' does not exist on type 'ProjectArrType'.

and I'm not sure why. Maybe I'm not defining it right?

dim raptor
#

your ProjectArrType is an array, not a single object

#

are you trying to just extract the first element? or maybe you don't want to pass an array to Project in the first place?

#

if the latter is correct you can do this:

formal oxideBOT
#
mkantor#0

Preview:ts ... const Project: ProjectType<ProjectArrType[number]> = ({ title, description, tools, }) => { ...

hexed lichen