Skip to content

Commit ea03c29

Browse files
authored
Fix/jsx syntax quickinfo (#42124)
* feat: add jsx type invalid check * feat: update jsxGenericQuickInfo test cases
1 parent fe297df commit ea03c29

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/services/services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2695,7 +2695,7 @@ namespace ts {
26952695
return symbol ? [symbol] : emptyArray;
26962696
}
26972697

2698-
const discriminatedPropertySymbols = mapDefined(contextualType.types, t => isObjectLiteralExpression(node.parent) && checker.isTypeInvalidDueToUnionDiscriminant(t, node.parent) ? undefined : t.getProperty(name));
2698+
const discriminatedPropertySymbols = mapDefined(contextualType.types, t => (isObjectLiteralExpression(node.parent)|| isJsxAttributes(node.parent)) && checker.isTypeInvalidDueToUnionDiscriminant(t, node.parent) ? undefined : t.getProperty(name));
26992699
if (unionSymbolOk && (discriminatedPropertySymbols.length === 0 || discriminatedPropertySymbols.length === contextualType.types.length)) {
27002700
const symbol = contextualType.getProperty(name);
27012701
if (symbol) return [symbol];

tests/cases/fourslash/jsxGenericQuickInfo.tsx

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,29 @@
66
//// }
77
//// interface ElementAttributesProperty { props }
88
//// }
9-
//// interface Props<T> {
10-
//// items: T[];
11-
//// renderItem: (item: T) => string;
9+
//// interface PropsA<T> {
10+
//// /** comments for A */
11+
//// name: 'A',
12+
//// items: T[];
13+
//// renderItem: (item: T) => string;
1214
//// }
13-
//// class Component<T> {
14-
//// constructor(props: Props<T>) {}
15-
//// props: Props<T>;
15+
//// interface PropsB<T> {
16+
//// /** comments for B */
17+
//// name: 'B',
18+
//// items: T[];
19+
//// renderItem: (item: T) => string;
1620
//// }
17-
//// var b = new Component({items: [0, 1, 2], render/*0*/Item: it/*1*/em => item.toFixed()});
18-
//// var c = <Component items={[0, 1, 2]} render/*2*/Item={it/*3*/em => item.toFixed()}
19-
verify.quickInfoAt("0", "(property) Props<number>.renderItem: (item: number) => string");
21+
//// class Component<T> {
22+
//// constructor(props: PropsA<T> | PropsB<T>) {}
23+
//// props: PropsA<T> | PropsB<T>;
24+
//// }
25+
//// var b = new Component({items: [0, 1, 2], render/*0*/Item: it/*1*/em => item.toFixed(), name/*2*/: 'A',});
26+
//// var c = <Component items={[0, 1, 2]} render/*3*/Item={it/*4*/em => item.toFixed()} name/*5*/="A" />
27+
28+
29+
verify.quickInfoAt("0", "(property) PropsA<number>.renderItem: (item: number) => string");
2030
verify.quickInfoAt("1", "(parameter) item: number");
21-
verify.quickInfoAt("2", "(JSX attribute) Props<number>.renderItem: (item: number) => string");
22-
verify.quickInfoAt("3", "(parameter) item: number");
31+
verify.quickInfoAt("2", `(property) PropsA<T>.name: "A"`, 'comments for A');
32+
verify.quickInfoAt("3", "(JSX attribute) PropsA<number>.renderItem: (item: number) => string");
33+
verify.quickInfoAt("4", "(parameter) item: number");
34+
verify.quickInfoAt("5", `(JSX attribute) PropsA<T>.name: "A"`, 'comments for A');

0 commit comments

Comments
 (0)