Skip to content

Commit def8d25

Browse files
authored
Fix animation types, add test (#8476)
1 parent b87c12e commit def8d25

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"lint-js": "eslint samples/**/*.html samples/**/*.js src/**/*.js test/**/*.js",
4141
"lint-md": "markdownlint-cli2 \"**/*.md\" \"#**/node_modules\"",
4242
"lint-tsc": "tsc",
43-
"lint-types": "eslint types/**/*.d.ts",
43+
"lint-types": "eslint types/**/*.d.ts && tsc -p types/tests/",
4444
"lint": "concurrently \"npm:lint-*\"",
4545
"test": "npm run lint && cross-env NODE_ENV=test karma start --auto-watch --single-run --coverage --grep",
4646
"typedoc": "npx typedoc"

types/index.esm.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ export type AnimationSpec = {
14891489
}
14901490

14911491
export type AnimationsSpec = {
1492-
[name: string]: AnimationSpec & {
1492+
[name: string]: false | AnimationSpec & {
14931493
properties: string[];
14941494

14951495
/**
@@ -1507,7 +1507,7 @@ export type AnimationsSpec = {
15071507
*
15081508
*/
15091509
to: Scriptable<Color | number | boolean, ScriptableContext>;
1510-
} | false
1510+
}
15111511
}
15121512

15131513
export type TransitionSpec = {
@@ -1520,7 +1520,7 @@ export type TransitionsSpec = {
15201520
}
15211521

15221522
export type AnimationOptions = {
1523-
animation: AnimationSpec & {
1523+
animation: false | AnimationSpec & {
15241524
/**
15251525
* Callback called on each step of an animation.
15261526
*/

types/tests/animation.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Chart } from '../index.esm';
2+
3+
const chart = new Chart('id', {
4+
type: 'bar',
5+
data: {
6+
labels: [],
7+
datasets: [{
8+
data: []
9+
}]
10+
},
11+
options: {
12+
animation: false,
13+
animations: {
14+
colors: false,
15+
numbers: {
16+
properties: ['a', 'b'],
17+
type: 'number',
18+
from: 0,
19+
to: 10,
20+
delay: (ctx) => ctx.dataIndex * 100,
21+
duration: (ctx) => ctx.datasetIndex * 1000,
22+
loop: true,
23+
easing: 'linear'
24+
}
25+
},
26+
transitions: {
27+
show: {
28+
animation: {
29+
duration: 10
30+
},
31+
animations: {
32+
numbers: false
33+
}
34+
},
35+
custom: {
36+
animation: {
37+
duration: 10
38+
}
39+
}
40+
}
41+
},
42+
});

types/tests/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES6",
4+
"moduleResolution": "Node",
5+
"alwaysStrict": true,
6+
"noEmit": true
7+
},
8+
"include": [
9+
"*.ts",
10+
"../index.esm.d.ts"
11+
]
12+
}

0 commit comments

Comments
 (0)