In JavaScript React I would do this to "merge" several styles:
const customStyle= {
fontWeight: 'bold'
};
<p
style={[{fontStyle: 'italic'}, customStyle]}>
{Some Text....}
</p>
However, when I try this in a TypeScript React project I get the following:
TS2322: Type '({ fontWeight: string; } | { fontStyle: string; })[]' is not assignable to type 'Properties<string | number, string & {}>'.
Types of property 'filter' are incompatible.
Type '{ <S extends { fontWeight: string; } | { fontStyle: string; }>(predicate: (value: { fontWeight: string; } | { fontStyle: string; }, index: number, array: ({ fontWeight: string; } | { fontStyle: string; })[]) => value is S, thisArg?: any): S[]; (predicate: (value: { ...; } | { ...; }, index: number, array: ({ ...; } ...' is not assignable to type 'Filter | undefined'.
This array construct comes in quite handy, because the order of the elements is important. With customStyle I could overwrite everything I defined in the object {fontStyle: 'italic'} before...
How would I pass several styles to the style prop of an HTML element?