Microsoft/TypeScript
在 GitHub 查看Error when accessing CSS property value using kebab case in `CSSStyleDeclaration` object
Open
#59,968 创建于 2024年9月14日
BugDomain: lib.d.tsHelp Wanted
仓库指标
- Star
- (48,455 star)
- PR 合并指标
- (平均合并 6天 17小时) (30 天内合并 9 个 PR)
描述
🔎 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
💻 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.