diff --git a/src/Context.ts b/src/Context.ts index 8aded528..5d011a6c 100644 --- a/src/Context.ts +++ b/src/Context.ts @@ -86,7 +86,7 @@ var CONTEXT_PROPERTIES = [ 'globalAlpha', 'globalCompositeOperation', 'imageSmoothingEnabled', -]; +] as const; const traceArrMax = 100; /** @@ -701,6 +701,11 @@ export class Context { } } +// supported context properties +type CanvasContextProps = Pick; + +export interface Context extends CanvasContextProps {}; + CONTEXT_PROPERTIES.forEach(function (prop) { Object.defineProperty(Context.prototype, prop, { get() { diff --git a/test/unit/Context-test.ts b/test/unit/Context-test.ts index 3c231326..7d5a256c 100644 --- a/test/unit/Context-test.ts +++ b/test/unit/Context-test.ts @@ -57,7 +57,7 @@ describe('Context', function () { 'textBaseline', 'globalAlpha', 'globalCompositeOperation', - ]; + ] as const; it('context wrapper should work like native context', function () { var stage = addStage(); @@ -108,10 +108,10 @@ describe('Context', function () { // test get nativeContext.fillStyle = '#ff0000'; - assert.equal(context['fillStyle'], '#ff0000'); + assert.equal(context.fillStyle, '#ff0000'); // test set - context['globalAlpha'] = 0.5; - assert.equal(context['globalAlpha'], 0.5); + context.globalAlpha = 0.5; + assert.equal(context.globalAlpha, 0.5); }); });