Skip to content

CSSStyleDeclaration string properties all have | null type declaration. #13644

Closed
@sccolbert

Description

@sccolbert

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
6814c1d

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions