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: {
[key in EventName]: RageFW_ServerEventCallback<EventName>
[event in EventName]: RageFW_ServerEventCallback<event>
}): void {
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[]) =>
Array.isArray(args)
? events[eventName as EventName](args)
: events[eventName as EventName](args),
),
Object.entries(events).map(([eventName, callback]) =>
rpc.register(eventName, (args: unknown[]) => {
return Array.isArray(args)
? (callback as (...arg: typeof args) => void)(...args)
: (callback as (arg: typeof args) => void)(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) => {
console.log(player, arg1, arg2)
return true
})
rage.event.registerMany({
customServerEvent: (player, arg1, arg2) => {
console.log(player, arg1, arg2)
return true
},
playerDeath: (player, reason, killer) => {
console.log(player, reason, killer)
return undefined
},
})

View File

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