You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect Type Inference for Array Properties in Recursive Type DefinitionsΒ #61394
typeGetter<T>=()=>TtypeSetter<T>={<UextendsT>(value: (prev: T)=>U): U<UextendsT>(value: Exclude<U,Function>): U}typeSignal<T>=Getter<T>&Setter<T>typeReactive<T>=Signal<T>&(Textendsobject ? {readonly[KinkeyofT]: Reactive<T[K]>} : {})typeReactiveArray=Reactive<Array<unknown>>typeReactiveMap=Reactive<Map<unknown,unknown>>typeArrayForEach=ReactiveArray['forEach']// Resolves to Array<unknown>['forEach']typeMapForEach=ReactiveMap['forEach']// Resolves to Signal<Map<unknown, unknown>>['forEach'] & {}
π Actual behavior
The forEach type is inferred as Array<unknown>['forEach'], retaining the original Array method signature instead of being transformed into a Signal type like Signal<Array<unknown>['forEach']> & {}. This issue affects all Array properties.
π Expected behavior
For ReactiveArray, defined as Reactive<Array<unknown>>, I expect ReactiveArray['forEach'] to be Signal<Array<unknown>['forEach']> & {}, similar to how ReactiveMap['forEach'] is inferred as Signal<Map<unknown, unknown>>['forEach'] & {}, reflecting the recursive application of Reactive<T>.
Homomorphic mapped types that iterate directly over keyof T have special support in the compiler when they are instantiated with an array/tuple type (or intersections of those). This isn't something that can be changed. You can work around this by changing your definition to this:
Activity
Andarist commentedon Mar 11, 2025
Homomorphic mapped types that iterate directly over
keyof Thave special support in the compiler when they are instantiated with an array/tuple type (or intersections of those). This isn't something that can be changed. You can work around this by changing your definition to this:ahzvenol commentedon Mar 11, 2025
It's useful, thank you for the response