@@ -1101,7 +1101,7 @@ namespace ts.Completions {
11011101 // each individual type has. This is because we're going to add all identifiers
11021102 // anyways. So we might as well elevate the members that were at least part
11031103 // of the individual types to a higher status since we know what they are.
1104- symbols . push ( ...getPropertiesForCompletion ( type , typeChecker , /*isForAccess*/ true ) ) ;
1104+ symbols . push ( ...getPropertiesForCompletion ( type , typeChecker ) ) ;
11051105 }
11061106 else {
11071107 for ( const symbol of type . getApparentProperties ( ) ) {
@@ -1221,7 +1221,7 @@ namespace ts.Completions {
12211221 if ( preferences . includeCompletionsWithInsertText && scopeNode . kind !== SyntaxKind . SourceFile ) {
12221222 const thisType = typeChecker . tryGetThisTypeAt ( scopeNode ) ;
12231223 if ( thisType ) {
1224- for ( const symbol of getPropertiesForCompletion ( thisType , typeChecker , /*isForAccess*/ true ) ) {
1224+ for ( const symbol of getPropertiesForCompletion ( thisType , typeChecker ) ) {
12251225 symbolToOriginInfoMap [ getSymbolId ( symbol ) ] = { type : "this-type" } ;
12261226 symbols . push ( symbol ) ;
12271227 }
@@ -1538,7 +1538,7 @@ namespace ts.Completions {
15381538 const typeForObject = typeChecker . getContextualType ( objectLikeContainer ) ;
15391539 if ( ! typeForObject ) return GlobalsSearch . Fail ;
15401540 isNewIdentifierLocation = hasIndexSignature ( typeForObject ) ;
1541- typeMembers = getPropertiesForCompletion ( typeForObject , typeChecker , /*isForAccess*/ false ) ;
1541+ typeMembers = getPropertiesForObjectExpression ( typeForObject , objectLikeContainer , typeChecker ) ;
15421542 existingMembers = objectLikeContainer . properties ;
15431543 }
15441544 else {
@@ -2159,19 +2159,25 @@ namespace ts.Completions {
21592159 return jsdoc && jsdoc . tags && ( rangeContainsPosition ( jsdoc , position ) ? findLast ( jsdoc . tags , tag => tag . pos < position ) : undefined ) ;
21602160 }
21612161
2162+ function getPropertiesForObjectExpression ( contextualType : Type , obj : ObjectLiteralExpression , checker : TypeChecker ) : Symbol [ ] {
2163+ return contextualType . isUnion ( )
2164+ ? checker . getAllPossiblePropertiesOfTypes ( contextualType . types . filter ( memberType =>
2165+ // 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.
2166+ ! ( memberType . flags & TypeFlags . Primitive ||
2167+ checker . isArrayLikeType ( memberType ) ||
2168+ typeHasCallOrConstructSignatures ( memberType , checker ) ||
2169+ checker . isTypeInvalidDueToUnionDiscriminant ( memberType , obj ) ) ) )
2170+ : contextualType . getApparentProperties ( ) ;
2171+ }
2172+
21622173 /**
21632174 * Gets all properties on a type, but if that type is a union of several types,
21642175 * excludes array-like types or callable/constructable types.
21652176 */
2166- function getPropertiesForCompletion ( type : Type , checker : TypeChecker , isForAccess : boolean ) : Symbol [ ] {
2167- if ( ! ( type . isUnion ( ) ) ) {
2168- return Debug . assertEachDefined ( type . getApparentProperties ( ) , "getApparentProperties() should all be defined" ) ;
2169- }
2170-
2171- // 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.
2172- const filteredTypes = isForAccess ? type . types : type . types . filter ( memberType =>
2173- ! ( memberType . flags & TypeFlags . Primitive || checker . isArrayLikeType ( memberType ) || typeHasCallOrConstructSignatures ( memberType , checker ) ) ) ;
2174- return Debug . assertEachDefined ( checker . getAllPossiblePropertiesOfTypes ( filteredTypes ) , "getAllPossiblePropertiesOfTypes() should all be defined" ) ;
2177+ function getPropertiesForCompletion ( type : Type , checker : TypeChecker ) : Symbol [ ] {
2178+ return type . isUnion ( )
2179+ ? Debug . assertEachDefined ( checker . getAllPossiblePropertiesOfTypes ( type . types ) , "getAllPossiblePropertiesOfTypes() should all be defined" )
2180+ : Debug . assertEachDefined ( type . getApparentProperties ( ) , "getApparentProperties() should all be defined" ) ;
21752181 }
21762182
21772183 /**
0 commit comments