]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix animation types, add test (#8476)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Sun, 21 Feb 2021 14:15:26 +0000 (16:15 +0200)
committerGitHub <noreply@github.com>
Sun, 21 Feb 2021 14:15:26 +0000 (09:15 -0500)
package.json
types/index.esm.d.ts
types/tests/animation.ts [new file with mode: 0644]
types/tests/tsconfig.json [new file with mode: 0644]

index 010223c214624575ba097c63151862747a3ce091..de00f13d5d415aea518ff6efcc2e6c0bf4ddeffc 100644 (file)
@@ -40,7 +40,7 @@
     "lint-js": "eslint samples/**/*.html samples/**/*.js src/**/*.js test/**/*.js",
     "lint-md": "markdownlint-cli2 \"**/*.md\" \"#**/node_modules\"",
     "lint-tsc": "tsc",
-    "lint-types": "eslint types/**/*.d.ts",
+    "lint-types": "eslint types/**/*.d.ts && tsc -p types/tests/",
     "lint": "concurrently \"npm:lint-*\"",
     "test": "npm run lint && cross-env NODE_ENV=test karma start --auto-watch --single-run --coverage --grep",
     "typedoc": "npx typedoc"
index 46c14653415cd7ced97c5a3be9d9704dbfc8e97c..5a7da61e6629f9bc363ec59d3371a6a7bcf5f0e7 100644 (file)
@@ -1489,7 +1489,7 @@ export type AnimationSpec = {
 }
 
 export type AnimationsSpec = {
-  [name: string]: AnimationSpec & {
+  [name: string]: false | AnimationSpec & {
     properties: string[];
 
     /**
@@ -1507,7 +1507,7 @@ export type AnimationsSpec = {
      *
      */
     to: Scriptable<Color | number | boolean, ScriptableContext>;
-  } | false
+  }
 }
 
 export type TransitionSpec = {
@@ -1520,7 +1520,7 @@ export type TransitionsSpec = {
 }
 
 export type AnimationOptions = {
-  animation: AnimationSpec & {
+  animation: false | AnimationSpec & {
     /**
      * Callback called on each step of an animation.
      */
diff --git a/types/tests/animation.ts b/types/tests/animation.ts
new file mode 100644 (file)
index 0000000..33fea27
--- /dev/null
@@ -0,0 +1,42 @@
+import { Chart } from '../index.esm';
+
+const chart = new Chart('id', {
+  type: 'bar',
+  data: {
+    labels: [],
+    datasets: [{
+      data: []
+    }]
+  },
+  options: {
+    animation: false,
+    animations: {
+      colors: false,
+      numbers: {
+        properties: ['a', 'b'],
+        type: 'number',
+        from: 0,
+        to: 10,
+        delay: (ctx) => ctx.dataIndex * 100,
+        duration: (ctx) => ctx.datasetIndex * 1000,
+        loop: true,
+        easing: 'linear'
+      }
+    },
+    transitions: {
+      show: {
+        animation: {
+          duration: 10
+        },
+        animations: {
+          numbers: false
+        }
+      },
+      custom: {
+        animation: {
+          duration: 10
+        }
+      }
+    }
+  },
+});
diff --git a/types/tests/tsconfig.json b/types/tests/tsconfig.json
new file mode 100644 (file)
index 0000000..774512d
--- /dev/null
@@ -0,0 +1,12 @@
+{
+  "compilerOptions": {
+    "target": "ES6",
+    "moduleResolution": "Node",
+    "alwaysStrict": true,
+    "noEmit": true
+  },
+  "include": [
+    "*.ts",
+    "../index.esm.d.ts"
+  ]
+}