This question is specific to arrow functions. Is it possible to include the default values alongside an interface in the function parameters, and without resorting to Object.assign()?
interface Props {
someBoolean?: boolean;
anotherBoolean?: boolean;
children: any;
}
const DefaultValues = {
someBoolean: false,
anotherBoolean: false,
}
export const StackOverflow: React.FC<Props> = (_props: Props) => {
const props = Object.assign({}, _props, DefaultValues);
return <React.Fragment>{props.children}</React.Fragment>;
};
const props = Object.assign({}, _props, DefaultValues);does not seem correct.DefaultValueswill overwrite every existing prop in_props. Should change the order toObject.assign({}, DefaultValues, _props);