Reputation: 9790
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
How can I typecast the properties properly?
Upvotes: 0
Views: 633
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