Skip to content

Commit a8a2ff5

Browse files
committed
Merge branch 'main' into fix/only-add-outermost-intra-expression-sites
2 parents 2aa9fe4 + 6947c98 commit a8a2ff5

9 files changed

+258
-6
lines changed

src/compiler/checker.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -30110,7 +30110,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3011030110
return links.immediateTarget;
3011130111
}
3011230112

30113-
function checkObjectLiteral(node: ObjectLiteralExpression, checkMode = CheckMode.Normal): Type {
30113+
function checkObjectLiteral(node: ObjectLiteralExpression, checkMode: CheckMode = CheckMode.Normal): Type {
3011430114
const inDestructuringPattern = isAssignmentTarget(node);
3011530115
// Grammar checking
3011630116
checkGrammarObjectLiteralExpression(node, inDestructuringPattern);
@@ -30236,7 +30236,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3023630236
hasComputedNumberProperty = false;
3023730237
hasComputedSymbolProperty = false;
3023830238
}
30239-
const type = getReducedType(checkExpression(memberDecl.expression));
30239+
const type = getReducedType(checkExpression(memberDecl.expression, checkMode & CheckMode.Inferential));
3024030240
if (isValidSpreadType(type)) {
3024130241
const mergedType = tryMergeUnionOfObjectTypeAndEmptyObject(type, inConstContext);
3024230242
if (allPropertiesTable) {
@@ -30436,7 +30436,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3043630436
* @remarks Because this function calls getSpreadType, it needs to use the same checks as checkObjectLiteral,
3043730437
* which also calls getSpreadType.
3043830438
*/
30439-
function createJsxAttributesTypeFromAttributesProperty(openingLikeElement: JsxOpeningLikeElement, checkMode = CheckMode.Normal) {
30439+
function createJsxAttributesTypeFromAttributesProperty(openingLikeElement: JsxOpeningLikeElement, checkMode: CheckMode = CheckMode.Normal) {
3044030440
const attributes = openingLikeElement.attributes;
3044130441
const contextualType = getContextualType(attributes, ContextFlags.None);
3044230442
const allAttributesTable = strictNullChecks ? createSymbolTable() : undefined;
@@ -30489,7 +30489,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3048930489
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, objectFlags, /*readonly*/ false);
3049030490
attributesTable = createSymbolTable();
3049130491
}
30492-
const exprType = getReducedType(checkExpressionCached(attributeDecl.expression, checkMode));
30492+
const exprType = getReducedType(checkExpression(attributeDecl.expression, checkMode & CheckMode.Inferential));
3049330493
if (isTypeAny(exprType)) {
3049430494
hasSpreadAnyType = true;
3049530495
}

tests/baselines/reference/intraExpressionInferences.errors.txt

+16-1
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,19 @@ tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInf
212212
let test1: "a" = u
213213
}
214214
})
215-
215+
216+
interface Props<T> {
217+
a: (x: string) => T;
218+
b: (arg: T) => void;
219+
}
220+
221+
declare function Foo<T>(props: Props<T>): null;
222+
223+
Foo({
224+
...{
225+
a: (x) => 10,
226+
b: (arg) => {
227+
arg.toString();
228+
},
229+
},
230+
});

tests/baselines/reference/intraExpressionInferences.js

+38-1
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,37 @@ branch({
197197
let test1: "a" = u
198198
}
199199
})
200-
200+
201+
interface Props<T> {
202+
a: (x: string) => T;
203+
b: (arg: T) => void;
204+
}
205+
206+
declare function Foo<T>(props: Props<T>): null;
207+
208+
Foo({
209+
...{
210+
a: (x) => 10,
211+
b: (arg) => {
212+
arg.toString();
213+
},
214+
},
215+
});
201216

202217
//// [intraExpressionInferences.js]
203218
"use strict";
204219
// Repros from #47599
220+
var __assign = (this && this.__assign) || function () {
221+
__assign = Object.assign || function(t) {
222+
for (var s, i = 1, n = arguments.length; i < n; i++) {
223+
s = arguments[i];
224+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
225+
t[p] = s[p];
226+
}
227+
return t;
228+
};
229+
return __assign.apply(this, arguments);
230+
};
205231
callIt({
206232
produce: function () { return 0; },
207233
consume: function (n) { return n.toFixed(); }
@@ -316,6 +342,12 @@ branch({
316342
var test1 = u;
317343
}
318344
});
345+
Foo(__assign({
346+
a: function (x) { return 10; },
347+
b: function (arg) {
348+
arg.toString();
349+
},
350+
}));
319351

320352

321353
//// [intraExpressionInferences.d.ts]
@@ -383,3 +415,8 @@ declare const branch: <T, U extends T>(_: {
383415
then: (u: U) => void;
384416
}) => void;
385417
declare const x: "a" | "b";
418+
interface Props<T> {
419+
a: (x: string) => T;
420+
b: (arg: T) => void;
421+
}
422+
declare function Foo<T>(props: Props<T>): null;

tests/baselines/reference/intraExpressionInferences.symbols

+42
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,45 @@ branch({
626626
}
627627
})
628628

