Below is the provided code snippet :
declare class BaseClass<TValue = any> {
value: TValue;
foo(value: TValue): void;
}
type Wrapped<T> = { value: T }
declare class ConcreteClasss<TValue> extends BaseClass<TValue> {
constructor(value: Wrapped<TValue> | TValue);
override foo(value: TValue | Wrapped<TValue>): void;
}
const valuesOf = <V>(base: BaseClass<V>): V => base.value;
const base = new ConcreteClasss('Alma');
//^?
const value = base.value;
//^? string
const value2 = valuesOf(base);
//^? string | Wrapped<string>
It appears that the foo
method serves as an inference site.
However, there seems to be a discrepancy in the type of value when accessed through a helper function. Why is this?