MrWolfZ / ngrx-forms

Enhance your forms in Angular applications with the power of ngrx
MIT License
374 stars 111 forks source link

Primitive unions are not supported #290

Open evantrimboli opened 2 years ago

evantrimboli commented 2 years ago

Describe the bug When using a union of string, number or boolean values, the types ultimately resolve back to the base type.

To Reproduce Steps to reproduce the behavior:

type OperatingState = 'good' | 'bad' | 'alright';
interface Thing {
  readonly state: OperatingState
}

// FormControlState<string>, should be FormControlState<OperatingState>
type Bad = FormGroupState<Thing>['controls']['state'];

[If possible, please also provide a reproduction repository or fork this code sandbox and reproduce the issue there.]

Expected behavior The union type should be retained.

Screenshots [If applicable, add screenshots to help explain your problem.]

Library version: 7.0.0

Additional context It seems like we could take advantage of some of the newer TS features in 4.7+ to achieve this:

type InferredStringFormState<T extends InferenceWrapper<any>> =
  T extends InferenceWrapper<infer U extends string | null | undefined> ? FormControlState<U>
  : never;

The same treatment could be applied to number and boolean.