Skip to content

Commit 39da6b1

Browse files
authored
Display property types in optional chains without optional type marker (#53804)
1 parent bc91920 commit 39da6b1

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27644,7 +27644,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2764427644
location = location.parent;
2764527645
}
2764627646
if (isExpressionNode(location) && (!isAssignmentTarget(location) || isWriteAccess(location))) {
27647-
const type = getTypeOfExpression(location as Expression);
27647+
const type = removeOptionalTypeMarker(getTypeOfExpression(location as Expression));
2764827648
if (getExportSymbolOfValueSymbolIfExported(getNodeLinks(location).resolvedSymbol) === symbol) {
2764927649
return type;
2765027650
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// <reference path='fourslash.ts'/>
2+
//
3+
// @strict: true
4+
//
5+
//// interface A {
6+
//// arr: string[];
7+
//// }
8+
////
9+
//// function test(a?: A): string {
10+
//// return a?.ar/*1*/r.length ? "A" : "B";
11+
//// }
12+
////
13+
//// interface Foo { bar: { baz: string } };
14+
//// declare const foo: Foo | undefined;
15+
////
16+
//// if (foo?.b/*2*/ar.b/*3*/az) {}
17+
////
18+
//// interface Foo2 { bar?: { baz: { qwe: string } } };
19+
//// declare const foo2: Foo2;
20+
////
21+
//// if (foo2.b/*4*/ar?.b/*5*/az.q/*6*/we) {}
22+
23+
verify.quickInfoAt("1", "(property) A.arr: string[]");
24+
verify.quickInfoAt("2", "(property) Foo.bar: {\n baz: string;\n}");
25+
verify.quickInfoAt("3", "(property) baz: string | undefined");
26+
verify.quickInfoAt("4", "(property) Foo2.bar?: {\n baz: {\n qwe: string;\n };\n} | undefined");
27+
verify.quickInfoAt("5", "(property) baz: {\n qwe: string;\n}");
28+
verify.quickInfoAt("6", "(property) qwe: string | undefined");

0 commit comments

Comments
 (0)