Avoid using Object or {}

πŸ”΄ Object / {}

function printRowAsTable(data: Object) {
    // Returns the data as a table representation, i.e.
    // | Key  | Value  |
    // |------|--------|
    // | key1 | value1 |
    // | key2 | value2 |
    // | key3 | value3 |
    // |------|--------|
}

βœ… Example 1 - These are type-safe:

printRowAsTable({ name: "Alice", age: 30, isActive: true });
printRowAsTable({ "2010": 123, "2011": 456, "2012": 789 });

⚠️ Example 2 - These are also type-safe but logically incorrect:

printRowAsTable(new Date());
printRowAsTable([1, 2, 3, 4, 5]);

🟒 Record

Invalid combinations like in Example 2 are now caught by the type system:

function printRowAsTable(data: Record<string, unknown>) {}

πŸ“š References