I have the following Code:
import { AbstractControl, ValidationErrors } from '@angular/forms';
import { Observable } from 'rxjs/Observable';
import { filter, map, tap} from 'rxjs/operators';
export function valueInCollectionValidator(collection: Observable<any[]>, propertyName: string) {
return (control: AbstractControl): Observable<ValidationErrors> => {
return collection.pipe(
filter(array => array.find(e => e[propertyName] == control.value)),
map(ok => ok ? undefined : { valueNotInCollection: false }),
);
};
}
When using angular CLI's ng serve, I get a build error:
ERROR in validators.ts (9,29): Property 'find' does not exist on type '{}'.
This is my jsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"module": "commonjs",
"lib": [
"es2017",
"dom"
]
}
}
Any idea why this won't work? Thanks!