Microsoft/TypeScript

`lib.dom.d.ts`: Keyframe interface should allow CSS Typed Object Model objects like CSSTransformValue, etc

開放

#63,325 建立於 2026年3月30日

 (1 則留言) (0 個反應) (0 位負責人)TypeScript (13,395 個分叉)batch import
BugDomain: lib.d.tsHelp Wanted

倉庫指標

星標
 (108,860 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

🔎 Search Terms

"Keyframe transform CSSRotate", "lib.dom.d.ts Keyframe Typed OM", "CSSTransformValue in Web Animations"

🕗 Version & Regression Information

Typescript version: 6.0.2

It's not a regression but a long-standing missing type definition

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBA1gUwJ4DMBOBDAtgiAuGAaWXWwQG0BdGAXhnICgZmYBvGKTSFENLAgORoQUDFAQAKAAwATBAHMAlAIC+AGiYt2nDN178YYBAHcYAYQDKFgEoixkgCwBWNTCmv35qwDkArjjQAS2AANQwAG18EADoABww0CEkBAE5ZBQFFRRUGSgYGUEhYBHCEHDBYOhkQYH8ECujgNAR7AFFS8qgJARlAgDdM-JKy+qho3UCsewlGFjYOLggePkFhUXFpOSVVDTntReWDI1NLGzsN5w8rrws-AOCwyJj4xOS0rczs3NdWTWYZXyYKCBcAEJxSKQMFSKIA

💻 Code

const keyframes: Keyframe[] = [
    { transform: 'rotate(0deg)'},
    { transform: new CSSRotate(45, 0, 0, CSSNumericValue.parse('90deg'))}
]

const element = document.createElement('div')

element.animate([
    { transform: 'rotate(0deg)'},
    { transform: new CSSRotate(45, 0, 0, CSSNumericValue.parse('90deg'))}
], {
    duration: 500
})

🙁 Actual behavior

TypeScript identifies the property as an invalid type because it only expects strings or numbers for CSS property values in the Keyframe record.

🙂 Expected behavior

The Keyframe interface should be updated to allow CSSTransformValue (and other Typed OM types) for relevant CSS properties, as these are valid at runtime in modern browsers.

Additional information about the issue

The Keyframe interface used by element.animate() currently only accepts string | number | null | undefined for CSS properties. However, the Web Animations API is compatible with the CSS Typed OM, allowing properties like transform to accept CSSTransformValue objects such as CSSRotate, CSSTranslate, etc.

貢獻者指南