MrWolfZ / ngrx-forms

Enhance your forms in Angular applications with the power of ngrx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Primitive unions are not supported

evantrimboli opened this issue · comments

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.