altmp / altv-types

Type definitions for the alt:V JavaScript modules.
https://www.npmjs.com/~vadzz
MIT License
29 stars 73 forks source link

client|server: Fix on, once, off #264

Closed xxshady closed 1 year ago

xxshady commented 1 year ago

Fixes built-in & custom event name collision from happening: (and cleans up on, once, off overloads a bit)

изображение

Does not break autocomplete of built-in and custom events:

изображение

Tests

Server

import * as alt from 'alt-server'

declare module 'alt-server' {
    interface ICustomEmitEvent {
        playerConnect: (impossible: string) => void
        test: (possible: string) => void
    }
}

alt.on("playerConnect", (player) => {}) // player: Player, valid
alt.on("playerConnect", (impossible: string) => {}) // now this is invalid
alt.on("playerConnect", (impossibleToo: number) => {}) // invalid

alt.once("playerConnect", (player) => {}) // player: Player, valid
alt.once("playerConnect", (impossible: string) => {}) // now this is invalid
alt.once("playerConnect", (impossibleToo: number) => {}) // invalid

alt.off("playerConnect", (player) => {}) // player: Player, valid
alt.off("playerConnect", (impossible: string) => {}) // now this is invalid
alt.off("playerConnect", (impossibleToo: number) => {}) // invalid

alt.on("test", (adawdawdw: number) => {}) // invalid
alt.once("test", (adawdawdw: number) => {}) // invalid
alt.off("test", (adawdawdw: number) => {}) // invalid

alt.on("awdawd", (adawdawdw: number) => {}) // valid
alt.once("awdawd", (adawdawdw: number) => {}) // valid
alt.off("awdawd", (adawdawdw: number) => {}) // valid

Client

import * as alt from 'alt-client'

declare module 'alt-client' {
    interface ICustomEmitEvent {
        anyResourceStop: (impossible: number) => void
        test: (possible: string) => void
    }
}

alt.on("anyResourceStop", (name) => {}) // name: string, valid
alt.on("anyResourceStop", (impossible: number) => {}) // now this is invalid
alt.on("anyResourceStop", (impossibleToo: boolean) => {}) // invalid

alt.once("anyResourceStop", (player) => {}) // name: string, valid
alt.once("anyResourceStop", (impossible: number) => {}) // now this is invalid
alt.once("anyResourceStop", (impossibleToo: boolean) => {}) // invalid

alt.off("anyResourceStop", (player) => {}) // name: string, valid
alt.off("anyResourceStop", (impossible: number) => {}) // now this is invalid
alt.off("anyResourceStop", (impossibleToo: boolean) => {}) // invalid

alt.on("test", (adawdawdw: number) => {}) // invalid
alt.once("test", (adawdawdw: number) => {}) // invalid
alt.off("test", (adawdawdw: number) => {}) // invalid

alt.on("awdawd", (adawdawdw: number) => {}) // valid
alt.once("awdawd", (adawdawdw: number) => {}) // valid
alt.off("awdawd", (adawdawdw: number) => {}) // valid