File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ import {
57
57
isNameOfFunctionDeclaration ,
58
58
isNewExpressionTarget ,
59
59
isObjectBindingPattern ,
60
+ isOptionalChain ,
60
61
isTaggedTemplateExpression ,
61
62
isThisInTypeQuery ,
62
63
isTransientSymbol ,
@@ -322,6 +323,12 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(
322
323
let signature : Signature | undefined ;
323
324
type ??= isThisExpression ? typeChecker . getTypeAtLocation ( location ) : typeChecker . getTypeOfSymbolAtLocation ( symbol , location ) ;
324
325
326
+ // For optional symbols, use the non-optional type to avoid showing both '?' and '| undefined'
327
+ // but only when not in optional chaining contexts where '| undefined' is semantically meaningful
328
+ if ( symbol . flags & SymbolFlags . Optional && type && ! isOptionalChain ( location ) ) {
329
+ type = typeChecker . getNonOptionalType ( type ) ;
330
+ }
331
+
325
332
if ( location . parent && location . parent . kind === SyntaxKind . PropertyAccessExpression ) {
326
333
const right = ( location . parent as PropertyAccessExpression ) . name ;
327
334
// Either the location is on the right of a property access, or on the left and the right is missing
Original file line number Diff line number Diff line change
1
+ /// <reference path='fourslash.ts'/>
2
+
3
+ //// interface Options {
4
+ //// width?: number;
5
+ //// height?: number;
6
+ //// color?: ColorOptions;
7
+ //// border?: BorderOptions;
8
+ //// }
9
+ ////
10
+ //// interface ColorOptions {
11
+ //// primary: string;
12
+ //// secondary: string;
13
+ //// }
14
+ ////
15
+ //// interface BorderOptions {
16
+ //// style: string;
17
+ //// width: number;
18
+ //// }
19
+ ////
20
+ //// function processOptions(options: Options) {
21
+ //// return options.wi/*1*/dth + options.he/*2*/ight + options.co/*3*/lor + options.bo/*4*/rder;
22
+ //// }
23
+
24
+ // Test that optional properties show consistently with '?' and not '| undefined'
25
+ verify . quickInfoAt ( "1" , "(property) Options.width?: number" ) ;
26
+ verify . quickInfoAt ( "2" , "(property) Options.height?: number" ) ;
27
+ verify . quickInfoAt ( "3" , "(property) Options.color?: ColorOptions" ) ;
28
+ verify . quickInfoAt ( "4" , "(property) Options.border?: BorderOptions" ) ;
You can’t perform that action at this time.
0 commit comments