var attributeStr = 'scaleX'
interface CSSTransformsAttr{
scaleX: number,
scaleY: number,
skewX: number,
skewY: number,
translateX: number,
translateY: number
}
How to check if the value of attributeStr
is equal to a key in CSSTransformsAttr
?
Why do i ask this?
I want to extends the CSSStyleDeclaration
with CSSTransformsAttr
.
If k
is key of CSSTransformsAttr
which is 'scaleX' | 'scaleY' | 'skewX' | 'skewY' | 'translateX' | 'translateY'
, i want to do something different than line (1). See below.
function setStyleAttributes(attrs: { [ k in keyof ( CSSStyleDeclaration & CSSTransformsAttr )]?: any }): void {
if (attrs !== undefined) {
Object.keys(attrs).forEach((key: string) => {
/// how to check if 'key' is from the CSSTransfomsAttr not CSSStyleDeclaration ?
/// ...
this.htmlElement.style[key]= attrs[key]; // (1) if key in keyof CSSStyleDeclaration
});
}
}