소스 검색

fix(editor): resolve pre-existing type errors blocking declaration emit

- Fix katex.ts mod type (use `.default` type, not module namespace)
- Add non-null assertions after null guards (useMarkdownDecorations, katex)
- Fix markdown-extensions.ts InlineParser return type, typed parse params, remove unsafe casts
Zander Hawke 1 주 전
부모
커밋
3e39d314b7
3개의 변경된 파일10개의 추가작업 그리고 12개의 파일을 삭제
  1. 1 1
      packages/editor/src/composables/useMarkdownDecorations.ts
  2. 3 3
      packages/editor/src/lib/katex.ts
  3. 6 8
      packages/editor/src/lib/markdown-extensions.ts

+ 1 - 1
packages/editor/src/composables/useMarkdownDecorations.ts

@@ -240,7 +240,7 @@ function buildTokenDecorations(
   // ── Inline math: show KaTeX when blurred; show source when focused ──
   if (token.type === "inline-math") {
     if (!isFocused) {
-      const tokenStart = offset + sorted[0].from
+      const tokenStart = offset + sorted[0]!.from
       // Hide all ranges
       const source = token.wrapperAttrs?.["data-math"] ?? ""
       for (const range of sorted) {

+ 3 - 3
packages/editor/src/lib/katex.ts

@@ -1,4 +1,4 @@
-let mod: typeof import("katex") | null = null
+let mod: typeof import("katex").default | null = null
 
 export async function renderKatex(
   source: string,
@@ -7,7 +7,7 @@ export async function renderKatex(
 ) {
   if (!mod) mod = (await import("katex")).default
   try {
-    mod.render(source, el, { throwOnError: false, displayMode })
+    mod!.render(source, el, { throwOnError: false, displayMode })
   } catch {
     el.textContent = source
   }
@@ -23,7 +23,7 @@ export function renderKatexSync(
     return
   }
   try {
-    mod.render(source, el, { throwOnError: false, displayMode })
+    mod!.render(source, el, { throwOnError: false, displayMode })
   } catch {
     el.textContent = source
   }

+ 6 - 8
packages/editor/src/lib/markdown-extensions.ts

@@ -10,6 +10,8 @@
 
 import type {
   BlockContext,
+  InlineContext,
+  InlineParser,
   LeafBlock,
   LeafBlockParser,
   MarkdownConfig,
@@ -118,12 +120,12 @@ function createPatternExtension(patterns: MarkdownPattern[]): MarkdownConfig {
   }
 }
 
-function createInlineMathParser(): MarkdownConfig["parseInline"] {
+function createInlineMathParser(): InlineParser {
   const nodeType = "InlineMath"
   return {
     name: nodeType,
     before: "Link",
-    parse(cx, _next, pos) {
+    parse(cx: InlineContext, _next: number, pos: number) {
       if (cx.char(pos) !== 36) return -1 // '$'
 
       // Don't consume $$ as inline math
@@ -281,15 +283,11 @@ export function createMarkdownExtensions(
 
   const merged: MarkdownConfig = {
     defineNodes: [
-      ...((patternExt.defineNodes as Array<{ name: string; block: boolean }>) ??
-        []),
+      ...(patternExt.defineNodes ?? []),
       { name: "InlineMath", block: false },
     ],
     parseInline: [
-      ...((patternExt.parseInline as Array<{
-        name: string
-        parse: (cx: unknown, next: number, pos: number) => number
-      }>) ?? []),
+      ...(patternExt.parseInline ?? []),
       inlineMathParser,
     ],
   }