Display write type for property accesses in write locations (#54777)

This commit is contained in:
Mateusz Burzyński 2023-08-15 21:01:21 +02:00 committed by GitHub
parent 0099e42451
commit b8b0d26cb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 2 deletions

View File

@ -11541,7 +11541,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
getWriteTypeOfSymbolWithDeferredType(symbol) || getTypeOfSymbolWithDeferredType(symbol) :
// NOTE: cast to TransientSymbol should be safe because only TransientSymbols can have CheckFlags.SyntheticProperty
(symbol as TransientSymbol).links.writeType || (symbol as TransientSymbol).links.type! :
getTypeOfSymbol(symbol);
removeMissingType(getTypeOfSymbol(symbol), !!(symbol.flags & SymbolFlags.Optional));
}
if (symbol.flags & SymbolFlags.Accessor) {
return checkFlags & CheckFlags.Instantiated ?
@ -27703,7 +27703,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
location = location.parent;
}
if (isExpressionNode(location) && (!isAssignmentTarget(location) || isWriteAccess(location))) {
const type = removeOptionalTypeMarker(getTypeOfExpression(location as Expression));
const type = removeOptionalTypeMarker(
isWriteAccess(location) && location.kind === SyntaxKind.PropertyAccessExpression ?
checkPropertyAccessExpression(location as PropertyAccessExpression, /*checkMode*/ undefined, /*writeOnly*/ true) :
getTypeOfExpression(location as Expression)
);
if (getExportSymbolOfValueSymbolIfExported(getNodeLinks(location).resolvedSymbol) === symbol) {
return type;
}

View File

@ -0,0 +1,8 @@
/// <reference path='fourslash.ts'/>
// @strict: true
// @exactOptionalPropertyTypes: true
//// declare const xx: { prop?: number };
//// xx.prop/*1*/ = 1;
verify.quickInfoAt('1', '(property) prop?: number');

View File

@ -0,0 +1,8 @@
/// <reference path='fourslash.ts'/>
// @strict: true
// @exactOptionalPropertyTypes: true
//// declare const xx: { prop?: number };
//// xx.prop/*1*/ += 1;
verify.quickInfoAt('1', '(property) prop?: number');

View File

@ -0,0 +1,8 @@
/// <reference path='fourslash.ts'/>
// @strict: true
// @exactOptionalPropertyTypes: true
//// declare const xx: { prop?: number };
//// xx.prop/*1*/ ??= 1;
verify.quickInfoAt('1', '(property) prop?: number');

View File

@ -0,0 +1,11 @@
/// <reference path='fourslash.ts'/>
// @strict: true
//// interface Serializer {
//// set value(v: string | number | boolean);
//// get value(): string;
//// }
//// declare let box: Serializer;
//// box.value/*1*/ = true;
verify.quickInfoAt('1', '(property) Serializer.value: string | number | boolean');

View File

@ -0,0 +1,11 @@
/// <reference path='fourslash.ts'/>
// @strict: true
//// interface Serializer {
//// set value(v: string | number);
//// get value(): string;
//// }
//// declare let box: Serializer;
//// box.value/*1*/ += 10;
verify.quickInfoAt('1', '(property) Serializer.value: string | number');