registerMany typed properly
This commit is contained in:
parent
3f911a7aec
commit
835c84261c
@ -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
|
||||
},
|
||||
})
|
||||
|
@ -1,7 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"lib": ["ESNext", "ES5"],
|
||||
"lib": [
|
||||
"ESNext",
|
||||
"ES5",
|
||||
"dom"
|
||||
],
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
|
Loading…
Reference in New Issue
Block a user