Home > Software engineering >  How to pass the TS type checking for component props
How to pass the TS type checking for component props

Time:06-30

export const Component: React.FC<SpaProps> = function({
    a,
    b,
    c,
    d
})

a, b, c belong to SpaProps. However, d doesn't. How I can add a prop type, which supports a,b,c,d together? BTW I know what the type for d

export interface IT {
    d: AxiosInstance;
}

CodePudding user response:

You can extend the type with Typescript like this:

export const Component: React.FC<SpaProps & IT> = function({
    a,
    b,
    c,
    d
})

Even if you didn't know the type, you could write it like this:

export const Component: React.FC<SpaProps & {d: AxiosInterface}> = function({
    a,
    b,
    c,
    d
})
  • Related