0

I have a function that returns the controls of a FormArray:

getFormFControls() {
    return this.form.get('opts') ? (<FormArray>this.formQuestions.get('opts')).controls : null;
}

But when running the Lint check, I get this error:

Type assertion using the '<>' syntax is forbidden. Use the 'as' syntax instead.

I tried many ways to solve this problem, but I can't find a solution when it's a FormArray.controls: AbstractControl[].

Can someone help me?

Tried to remove the and add the 'as FormArray' at the end, but I get an error.

I need to solve this without putting comment to ignore lint in the line

1 Answer 1

1

Your error is trying to tell you to change this:

(<FormArray>this.formQuestions.get('opts')).controls : null;

to this:

(this.formQuestions.get('opts') as FormArray).controls : null;

They are equivalent but the first has fallen out of use as it gets confused with JSX.

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.