629+
interface Props<T> {
630+
>Props : Symbol(Props, Decl(intraExpressionInferences.ts, 197, 2))
631+
>T : Symbol(T, Decl(intraExpressionInferences.ts, 199, 16))
632+
633+
a: (x: string) => T;
634+
>a : Symbol(Props.a, Decl(intraExpressionInferences.ts, 199, 20))
635+
>x : Symbol(x, Decl(intraExpressionInferences.ts, 200, 6))
636+
>T : Symbol(T, Decl(intraExpressionInferences.ts, 199, 16))
637+
638+
b: (arg: T) => void;
639+
>b : Symbol(Props.b, Decl(intraExpressionInferences.ts, 200, 22))
640+
>arg : Symbol(arg, Decl(intraExpressionInferences.ts, 201, 6))
641+
>T : Symbol(T, Decl(intraExpressionInferences.ts, 199, 16))
642+
}
643+
644+
declare function Foo<T>(props: Props<T>): null;
645+
>Foo : Symbol(Foo, Decl(intraExpressionInferences.ts, 202, 1))
646+
>T : Symbol(T, Decl(intraExpressionInferences.ts, 204, 21))
647+
>props : Symbol(props, Decl(intraExpressionInferences.ts, 204, 24))
648+
>Props : Symbol(Props, Decl(intraExpressionInferences.ts, 197, 2))
649+
>T : Symbol(T, Decl(intraExpressionInferences.ts, 204, 21))
650+
651+
Foo({
652+
>Foo : Symbol(Foo, Decl(intraExpressionInferences.ts, 202, 1))
653+
654+
...{
655+
a: (x) => 10,
656+
>a : Symbol(a, Decl(intraExpressionInferences.ts, 207, 6))
657+
>x : Symbol(x, Decl(intraExpressionInferences.ts, 208, 8))
658+
659+
b: (arg) => {
660+
>b : Symbol(b, Decl(intraExpressionInferences.ts, 208, 17))
661+
>arg : Symbol(arg, Decl(intraExpressionInferences.ts, 209, 8))
662+
663+
arg.toString();
664+
>arg.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
665+
>arg : Symbol(arg, Decl(intraExpressionInferences.ts, 209, 8))
666+
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
667+
668+
},
669+
},
670+
});

tests/baselines/reference/intraExpressionInferences.types

+42
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,45 @@ branch({
659659
}
660660
})
661661

662+
interface Props<T> {
663+
a: (x: string) => T;
664+
>a : (x: string) => T
665+
>x : string
666+
667+
b: (arg: T) => void;
668+
>b : (arg: T) => void
669+
>arg : T
670+
}
671+
672+
declare function Foo<T>(props: Props<T>): null;
673+
>Foo : <T>(props: Props<T>) => null
674+
>props : Props<T>
675+
676+
Foo({
677+
>Foo({ ...{ a: (x) => 10, b: (arg) => { arg.toString(); }, },}) : null
678+
>Foo : <T>(props: Props<T>) => null
679+
>{ ...{ a: (x) => 10, b: (arg) => { arg.toString(); }, },} : { a: (x: string) => number; b: (arg: number) => void; }
680+
681+
...{
682+
>{ a: (x) => 10, b: (arg) => { arg.toString(); }, } : { a: (x: string) => number; b: (arg: number) => void; }
683+
684+
a: (x) => 10,
685+
>a : (x: string) => number
686+
>(x) => 10 : (x: string) => number
687+
>x : string
688+
>10 : 10
689+
690+
b: (arg) => {
691+
>b : (arg: number) => void
692+
>(arg) => { arg.toString(); } : (arg: number) => void
693+
>arg : number
694+
695+
arg.toString();
696+
>arg.toString() : string
697+
>arg.toString : (radix?: number | undefined) => string
698+
>arg : number
699+
>toString : (radix?: number | undefined) => string
700+
701+
},
702+
},
703+
});
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+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
25+
<GenericComponent {...omit(['bar'], otherProps)} />; // no error
26+
><GenericComponent {...omit(['bar'], otherProps)} /> : JSX.Element
27+
>GenericComponent : <T>(props: T) => null
28+
>omit(['bar'], otherProps) : Omit<{ bar: string; qwe: boolean; }, "bar">
29+
>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>; }
30+
>['bar'] : "bar"[]
31+
>'bar' : "bar"
32+
>otherProps : { bar: string; qwe: boolean; }
33+
34+
35+
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+

tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInferences.ts

+16
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,19 @@ branch({
199199
let test1: "a" = u
200200
}
201201
})
202+
203+
interface Props<T> {
204+
a: (x: string) => T;
205+
b: (arg: T) => void;
206+
}
207+
208+
declare function Foo<T>(props: Props<T>): null;
209+
210+
Foo({
211+
...{
212+
a: (x) => 10,
213+
b: (arg) => {
214+
arg.toString();
215+
},
216+
},
217+
});

0 commit comments

Comments
 (0)