taoqf / node-html-parser

A very fast HTML parser, generating a simplified DOM, with basic element query support.
MIT License
1.11k stars 107 forks source link

Typescript signature could be improved (constructor of Node + HTMLElement) #230

Closed xatian closed 1 year ago

xatian commented 1 year ago

I think the typescript-declarations in a few places could be improved.


Node currently it is like this:

export default class TextNode extends Node {
    constructor(rawText: string, parentNode: HTMLElement, range?: [number, number]);
}

seeing in the JS-code that the parentNode is not required it should be like this:

export default class TextNode extends Node {
    constructor(rawText: string, parentNode?: HTMLElement, range?: [number, number]);
}

same issue in the constructor of CommentNode.


HTMLElement currently it is like this:

export default class HTMLElement extends Node {
    constructor(tagName: string, keyAttrs: KeyAttributes, rawAttrs: string, parentNode: HTMLElement | null, range: [number, number], voidTag?: VoidTag, _parseOptions?: Partial<Options>);
}

seeing in the JS-code that only tagName and keyAttrs are required it should be:

export default class HTMLElement extends Node {
    constructor(tagName: string, keyAttrs: KeyAttributes, rawAttrs?: string, parentNode?: HTMLElement, range?: [number, number], voidTag?: VoidTag, _parseOptions?: Partial<Options>);
}


Thank you!

taoqf commented 1 year ago

Thank you.