From fd0936755bd33ae23f2de17008cc16312ef24c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 3 Nov 2023 18:38:28 +0100 Subject: [PATCH] Improve quick info display on properties belonging to all union contextual type members (#56088) --- src/services/services.ts | 4 +- ...nfoJsDocNonDiscriminatedUnionSharedProp.ts | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/quickInfoJsDocNonDiscriminatedUnionSharedProp.ts diff --git a/src/services/services.ts b/src/services/services.ts index 56af0f72d70..30eee5e120c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3282,7 +3282,9 @@ export function getPropertySymbolsFromContextualType(node: ObjectLiteralElementW // Bad discriminant -- do again without discriminating return mapDefined(contextualType.types, t => t.getProperty(name)); } - return discriminatedPropertySymbols; + // by eliminating duplicates we might even end up with a single symbol + // that helps with displaying better quick infos on properties of union types + return deduplicate(discriminatedPropertySymbols, equateValues); } function isArgumentOfElementAccessExpression(node: Node) { diff --git a/tests/cases/fourslash/quickInfoJsDocNonDiscriminatedUnionSharedProp.ts b/tests/cases/fourslash/quickInfoJsDocNonDiscriminatedUnionSharedProp.ts new file mode 100644 index 00000000000..ad4300f2696 --- /dev/null +++ b/tests/cases/fourslash/quickInfoJsDocNonDiscriminatedUnionSharedProp.ts @@ -0,0 +1,45 @@ +/// + +//// interface Entries { +//// /** +//// * Plugins info... +//// */ +//// plugins?: Record>; +//// /** +//// * Output info... +//// */ +//// output?: string; +//// /** +//// * Format info... +//// */ +//// format?: string; +//// } +//// +//// interface Input extends Entries { +//// /** +//// * Input info... +//// */ +//// input: string; +//// } +//// +//// interface Types extends Entries { +//// /** +//// * Types info... +//// */ +//// types: string; +//// } +//// +//// type EntriesOptions = Input | Types; +//// +//// const options: EntriesOptions[] = [ +//// { +//// input: "./src/index.ts", +//// /*1*/output: "./dist/index.mjs", +//// }, +//// { +//// types: "./src/types.ts", +//// format: "esm", +//// }, +//// ]; + +verify.quickInfoAt("1", "(property) Entries.output?: string", "Output info...");