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

How to get inferred types for nested form group #648

Open
Will-at-FreedomDev opened this issue Mar 29, 2024 · 0 comments
Open

How to get inferred types for nested form group #648

Will-at-FreedomDev opened this issue Mar 29, 2024 · 0 comments

Comments

@Will-at-FreedomDev
Copy link

Describe the problem statement?

How to get the correct typing information when I have a nested form group?

In the following example, I have to implement the following workaround in order to get the "correct" type for the orderLine form group.

formGroup = inject(RxFormBuilder).formGroup(RefundOrderLineModel) as IFormGroup<RefundOrderLineModel>;

// hack: need to use as any as IFormGroup<OrderLineModel> to get correct typing information
get orderLineFormGroup() {
 return this.formGroup.controls.orderLine as any as IFormGroup<OrderLineModel>;
}

class RefundOrderLineModel {
  @propObject(OrderLineModel)
  orderLine = new OrderLineModel();
}

class OrderLineModel {
  @prop()
  quantity= 0;
}

This is no good.
image

This doesn't compile.
image

The expected solution you would like

I'd like the compiler to see this.formGroup.controls.orderLine as an IFormGroup<OrderLineModel>, or at least be able to cast to it without as any. Ideally, types would be inferred without any as keywords. Or an alternative solution which has correct inferred types.

Url

n/a

Package version

"@rxweb/reactive-form-validators": "^13.0.1",
"@rxweb/types": "^1.0.8",

@Will-at-FreedomDev Will-at-FreedomDev changed the title How to get accurate types for nested form group How to get inferred types for nested form group Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant