Search By Label
// @ts-nocheck
// @ts-expect-error
types
are indexed by the default whereas interfaces
are not. It makes interfaces
more safe. type Admin = { name: string, privileges: string[] } type Employee = { name: string, startDate: Date } type CombinedType = Admin & Employee; interface CombinedInterface extends Admin, Employee { } const interfaceData: CombinedInterface = { name: '', privileges: [], startDate: new Date() } const typeData: CombinedType = { name: '', privileges: [], startDate: new Date() } const handleType = (obj: Record<string, unknown>) => { obj['name'] = 42 // unsafe } handleType(interfaceData) // error handleType(typeData) // ok
const numbers: readonly number[] = [1, 2, 3]; numbers[0] = 4; // Error! Cannot assign to an element of a readonly array numbers.push(4); // Error! Cannot push to a readonly array