Skip to content

Commit 63495be

Browse files
authored
Fixed an issue with spreading a spreadable generic expression into generic JSX (#51580)
1 parent 7a65c34 commit 63495be

4 files changed

+102
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30285,7 +30285,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3028530285
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, objectFlags, /*readonly*/ false);
3028630286
attributesTable = createSymbolTable();
3028730287
}
30288-
const exprType = getReducedType(checkExpressionCached(attributeDecl.expression, checkMode));
30288+
const exprType = getReducedType(checkExpression(attributeDecl.expression));
3028930289
if (isTypeAny(exprType)) {
3029030290
hasSpreadAnyType = true;
3029130291
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
=== tests/cases/compiler/jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx ===
2+
/// <reference path="react16.d.ts" />
3+
4+
// repro #51577
5+
6+
declare function omit<T, K extends string>(names: readonly K[], obj: T): Omit<T, K>;
7+
>omit : Symbol(omit, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 0, 0), Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 84))
8+
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 22))
9+
>K : Symbol(K, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 24))
10+
>names : Symbol(names, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 43))
11+
>K : Symbol(K, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 24))
12+
>obj : Symbol(obj, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 63))
13+
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 22))
14+
>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --))
15+
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 22))
16+
>K : Symbol(K, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 24))
17+
18+
declare function omit<K extends string>(names: readonly K[]): <T>(obj: T) => Omit<T, K>;
19+
>omit : Symbol(omit, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 0, 0), Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 84))
20+
>K : Symbol(K, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 22))
21+
>names : Symbol(names, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 40))
22+
>K : Symbol(K, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 22))
23+
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 63))
24+
>obj : Symbol(obj, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 66))
25+
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 63))
26+
>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --))
27+
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 63))
28+
>K : Symbol(K, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 5, 22))
29+
30+
declare const otherProps: { bar: string, qwe: boolean }
31+
>otherProps : Symbol(otherProps, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 7, 13))
32+
>bar : Symbol(bar, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 7, 27))
33+
>qwe : Symbol(qwe, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 7, 40))
34+
35+
declare function GenericComponent<T>(props: T): null
36+
>GenericComponent : Symbol(GenericComponent, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 7, 55))
37+
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 9, 34))
38+
>props : Symbol(props, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 9, 37))
39+
>T : Symbol(T, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 9, 34))
40+
41+
<GenericComponent {...omit(['bar'], otherProps)} />; // no error
42+
>GenericComponent : Symbol(GenericComponent, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 7, 55))
43+
>omit : Symbol(omit, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 0, 0), Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 4, 84))
44+
>otherProps : Symbol(otherProps, Decl(jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx, 7, 13))
45+
46+
47+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
=== tests/cases/compiler/jsxGenericComponentWithSpreadingResultOfGenericFunction.tsx ===
2+
/// <reference path="react16.d.ts" />
3+
4+
// repro #51577
5+
6+
declare function omit<T, K extends string>(names: readonly K[], obj: T): Omit<T, K>;
7+
>omit : { <T, K extends string>(names: readonly K[], obj: T): Omit<T, K>; <K extends string>(names: readonly K[]): <T>(obj: T) => Omit<T, K>; }
8+
>names : readonly K[]
9+
>obj : T
10+
11+
declare function omit<K extends string>(names: readonly K[]): <T>(obj: T) => Omit<T, K>;
12+
>omit : { <T, K extends string>(names: readonly K[], obj: T): Omit<T, K>; <K extends string>(names: readonly K[]): <T>(obj: T) => Omit<T, K>; }
13+
>names : readonly K[]
14+
>obj : T
15+
16+
declare const otherProps: { bar: string, qwe: boolean }
17+
>otherProps : { bar: string; qwe: boolean; }
18+
>bar : string
19+
>qwe : boolean
20+
21+
declare function GenericComponent<T>(props: T): null
22+
>GenericComponent : <T>(props: T) => null
23+
>props : T
24+
>null : null
25+
26+
<GenericComponent {...omit(['bar'], otherProps)} />; // no error
27+
><GenericComponent {...omit(['bar'], otherProps)} /> : JSX.Element
28+
>GenericComponent : <T>(props: T) => null
29+
>omit(['bar'], otherProps) : Omit<{ bar: string; qwe: boolean; }, "bar">
30+
>omit : { <T, K extends string>(names: readonly K[], obj: T): Omit<T, K>; <K extends string>(names: readonly K[]): <T>(obj: T) => Omit<T, K>; }
31+
>['bar'] : "bar"[]
32+
>'bar' : "bar"
33+
>otherProps : { bar: string; qwe: boolean; }
34+
35+
36+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @strict: true
2+
// @noEmit: true
3+
// @jsx: preserve
4+
5+
/// <reference path="/.lib/react16.d.ts" />
6+
7+
// repro #51577
8+
9+
declare function omit<T, K extends string>(names: readonly K[], obj: T): Omit<T, K>;
10+
declare function omit<K extends string>(names: readonly K[]): <T>(obj: T) => Omit<T, K>;
11+
12+
declare const otherProps: { bar: string, qwe: boolean }
13+
14+
declare function GenericComponent<T>(props: T): null
15+
16+
<GenericComponent {...omit(['bar'], otherProps)} />; // no error
17+
18+

0 commit comments

Comments
 (0)