TypeError for FromGroup.removeControl
See original GitHub issueWhich @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:
- Created a year ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In that case I think you’re looking for
FormRecord
(new since typed forms) instead ofFormGroup
.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.