Skip to content

Commit 39f484c

Browse files
authored
Merge pull request #37 from VariableThe/fix/ts-build-errors
fix: resolve TS build errors related to expr-eval and vitest
2 parents 7e85f4c + af869e4 commit 39f484c

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/hooks/useVariables.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect } from 'react'
22

33
import { useAppStore } from '../store/useAppStore'
44
import { useVariableStore } from '../store/useVariableStore'
5-
import { Parser } from 'expr-eval'
5+
import { Parser, type Values } from 'expr-eval'
66

77
export function useVariables() {
88
const notes = useAppStore((state) => state.notes)
@@ -21,7 +21,7 @@ export function useVariables() {
2121
while ((varMatch = reVar.exec(note.content)) !== null) {
2222
const name = varMatch[1]
2323
try {
24-
globals[name] = parser.evaluate(varMatch[2], globals as Record<string, unknown>)
24+
globals[name] = parser.evaluate(varMatch[2], globals as Values)
2525
} catch (e) {
2626
// eslint-disable-next-line no-console
2727
console.error(`useVariables evaluation error for ${name}:`, e)

src/lib/editor/MathEvaluator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { EditorView } from '@codemirror/view'
22
import { getScope } from './VariableScope'
3-
import { Parser } from 'expr-eval'
3+
import { Parser, type Values } from 'expr-eval'
44

55
export function evaluateMath(
66
docStr: string,
@@ -20,7 +20,7 @@ export function evaluateMath(
2020
const expr = text.substring(0, text.lastIndexOf('=')).trim()
2121
if (expr && !expr.startsWith('/var') && !expr.startsWith('/globvar')) {
2222
try {
23-
const result = String(parser.evaluate(expr, scope))
23+
const result = String(parser.evaluate(expr, scope as Values))
2424
changes.push({
2525
from: offset + lineLen,
2626
to: offset + lineLen,
@@ -45,7 +45,7 @@ export function evaluateMath(
4545
const expr = exprPart.replace(/=\s*$/, '').trim()
4646
if (expr) {
4747
try {
48-
const newResult = String(parser.evaluate(expr, scope))
48+
const newResult = String(parser.evaluate(expr, scope as Values))
4949
if (newResult !== oldResult) {
5050
const startReplace = calcMatch.index + exprPart.length + 1 // +1 for \u200B
5151
const endReplace = calcMatch.index + calcMatch[0].length

src/lib/editor/VariableScope.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { EditorView } from '@codemirror/view'
22
import { StateEffect } from '@codemirror/state'
33
import { useVariableStore } from '../../store/useVariableStore'
4-
import { Parser } from 'expr-eval'
4+
import { Parser, type Values } from 'expr-eval'
55
import { MathEvaluator } from './MathEvaluator'
66

77
export const scopeChangedEffect = StateEffect.define<void>()
@@ -30,7 +30,7 @@ export class VariableScope {
3030
const name = varMatch[1]
3131
try {
3232
const mergedScope = Object.assign({}, globalVars, newScope)
33-
const val = parser.evaluate(varMatch[2], mergedScope as Record<string, unknown>)
33+
const val = parser.evaluate(varMatch[2], mergedScope as Values)
3434
newScope[name] = val
3535
} catch (e) {
3636
// eslint-disable-next-line no-console

src/lib/safeStorage.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeEach } from 'vitest'
1+
import { describe, it, expect, beforeEach, vi } from 'vitest'
22
import { setSecure, getSecure } from './safeStorage'
33

44
describe('safeStorage (Renderer Flow)', () => {

0 commit comments

Comments
 (0)