question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError for FromGroup.removeControl

See original GitHub issue

Which @angular/* package(s) are the source of the bug?

forms

Is this a regression?

No

Description

FormControl.removeControl shows type error when TypeScript strictNullChecks is enabled.

const group = new FormGroup({"a": new FormControl("test")})
group.removeControl("a")

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/angular-hy5qkn?file=tsconfig.json,src%2Fapp%2Fapp.component.ts

Please provide the exception or error you saw

Error in src/app/app.component.ts (14:5)
No overload matches this call.
Overload 1 of 2, '(this: FormGroup<{ [key: string]: AbstractControl<any, any>; }>, name: string, options?: { emitEvent?: boolean | undefined; } | undefined): void', gave the following error.
The 'this' context of type 'FormGroup<{ a: FormControl<string | null>; }>' is not assignable to method's 'this' of type 'FormGroup<{ [key: string]: AbstractControl<any, any>; }>'.
Property '"a"' is missing in type '{ [key: string]: AbstractControl<any, any>; }' but required in type '{ a: FormControl<string | null>; }'.
Overload 2 of 2, '(name: never, options?: { emitEvent?: boolean | undefined; } | undefined): void', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'never'.

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 14.2.1
Node: 16.13.2
Package Manager: npm 8.5.5 
OS: win32 x64

Angular: 14.2.0
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router     

Package                         Version
---------------------------------------------------------  
@angular-devkit/architect       0.1402.1
@angular-devkit/build-angular   14.2.1
@angular-devkit/core            14.2.1
@angular-devkit/schematics      14.2.1
@angular/cli                    14.2.1
@schematics/angular             14.2.1
rxjs                            7.5.6
typescript                      4.8.2

Anything else?

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
JoostKcommented, Aug 31, 2022

In that case I think you’re looking for FormRecord (new since typed forms) instead of FormGroup.

0reactions
angular-automatic-lock-bot[bot]commented, Oct 1, 2022

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'removeControl' of undefined ...
Using removeControl() of FormGroup in my component getting TypeError: Cannot read property 'removeControl' of undefined in my test case
Read more >
When FormGroup contains a FormControl instead of ...
rxweb-reactive-form-validators.js:formatted:1 ERROR TypeError: this.controls[columnName].getControlValue is not a ... removeControl('email'); formGroup.
Read more >
Angular FormGroup addControl() and removeControl()
Here on this page we will provide complete example to add and remove FormGroup , FormControl and FormArray controls to an existing FormGroup...
Read more >
How to Use Angular FormArray(s) within FormGroup(s) In ...
error TS2740: Type 'AbstractControl' is missing the following properties from type 'FormGroup': controls, registerControl, addControl, ...
Read more >
FormGroupDirective
Binds an existing FormGroup or FormRecord to a DOM element. ... instance from the internal list of directives. removeControl(dir: FormControlName): void ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found