registerMany typed properly

This commit is contained in:
Danya H 2024-06-09 22:53:59 +01:00
parent 3f911a7aec
commit 835c84261c
2 changed files with 27 additions and 12 deletions

View File

@ -10,19 +10,24 @@ class Server implements RageFW_Server {
} }
public registerMany<EventName extends RageFW_ServerEvent>(events: { public registerMany<EventName extends RageFW_ServerEvent>(events: {
[key in EventName]: RageFW_ServerEventCallback<EventName> [event in EventName]: RageFW_ServerEventCallback<event>
}): void { }): void {
Object.keys(events).forEach(eventName => Object.entries(events).map(([eventName, callback]) =>
// unknown[] ? rpc.register(eventName, (args: unknown[]) => {
// rpc.register(eventName, (args: unknown[]) => return Array.isArray(args)
// Array.isArray(args) ? events[eventName as keyof typeof events](...args) : callback(args), ? (callback as (...arg: typeof args) => void)(...args)
// ), : (callback as (arg: typeof args) => void)(args)
rpc.register(eventName, (args: unknown[]) => }),
Array.isArray(args)
? events[eventName as EventName](args)
: events[eventName as EventName](args),
),
) )
// Object.keys(events).forEach(eventName =>
// // unknown[] ?
// // rpc.register(eventName, (args: unknown[]) =>
// // Array.isArray(args) ? events[eventName as keyof typeof events](...args) : callback(args),
// // ),
// rpc.register(eventName, (...args: unknown[]) =>
// events[eventName as EventName](args),
// ),
// )
} }
} }
@ -31,11 +36,17 @@ export const rage = {
} }
rage.event.register('customServerEvent', (player, arg1, arg2) => { rage.event.register('customServerEvent', (player, arg1, arg2) => {
console.log(player, arg1, arg2)
return true return true
}) })
rage.event.registerMany({ rage.event.registerMany({
customServerEvent: (player, arg1, arg2) => { customServerEvent: (player, arg1, arg2) => {
console.log(player, arg1, arg2)
return true return true
}, },
playerDeath: (player, reason, killer) => {
console.log(player, reason, killer)
return undefined
},
}) })

View File

@ -1,7 +1,11 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ESNext", "target": "ESNext",
"lib": ["ESNext", "ES5"], "lib": [
"ESNext",
"ES5",
"dom"
],
"module": "ESNext", "module": "ESNext",
"moduleResolution": "NodeNext", "moduleResolution": "NodeNext",
"esModuleInterop": true, "esModuleInterop": true,