@@ -1273,7 +1273,7 @@ namespace ts.Completions {
1273
1273
// Cursor is inside a JSX self-closing element or opening element
1274
1274
const attrsType = jsxContainer && typeChecker . getContextualType ( jsxContainer . attributes ) ;
1275
1275
if ( ! attrsType ) return GlobalsSearch . Continue ;
1276
- symbols = filterJsxAttributes ( getPropertiesForObjectExpression ( attrsType , jsxContainer ! . attributes , typeChecker ) , jsxContainer ! . attributes . properties ) ;
1276
+ symbols = filterJsxAttributes ( getPropertiesForObjectExpression ( attrsType , /*baseType*/ undefined , jsxContainer ! . attributes , typeChecker ) , jsxContainer ! . attributes . properties ) ;
1277
1277
setSortTextToOptionalMember ( ) ;
1278
1278
completionKind = CompletionKind . MemberLike ;
1279
1279
isNewIdentifierLocation = false ;
@@ -1780,10 +1780,11 @@ namespace ts.Completions {
1780
1780
let existingMembers : readonly Declaration [ ] | undefined ;
1781
1781
1782
1782
if ( objectLikeContainer . kind === SyntaxKind . ObjectLiteralExpression ) {
1783
- const typeForObject = typeChecker . getContextualType ( objectLikeContainer , ContextFlags . Completion ) ;
1784
- if ( ! typeForObject ) return GlobalsSearch . Fail ;
1785
- isNewIdentifierLocation = hasIndexSignature ( typeForObject ) ;
1786
- typeMembers = getPropertiesForObjectExpression ( typeForObject , objectLikeContainer , typeChecker ) ;
1783
+ const instantiatedType = typeChecker . getContextualType ( objectLikeContainer ) ;
1784
+ const baseType = instantiatedType && typeChecker . getContextualType ( objectLikeContainer , ContextFlags . BaseConstraint ) ;
1785
+ if ( ! instantiatedType || ! baseType ) return GlobalsSearch . Fail ;
1786
+ isNewIdentifierLocation = hasIndexSignature ( instantiatedType || baseType ) ;
1787
+ typeMembers = getPropertiesForObjectExpression ( instantiatedType , baseType , objectLikeContainer , typeChecker ) ;
1787
1788
existingMembers = objectLikeContainer . properties ;
1788
1789
}
1789
1790
else {
@@ -2514,15 +2515,19 @@ namespace ts.Completions {
2514
2515
return jsdoc && jsdoc . tags && ( rangeContainsPosition ( jsdoc , position ) ? findLast ( jsdoc . tags , tag => tag . pos < position ) : undefined ) ;
2515
2516
}
2516
2517
2517
- function getPropertiesForObjectExpression ( contextualType : Type , obj : ObjectLiteralExpression | JsxAttributes , checker : TypeChecker ) : Symbol [ ] {
2518
- return contextualType . isUnion ( )
2519
- ? checker . getAllPossiblePropertiesOfTypes ( contextualType . types . filter ( memberType =>
2518
+ function getPropertiesForObjectExpression ( contextualType : Type , baseConstrainedType : Type | undefined , obj : ObjectLiteralExpression | JsxAttributes , checker : TypeChecker ) : Symbol [ ] {
2519
+ const type = baseConstrainedType && ! ( baseConstrainedType . flags & TypeFlags . AnyOrUnknown )
2520
+ ? checker . getUnionType ( [ contextualType , baseConstrainedType ] )
2521
+ : contextualType ;
2522
+
2523
+ return type . isUnion ( )
2524
+ ? checker . getAllPossiblePropertiesOfTypes ( type . types . filter ( memberType =>
2520
2525
// If we're providing completions for an object literal, skip primitive, array-like, or callable types since those shouldn't be implemented by object literals.
2521
2526
! ( memberType . flags & TypeFlags . Primitive ||
2522
2527
checker . isArrayLikeType ( memberType ) ||
2523
2528
typeHasCallOrConstructSignatures ( memberType , checker ) ||
2524
2529
checker . isTypeInvalidDueToUnionDiscriminant ( memberType , obj ) ) ) )
2525
- : contextualType . getApparentProperties ( ) ;
2530
+ : type . getApparentProperties ( ) ;
2526
2531
}
2527
2532
2528
2533
/**
0 commit comments