From af869e4b799296673b3a577093544daf8079ddba Mon Sep 17 00:00:00 2001 From: Aditya Date: Tue, 23 Jun 2026 00:15:38 +0530 Subject: [PATCH] fix: resolve TS build errors related to expr-eval and vitest --- src/hooks/useVariables.ts | 4 ++-- src/lib/editor/MathEvaluator.ts | 6 +++--- src/lib/editor/VariableScope.ts | 4 ++-- src/lib/safeStorage.test.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hooks/useVariables.ts b/src/hooks/useVariables.ts index 738b4ae..0acd66c 100644 --- a/src/hooks/useVariables.ts +++ b/src/hooks/useVariables.ts @@ -2,7 +2,7 @@ import { useEffect } from 'react' import { useAppStore } from '../store/useAppStore' import { useVariableStore } from '../store/useVariableStore' -import { Parser } from 'expr-eval' +import { Parser, type Values } from 'expr-eval' export function useVariables() { const notes = useAppStore((state) => state.notes) @@ -21,7 +21,7 @@ export function useVariables() { while ((varMatch = reVar.exec(note.content)) !== null) { const name = varMatch[1] try { - globals[name] = parser.evaluate(varMatch[2], globals as Record) + globals[name] = parser.evaluate(varMatch[2], globals as Values) } catch (e) { // eslint-disable-next-line no-console console.error(`useVariables evaluation error for ${name}:`, e) diff --git a/src/lib/editor/MathEvaluator.ts b/src/lib/editor/MathEvaluator.ts index 2445703..3213c85 100644 --- a/src/lib/editor/MathEvaluator.ts +++ b/src/lib/editor/MathEvaluator.ts @@ -1,6 +1,6 @@ import type { EditorView } from '@codemirror/view' import { getScope } from './VariableScope' -import { Parser } from 'expr-eval' +import { Parser, type Values } from 'expr-eval' export function evaluateMath( docStr: string, @@ -20,7 +20,7 @@ export function evaluateMath( const expr = text.substring(0, text.lastIndexOf('=')).trim() if (expr && !expr.startsWith('/var') && !expr.startsWith('/globvar')) { try { - const result = String(parser.evaluate(expr, scope)) + const result = String(parser.evaluate(expr, scope as Values)) changes.push({ from: offset + lineLen, to: offset + lineLen, @@ -45,7 +45,7 @@ export function evaluateMath( const expr = exprPart.replace(/=\s*$/, '').trim() if (expr) { try { - const newResult = String(parser.evaluate(expr, scope)) + const newResult = String(parser.evaluate(expr, scope as Values)) if (newResult !== oldResult) { const startReplace = calcMatch.index + exprPart.length + 1 // +1 for \u200B const endReplace = calcMatch.index + calcMatch[0].length diff --git a/src/lib/editor/VariableScope.ts b/src/lib/editor/VariableScope.ts index d8224d7..8f2468e 100644 --- a/src/lib/editor/VariableScope.ts +++ b/src/lib/editor/VariableScope.ts @@ -1,7 +1,7 @@ import type { EditorView } from '@codemirror/view' import { StateEffect } from '@codemirror/state' import { useVariableStore } from '../../store/useVariableStore' -import { Parser } from 'expr-eval' +import { Parser, type Values } from 'expr-eval' import { MathEvaluator } from './MathEvaluator' export const scopeChangedEffect = StateEffect.define() @@ -30,7 +30,7 @@ export class VariableScope { const name = varMatch[1] try { const mergedScope = Object.assign({}, globalVars, newScope) - const val = parser.evaluate(varMatch[2], mergedScope as Record) + const val = parser.evaluate(varMatch[2], mergedScope as Values) newScope[name] = val } catch (e) { // eslint-disable-next-line no-console diff --git a/src/lib/safeStorage.test.ts b/src/lib/safeStorage.test.ts index ba53d60..b7e4141 100644 --- a/src/lib/safeStorage.test.ts +++ b/src/lib/safeStorage.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, beforeEach } from 'vitest' +import { describe, it, expect, beforeEach, vi } from 'vitest' import { setSecure, getSecure } from './safeStorage' describe('safeStorage (Renderer Flow)', () => {