teste hoje - typescript - Property id does not exist on type string - Stack Overflow

PHOTO EMBED

Sat Jan 07 2023 03:29:01 GMT+0000 (Coordinated Universal Time)

Saved by @ocnarb

const allCustomers: ICustomer[] = customers();

interface ICustomer {
    id: number;
    name: string;
    age: number;
    city: string;
}

function customers(): ICustomer[] {
    let id: number = 0;

    return [
        createCustomer(id++, "Drew", 22, "Glassboro"),
        createCustomer(id++, "Mike", 40, "Rineyville"),
        createCustomer(id++, "Justin", 19, "Jonesboro"),
        createCustomer(id++, "Alex", 15, "Paulsboro"),
        createCustomer(id++, "Phil", 32, "Glassboro")
    ];
}

function createCustomer(id: number, name: string, age: number, city: string): ICustomer {
    return { id, name, age, city };
}

function getCustomerInformation(customers: ICustomer[], id: number): ICustomer {
    // Note undefined is returned if object not found
    return customers.find(customer => customer.id === id);
}
content_copyCOPY

https://stackoverflow.com/questions/41269866/property-id-does-not-exist-on-type-string