Anuj TBE
Anuj TBE

Reputation: 9790

typecast react typescript component class props

Starting with React, Nextjs with typescript

I have the following class which gives an error while accessing avatar and name

Property does not exists on type readonly

enter image description here

How can I typecast the properties properly?

Upvotes: 0

Views: 633

Answers (1)

Nicholas Tower
Nicholas Tower

Reputation: 84912

React.Component is a generic class. You can specify the props there:

interface AvatarProps {
  avatar?: string;
  name: string;
}

class Avatar extends React.Component<AvatarProps> {

If you leave it out, the default is to assume there are no props.

Upvotes: 2

Related Questions