altmp / altv-types

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

Rest of Custom On, Once, Off, On, etc. typings #262

Closed Stuyk closed 1 year ago

Stuyk commented 1 year ago

Client

import * as alt from 'alt-client';

declare module 'alt-client' {
    interface ICustomEmitEvent {
        testing: (arg1: string) => void;
    }
}

declare module 'alt-shared' {
    interface ICustomClientServerEvent {
        testFromClient: (value1: string) => void;
    }
}

// alt.emit
alt.emit('disconnect'); // invalid

alt.emit('hello', 'whatever', 5, {}); // valid

alt.emit('testing', 5); // invalid
alt.emit('testing', 'valid'); // valid

// alt.once
alt.once('anyResourceError', () => {}); // valid;
alt.once('whatever', () => {}); // valid
alt.once('testing', (arg1: string) => {}); // valid

// alt.off & alt.on
alt.on('whatever', (could: string, be: number, anything: Object) => {}); // valid

const testing = (arg1: string) => {}; // valid
alt.on('testing', testing); // valid
alt.off('testing', testing); // valid

alt.off('testing', (whatever: number) => {}); // invalid

const enterVehicle = (vehicle: alt.Vehicle, seat: number) => {}; // valid
alt.on('enteredVehicle', enterVehicle); // valid

// alt.emitServer
alt.emitServer('hello', 'whatever', 5, {}); // valid

alt.emitServer('testFromClient', 5); // invalid
alt.emitServer('testFromClient', 'valid'); // valid

// alt.emitServerRaw
alt.emitServerRaw('hello', 'whatever', 5, {}); // valid

alt.emitServerRaw('testFromClient', 5); // invalid
alt.emitServerRaw('testFromClient', 'valid'); // valid

// alt.emitServerUnreliable
alt.emitServerUnreliable('hello', 'whatever', 5, {}); // valid

alt.emitServerUnreliable('testFromClient', 5); // invalid
alt.emitServerUnreliable('testFromClient', 'valid'); // valid

// alt.onServer
alt.onServer('abc123', (player, value1) => {}); // valid;
alt.onServer('testFromServer', (player, value1) => {}); // valid;

// alt.offServer
alt.offServer('testFromServer', () => {}); // valid
alt.offServer('whatever', () => {}); // valid

Server

import * as alt from 'alt-server';

declare module 'alt-server' {
    interface ICustomEmitEvent {
        test: (value1: string) => void;
    }
}

declare module 'alt-shared' {
    interface ICustomServerClientEvent {
        testFromServer: (value1: string) => void;
    }
}

alt.on('playerConnect', (player) => {
    alt.emit('playerConnect'); // invalid

    // emit
    alt.emit('hello', 'whatever', 5, {}); // valid

    alt.emit('test', 5); // invalid
    alt.emit('test', 'valid'); // valid

    alt.off('test', (value1: string) => {}); //valid;
    alt.off('whatever', () => {});
    alt.off('playerConnect', () => {}); // valid;

    // alt.once
    alt.once('anyResourceError', () => {}); // valid;
    alt.once('whatever', () => {}); // valid
    alt.once('testing', (arg1: string) => {}); // valid

    // emitRaw
    alt.emitRaw('hello', 'whatever', 5, {}); // valid

    alt.emitRaw('test', 5); // invalid
    alt.emitRaw('test', 'valid'); // valid

    // player.emit
    player.emit('whatever', 'hi', 5, {}); // valid

    player.emit('testFromServer', 5); // invalid
    player.emit('testFromServer', 'valid'); // valid;

    // player.emitRaw
    player.emitRaw('whatever', 'hi', 5, {}); // valid

    player.emitRaw('testFromServer', 5); // invalid
    player.emitRaw('testFromServer', 'valid'); // valid;

    // emitClient
    alt.emitClient(player, 'whatever', 'hi', 5, {}); // valid
    alt.emitClient([player], 'whatever', 'hi', 5, {}); // valid

    alt.emitClient(player, 'testFromServer', 5); // invalid
    alt.emitClient(player, 'testFromServer', 'valid'); // valid

    alt.emitClient([player], 'testFromServer', 5); // invalid
    alt.emitClient([player], 'testFromServer', 'hi'); // valid

    // emitClientRaw
    alt.emitClientRaw(player, 'whatever', 'hi', 5, {}); // valid
    alt.emitClientRaw([player], 'whatever', 'hi', 5, {}); // valid

    alt.emitClientRaw(player, 'testFromServer', 5); // invalid
    alt.emitClientRaw(player, 'testFromServer', 'valid'); // valid

    alt.emitClientRaw([player], 'testFromServer', 5); // invalid
    alt.emitClientRaw([player], 'testFromServer', 'valid'); // valid

    // emitClientUnreliable
    alt.emitClientUnreliable(player, 'whatever', 'hi', 5, {}); // valid;
    alt.emitClientUnreliable([player], 'whatever', 'hi', 5, {}); // valid;

    alt.emitClientUnreliable(player, 'testFromServer', 5); // invalid
    alt.emitClientUnreliable(player, 'testFromServer', 'valid'); // valid

    alt.emitClientUnreliable([player], 'testFromServer', 5); // invalid
    alt.emitClientUnreliable([player], 'testFromServer', 'valid'); // valid

    // emitAllClients
    alt.emitAllClients('whatever', 'hi', 5, {}); // valid;

    alt.emitAllClients('testFromServer', 5); // invalid;
    alt.emitAllClients('testFromServer', 'valid'); // valid;

    // emitAllClientsRaw
    alt.emitAllClientsRaw('whatever', 'hi', 5, {}); // valid;

    alt.emitAllClientsRaw('testFromServer', 5); // invalid;
    alt.emitAllClientsRaw('testFromServer', 'valid'); // valid;

    // emitAllClientsUnreliable
    alt.emitAllClientsUnreliable('whatever', 'hi', 5, {}); // valid;

    alt.emitAllClientsUnreliable('testFromServer', 5); // invalid;
    alt.emitAllClientsUnreliable('testFromServer', 'valid'); // valid;
});

// alt.onClient
alt.onClient('whatever', (player, whatever: string) => {}); // valid
alt.onClient((event: 'testFromClient', player, value1: string) => {
    if (event === 'testFromClient') {
    } // valid
});

alt.onClient((event, player, whatever) => {
    if (event === 'whatever') {
    } // valid
});

// alt.onClient
alt.onClient('test', (player) => {}); // valid

alt.onClient('testFromClient', (player, value1: string) => {}); // valid

// alt.offClient
alt.offClient('whatever', () => {}); // valid
alt.offClient('testFromClient', () => {}); // valid