From 0568cfc7c99b2cbd03ee0fc1d04605e59185aa10 Mon Sep 17 00:00:00 2001 From: Nathan Muir Date: Wed, 20 Aug 2025 11:16:11 +1200 Subject: [PATCH] refactor: enable typescript option `erasableSyntaxOnly` --- src/Context.ts | 4 ++-- src/Node.ts | 2 +- src/Util.ts | 4 ++-- src/types.ts | 42 +++++++++++++++++++++--------------------- tsconfig.json | 2 +- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Context.ts b/src/Context.ts index e054787b..4141c5b4 100644 --- a/src/Context.ts +++ b/src/Context.ts @@ -664,10 +664,10 @@ export class Context { this._context.setLineDash(segments); } else if ('mozDash' in this._context) { // verified that this works in firefox - (this._context['mozDash']) = segments; + (this._context as any)['mozDash'] = segments; } else if ('webkitLineDash' in this._context) { // does not currently work for Safari - (this._context['webkitLineDash']) = segments; + (this._context as any)['webkitLineDash'] = segments; } // no support for IE9 and IE10 diff --git a/src/Node.ts b/src/Node.ts index 003ebcff..2a4a01d0 100644 --- a/src/Node.ts +++ b/src/Node.ts @@ -1911,7 +1911,7 @@ export abstract class Node { attrs[key] = obj[key]; } - const node = new (this.constructor)(attrs); + const node = new (this.constructor as any)(attrs); // copy over listeners for (key in this.eventListeners) { allListeners = this.eventListeners[key]; diff --git a/src/Util.ts b/src/Util.ts index 44701ba8..1b9dffc2 100644 --- a/src/Util.ts +++ b/src/Util.ts @@ -529,7 +529,7 @@ export const Util = { const canvas = document.createElement('canvas'); // on some environments canvas.style is readonly try { - (canvas).style = canvas.style || {}; + (canvas as any).style = canvas.style || {}; } catch (e) {} return canvas; }, @@ -991,7 +991,7 @@ export const Util = { // very simplified version of Object.assign _assign(target: T, source: U) { for (const key in source) { - (target)[key] = source[key]; + (target as any)[key] = source[key]; } return target as T & U; }, diff --git a/src/types.ts b/src/types.ts index 95cccb23..cc87dc18 100644 --- a/src/types.ts +++ b/src/types.ts @@ -51,27 +51,27 @@ export interface IFrame { export type AnimationFn = (frame: IFrame) => boolean | void; -export enum KonvaNodeEvent { - mouseover = 'mouseover', - mouseout = 'mouseout', - mousemove = 'mousemove', - mouseleave = 'mouseleave', - mouseenter = 'mouseenter', - mousedown = 'mousedown', - mouseup = 'mouseup', - wheel = 'wheel', - contextmenu = 'contextmenu', - click = 'click', - dblclick = 'dblclick', - touchstart = 'touchstart', - touchmove = 'touchmove', - touchend = 'touchend', - tap = 'tap', - dbltap = 'dbltap', - dragstart = 'dragstart', - dragmove = 'dragmove', - dragend = 'dragend', -} +export const KonvaNodeEvent = { + mouseover: 'mouseover', + mouseout: 'mouseout', + mousemove: 'mousemove', + mouseleave: 'mouseleave', + mouseenter: 'mouseenter', + mousedown: 'mousedown', + mouseup: 'mouseup', + wheel: 'wheel', + contextmenu: 'contextmenu', + click: 'click', + dblclick: 'dblclick', + touchstart: 'touchstart', + touchmove: 'touchmove', + touchend: 'touchend', + tap: 'tap', + dbltap: 'dbltap', + dragstart: 'dragstart', + dragmove: 'dragmove', + dragend: 'dragend', +} as const; export interface RGB { r: number; diff --git a/tsconfig.json b/tsconfig.json index 3e84e17d..99e36024 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,8 +7,8 @@ "noUncheckedSideEffectImports": true, "rewriteRelativeImportExtensions": true, "isolatedModules": true, + "erasableSyntaxOnly": true, // ideally we want to enable erasableSyntaxOnly & verbatimModuleSyntax for true node interop - "erasableSyntaxOnly": false, "verbatimModuleSyntax": false, // "sourceMap": true, "noEmitOnError": true,