1
0
Fork 0

Proper typechecking for decorators

This commit is contained in:
Pabloader 2026-04-28 12:08:08 +00:00
parent ab68a5ffc6
commit 87837754f6
1 changed files with 10 additions and 3 deletions

View File

@ -14,8 +14,12 @@ export abstract class RPGComponentBase implements RPGComponent {
const vars: RPGVariables = {}; const vars: RPGVariables = {};
for (const [methodKey, exportName] of keys) { for (const [methodKey, exportName] of keys) {
const k = String(methodKey); const k = String(methodKey);
const v = (this as unknown as Record<string, RPGVariables[string]>)[k]; const v = (this as Record<string, unknown>)[k];
if (v != null) { if (
typeof v === 'number'
|| typeof v === 'string'
|| typeof v === 'boolean'
) {
vars[exportName] = v; vars[exportName] = v;
} }
} }
@ -29,7 +33,10 @@ export abstract class RPGComponentBase implements RPGComponent {
const actions: RPGActions = {}; const actions: RPGActions = {};
for (const key of keys) { for (const key of keys) {
const k = String(key); const k = String(key);
actions[k] = (arg?: unknown) => (this as unknown as Record<string, (a?: unknown) => unknown>)[k](arg); const fn = (this as Record<string, unknown>)[k];
if (typeof fn === 'function') {
actions[k] = fn.bind(this);
}
} }
return actions; return actions;
} }