ControlOptions Type Assertion Required for FormArray but Breaks FormGroup

I’m facing an interesting discrepancy between passing AbstractControlOptions to FormGroup vs FormArray.

I have my own classes for my form control objects and I have a custom type in order to keep the everything strongly typed.

type StageControlType = {
  stageVolume: FormControl<number>;
  actions: FormArray<ActionControl>;
};


export class StageControl extends FormGroup<StageControlType> {
  constructor() {
    super({
      stageVolume: new FormControl(DEFAULT_STAGE_VALUES.stageVolume),
      actions: new FormArray<ActionControl>(
        [].actions.map(() => new ActionControl()),
      ),
    });
  }
}

This gives me an expected error:

error TS2322: Type 'FormControl<number | null>' is not assignable to type 'FormControl<number>'.
  Type 'number | null' is not assignable to type 'number'.
    Type 'null' is not assignable to type 'number'.

          stageVolume: new FormControl(DEFAULT_STAGE_VALUES.stageVolume),

To fix this, I add the non-nullable option to the stageVolume attribute:

stageVolume: new FormControl(DEFAULT_STAGE_VALUES.stageVolume{
  nonNullable: true, ????
})

This fixes the error. At this point, I wonder why I’m getting the error with my FormGroup property but not my FormArray property. So just to be safe, I add non-nullable to my FormArray property too:

actions: new FormArray<ActionControl>(
  DEFAULT_STAGE_VALUES.actions.map(() => new ActionControl()),
  {nonNullable: true}, ????
),

And that change gives me this error

error TS2353: Object literal may only specify known properties, 
and 'nonNullable' does not exist in type 
'AbstractControlOptions | ValidatorFn | ValidatorFn[]'.

            {nonNullable: true},
             ~~~~~~~~~~~

That error does not make any sense to me, because FormGroup and FormArray both extend AbstractControl and accept AbstractControlOptions as their second parameter. I would expect them to behave the exact same way.

So I try forcing the type of the AbstractControlOptions:

actions: new FormArray<ActionControl>(
  DEFAULT_STAGE_VALUES.actions.map(() => new ActionControl()),
  {nonNullable: true} as AbstractControlOptions, ????
),

As I guessed, that fixed the issue. For some reason it wasn’t interpreting the type correctly.

So I thought perhaps I would find out what happens if I add that type force to FormGroup:

actions: new FormArray<ActionControl>(
  DEFAULT_STAGE_VALUES.actions.map(() => new ActionControl()),
  {nonNullable: true} as AbstractControlOptions, ????
),

Surprisingly, that yields this error:

error TS2322: Type 'FormControl<number | null>' is not assignable to type 'FormControl<number>'.
  Type 'number | null' is not assignable to type 'number'.
    Type 'null' is not assignable to type 'number'.

          stageVolume: new FormControl(
          ~~~~~~~~~~~

So my question is: why do the FormArray options require an as AbstractControlOptions to work, while the same type assertion in FormGroup breaks it?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật