Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If the CSSRule.type property is deprecated what can I used instead

Tags:

dom

css

The CSSRule docs in MDN states that the CSSRule.type property is deprecated and is not clear to me what should be used instead if one wants to check the type of CSSRule. Adding some code for reference.

const isStyleOrImportRule = (rule: CSSRule): boolean => {
  // 1 -> CSSRule.STYLE_RULE
  // 3 -> CSSRule.IMPORT_RULE   
  return  [1,3].includes(rule.type)
}
like image 453
Andres Zapata Avatar asked Sep 15 '25 03:09

Andres Zapata


1 Answers

There is a better way to do this and avoiding deprecation issues referencing the constructor function name.

const isStyleOrImportRule = (rule: CSSRule): boolean => {
  return ['CSSStyleRule', 'CSSImportRule'].includes(rule.constructor.name)
}
like image 90
Andres Zapata Avatar answered Sep 17 '25 20:09

Andres Zapata