TS compiler complains when PropTypes property is set externally from the component.propTypes
dominikj111 opened this issue · 2 comments
I have this snippet where the ChippedMultiSelect.propTypes.value
passes, but ChippedMultiSelect.propTypes.options
doesn't.
The const optionItemPropType
contains same config as the ChippedMultiSelect.propTypes.value
.
The TS compiler complains only about the options config where the issue is
Argument of type 'Requireable<InferProps<{ value: Validator<NonNullable<NonNullable<string | number | null | undefined>>>; label: Validator; }>>' is not assignable to parameter of type 'ValidationMap'.ts(2345)
const optionItemPropType = PropTypes.shape({
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
label: PropTypes.string.isRequired,
});
ChippedMultiSelect.propTypes = {
value: PropTypes.arrayOf(
PropTypes.shape({
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
label: PropTypes.string.isRequired,
}),
),
options: PropTypes.arrayOf(
PropTypes.oneOfType([
PropTypes.shape(optionItemPropType),
PropTypes.shape({
label: PropTypes.string,
chips: PropTypes.arrayOf(PropTypes.shape(optionItemPropType)),
options: PropTypes.arrayOf(PropTypes.shape(optionItemPropType)),
items: PropTypes.arrayOf(PropTypes.shape(optionItemPropType)),
}),
]),
),
};
I would to expect to be able to store the PropTypes config to the variable, is it not that case, or is that an issue?
typescript version: 5.3.3
prop-types version: 15.18.1
Issues with TS aren't really something this project can fix, and the TS types are kept in the DefinitelyTyped repo, not here.
Trying my luck here then DefinitelyTyped/DefinitelyTyped#68215