From d818a93c0f4e49f05fb03c33dc5187914ef89602 Mon Sep 17 00:00:00 2001 From: JohnDoe6345789 Date: Tue, 30 Dec 2025 00:48:08 +0000 Subject: [PATCH] fix(types): enhance type safety in callLuaFunction and loadPackageComponents functions --- .../src/lib/lua/ui/call-lua-function.ts | 4 +++- .../components/load-package-components.ts | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/frontends/nextjs/src/lib/lua/ui/call-lua-function.ts b/frontends/nextjs/src/lib/lua/ui/call-lua-function.ts index 86b84c8d2..b9927bfeb 100644 --- a/frontends/nextjs/src/lib/lua/ui/call-lua-function.ts +++ b/frontends/nextjs/src/lib/lua/ui/call-lua-function.ts @@ -1,6 +1,8 @@ import * as fengari from 'fengari-web' import { fromLua } from '@/lib/lua/functions/converters/from-lua' +import type { JsonValue } from '@/types/utility-types' +import type { LuaState } from '@/lib/lua/functions/types' const lua = fengari.lua @@ -11,7 +13,7 @@ const lua = fengari.lua * @param functionName - Name of the function to call * @returns The result of the function call */ -export function callLuaFunction(L: any, tableIndex: number, functionName: string): any { +export function callLuaFunction(L: LuaState, tableIndex: number, functionName: string): JsonValue { // Get the function from the table lua.lua_getfield(L, tableIndex, fengari.to_luastring(functionName)) diff --git a/frontends/nextjs/src/lib/rendering/declarative-component-renderer/components/load-package-components.ts b/frontends/nextjs/src/lib/rendering/declarative-component-renderer/components/load-package-components.ts index f4b1373a9..bff567d3b 100644 --- a/frontends/nextjs/src/lib/rendering/declarative-component-renderer/components/load-package-components.ts +++ b/frontends/nextjs/src/lib/rendering/declarative-component-renderer/components/load-package-components.ts @@ -1,7 +1,22 @@ import { getDeclarativeRenderer } from '../renderer/get-declarative-renderer' import type { DeclarativeComponentConfig } from '../types' -export function loadPackageComponents(packageContent: any) { +interface LuaScriptConfig { + id: string + code: string + parameters?: { name: string }[] + returnType?: string + isSandboxed?: boolean + allowedGlobals?: string[] + timeoutMs?: number +} + +interface PackageContent { + componentConfigs?: Record + luaScripts?: LuaScriptConfig[] +} + +export function loadPackageComponents(packageContent: PackageContent) { const renderer = getDeclarativeRenderer() if (packageContent.componentConfigs) { @@ -11,7 +26,7 @@ export function loadPackageComponents(packageContent: any) { } if (packageContent.luaScripts) { - packageContent.luaScripts.forEach((script: any) => { + packageContent.luaScripts.forEach((script: LuaScriptConfig) => { renderer.registerLuaScript(script.id, { code: script.code, parameters: script.parameters || [],