Skip to content

Commit b8b0d26

Browse files
authored
Display write type for property accesses in write locations (microsoft#54777)
1 parent 0099e42 commit b8b0d26

6 files changed

+52
-2
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11541,7 +11541,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1154111541
getWriteTypeOfSymbolWithDeferredType(symbol) || getTypeOfSymbolWithDeferredType(symbol) :
1154211542
// NOTE: cast to TransientSymbol should be safe because only TransientSymbols can have CheckFlags.SyntheticProperty
1154311543
(symbol as TransientSymbol).links.writeType || (symbol as TransientSymbol).links.type! :
11544-
getTypeOfSymbol(symbol);
11544+
removeMissingType(getTypeOfSymbol(symbol), !!(symbol.flags & SymbolFlags.Optional));
1154511545
}
1154611546
if (symbol.flags & SymbolFlags.Accessor) {
1154711547
return checkFlags & CheckFlags.Instantiated ?
@@ -27703,7 +27703,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2770327703
location = location.parent;
2770427704
}
2770527705
if (isExpressionNode(location) && (!isAssignmentTarget(location) || isWriteAccess(location))) {
27706-
const type = removeOptionalTypeMarker(getTypeOfExpression(location as Expression));
27706+
const type = removeOptionalTypeMarker(
27707+
isWriteAccess(location) && location.kind === SyntaxKind.PropertyAccessExpression ?
27708+
checkPropertyAccessExpression(location as PropertyAccessExpression, /*checkMode*/ undefined, /*writeOnly*/ true) :
27709+
getTypeOfExpression(location as Expression)
27710+
);
2770727711
if (getExportSymbolOfValueSymbolIfExported(getNodeLinks(location).resolvedSymbol) === symbol) {
2770827712
return type;
2770927713
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @strict: true
4+
// @exactOptionalPropertyTypes: true
5+
//// declare const xx: { prop?: number };
6+
//// xx.prop/*1*/ = 1;
7+
8+
verify.quickInfoAt('1', '(property) prop?: number');
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @strict: true
4+
// @exactOptionalPropertyTypes: true
5+
//// declare const xx: { prop?: number };
6+
//// xx.prop/*1*/ += 1;
7+
8+
verify.quickInfoAt('1', '(property) prop?: number');
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @strict: true
4+
// @exactOptionalPropertyTypes: true
5+
//// declare const xx: { prop?: number };
6+
//// xx.prop/*1*/ ??= 1;
7+
8+
verify.quickInfoAt('1', '(property) prop?: number');
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @strict: true
4+
//// interface Serializer {
5+
//// set value(v: string | number | boolean);
6+
//// get value(): string;
7+
//// }
8+
//// declare let box: Serializer;
9+
//// box.value/*1*/ = true;
10+
11+
verify.quickInfoAt('1', '(property) Serializer.value: string | number | boolean');
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @strict: true
4+
//// interface Serializer {
5+
//// set value(v: string | number);
6+
//// get value(): string;
7+
//// }
8+
//// declare let box: Serializer;
9+
//// box.value/*1*/ += 10;
10+
11+
verify.quickInfoAt('1', '(property) Serializer.value: string | number');

0 commit comments

Comments
 (0)