@@ -1101,7 +1101,7 @@ namespace ts.Completions {
1101
1101
// each individual type has. This is because we're going to add all identifiers
1102
1102
// anyways. So we might as well elevate the members that were at least part
1103
1103
// 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 ) ) ;
1105
1105
}
1106
1106
else {
1107
1107
for ( const symbol of type . getApparentProperties ( ) ) {
@@ -1221,7 +1221,7 @@ namespace ts.Completions {
1221
1221
if ( preferences . includeCompletionsWithInsertText && scopeNode . kind !== SyntaxKind . SourceFile ) {
1222
1222
const thisType = typeChecker . tryGetThisTypeAt ( scopeNode ) ;
1223
1223
if ( thisType ) {
1224
- for ( const symbol of getPropertiesForCompletion ( thisType , typeChecker , /*isForAccess*/ true ) ) {
1224
+ for ( const symbol of getPropertiesForCompletion ( thisType , typeChecker ) ) {
1225
1225
symbolToOriginInfoMap [ getSymbolId ( symbol ) ] = { type : "this-type" } ;
1226
1226
symbols . push ( symbol ) ;
1227
1227
}
@@ -1538,7 +1538,7 @@ namespace ts.Completions {
1538
1538
const typeForObject = typeChecker . getContextualType ( objectLikeContainer ) ;
1539
1539
if ( ! typeForObject ) return GlobalsSearch . Fail ;
1540
1540
isNewIdentifierLocation = hasIndexSignature ( typeForObject ) ;
1541
- typeMembers = getPropertiesForCompletion ( typeForObject , typeChecker , /*isForAccess*/ false ) ;
1541
+ typeMembers = getPropertiesForObjectExpression ( typeForObject , objectLikeContainer , typeChecker ) ;
1542
1542
existingMembers = objectLikeContainer . properties ;
1543
1543
}
1544
1544
else {
@@ -2159,19 +2159,25 @@ namespace ts.Completions {
2159
2159
return jsdoc && jsdoc . tags && ( rangeContainsPosition ( jsdoc , position ) ? findLast ( jsdoc . tags , tag => tag . pos < position ) : undefined ) ;
2160
2160
}
2161
2161
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
+
2162
2173
/**
2163
2174
* Gets all properties on a type, but if that type is a union of several types,
2164
2175
* excludes array-like types or callable/constructable types.
2165
2176
*/
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" ) ;
2175
2181
}
2176
2182
2177
2183
/**
0 commit comments