Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sudo-barun opened this issue Sep 14, 2024 · 1 comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Milestone

Comments

@sudo-barun
Copy link

🔎 Search Terms

"CSS property value kebab case dash", "CSSStyleDeclaration", "getComputedStyle", "getPropertyValue"

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "CSSStyleDeclaration", "getComputedStyle"

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240914#code/OYUwLgwg9gtgDgVzCAJgZTATwDYgBQpQDGCMIAdmAHQBGUKmAlANoDkNAhkQNbABOUBORQBaIlGxQ+rALpA

💻 Code

getComputedStyle(document.body)['background-color']

🙁 Actual behavior

TypeScript reports following error:

Element implicitly has an 'any' type because index expression is not of type 'number'.

🙂 Expected behavior

TypeScript should not report any error.

Additional information about the issue

If I update the file node_modules/typescript/lib/lib.dom.d.ts to include background-color as follows:

interface CSSStyleDeclaration {
  // ...
  'background-color': string;
  // ...
}

the error does not occur for background-color property.

@whzx5byb
Copy link

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Sep 16, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants