[edited with more information ]Typescript ES6 equivalent of .includes?

Hello i have a question today,

error trow in console happening when i use the command line :

picklist.ts:80:17 - error TS2339: Property 'includes' does not exist on type 'IProduct[]'.

i need the equivalent of .includes function for a school project that I MUST do in ES6 with the following command line :

tsc -t es6

i know it is working on es2015 but my teacher seems to be a bit close-minded on method to use.

Does something exist to do this :

if (!Listpush.includes(valueSelectionned)) {
    productList.splice(valueIdList1, 1)
    Listpush.push(valueSelectionned);
    valueIdList1 = null
} else {
    valueSelectionned = Listpush[valueIdList2]
    Listpush.splice(valueIdList2, 1)
    productList.push(valueSelectionned);
    valueIdList2 = null
}

i tried with indexOf but it didnt work either

here how i set my interface :

interface IProduct {
    img: string;
    name: string;
    category: string;
    stock: string;
}

let productList: IProduct[] = [
    { img: "fh0g3", name: "Bamboo Watch", category: "Accessories", stock: "Instock" },
    { img: "el433", name: "Black Watch", category: "Accessories", stock: "Instock" },
    { img: "cz3c1", name: "Blue Band", category: "Fitness", stock: "Lowstok" },
    { img: "vgerg2", name: "Blue T-Shirt", category: "Clothing", stock: "Instock" },
    { img: "6wer53", name: "Bracelet", category: "Accessories", stock: "Lowstok" },
    { img: "31fwg", name: "Brown Purse", category: "Accessories", stock: "Instock" }
]

let Listpush: IProduct[] = [];//where i want to push my data

thx for your help everyone !!!



Read more here: https://stackoverflow.com/questions/64944849/edited-with-more-information-typescript-es6-equivalent-of-includes

Content Attribution

This content was originally published by Arnaud Rey at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: