question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSSStyleDeclaration string properties all have `| null` type declaration.

See original GitHub issue

lib.dom.d.ts has recently suffixed all of the properties of CSSStyleDeclaration with | null: https://github.com/Microsoft/TypeScript/blob/master/lib/lib.dom.d.ts#L1382 https://github.com/Microsoft/TypeScript/commit/6814c1d883791a1ad976f3146315de30e00dc0b9

For those of us using --strictNullChecks, this is forcing a null assertion (!) every time a property is used, even though according to the spec null will never be returned, only an empty string: https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-getpropertyvalue

The camel-cased attribute attribute, on getting, must return the result of invoking getPropertyValue() with the argument being the result of running the IDL attribute to CSS property algorithm for camel-cased attribute.

The spec does seem to allow null as an argument for setPropertyValue, so technically this a case where allowing a different type for a getter and setter (#2521) would be required to accurately model a builtin.

But in the absence of that, this particular object treats the empty string the same as null for setting, so I think it would be cleaner to simply remove | null from this definition so that we don’t have to needlessly null-assert everywhere CSSStyleDeclaration is used.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
HolgerJeromincommented, Sep 4, 2019

Currently we have mixed string and string | null typings 8-/ https://github.com/Microsoft/TypeScript/blob/master/lib/lib.dom.d.ts#L2749

0reactions
amakhrovcommented, Apr 9, 2020

Looks like this has landed in TS 3.6.4

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSSStyleDeclaration - Web APIs | MDN
Chrome Edge CSSStyleDeclaration Full support. Chrome1. Toggle history Full support. Edge12. Toggle... @@iterator Full support. Chrome51. Toggle history Full support. Edge18. Toggle... cssFloat Full support. Chrome1....
Read more >
CSSStyleDeclaration | typescript - v3.7.7
An object that is a CSS declaration block, and exposes style information and various style-related methods and properties.
Read more >
Union type of Partial<CssStyleDeclaration> and dictionary ...
CSSStyleDeclaration doesn't have a index signature while Dictionary does. ... Partial<CSSStyleDeclaration> & Record<string, string | null> ...
Read more >
CSSStyleDeclaration (Common DOM API ) - Oracle Help Center
Used to retrieve the object representation of the value of a CSS property if it has been explicitly set within this declaration block....
Read more >
CSSStyleDeclaration - ApacheFlex API Reference
The CSSStyleDeclaration class represents a set of CSS style rules. ... methods to get, set, and clear style properties on a CSSStyleDeclaration.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found