TypeScript-DOM-lib-generator
TypeScript-DOM-lib-generator copied to clipboard
CSS Typed OM get property return types
Narrow down return type of StylePropertyMapReadOnly.get() to match CSS Types OM specification. Properties now return their specific CSSStyleValue sub classes:
- CSSUnitValue
- CSSKeywordValue
- CSSTransformValue
- Default: CSSStyleValue
This change provides better type safety and autocompletion when working with computedStyleMap().
Changes:
- Added specific return types for common CSS properties in StylePropertyMap
- Maintained backwards compatibility with fallback to
CSSStyleValue - Included links to MDN documentation
Thanks for the PR!
This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged.
@microsoft-github-policy-service agree
I realized that there are more type definitions such as:
- CSSImageValue
- CSSUnparsedValue
- CSSMathValue I've mapped all the properties listed in MDN and consolidated those into a couple of function overloads.
The process involved:
- Querying MDN for all possible properties.
- Testing each property with common values to reflect the CSSStyleValue subclasses:
[
/* Units: */
'10px',
'10%',
/* Keywords: */
'auto',
'none',
/* Math: */
'calc(100% - 20px)',
/* Style: */
'rgb(255,0,0)',
/* Image: */
'url("test.jpg")',
/* Transform: */
'matrix(1, 0, 0, 1, 0, 0)'
]
- Grouping properties by their return type combinations.
- Adding relevant MDN references for each group
Hope it helps people use computedStyleMap().