1

I'm trying to create a base class from React.Component and two classes from the base class like this:

interface BaseItemProps {
    base_prop: string;
}

class BaseItem<P, T> extends React.Component<BaseItemProps, any> {
}

class ItemClass1 extends BaseItem<BaseItemProps, any> {
}


interface ItemProps extends BaseItemProps {
    item_prop: string;
}

class ItemClass2 extends BaseItem<ItemProps, any> {
}

The problem is that class ItemClass2 doesn't see this.props as ItemProps but as BaseItemProps (this.props.item_prop is not available). What am I doing wrong?

1 Answer 1

1

You are not flowing the type for properties to React.Component, P needs to be passed to React.Component, you can use a constraint to ensure it extends BaseItemProps

class BaseItem<P extends BaseItemProps, T> extends React.Component<P, any> {
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.