Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Typescript type errors

未关闭
#167 19 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
typescript
领域
web-dev

调研方向

使用 TypeScript 重现这些错误,并结合 TypeScript 的 lib.dom.d.ts 检查 types/dom/parser.d.ts、types/html/anchor-element.d.ts 和 types/html/document.d.ts 中的声明。比较报告中的继承签名和实现签名,以确定这些类型是否可以与全局 DOM 接口协调一致。完成的标准是,报告的类型错误不再需要 tsc --skipLibCheck。

由索引模型根据 Issue 内容生成。

描述

Hi there,
I'm running into loads of type errors from linkedom when using the library in a typescript project.

These type errors appear to all be either missing properties or incorrect implementations of base class methods (due to parameter types or return types not matching).

The errors are too long to send but I will send a few:

node_modules/linkedom/types/dom/parser.d.ts:12:5 - error TS2416: Property 'parseFromString' in type 'DOMParser' is not assignable to the same property in base type 'DOMParser'.
  Type '<MIME extends "image/svg+xml" | "text/html" | "text/xml">(markupLanguage: string, mimeType: MIME) => { "text/html": HTMLDocument; "image/svg+xml": SVGDocument; "text/xml": XMLDocument; }[MIME]' is not assignable to type '(string: string, type: DOMParserSupportedType) => Document'.
    Type 'HTMLDocument | SVGDocument | XMLDocument' is not assignable to type 'Document'.
      Type 'HTMLDocument' is missing the following properties from type 'Document': URL, alinkColor, anchors, applets, and 181 more.

12     parseFromString<MIME extends keyof {
       ~~~~~~~~~~~~~~~

node_modules/linkedom/types/html/anchor-element.d.ts:4:14 - error TS2420: Class 'import("C:/Users/felis/home/projects/test-linkedom/node_modules/linkedom/types/html/anchor-element").HTMLAnchorElement' incorrectly implements interface 'HTMLAnchorElement'.
  Type 'HTMLAnchorElement' is missing the following properties from type 'HTMLAnchorElement': charset, coords, hreflang, name, and 132 more.

4 export class HTMLAnchorElement extends HTMLElement implements globalThis.HTMLAnchorElement {
               ~~~~~~~~~~~~~~~~~

...

node_modules/linkedom/types/html/document.d.ts:6:9 - error TS2416: Property 'all' in type 'HTMLDocument' is not assignable to the same property in base type 'HTMLDocument'.
  Property 'namedItem' is missing in type 'NodeList' but required in type 'HTMLAllCollection'.

6     get all(): NodeList;
          ~~~

  ../../../AppData/Roaming/npm/node_modules/typescript/lib/lib.dom.d.ts:5953:5
    5953     namedItem(name: string): HTMLCollection | Element | null;
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'namedItem' is declared here.

node_modules/linkedom/types/html/document.d.ts:15:9 - error TS2416: Property 'title' in type 'HTMLDocument' is not assignable to the same property in base type 'HTMLDocument'.
  Type 'HTMLTitleElement' is not assignable to type 'string'.

15     set title(arg: HTMLTitleElement);
           ~~~~~

...

Workaround: tsc --skipLibCheck

It'd be great to get the types correct here so --skipLibCheck isn't needed. I would make a PR for this however it seems design decisions would need to be made to fix the types. I'm not sure if the types can be reconciled while still extending / implementing globalThis.DOMParser, globalThis.HTMLElement, /globalThis\.HTML.*Element/, etc.

主要语言
HTML
星标
2.1k
派生
104
PR 合并指标
30 天内没有已合并 PR

环境准备

我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

WebReflection/linkedom 的其他 Issue

查看 WebReflection/linkedom 的全部 Issue

相似的 Issue

更多 Web Dev Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。