Skip to content

Commit ed924d0

Browse files
TypeScript Botahejlsberg
TypeScript Bot
andauthored
🤖 Pick PR #54112 (Fix isGenericReducibleType to all...) into release-5.1 (#54349)
Co-authored-by: Anders Hejlsberg <[email protected]>
1 parent cbb5826 commit ed924d0

File tree

4 files changed

+198
-1
lines changed

4 files changed

+198
-1
lines changed

Diff for: ‎src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14046,7 +14046,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1404614046
else if (type !== firstType) {
1404714047
checkFlags |= CheckFlags.HasNonUniformType;
1404814048
}
14049-
if (isLiteralType(type) || isPatternLiteralType(type) || type === uniqueLiteralType) {
14049+
if (isLiteralType(type) || isPatternLiteralType(type)) {
1405014050
checkFlags |= CheckFlags.HasLiteralType;
1405114051
}
1405214052
if (type.flags & TypeFlags.Never && type !== uniqueLiteralType) {
+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
=== tests/cases/compiler/inferenceAndHKTs.ts ===
2+
// Repro from #53970
3+
4+
export interface TypeLambda {
5+
>TypeLambda : Symbol(TypeLambda, Decl(inferenceAndHKTs.ts, 0, 0))
6+
7+
readonly A: unknown;
8+
>A : Symbol(TypeLambda.A, Decl(inferenceAndHKTs.ts, 2, 29))
9+
}
10+
11+
export interface TypeClass<F extends TypeLambda> {
12+
>TypeClass : Symbol(TypeClass, Decl(inferenceAndHKTs.ts, 4, 1))
13+
>F : Symbol(F, Decl(inferenceAndHKTs.ts, 6, 27))
14+
>TypeLambda : Symbol(TypeLambda, Decl(inferenceAndHKTs.ts, 0, 0))
15+
16+
readonly _F: F;
17+
>_F : Symbol(TypeClass._F, Decl(inferenceAndHKTs.ts, 6, 50))
18+
>F : Symbol(F, Decl(inferenceAndHKTs.ts, 6, 27))
19+
}
20+
21+
export type Apply<F extends TypeLambda, A> = F extends { readonly type: unknown }
22+
>Apply : Symbol(Apply, Decl(inferenceAndHKTs.ts, 8, 1))
23+
>F : Symbol(F, Decl(inferenceAndHKTs.ts, 10, 18))
24+
>TypeLambda : Symbol(TypeLambda, Decl(inferenceAndHKTs.ts, 0, 0))
25+
>A : Symbol(A, Decl(inferenceAndHKTs.ts, 10, 39))
26+
>F : Symbol(F, Decl(inferenceAndHKTs.ts, 10, 18))
27+
>type : Symbol(type, Decl(inferenceAndHKTs.ts, 10, 56))
28+
29+
? (F & { readonly A: A })['type']
30+
>F : Symbol(F, Decl(inferenceAndHKTs.ts, 10, 18))
31+
>A : Symbol(A, Decl(inferenceAndHKTs.ts, 11, 12))
32+
>A : Symbol(A, Decl(inferenceAndHKTs.ts, 10, 39))
33+
34+
: { readonly F: F, readonly A: A };
35+
>F : Symbol(F, Decl(inferenceAndHKTs.ts, 12, 7))
36+
>F : Symbol(F, Decl(inferenceAndHKTs.ts, 10, 18))
37+
>A : Symbol(A, Decl(inferenceAndHKTs.ts, 12, 22))
38+
>A : Symbol(A, Decl(inferenceAndHKTs.ts, 10, 39))
39+
40+
export interface T<A> {
41+
>T : Symbol(T, Decl(inferenceAndHKTs.ts, 12, 39))
42+
>A : Symbol(A, Decl(inferenceAndHKTs.ts, 14, 19))
43+
44+
value: A;
45+
>value : Symbol(T.value, Decl(inferenceAndHKTs.ts, 14, 23))
46+
>A : Symbol(A, Decl(inferenceAndHKTs.ts, 14, 19))
47+
}
48+
49+
export interface TTypeLambda extends TypeLambda {
50+
>TTypeLambda : Symbol(TTypeLambda, Decl(inferenceAndHKTs.ts, 16, 1))
51+
>TypeLambda : Symbol(TypeLambda, Decl(inferenceAndHKTs.ts, 0, 0))
52+
53+
readonly type: T<this["A"]>;
54+
>type : Symbol(TTypeLambda.type, Decl(inferenceAndHKTs.ts, 18, 49))
55+
>T : Symbol(T, Decl(inferenceAndHKTs.ts, 12, 39))
56+
}
57+
58+
export declare const map: <F extends TypeLambda>(F: TypeClass<F>) => <A, B>(a: Apply<F, A>, f: (a: A) => B) => Apply<F, B>;
59+
>map : Symbol(map, Decl(inferenceAndHKTs.ts, 22, 20))
60+
>F : Symbol(F, Decl(inferenceAndHKTs.ts, 22, 27), Decl(inferenceAndHKTs.ts, 22, 49))
61+
>TypeLambda : Symbol(TypeLambda, Decl(inferenceAndHKTs.ts, 0, 0))
62+
>F : Symbol(F, Decl(inferenceAndHKTs.ts, 22, 27), Decl(inferenceAndHKTs.ts, 22, 49))
63+
>TypeClass : Symbol(TypeClass, Decl(inferenceAndHKTs.ts, 4, 1))
64+
>F : Symbol(F, Decl(inferenceAndHKTs.ts, 22, 27), Decl(inferenceAndHKTs.ts, 22, 49))
65+
>A : Symbol(A, Decl(inferenceAndHKTs.ts, 22, 70))
66+
>B : Symbol(B, Decl(inferenceAndHKTs.ts, 22, 72))
67+
>a : Symbol(a, Decl(inferenceAndHKTs.ts, 22, 76))
68+
>Apply : Symbol(Apply, Decl(inferenceAndHKTs.ts, 8, 1))
69+
>F : Symbol(F, Decl(inferenceAndHKTs.ts, 22, 27), Decl(inferenceAndHKTs.ts, 22, 49))
70+
>A : Symbol(A, Decl(inferenceAndHKTs.ts, 22, 70))
71+
>f : Symbol(f, Decl(inferenceAndHKTs.ts, 22, 91))
72+
>a : Symbol(a, Decl(inferenceAndHKTs.ts, 22, 96))
73+
>A : Symbol(A, Decl(inferenceAndHKTs.ts, 22, 70))
74+
>B : Symbol(B, Decl(inferenceAndHKTs.ts, 22, 72))
75+
>Apply : Symbol(Apply, Decl(inferenceAndHKTs.ts, 8, 1))
76+
>F : Symbol(F, Decl(inferenceAndHKTs.ts, 22, 27), Decl(inferenceAndHKTs.ts, 22, 49))
77+
>B : Symbol(B, Decl(inferenceAndHKTs.ts, 22, 72))
78+
79+
declare const typeClass: TypeClass<TTypeLambda>;
80+
>typeClass : Symbol(typeClass, Decl(inferenceAndHKTs.ts, 24, 13))
81+
>TypeClass : Symbol(TypeClass, Decl(inferenceAndHKTs.ts, 4, 1))
82+
>TTypeLambda : Symbol(TTypeLambda, Decl(inferenceAndHKTs.ts, 16, 1))
83+
84+
declare const a: T<number>;
85+
>a : Symbol(a, Decl(inferenceAndHKTs.ts, 26, 13))
86+
>T : Symbol(T, Decl(inferenceAndHKTs.ts, 12, 39))
87+
88+
const x1 = map(typeClass);
89+
>x1 : Symbol(x1, Decl(inferenceAndHKTs.ts, 28, 5))
90+
>map : Symbol(map, Decl(inferenceAndHKTs.ts, 22, 20))
91+
>typeClass : Symbol(typeClass, Decl(inferenceAndHKTs.ts, 24, 13))
92+
93+
const x2 = map(typeClass)(a, (_) => _); // T<number>
94+
>x2 : Symbol(x2, Decl(inferenceAndHKTs.ts, 29, 5))
95+
>map : Symbol(map, Decl(inferenceAndHKTs.ts, 22, 20))
96+
>typeClass : Symbol(typeClass, Decl(inferenceAndHKTs.ts, 24, 13))
97+
>a : Symbol(a, Decl(inferenceAndHKTs.ts, 26, 13))
98+
>_ : Symbol(_, Decl(inferenceAndHKTs.ts, 29, 30))
99+
>_ : Symbol(_, Decl(inferenceAndHKTs.ts, 29, 30))
100+

Diff for: ‎tests/baselines/reference/inferenceAndHKTs.types

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
=== tests/cases/compiler/inferenceAndHKTs.ts ===
2+
// Repro from #53970
3+
4+
export interface TypeLambda {
5+
readonly A: unknown;
6+
>A : unknown
7+
}
8+
9+
export interface TypeClass<F extends TypeLambda> {
10+
readonly _F: F;
11+
>_F : F
12+
}
13+
14+
export type Apply<F extends TypeLambda, A> = F extends { readonly type: unknown }
15+
>Apply : Apply<F, A>
16+
>type : unknown
17+
18+
? (F & { readonly A: A })['type']
19+
>A : A
20+
21+
: { readonly F: F, readonly A: A };
22+
>F : F
23+
>A : A
24+
25+
export interface T<A> {
26+
value: A;
27+
>value : A
28+
}
29+
30+
export interface TTypeLambda extends TypeLambda {
31+
readonly type: T<this["A"]>;
32+
>type : T<this["A"]>
33+
}
34+
35+
export declare const map: <F extends TypeLambda>(F: TypeClass<F>) => <A, B>(a: Apply<F, A>, f: (a: A) => B) => Apply<F, B>;
36+
>map : <F extends TypeLambda>(F: TypeClass<F>) => <A, B>(a: Apply<F, A>, f: (a: A) => B) => Apply<F, B>
37+
>F : TypeClass<F>
38+
>a : Apply<F, A>
39+
>f : (a: A) => B
40+
>a : A
41+
42+
declare const typeClass: TypeClass<TTypeLambda>;
43+
>typeClass : TypeClass<TTypeLambda>
44+
45+
declare const a: T<number>;
46+
>a : T<number>
47+
48+
const x1 = map(typeClass);
49+
>x1 : <A, B>(a: T<A>, f: (a: A) => B) => T<B>
50+
>map(typeClass) : <A, B>(a: T<A>, f: (a: A) => B) => T<B>
51+
>map : <F extends TypeLambda>(F: TypeClass<F>) => <A, B>(a: Apply<F, A>, f: (a: A) => B) => Apply<F, B>
52+
>typeClass : TypeClass<TTypeLambda>
53+
54+
const x2 = map(typeClass)(a, (_) => _); // T<number>
55+
>x2 : T<number>
56+
>map(typeClass)(a, (_) => _) : T<number>
57+
>map(typeClass) : <A, B>(a: T<A>, f: (a: A) => B) => T<B>
58+
>map : <F extends TypeLambda>(F: TypeClass<F>) => <A, B>(a: Apply<F, A>, f: (a: A) => B) => Apply<F, B>
59+
>typeClass : TypeClass<TTypeLambda>
60+
>a : T<number>
61+
>(_) => _ : (_: number) => number
62+
>_ : number
63+
>_ : number
64+

Diff for: ‎tests/cases/compiler/inferenceAndHKTs.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
// Repro from #53970
5+
6+
export interface TypeLambda {
7+
readonly A: unknown;
8+
}
9+
10+
export interface TypeClass<F extends TypeLambda> {
11+
readonly _F: F;
12+
}
13+
14+
export type Apply<F extends TypeLambda, A> = F extends { readonly type: unknown }
15+
? (F & { readonly A: A })['type']
16+
: { readonly F: F, readonly A: A };
17+
18+
export interface T<A> {
19+
value: A;
20+
}
21+
22+
export interface TTypeLambda extends TypeLambda {
23+
readonly type: T<this["A"]>;
24+
}
25+
26+
export declare const map: <F extends TypeLambda>(F: TypeClass<F>) => <A, B>(a: Apply<F, A>, f: (a: A) => B) => Apply<F, B>;
27+
28+
declare const typeClass: TypeClass<TTypeLambda>;
29+
30+
declare const a: T<number>;
31+
32+
const x1 = map(typeClass);
33+
const x2 = map(typeClass)(a, (_) => _); // T<number>

0 commit comments

Comments
 (0)