[typescript]I don't know why only find() method doesn't work

Hello, I’m studying LEARN TYPESCRIPT: FUNDAMENTALS now.
I’m doing TypeMart in it, then occured weird error again and again.

the link is below:
https://www.codecademy.com/courses/learn-typescript-fundamentals/projects/typemart

I got unstuck at task3,
I used find() method on products for product, but it made error and it is below.

index.ts:12:26 - error TS2550: Property ‘find’ does not exist on type ‘{ name: string; price: string; preOrder: string; }’. Do you need to change your target library? Try changing the ‘lib’ compiler option to ‘es2015’ or later.

12 const product = products.find(p => p.name === productName);

but, when I use filter(), it works. I really don’t know why, and it’s even said to use find() on hint box!
I’ve just started to study Typescript, so many things are new for me.

Please help me.
Thank you.

The difference is that the filter method returns an empty array if no product is found whereas the find method returns ‘undefined’ in that case. So product is a different type when you use find or filter. Until step 3 that should not matter. Have you already written code from the following steps?

1 Like

Thank you for your help.
I got the difference between find and filter.
anyway, I tried that code without following steps but it didn’t work.

I’ll try this again from beginning.

I tried both methods, too, and did not get an error after compiling. Maybe you should post all of your code from index.ts

1 Like

Thanks! I tried again and it works well haha

1 Like