diff --git a/README.md b/README.md index e3bbeaba..26ad0fde 100644 --- a/README.md +++ b/README.md @@ -324,7 +324,7 @@ export class VehicleProductComponent extends NgxSubFormRemapComponent | null { switch (formValue.vehicleType) { case VehicleType.SPEEDER: return formValue.speeder; @@ -381,7 +381,7 @@ export class VehicleProductComponent extends NgxSubFormRemapComponent | null { switch (formValue.vehicleType) { case VehicleType.SPEEDER: return formValue.speeder; @@ -441,7 +441,7 @@ export class CrewMembersComponent extends NgxSubFormRemapComponent | null { return formValue.crewMembers; } diff --git a/projects/ngx-sub-form/src/lib/ngx-root-form.component.spec.ts b/projects/ngx-sub-form/src/lib/ngx-root-form.component.spec.ts index fc862779..3a9b6de0 100644 --- a/projects/ngx-sub-form/src/lib/ngx-root-form.component.spec.ts +++ b/projects/ngx-sub-form/src/lib/ngx-root-form.component.spec.ts @@ -6,7 +6,7 @@ import { BehaviorSubject } from 'rxjs'; import { TestBed, async, ComponentFixture, fakeAsync, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { DataInput } from './ngx-sub-form.decorators'; -import { NgxFormWithArrayControls } from './ngx-sub-form.types'; +import { NgxFormWithArrayControls, NoExtraProperties } from './ngx-sub-form.types'; interface Vehicle { color?: string | null; @@ -209,7 +209,7 @@ class RootFormArrayComponent extends NgxRootFormComponent | null { return formValue.vehicles; } diff --git a/projects/ngx-sub-form/src/lib/ngx-root-form.component.ts b/projects/ngx-sub-form/src/lib/ngx-root-form.component.ts index e443bedc..4a8ecb0d 100644 --- a/projects/ngx-sub-form/src/lib/ngx-root-form.component.ts +++ b/projects/ngx-sub-form/src/lib/ngx-root-form.component.ts @@ -4,6 +4,7 @@ import { BehaviorSubject, Subject } from 'rxjs'; import { filter, tap } from 'rxjs/operators'; import { NgxSubFormRemapComponent } from './ngx-sub-form.component'; import { takeUntilDestroyed, isNullOrUndefined } from './ngx-sub-form-utils'; +import { NoExtraProperties } from './ngx-sub-form.types'; @Directive() // tslint:disable-next-line: directive-class-suffix @@ -90,8 +91,8 @@ export abstract class NgxRootFormComponent | null { + return (formValue as unknown) as NoExtraProperties; } public manualSave(): void { diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form.component.spec.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form.component.spec.ts index 44b5bce9..b0fdc76d 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form.component.spec.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form.component.spec.ts @@ -11,6 +11,7 @@ import { ArrayPropertyKey, ArrayPropertyValue, NgxFormWithArrayControls, + NoExtraProperties, } from '../public_api'; import { Observable } from 'rxjs'; @@ -566,7 +567,7 @@ class SubRemapComponent extends NgxSubFormRemapComponent { }; } - protected transformFromFormGroup(formValue: VehicleForm): Vehicle | null { + protected transformFromFormGroup(formValue: VehicleForm): NoExtraProperties | null { return { color: formValue.vehicleColor, canFire: formValue.vehicleCanFire, @@ -668,7 +669,7 @@ class SubArrayComponent extends NgxSubFormRemapComponent | null { return formValue.vehicles; } diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts index e68f48d1..43dffd5e 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form.component.ts @@ -24,7 +24,7 @@ import { TypedAbstractControl, TypedFormGroup, } from './ngx-sub-form-utils'; -import { FormGroupOptions, NgxFormWithArrayControls, OnFormUpdate } from './ngx-sub-form.types'; +import { FormGroupOptions, NgxFormWithArrayControls, OnFormUpdate, NoExtraProperties } from './ngx-sub-form.types'; type MapControlFunction = ( ctrl: TypedAbstractControl, @@ -340,8 +340,8 @@ export abstract class NgxSubFormComponent | null { + return (formValue as any) as NoExtraProperties; } public registerOnChange(fn: (_: any) => void): void { @@ -437,5 +437,5 @@ export abstract class NgxSubFormRemapComponent obj: ControlInterface | null, defaultValues: Partial | null, ): FormInterface | null; - protected abstract transformFromFormGroup(formValue: FormInterface): ControlInterface | null; + protected abstract transformFromFormGroup(formValue: FormInterface): NoExtraProperties | null; } diff --git a/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts b/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts index 8f881c3d..72705ec5 100644 --- a/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts +++ b/projects/ngx-sub-form/src/lib/ngx-sub-form.types.ts @@ -41,3 +41,12 @@ export interface FormGroupOptions { export interface NgxFormWithArrayControls { createFormArrayControl(key: ArrayPropertyKey, value: ArrayPropertyValue): FormControl; } + +type Impossible = { + [P in K]?: undefined | never; +}; + +export type NoExtraProperties = U extends Array + ? NoExtraProperties[] + : Omit>> + // & Impossible>; diff --git a/src/app/main/listing/listing-form/droid-listing/droid-product.component.ts b/src/app/main/listing/listing-form/droid-listing/droid-product.component.ts index 6bb3d181..4f42f06f 100644 --- a/src/app/main/listing/listing-form/droid-listing/droid-product.component.ts +++ b/src/app/main/listing/listing-form/droid-listing/droid-product.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import { FormControl, Validators } from '@angular/forms'; -import { Controls, NgxSubFormRemapComponent, subformComponentProviders } from 'ngx-sub-form'; +import { Controls, NgxSubFormRemapComponent, subformComponentProviders, NoExtraProperties } from 'ngx-sub-form'; import { AssassinDroid, AstromechDroid, @@ -52,7 +52,7 @@ export class DroidProductComponent extends NgxSubFormRemapComponent | null { switch (formValue.droidType) { case DroidType.PROTOCOL: return formValue.protocolDroid; diff --git a/src/app/main/listing/listing-form/listing-form.component.ts b/src/app/main/listing/listing-form/listing-form.component.ts index 75fecc91..8a13ae03 100644 --- a/src/app/main/listing/listing-form/listing-form.component.ts +++ b/src/app/main/listing/listing-form/listing-form.component.ts @@ -7,6 +7,7 @@ import { // NGX_SUB_FORM_HANDLE_VALUE_CHANGES_RATE_STRATEGIES, DataInput, NgxRootFormComponent, + NoExtraProperties, } from 'ngx-sub-form'; import { tap } from 'rxjs/operators'; import { ListingType, OneListing } from 'src/app/interfaces/listing.interface'; @@ -64,7 +65,7 @@ export class ListingFormComponent extends NgxRootFormComponent | null { const { vehicleProduct, droidProduct, listingType, ...commonValues } = formValue; switch (listingType) { diff --git a/src/app/main/listing/listing-form/vehicle-listing/crew-members/crew-members.component.ts b/src/app/main/listing/listing-form/vehicle-listing/crew-members/crew-members.component.ts index 82e62ab5..7a92e532 100644 --- a/src/app/main/listing/listing-form/vehicle-listing/crew-members/crew-members.component.ts +++ b/src/app/main/listing/listing-form/vehicle-listing/crew-members/crew-members.component.ts @@ -7,6 +7,7 @@ import { ArrayPropertyKey, ArrayPropertyValue, NgxFormWithArrayControls, + NoExtraProperties, } from 'ngx-sub-form'; import { CrewMember } from '../../../../../interfaces/crew-member.interface'; @@ -40,7 +41,7 @@ export class CrewMembersComponent extends NgxSubFormRemapComponent | null { return formValue.crewMembers; } diff --git a/src/app/main/listing/listing-form/vehicle-listing/vehicle-product.component.ts b/src/app/main/listing/listing-form/vehicle-listing/vehicle-product.component.ts index 06cd0f37..5dbdaae1 100644 --- a/src/app/main/listing/listing-form/vehicle-listing/vehicle-product.component.ts +++ b/src/app/main/listing/listing-form/vehicle-listing/vehicle-product.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import { FormControl, Validators } from '@angular/forms'; -import { Controls, NgxSubFormRemapComponent, subformComponentProviders } from 'ngx-sub-form'; +import { Controls, NgxSubFormRemapComponent, subformComponentProviders, NoExtraProperties } from 'ngx-sub-form'; import { OneVehicle, Spaceship, Speeder, VehicleType } from 'src/app/interfaces/vehicle.interface'; import { UnreachableCase } from 'src/app/shared/utils'; @@ -39,7 +39,7 @@ export class VehicleProductComponent extends NgxSubFormRemapComponent | null { switch (formValue.vehicleType) { case VehicleType.SPEEDER: return formValue.speeder; diff --git a/src/readme/vehicle-product.component.simplified.ts b/src/readme/vehicle-product.component.simplified.ts index 37444e81..56c19ffd 100644 --- a/src/readme/vehicle-product.component.simplified.ts +++ b/src/readme/vehicle-product.component.simplified.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import { FormControl, Validators } from '@angular/forms'; -import { Controls, NgxSubFormRemapComponent, subformComponentProviders } from 'ngx-sub-form'; +import { Controls, NgxSubFormRemapComponent, subformComponentProviders, NoExtraProperties } from 'ngx-sub-form'; import { VehicleType } from '../app/interfaces/vehicle.interface'; import { UnreachableCase } from '../app/shared/utils'; @@ -58,7 +58,7 @@ export class VehicleProductComponent extends NgxSubFormRemapComponent | null { switch (formValue.vehicleType) { case VehicleType.SPEEDER: return formValue.speeder;