1

I have an angular2 project (2.0.0) using typescript 2.0.4.

I have this code:

var assignedIds: Array<string> = this.AssignedUsers.map(u => u.id);
var users = this.AllUsers.filter(all => all.id != assignedIds.find(id => id == all.id));

I'm getting an error on the find method:

Property 'find' does not exist on type 'string[]'.

I get this error on several arrays - not just this one. A couple are number[], one is string[], and one it a custom object.

If I compile to es6 it works but I need to target es5.

Do I need some typings?

2
  • You need a polyfill (see here), as you do anytime you want to use an es6 feature (like Array.find) in an environment that only supports es5 Commented Oct 14, 2016 at 19:56
  • Do I need to make a polyfill? I thought Angular2 had a solution for this that didn't require custom code. Commented Oct 14, 2016 at 20:15

1 Answer 1

2

find() did not exist in ES5, so you get the error. You can solve that with a polyfill (as mentioned in a comment).

However, you actually should simply your code:

var assignedIds: Array<string> = this.AssignedUsers.map(u => u.id);
var users = this.AllUsers.filter(all => assignedIds.some(id => id == all.id));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.