menu

Search By Label

You can add this line at the beginning of a file to ignore all checks:
// @ts-nocheck
or 
// @ts-expect-error
To skip only the next line.
types are indexed by the default whereas interfaces are not. It makes interfaces more safe. 

Consider this example:
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

Source: https://stackoverflow.com/questions/72598769/intersection-types-vs-interfaces-in-typescript
The "readonly" modifier is used to indicate that a property or variable should not be modified once it has been initialized. It ensures that the value of the property remains constant throughout the lifetime of the object or variable.
 
Example with an array:

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