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: {
|
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
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user