From 24fd055913125a964cb5aa61330376274c938035 Mon Sep 17 00:00:00 2001 From: taoqf Date: Thu, 17 Aug 2023 09:33:08 +0800 Subject: [PATCH] fix: improve constructor types #230 --- src/nodes/comment.ts | 2 +- src/nodes/html.ts | 2 +- src/nodes/text.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nodes/comment.ts b/src/nodes/comment.ts index 13925c2..8ba5ff8 100644 --- a/src/nodes/comment.ts +++ b/src/nodes/comment.ts @@ -6,7 +6,7 @@ export default class CommentNode extends Node { public clone(): CommentNode { return new CommentNode(this.rawText, null); } - public constructor(public rawText: string, parentNode: HTMLElement, range?: [number, number]) { + public constructor(public rawText: string, parentNode = null as HTMLElement | null, range?: [number, number]) { super(parentNode, range); } diff --git a/src/nodes/html.ts b/src/nodes/html.ts index 273f1cb..4c75e33 100644 --- a/src/nodes/html.ts +++ b/src/nodes/html.ts @@ -172,7 +172,7 @@ export default class HTMLElement extends Node { tagName: string, keyAttrs: KeyAttributes, public rawAttrs = '', - parentNode: HTMLElement | null, + parentNode = null as HTMLElement | null, range: [number, number], private voidTag = new VoidTag(), _parseOptions = {} as Partial diff --git a/src/nodes/text.ts b/src/nodes/text.ts index 3ed36b7..0eb9cd5 100644 --- a/src/nodes/text.ts +++ b/src/nodes/text.ts @@ -11,7 +11,7 @@ export default class TextNode extends Node { public clone(): TextNode { return new TextNode(this._rawText, null); } - public constructor(rawText: string, parentNode: HTMLElement, range?: [number, number]) { + public constructor(rawText: string, parentNode = null as HTMLElement | null, range?: [number, number]) { super(parentNode, range); this._rawText = rawText; }