From f97671596a46cc59dd4e8fdec318513e18507158 Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Fri, 18 Aug 2023 12:09:19 +0800 Subject: [PATCH] fix: tsc errors --- src/modules/convert/api.ts | 12 ++++++------ src/modules/reader.ts | 4 ++-- src/utils/note.ts | 4 ++-- tsconfig.json | 1 + 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/modules/convert/api.ts b/src/modules/convert/api.ts index dc698ab..05146d1 100644 --- a/src/modules/convert/api.ts +++ b/src/modules/convert/api.ts @@ -18,9 +18,9 @@ import rehypeFormat from "rehype-format"; import { h } from "hastscript"; import YAML = require("yamljs"); -import { Root as HRoot } from "hast"; +import { Root as HRoot, RootContent } from "hast"; import { Root as MRoot } from "mdast"; -import { Node } from "hast-util-to-text/lib"; +import { Nodes } from "hast-util-to-text/lib"; import { fileExists, formatPath, randomString } from "../../utils/str"; import { parseCitationHTML } from "../../utils/citation"; import { @@ -575,8 +575,8 @@ function rehype2note(rehype: HRoot) { ); // Ignore empty lines, as they are not parsed to md - const tempChildren = []; - const isEmptyNode = (_n: Node) => + const tempChildren: RootContent[] = []; + const isEmptyNode = (_n: Nodes) => (_n.type === "text" && !_n.value.trim()) || (_n.type === "element" && _n.tagName === "p" && @@ -585,8 +585,8 @@ function rehype2note(rehype: HRoot) { for (const child of rehype.children) { if ( tempChildren.length && - isEmptyNode(tempChildren[tempChildren.length - 1]) && - isEmptyNode(child) + isEmptyNode(tempChildren[tempChildren.length - 1] as Nodes) && + isEmptyNode(child as Nodes) ) { continue; } diff --git a/src/modules/reader.ts b/src/modules/reader.ts index 7729d51..71b6c33 100644 --- a/src/modules/reader.ts +++ b/src/modules/reader.ts @@ -50,7 +50,7 @@ async function initializeReaderAnnotationButton( return []; } const hitItems: Zotero.Item[] = []; - for (const moreButton of _document.querySelectorAll(".more")) { + for (const moreButton of Array.from(_document.querySelectorAll(".more"))) { if (moreButton.getAttribute("_betternotesInitialized") === "true") { continue; } @@ -171,7 +171,7 @@ async function unInitializeReaderAnnotationButton( if (!_document) { return; } - for (const moreButton of _document.querySelectorAll(".more")) { + for (const moreButton of Array.from(_document.querySelectorAll(".more"))) { if (moreButton.getAttribute("_betternotesInitialized") === "true") { moreButton.removeAttribute("_betternotesInitialized"); } diff --git a/src/utils/note.ts b/src/utils/note.ts index 002df40..4478c7e 100644 --- a/src/utils/note.ts +++ b/src/utils/note.ts @@ -1,5 +1,5 @@ import TreeModel = require("tree-model"); -import katex from "katex"; +import katex = require("katex"); import { getEditorInstance, getPositionAtLine, insert } from "./editor"; import { formatPath, getItemDataURL } from "./str"; import { showHint } from "./hint"; @@ -220,7 +220,7 @@ async function renderNoteHTML( const bgNodes = doc.querySelectorAll( "span[style]", ) as NodeListOf; - for (const node of bgNodes) { + for (const node of Array.from(bgNodes)) { // Browser converts #RRGGBBAA hex color to rgba function, and we convert it to rgb function, // because word processors don't understand colors with alpha channel if ( diff --git a/tsconfig.json b/tsconfig.json index a033072..7034702 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "experimentalDecorators": true, "module": "commonjs", + "lib": ["ESNext", "DOM"], "target": "ES2016", "resolveJsonModule": true, "skipLibCheck": true,