Skip to content

Allow kebab-case indexing on CSSStyleDeclaration - #64340

Draft
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-css-property-value-error
Draft

Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-css-property-value-error

Conversation

Copilot AI commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

CSSStyleDeclaration supports accessing CSS properties via dashed/kebab-case names at runtime (e.g. style['background-color']), but the type only declared a numeric index signature plus camelCase named properties. This caused TS7015 ("implicitly has an 'any' type") under --noImplicitAny:

getComputedStyle(document.body)['background-color']; // Error, TS7015

Changes

  • Added [index: string]: any to CSSStyleDeclarationBase in lib.dom.d.ts.
    • A string-typed index signature wasn't viable: methods like getPropertyPriority(property: string): string have a function type incompatible with a string index signature, and this conflict propagates to the merged CSSStyleDeclaration/CSSStyleProperties type.
    • any avoids that conflict (compatible with any property type) while resolving string-keyed access without an implicit-any error. Existing named properties and methods keep their specific declared types; only unrecognized string keys fall back to any.
  • Added a compiler test (cssStyleDeclarationKebabCaseIndex.ts) covering read/write access via kebab-case property names under --noImplicitAny.

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug and removed For Milestone Bug PRs that fix a bug with a specific milestone labels Sep 19, 2026
Copilot AI changed the title [WIP] Fix error accessing CSS property value using kebab case Allow kebab-case indexing on CSSStyleDeclaration Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when accessing CSS property value using kebab case in CSSStyleDeclaration object

2 participants