diff --git a/src/parser/parse.ts b/src/parser/parse.ts index 41ae448..d2c9ac0 100644 --- a/src/parser/parse.ts +++ b/src/parser/parse.ts @@ -96,8 +96,8 @@ class ParserRun { if (whiteSpaceOrTextNode.value instanceof parts.Text && current.value[current.value.length - 1] instanceof parts.Text) { // Merge consecutive text parts into one part - const previousTextPart = current.value[current.value.length - 1]; - current.value[current.value.length - 1] = new parts.Text(previousTextPart.value + (whiteSpaceOrTextNode.value).value); + const previousTextPart = current.value[current.value.length - 1] as parts.Text; + current.value[current.value.length - 1] = new parts.Text(previousTextPart.value + (whiteSpaceOrTextNode.value as parts.Text).value); } else { current.value.push(whiteSpaceOrTextNode.value); @@ -113,7 +113,7 @@ class ParserRun { } else if (part instanceof parts.Text && inDrawingMode) { - current.value[i] = new parts.DrawingInstructions(parse(part.value, "drawingInstructions")); + current.value[i] = new parts.DrawingInstructions(parse(part.value, "drawingInstructions") as parts.drawing.Instruction[]); } }); @@ -211,8 +211,8 @@ class ParserRun { // Merge consecutive comment parts into one part current.value[current.value.length - 1] = new parts.Comment( - (current.value[current.value.length - 1]).value + - (childNode.value).value + (current.value[current.value.length - 1] as parts.Comment).value + + (childNode.value as parts.Comment).value ); } else { @@ -1323,8 +1323,8 @@ class ParserRun { // Merge consecutive comment parts into one part transformTags[transformTags.length - 1] = new parts.Comment( - (transformTags[transformTags.length - 1]).value + - (childNode.value).value + (transformTags[transformTags.length - 1] as parts.Comment).value + + (childNode.value as parts.Comment).value ); } else { @@ -1502,7 +1502,7 @@ class ParserRun { break; } - const newType = (typePart.value).value; + const newType = (typePart.value as parts.Text).value; switch (newType) { case "m": case "l": @@ -1868,7 +1868,7 @@ class ParserRun { commandsNode.value += next; } - current.value = new parts.VectorClip((scaleNode !== null) ? scaleNode.value : 1, parse(commandsNode.value, "drawingInstructions"), tagName === "clip"); + current.value = new parts.VectorClip((scaleNode !== null) ? scaleNode.value : 1, parse(commandsNode.value, "drawingInstructions") as parts.drawing.Instruction[], tagName === "clip"); } if (this.read(current, ")") === null) { @@ -1894,8 +1894,8 @@ function makeTagParserFunction( valueParser: (current: ParseNode) => ParseNode, required: boolean ): void { - (ParserRun.prototype)[`parse_tag_${ tagName }`] = function (parent: ParseNode): ParseNode { - const self = this; + (ParserRun.prototype as any)[`parse_tag_${ tagName }`] = function (parent: ParseNode): ParseNode { + const self = this as ParserRun; const current = new ParseNode(parent); if (self.read(current, tagName) === null) { @@ -1953,8 +1953,8 @@ makeTagParserFunction("4a", parts.ShadowAlpha, ParserRun.prototype.parse_alpha, makeTagParserFunction("4c", parts.ShadowColor, ParserRun.prototype.parse_color, false); for (const key of Object.keys(ParserRun.prototype)) { - if (key.indexOf("parse_") === 0 && typeof (ParserRun.prototype)[key] === "function") { - rules.set(key.substr("parse_".length), (ParserRun.prototype)[key]); + if (key.indexOf("parse_") === 0 && typeof (ParserRun.prototype as any)[key] === "function") { + rules.set(key.substr("parse_".length), (ParserRun.prototype as any)[key]); } } diff --git a/src/parser/ttf.ts b/src/parser/ttf.ts index 22baf55..a22019c 100644 --- a/src/parser/ttf.ts +++ b/src/parser/ttf.ts @@ -165,7 +165,7 @@ export function getTtfNames(attachment: Attachment): Set { * @return {!function(new(): T)} */ function struct(clazz: { new (): T; read(reader: DataReader): T; }): { new (): T; read(reader: DataReader): T; } { - const fields: StructMemberDefinition[] = (clazz).__fields; + const fields: StructMemberDefinition[] = (clazz as any).__fields; clazz.read = (reader: DataReader) => { const result: any = new clazz(); diff --git a/src/parts/index.ts b/src/parts/index.ts index 4cc6d0a..bc9dbfc 100644 --- a/src/parts/index.ts +++ b/src/parts/index.ts @@ -1302,7 +1302,7 @@ const addToString = function (ctor: Function, ctorName: string) { ctor.prototype.toString = function () { return ( ctorName + " { " + - propertyNames.map(name => `${ name }: ${ (this)[name] }`).join(", ") + + propertyNames.map(name => `${ name }: ${ (this as any)[name] }`).join(", ") + ((propertyNames.length > 0) ? " " : "") + "}" ); @@ -1323,7 +1323,7 @@ for (const key of Object.keys(exports)) { } for (const key of Object.keys(drawing)) { - const value: any = (drawing)[key]; + const value: any = (drawing as any)[key]; if (value instanceof Function) { addToString(value, `Drawing${ key }`); registerClass(value); diff --git a/src/renderers/settings.ts b/src/renderers/settings.ts index 79817e2..aa6220c 100644 --- a/src/renderers/settings.ts +++ b/src/renderers/settings.ts @@ -116,7 +116,7 @@ export class RendererSettings { static makeFontMapFromStyleElement(linkStyle: LinkStyle): Map { const fontMap = new Map(); - const styleSheet = linkStyle.sheet; + const styleSheet = linkStyle.sheet as CSSStyleSheet; for (let i = 0; i < styleSheet.cssRules.length; i++) { const rule = styleSheet.cssRules[i]; @@ -156,7 +156,7 @@ export class RendererSettings { enableSvg = RendererSettings._testSupportsSvg(), fallbackFonts = 'Arial, Helvetica, sans-serif, "Segoe UI Symbol"', useAttachedFonts = false, - } = object; + } = object as RendererSettings; const result = new RendererSettings(); result.fontMap = fontMap; @@ -196,7 +196,7 @@ export class RendererSettings { catch (ex) { if (debugMode) { if (ex instanceof DOMException) { - const domException = ex; + const domException = ex as DOMException; if (domException.code === DOMException.NO_MODIFICATION_ALLOWED_ERR) { console.log("Setting SVGFEMorphologyElement.radiusX.baseVal threw NoModificationAllowedError. This browser doesn't support SVG DOM correctly."); } diff --git a/src/renderers/web/renderer.ts b/src/renderers/web/renderer.ts index fa6d52d..5f97312 100644 --- a/src/renderers/web/renderer.ts +++ b/src/renderers/web/renderer.ts @@ -111,8 +111,8 @@ export class WebRenderer extends NullRenderer implements EventSource { super(ass, clock, (() => { if (!(_libjassSubsWrapper instanceof HTMLDivElement)) { const temp = settings; - settings = _libjassSubsWrapper; - _libjassSubsWrapper = temp; + settings = _libjassSubsWrapper as any; + _libjassSubsWrapper = temp as any; console.warn("WebRenderer's constructor now takes libjassSubsWrapper as the third parameter and settings as the fourth parameter. Please update the caller."); } @@ -904,7 +904,7 @@ export class WebRenderer extends NullRenderer implements EventSource { applyAnimationDelays(result); const animatedDescendants = result.querySelectorAll('[style*="animation:"]'); for (let i = 0; i < animatedDescendants.length; i++) { - applyAnimationDelays(animatedDescendants[i]); + applyAnimationDelays(animatedDescendants[i] as HTMLElement); } const layer = dialogue.layer; @@ -952,7 +952,7 @@ export class WebRenderer extends NullRenderer implements EventSource { // Workaround for IE const dialogueAnimationStylesElement = result.getElementsByTagName("style")[0]; if (dialogueAnimationStylesElement !== undefined) { - const sheet = dialogueAnimationStylesElement.sheet; + const sheet = dialogueAnimationStylesElement.sheet as CSSStyleSheet; if (sheet.cssRules.length === 0) { sheet.cssText = dialogueAnimationStylesElement.textContent; } diff --git a/src/types/ass.ts b/src/types/ass.ts index ff125a9..d2b2964 100644 --- a/src/types/ass.ts +++ b/src/types/ass.ts @@ -210,7 +210,7 @@ export class ASS { result._stylesFormatSpecifier = this._stylesFormatSpecifier; result._dialoguesFormatSpecifier = this._dialoguesFormatSpecifier; - result._classTag = (ASS.prototype)._classTag; + result._classTag = (ASS.prototype as any)._classTag; return result; } diff --git a/src/types/dialogue.ts b/src/types/dialogue.ts index 7d3cd57..b1b356f 100644 --- a/src/types/dialogue.ts +++ b/src/types/dialogue.ts @@ -202,7 +202,7 @@ export class Dialogue { * Parses this dialogue's parts from the raw parts string. */ private _parsePartsString(): void { - this._parts = parse(this._rawPartsString, "dialogueParts"); + this._parts = parse(this._rawPartsString, "dialogueParts") as parts.Part[]; this._alignment = this._style.alignment; diff --git a/src/types/style.ts b/src/types/style.ts index 5a562da..eb9e1eb 100644 --- a/src/types/style.ts +++ b/src/types/style.ts @@ -117,13 +117,13 @@ export class Style { this._rotationZ = valueOrDefault(template, "angle", parseFloat, value => !isNaN(value), "0"); - this._primaryColor = valueOrDefault(template, "primarycolour", str => parse(str, "colorWithAlpha"), null, "&H00FFFFFF"); - this._secondaryColor = valueOrDefault(template, "secondarycolour", str => parse(str, "colorWithAlpha"), null, "&H00FFFF00"); - this._outlineColor = valueOrDefault(template, "outlinecolour", str => parse(str, "colorWithAlpha"), null, "&H00000000"); - this._shadowColor = valueOrDefault(template, "backcolour", str => parse(str, "colorWithAlpha"), null, "&H80000000"); + this._primaryColor = valueOrDefault(template, "primarycolour", str => parse(str, "colorWithAlpha") as Color, null, "&H00FFFFFF"); + this._secondaryColor = valueOrDefault(template, "secondarycolour", str => parse(str, "colorWithAlpha") as Color, null, "&H00FFFF00"); + this._outlineColor = valueOrDefault(template, "outlinecolour", str => parse(str, "colorWithAlpha") as Color, null, "&H00000000"); + this._shadowColor = valueOrDefault(template, "backcolour", str => parse(str, "colorWithAlpha") as Color, null, "&H80000000"); this._outlineThickness = valueOrDefault(template, "outline", parseFloat, value => value >= 0, "2"); - this._borderStyle = valueOrDefault(template, "borderstyle", parseInt, value => (BorderStyle)[(BorderStyle)[value]] === value, "1"); + this._borderStyle = valueOrDefault(template, "borderstyle", parseInt, value => (BorderStyle as any)[(BorderStyle as any)[value]] === value, "1"); this._shadowDepth = valueOrDefault(template, "shadow", parseFloat, value => value >= 0, "3"); diff --git a/src/utility/map.ts b/src/utility/map.ts index bc3b7c5..f903bd6 100644 --- a/src/utility/map.ts +++ b/src/utility/map.ts @@ -218,8 +218,8 @@ class SimpleMap { return `'${ key }`; } - if ((key).id !== undefined) { - return `!${ (key).id }`; + if ((key as any).id !== undefined) { + return `!${ (key as any).id }`; } return null; diff --git a/src/utility/promise.ts b/src/utility/promise.ts index 078b2ad..aeeb4c2 100644 --- a/src/utility/promise.ts +++ b/src/utility/promise.ts @@ -159,7 +159,7 @@ class SimplePromise { const resultCapability = new DeferredPromise(); if (typeof onFulfilled !== "function") { - onFulfilled = (value: T) => value; + onFulfilled = (value: T) => value as any as U; } if (typeof onRejected !== "function") { @@ -278,12 +278,12 @@ class SimplePromise { } if (resolution === null || (typeof resolution !== "object" && typeof resolution !== "function")) { - this._fulfill(resolution); + this._fulfill(resolution as T); return; } try { - var then = (>resolution).then; + var then = (resolution as Thenable).then; } catch (ex) { this._reject(ex); @@ -291,11 +291,11 @@ class SimplePromise { } if (typeof then !== "function") { - this._fulfill(resolution); + this._fulfill(resolution as T); return; } - enqueueJob(() => this._resolveWithThenable(>resolution, then)); + enqueueJob(() => this._resolveWithThenable(resolution as Thenable, then)); }; const reject = (reason: any): void => { diff --git a/src/webworker/channel.ts b/src/webworker/channel.ts index c94cf7e..1db5caf 100644 --- a/src/webworker/channel.ts +++ b/src/webworker/channel.ts @@ -136,7 +136,7 @@ export class WorkerChannelImpl implements WorkerChannel { private _pendingRequests = new Map>(); constructor(private _comm: WorkerCommunication) { - this._comm.addEventListener("message", ev => this._onMessage(ev.data), false); + this._comm.addEventListener("message", ev => this._onMessage(ev.data as string), false); } /** @@ -183,10 +183,10 @@ export class WorkerChannelImpl implements WorkerChannel { * @param {string} rawMessage */ private _onMessage(rawMessage: string): void { - const message = <{ command: WorkerCommands }>deserialize(rawMessage); + const message = deserialize(rawMessage) as { command: WorkerCommands }; if (message.command === WorkerCommands.Response) { - const responseMessage = message; + const responseMessage = message as any as WorkerResponseMessage; const deferred = this._pendingRequests.get(responseMessage.requestId); if (deferred !== undefined) { @@ -200,7 +200,7 @@ export class WorkerChannelImpl implements WorkerChannel { } } else { - const requestMessage = message; + const requestMessage = message as WorkerRequestMessage; const requestId = requestMessage.requestId; const commandCallback = getWorkerCommandHandler(requestMessage.command);