Skip to content

Commit 4ea8ec4

Browse files
committed
Fixed an issue with spreading a spreadable generic expression into generic JSX
1 parent 8eed2ca commit 4ea8ec4

5 files changed

+104
-3
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28781,7 +28781,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2878128781
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, objectFlags, /*readonly*/ false);
2878228782
attributesTable = createSymbolTable();
2878328783
}
28784-
const exprType = getReducedType(checkExpressionCached(attributeDecl.expression, checkMode));
28784+
const exprType = getReducedType(checkExpressionCached(attributeDecl.expression));
2878528785
if (isTypeAny(exprType)) {
2878628786
hasSpreadAnyType = true;
2878728787
}

tests/baselines/reference/contextuallyTypedStringLiteralsInJsxAttributes02.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(29,43): err
1717
Type '{ extra: true; goTo: string; }' is not assignable to type 'IntrinsicAttributes & ButtonProps'.
1818
Property 'extra' does not exist on type 'IntrinsicAttributes & ButtonProps'.
1919
Overload 2 of 2, '(linkProps: LinkProps): Element', gave the following error.
20-
Type '{ extra: true; goTo: "home"; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.
20+
Type '{ extra: true; goTo: string; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.
2121
Property 'extra' does not exist on type 'IntrinsicAttributes & LinkProps'.
2222
tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(30,12): error TS2769: No overload matches this call.
2323
Overload 1 of 2, '(buttonProps: ButtonProps): Element', gave the following error.
@@ -84,7 +84,7 @@ tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(36,44): err
8484
!!! error TS2769: Type '{ extra: true; goTo: string; }' is not assignable to type 'IntrinsicAttributes & ButtonProps'.
8585
!!! error TS2769: Property 'extra' does not exist on type 'IntrinsicAttributes & ButtonProps'.
8686
!!! error TS2769: Overload 2 of 2, '(linkProps: LinkProps): Element', gave the following error.
87-
!!! error TS2769: Type '{ extra: true; goTo: "home"; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.
87+
!!! error TS2769: Type '{ extra: true; goTo: string; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.
8888
!!! error TS2769: Property 'extra' does not exist on type 'IntrinsicAttributes & LinkProps'.
8989
const b4 = <MainButton goTo="home" extra />; // goTo has type "home" | "contact"
9090
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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)