File tree 2 files changed +11
-7
lines changed 2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -1463,12 +1463,14 @@ namespace ts.FindAllReferences.Core {
1463
1463
}
1464
1464
1465
1465
/** Gets all symbols for one property. Does not get symbols for every property. */
1466
- function getPropertySymbolsFromContextualType ( node : ObjectLiteralElement , checker : TypeChecker ) : ReadonlyArray < Symbol > {
1466
+ function getPropertySymbolsFromContextualType ( node : ObjectLiteralElementWithName , checker : TypeChecker ) : ReadonlyArray < Symbol > {
1467
1467
const contextualType = checker . getContextualType ( < ObjectLiteralExpression > node . parent ) ;
1468
- const name = getNameFromPropertyName ( node . name ! ) ;
1469
- const symbol = contextualType && name && contextualType . getProperty ( name ) ;
1468
+ if ( ! contextualType ) return emptyArray ;
1469
+ const name = getNameFromPropertyName ( node . name ) ;
1470
+ if ( ! name ) return emptyArray ;
1471
+ const symbol = contextualType . getProperty ( name ) ;
1470
1472
return symbol ? [ symbol ] :
1471
- contextualType && contextualType . isUnion ( ) ? mapDefined ( contextualType . types , t => t . getProperty ( name ! ) ) : emptyArray ; // TODO: GH#18217
1473
+ contextualType . isUnion ( ) ? mapDefined ( contextualType . types , t => t . getProperty ( name ) ) : emptyArray ;
1472
1474
}
1473
1475
1474
1476
/**
Original file line number Diff line number Diff line change @@ -2186,21 +2186,23 @@ namespace ts {
2186
2186
* Returns the containing object literal property declaration given a possible name node, e.g. "a" in x = { "a": 1 }
2187
2187
*/
2188
2188
/* @internal */
2189
- export function getContainingObjectLiteralElement ( node : Node ) : ObjectLiteralElement | undefined {
2189
+ export function getContainingObjectLiteralElement ( node : Node ) : ObjectLiteralElementWithName | undefined {
2190
2190
switch ( node . kind ) {
2191
2191
case SyntaxKind . StringLiteral :
2192
2192
case SyntaxKind . NumericLiteral :
2193
2193
if ( node . parent . kind === SyntaxKind . ComputedPropertyName ) {
2194
- return isObjectLiteralElement ( node . parent . parent ) ? node . parent . parent : undefined ;
2194
+ return isObjectLiteralElement ( node . parent . parent ) ? node . parent . parent as ObjectLiteralElementWithName : undefined ;
2195
2195
}
2196
2196
// falls through
2197
2197
case SyntaxKind . Identifier :
2198
2198
return isObjectLiteralElement ( node . parent ) &&
2199
2199
( node . parent . parent . kind === SyntaxKind . ObjectLiteralExpression || node . parent . parent . kind === SyntaxKind . JsxAttributes ) &&
2200
- node . parent . name === node ? node . parent : undefined ;
2200
+ node . parent . name === node ? node . parent as ObjectLiteralElementWithName : undefined ;
2201
2201
}
2202
2202
return undefined ;
2203
2203
}
2204
+ /* @internal */
2205
+ export type ObjectLiteralElementWithName = ObjectLiteralElement & { name : PropertyName } ;
2204
2206
2205
2207
/* @internal */
2206
2208
export function getPropertySymbolsFromContextualType ( typeChecker : TypeChecker , node : ObjectLiteralElement ) : Symbol [ ] {
You can’t perform that action at this time.
0 commit comments