question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Web Animation API `Keyframe` requires all `CSSStyleDeclaration` Keys

See original GitHub issue

There appears to be some unexpected behaviour with the way in which animation Keyframes are now declared in the latest version in lib.dom.d.ts:

interface Keyframe extends Record<keyof CSSStyleDeclaration, string> {
    composite?: CompositeOperation | null;
    easing?: string;
    offset?: number | null;
}

Record<keyof CSSStyleDeclaration, string> is causing TypeScript to expect every possible key in CSSStyleDeclaration to be declared when writing animation keyframes:

el.animate([
    { transform: 'translateX(100px)' },
    { transform: 'translateX(0)' }
]);
Argument of type '{ transform: string; }[]' is not assignable to parameter of type 'Keyframe[] | PropertyIndexedKeyframes'.
  Type '{ transform: string; }[]' is not assignable to type 'Keyframe[]'.
    Type '{ transform: string; }' is not assignable to type 'Keyframe'.
      Property 'left' is missing in type '{ transform: string; }'.

This appears to be fixed if I change [P in K] in type Record to be optional:

type Record<K extends keyof any, T> = {
    [P in K]?: T;
};

See reduced test case and playground link below.

TypeScript Version: 3.1.0-dev.20180728

Search Terms: keyof optional, keyof, Record, CSSStyleDeclaration, animation

Code

type Rec<K extends keyof any, T> = {
    [P in K]: T;
};

interface Declarations {
    x: string | null;
    y: string | null;
    z: string | null;
}

interface X extends Rec<keyof Declarations, string> {}

const test: X = { x: 'string' };

Expected behavior: Should not require declaration of y and z properties.

Actual behavior:

Type '{ x: string; }' is not assignable to type 'X'.
  Property 'y' is missing in type '{ x: string; }'.

Playground Link: https://www.typescriptlang.org/play/#src=type Rec<K extends keyof any%2C T> %3D { [P in K]%3A T%3B }%3B interface Declarations { x%3A string | null%3B y%3A string | null%3B z%3A string | null%3B } interface X extends Rec<keyof Declarations%2C string> {} const test%3A X %3D { x%3A ‘string’ }%3B

Related Issues: Couldn’t find any.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:9
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
birtlescommented, Oct 11, 2018

Thanks to @DanielRosenwasser https://github.com/Microsoft/TSJS-lib-generator/pull/567 has now been merged! I suppose that means this will be fixed in the next release of TS. Thanks Daniel!

7reactions
jonchardycommented, Sep 26, 2018

Would love to see the above PR merged, we’re currently unable to update to TS3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keyframe Formats - Web APIs | MDN
An array of objects (keyframes) consisting of properties and values to iterate over. This is the canonical format returned by the getKeyframes() ...
Read more >
it seems you are interpolating a keyframe declaration
Not able to style nested animations with keyframes with styled-components ... Animation API `Keyframe` requires all `CSSStyleDeclaration` Keys#26073.
Read more >
Web Animations - W3C
The programming interface in this specification allows such applications to wait for all currently running animation to complete, regardless of ...
Read more >
How to describe an object with alternative structures / entries ...
We'll intersect all the possible keys, with our own easing and transform values ... type KeyFrame = Partial<CSSStyleDeclaration> & { easing: ...
Read more >
Safari Technology Preview Release Notes - Apple Developer
Changed animation-* declarations in @keyframes to be a parse error ... for the Web Lock API (r286284); Fixed Cross-Origin-Embedder-Policy: require-corp to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found