Skip to content

cannot set element.style.cssProperty to nullΒ #60380

@sudo-barun

Description

@sudo-barun

πŸ”Ž Search Terms

style css property null CSSStyleDeclaration

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "style css property null CSSStyleDeclaration".

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/CYewxgrgtgpgdgFwHQCMTAJ5IM4IwGxlQEMwBrAcwCcQI5gBhEfEKgAgF42ByKmYbgG4AUKEixEqdFlwEiKUpRp1GzVpzZwI+fIKA

πŸ’» Code

document.body.style.backgroundColor = null;

πŸ™ Actual behavior

Errors in code

Type 'null' is not assignable to type 'string'.

πŸ™‚ Expected behavior

No error is expected.

Additional information about the issue

This can be fixed by updating the lib.dom.d.ts as follows:

interface CSSStyleDeclaration {
// ...
-    backgroundColor: string;
+    get backgroundColor(): string;
+    set backgroundColor(value: string|null);
// ...
}

Same change has to applied to other CSS properties.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions