Proper typechecking for decorators
This commit is contained in:
parent
ab68a5ffc6
commit
87837754f6
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue