Skip to content

Commit 7a755d2

Browse files
committed
Display write type for property accesses in write locations
1 parent 11b1ccc commit 7a755d2

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
@@ -11484,7 +11484,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1148411484
getWriteTypeOfSymbolWithDeferredType(symbol) || getTypeOfSymbolWithDeferredType(symbol) :
1148511485
// NOTE: cast to TransientSymbol should be safe because only TransientSymbols can have CheckFlags.SyntheticProperty
1148611486
(symbol as TransientSymbol).links.writeType || (symbol as TransientSymbol).links.type! :
11487-
getTypeOfSymbol(symbol);
11487+
removeMissingType(getTypeOfSymbol(symbol), !!(symbol.flags & SymbolFlags.Optional));
1148811488
}
1148911489
if (symbol.flags & SymbolFlags.Accessor) {
1149011490
return checkFlags & CheckFlags.Instantiated ?
@@ -27645,7 +27645,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2764527645
location = location.parent;
2764627646
}
2764727647
if (isExpressionNode(location) && (!isAssignmentTarget(location) || isWriteAccess(location))) {
27648-
const type = removeOptionalTypeMarker(getTypeOfExpression(location as Expression));
27648+
const type = removeOptionalTypeMarker(
27649+
isWriteAccess(location) && location.kind === SyntaxKind.PropertyAccessExpression ?
27650+
checkPropertyAccessExpression(location as PropertyAccessExpression, /*checkMode*/ undefined, /*writeOnly*/ true) :
27651+
getTypeOfExpression(location as Expression)
27652+
);
2764927653
if (getExportSymbolOfValueSymbolIfExported(getNodeLinks(location).resolvedSymbol) === symbol) {
2765027654
return type;
2765127655
}
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)