Skip to content

LuaTable improvements #708

@ark120202

Description

@ark120202

Missing members of ES keyed collections API:

delete(key: K): void (statement) -> table[key] = nil
has(key: K): boolean (expression) -> table[key] ~= nil

(it's also missing iteration methods, but we have decided to prefer pairs/ipairs instead).


Few utility methods that may be worthy to consider:

unwrap(): Partial<Record<K, V>>;
static wrap<K extends {}, V>(table: Partial<Record<K, V>>): LuaTable<K, V>;

These are purely type helpers, so LuaTable.of(table) -> table, table.unwrap() -> table.


We also may consider to make it an interface instead of a class, since it's not a real class and doesn't have a .prototype:

/** @luaTable */
interface LuaTable<K extends {}, V> {
    readonly length: number;
    set(key: K, value: V | undefined): void;
    get(key: K): V | undefined;
}

interface LuaTableConstructor {
    new(): LuaTable<{}, any>;
    new<K extends {}, V>(): LuaTable<K, V>;
}

/** @luaTable */
declare const LuaTable: LuaTableConstructor;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions