File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -322,6 +322,11 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(
322
322
let signature : Signature | undefined ;
323
323
type ??= isThisExpression ? typeChecker . getTypeAtLocation ( location ) : typeChecker . getTypeOfSymbolAtLocation ( symbol , location ) ;
324
324
325
+ // For optional symbols, use the non-optional type to avoid showing both '?' and '| undefined'
326
+ if ( symbol . flags & SymbolFlags . Optional && type ) {
327
+ type = typeChecker . getNonOptionalType ( type ) ;
328
+ }
329
+
325
330
if ( location . parent && location . parent . kind === SyntaxKind . PropertyAccessExpression ) {
326
331
const right = ( location . parent as PropertyAccessExpression ) . name ;
327
332
// 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 23
23
verify . quickInfoAt ( "1" , "(property) A.arr: string[]" ) ;
24
24
verify . quickInfoAt ( "2" , "(property) Foo.bar: {\n baz: string;\n}" ) ;
25
25
verify . quickInfoAt ( "3" , "(property) baz: string | undefined" ) ;
26
- verify . quickInfoAt ( "4" , "(property) Foo2.bar?: {\n baz: {\n qwe: string;\n };\n} | undefined " ) ;
26
+ verify . quickInfoAt ( "4" , "(property) Foo2.bar?: {\n baz: {\n qwe: string;\n };\n}" ) ;
27
27
verify . quickInfoAt ( "5" , "(property) baz: {\n qwe: string;\n}" ) ;
28
28
verify . quickInfoAt ( "6" , "(property) qwe: string | undefined" ) ;
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