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
Type of generic function parameter not being inferred from interface generic type. #30505
exporttypeProp<T>={(): T}exporttypePropType<T>=Prop<T>;exporttypePropDefaultValue<T>=T;exporttypePropValidatorFunction<T>=(value: T)=>boolean;exporttypePropValidator<T>=PropOptions<T>;exporttypePropOptions<T>={type: PropType<T>;value?: PropDefaultValue<T>,required?: boolean;validator?: PropValidatorFunction<T>;}exporttypeRecordPropsDefinition<T>={[KinkeyofT]: PropValidator<T[K]>}exporttypePropsDefinition<T>=RecordPropsDefinition<T>;declarefunctionextend<T>({ props }: {props: PropsDefinition<T>}): PropsDefinition<T>;interfaceMyType{valid: boolean;}constr=extend({props: {// gets resolved to PropOptions<any> but should be PropType<MyType>notResolved: {type: ObjectasPropType<MyType>,// type not inferred validator: (x)=>{returnx.valid;}},// gets resolved currectly to PropType<MyType>// on typescript@3.4rc doest resolve to PropType<MyType>explicit: {type: ObjectasPropType<MyType>,// type not inferred validator: (x: MyType)=>{returnx.valid;}}}})// return type on 3.4@rc doesn't get resolvedr.explicitr.notResolvedr.explicit.requiredr.notResolved.required
Expected behavior:
The validator parameter as typescript type inferred from T.
Props record values to be resolved with the interface of PropType
Return type to be PropsDefinition<T>
Actual behavior:
Getting validator parameter resolved as any/unknown.
Record types are not getting resolve to the type PropOptions<T> in 3.4@rc but working in 3.3.x
The return type not working in 3.4@rc
The key issue here is that during the initial pass in type inference where we defer context sensitive function expressions and arrow functions, we never perform reverse mapped type inference on types that contain anything context sensitive. That is too conservative because, as illustrated by the examples, there are cases where we want to infer from the properties that aren't context sensitive and then apply those inferences to the context sensitive locations. I will be putting up a PR that does this.
Reacted by Carlos Rodrigues, agra, Andrew Smiley and Moritz Mahringer
Activity
RyanCavanaugh commentedon Mar 26, 2019
This hasn't worked particularly well in any version, but this seems to be regressing:
Don't pass a candidates array to getResolvedSignature
Don't pass a candidates array to getResolvedSignature (#31203)
ahejlsberg commentedon May 2, 2019
The key issue here is that during the initial pass in type inference where we defer context sensitive function expressions and arrow functions, we never perform reverse mapped type inference on types that contain anything context sensitive. That is too conservative because, as illustrated by the examples, there are cases where we want to infer from the properties that aren't context sensitive and then apply those inferences to the context sensitive locations. I will be putting up a PR that does this.