From ea03c2966bcdee0dd7099314b4bf6cc9b7d9e35b Mon Sep 17 00:00:00 2001 From: chenjigeng <178854407@qq.com> Date: Tue, 29 Dec 2020 01:43:43 +0800 Subject: [PATCH] Fix/jsx syntax quickinfo (#42124) * feat: add jsx type invalid check * feat: update jsxGenericQuickInfo test cases --- src/services/services.ts | 2 +- tests/cases/fourslash/jsxGenericQuickInfo.tsx | 34 +++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 7eedf0a2b85..e2ef969a7b2 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2695,7 +2695,7 @@ namespace ts { return symbol ? [symbol] : emptyArray; } - const discriminatedPropertySymbols = mapDefined(contextualType.types, t => isObjectLiteralExpression(node.parent) && checker.isTypeInvalidDueToUnionDiscriminant(t, node.parent) ? undefined : t.getProperty(name)); + const discriminatedPropertySymbols = mapDefined(contextualType.types, t => (isObjectLiteralExpression(node.parent)|| isJsxAttributes(node.parent)) && checker.isTypeInvalidDueToUnionDiscriminant(t, node.parent) ? undefined : t.getProperty(name)); if (unionSymbolOk && (discriminatedPropertySymbols.length === 0 || discriminatedPropertySymbols.length === contextualType.types.length)) { const symbol = contextualType.getProperty(name); if (symbol) return [symbol]; diff --git a/tests/cases/fourslash/jsxGenericQuickInfo.tsx b/tests/cases/fourslash/jsxGenericQuickInfo.tsx index 359701d5c17..75661937376 100644 --- a/tests/cases/fourslash/jsxGenericQuickInfo.tsx +++ b/tests/cases/fourslash/jsxGenericQuickInfo.tsx @@ -6,17 +6,29 @@ //// } //// interface ElementAttributesProperty { props } //// } -//// interface Props { -//// items: T[]; -//// renderItem: (item: T) => string; +//// interface PropsA { +//// /** comments for A */ +//// name: 'A', +//// items: T[]; +//// renderItem: (item: T) => string; +//// } +//// interface PropsB { +//// /** comments for B */ +//// name: 'B', +//// items: T[]; +//// renderItem: (item: T) => string; //// } //// class Component { -//// constructor(props: Props) {} -//// props: Props; -//// } -//// var b = new Component({items: [0, 1, 2], render/*0*/Item: it/*1*/em => item.toFixed()}); -//// var c = item.toFixed()} -verify.quickInfoAt("0", "(property) Props.renderItem: (item: number) => string"); +//// constructor(props: PropsA | PropsB) {} +//// props: PropsA | PropsB; +//// } +//// var b = new Component({items: [0, 1, 2], render/*0*/Item: it/*1*/em => item.toFixed(), name/*2*/: 'A',}); +//// var c = item.toFixed()} name/*5*/="A" /> + + +verify.quickInfoAt("0", "(property) PropsA.renderItem: (item: number) => string"); verify.quickInfoAt("1", "(parameter) item: number"); -verify.quickInfoAt("2", "(JSX attribute) Props.renderItem: (item: number) => string"); -verify.quickInfoAt("3", "(parameter) item: number"); +verify.quickInfoAt("2", `(property) PropsA.name: "A"`, 'comments for A'); +verify.quickInfoAt("3", "(JSX attribute) PropsA.renderItem: (item: number) => string"); +verify.quickInfoAt("4", "(parameter) item: number"); +verify.quickInfoAt("5", `(JSX attribute) PropsA.name: "A"`, 'comments for A');