Closed
Description
Bug Report
π Search Terms
inference, intersection, polymorphic this, deferred index access
π Version & Regression Information
- This changed between versions 5.1.0-dev.20230313 and 5.1.0-dev.20230315
β― Playground Link
Playground link with relevant code
π» Code
export interface TypeLambda {
readonly A: unknown
}
export interface TypeClass<F extends TypeLambda> {
readonly _F: F
}
export type Apply<F extends TypeLambda, A> = F extends { readonly type: unknown }
? (F & { readonly A: A })['type']
: { readonly F: F, readonly A: A }
export interface T<A> {
value: A
}
export interface TTypeLambda extends TypeLambda {
readonly type: T<this["A"]>
}
export declare const map: <F extends TypeLambda>(F: TypeClass<F>) => <A, B>(a: Apply<F, A>, f: (a: A) => B) => Apply<F, B>
declare const typeClass: TypeClass<TTypeLambda>
declare const a: T<number>
map(typeClass)
// TS 5.0.4: <A, B>(a: T<A>, f: (a: A) => B) => T<B>
// TS 5.1.0-dev.20230422: <A, B>(a: (TTypeLambda & { readonly A: A; })["type"], f: (a: A) => B) => (TTypeLambda & { readonly A: B; })["type"]
map(typeClass)(a, (_) => _)
// ^ TS 5.0.4 infers number
// TS 5.1.0-dev.20230422 infers unknown
π Actual behavior
Each version including and after 5.1.0-dev.20230315 defers the index access in the Apply
type and doesn't allow inference to continue.
π Expected behavior
Inference should continue to work in this case.
After a bit of research, I think that #53098 is the PR that introduced this change.