Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type TypedFormGroup<> is not assignable to type FormGroup #273

Open
rlzdesenv opened this issue Aug 24, 2022 · 4 comments
Open

Type TypedFormGroup<> is not assignable to type FormGroup #273

rlzdesenv opened this issue Aug 24, 2022 · 4 comments
Labels
type: bug/fix This is a bug or at least needs a fix workaround-1: obvious Obvious workaround

Comments

@rlzdesenv
Copy link

is it possible to remove this alert, i followed the whole manual to create the FormGroup

public form:NgxSubForm<Endereco, Endereco> help on to find out the name of the variables in [formControlName]="form.formControlNames.city"

image

<div class="row gy-1 gx-2" [formGroup]="form.formGroup">
    <div class="col-md-6">
        <app-input-text label="Email" [formControlName]="form.formControlNames.city"></app-input-text>
    </div>
</div>
import {Component, forwardRef, OnInit} from '@angular/core';
import {createForm, FormType, NgxSubForm, subformComponentProviders} from 'ngx-sub-form';
import {FormControl, FormGroup, Validators} from '@angular/forms';

export interface Endereco {
    street: string;
    city: string;
    state: string;
    zipCode: string;
}

@Component({
    selector: 'app-endereco-form',
    templateUrl: './endereco.form.html',
    styleUrls: ['./endereco.form.scss'],
    providers: subformComponentProviders( forwardRef(() => EnderecoForm) ),
})
export class EnderecoForm implements OnInit {

    public form:NgxSubForm<Endereco, Endereco> = createForm<Endereco>(this, {
        formType: FormType.SUB,
        formControls: {
            street: new FormControl(null, Validators.required),
            city: new FormControl(null, Validators.required),
            state: new FormControl(null, Validators.required),
            zipCode: new FormControl(null, Validators.required),
        },
    });

    constructor() {
    }

    ngOnInit(): void {
    }

}
@maxime1992
Copy link
Contributor

Yep the typings introduced by Angular 14 are a major change in forms, at least ofc typing wise and ngx-sub-form had made it's own typings since we had none provided previously.

We haven't investigated any further if we should ditch our own types and use the ones from angular only. I think that while it may seem like a good idea there are numbers of places where it'd clash with ngx-sub-form so unsure for now.

At the moment, the only way to get rid of that while keeping type safety template side; it's to use $any. Example:

[formGroup]="$any(form.formGroup)"

I hate to say this because I'm always all for maximum type safety but for now it's the best we've got. It's not too bad because it's not like the type of form.formGroup is likely to change at all and you still get type safety for all the rest

@rlzdesenv
Copy link
Author

thanks

@maxime1992 maxime1992 added type: bug/fix This is a bug or at least needs a fix workaround-1: obvious Obvious workaround labels Aug 25, 2022
@andreashouben
Copy link

Hi there, I also encountered that issue and noticed that it only occurs in IntelliJ/Webstorm. VS Code doesn't have to seem that problem. Any idea why?

@maxime1992
Copy link
Contributor

Could be that your IDE is using a custom tsconfig behind the scenes with different values for the angular compiler options (probably something stricter).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug/fix This is a bug or at least needs a fix workaround-1: obvious Obvious workaround
Projects
None yet
Development

No branches or pull requests

3 participants