@@ -38,6 +38,7 @@ namespace ts.Completions {
38
38
InterfaceElementKeywords , // Keywords inside interface body
39
39
ConstructorParameterKeywords , // Keywords at constructor parameter
40
40
FunctionLikeBodyKeywords , // Keywords at function like body
41
+ TypeAssertionKeywords ,
41
42
TypeKeywords ,
42
43
Last = TypeKeywords
43
44
}
@@ -441,7 +442,7 @@ namespace ts.Completions {
441
442
( symbol . escapedName === InternalSymbolName . ExportEquals ) )
442
443
// Name of "export default foo;" is "foo". Name of "export default 0" is the filename converted to camelCase.
443
444
? firstDefined ( symbol . declarations , d => isExportAssignment ( d ) && isIdentifier ( d . expression ) ? d . expression . text : undefined )
444
- || codefix . moduleSymbolToValidIdentifier ( origin . moduleSymbol , target )
445
+ || codefix . moduleSymbolToValidIdentifier ( origin . moduleSymbol , target )
445
446
: symbol . name ;
446
447
}
447
448
@@ -632,9 +633,9 @@ namespace ts.Completions {
632
633
// At `,`, treat this as the next argument after the comma.
633
634
? checker . getContextualTypeForArgumentAtIndex ( argInfo . invocation , argInfo . argumentIndex + ( previousToken . kind === SyntaxKind . CommaToken ? 1 : 0 ) )
634
635
: isEqualityOperatorKind ( previousToken . kind ) && isBinaryExpression ( parent ) && isEqualityOperatorKind ( parent . operatorToken . kind )
635
- // completion at `x ===/**/` should be for the right side
636
- ? checker . getTypeAtLocation ( parent . left )
637
- : checker . getContextualType ( previousToken as Expression ) ;
636
+ // completion at `x ===/**/` should be for the right side
637
+ ? checker . getTypeAtLocation ( parent . left )
638
+ : checker . getContextualType ( previousToken as Expression ) ;
638
639
}
639
640
}
640
641
@@ -1182,7 +1183,11 @@ namespace ts.Completions {
1182
1183
function filterGlobalCompletion ( symbols : Symbol [ ] ) : void {
1183
1184
const isTypeOnly = isTypeOnlyCompletion ( ) ;
1184
1185
const allowTypes = isTypeOnly || ! isContextTokenValueLocation ( contextToken ) && isPossiblyTypeArgumentPosition ( contextToken , sourceFile , typeChecker ) ;
1185
- if ( isTypeOnly ) keywordFilters = KeywordCompletionFilters . TypeKeywords ;
1186
+ if ( isTypeOnly ) {
1187
+ keywordFilters = isTypeAssertion ( )
1188
+ ? KeywordCompletionFilters . TypeAssertionKeywords
1189
+ : KeywordCompletionFilters . TypeKeywords ;
1190
+ }
1186
1191
1187
1192
filterMutate ( symbols , symbol => {
1188
1193
if ( ! isSourceFile ( location ) ) {
@@ -1212,6 +1217,10 @@ namespace ts.Completions {
1212
1217
} ) ;
1213
1218
}
1214
1219
1220
+ function isTypeAssertion ( ) : boolean {
1221
+ return isAssertionExpression ( contextToken . parent ) ;
1222
+ }
1223
+
1215
1224
function isTypeOnlyCompletion ( ) : boolean {
1216
1225
return insideJsDocTagTypeExpression || ! isContextTokenValueLocation ( contextToken ) && ( isPartOfTypeNode ( location ) || isContextTokenTypeLocation ( contextToken ) ) ;
1217
1226
}
@@ -1240,7 +1249,8 @@ namespace ts.Completions {
1240
1249
return parentKind === SyntaxKind . AsExpression ;
1241
1250
1242
1251
case SyntaxKind . LessThanToken :
1243
- return parentKind === SyntaxKind . TypeReference ;
1252
+ return parentKind === SyntaxKind . TypeReference ||
1253
+ parentKind === SyntaxKind . TypeAssertionExpression ;
1244
1254
1245
1255
case SyntaxKind . ExtendsKeyword :
1246
1256
return parentKind === SyntaxKind . TypeParameter ;
@@ -1516,7 +1526,7 @@ namespace ts.Completions {
1516
1526
// 3. at the end of a regular expression (due to trailing flags like '/foo/g').
1517
1527
return ( isRegularExpressionLiteral ( contextToken ) || isStringTextContainingNode ( contextToken ) ) && (
1518
1528
rangeContainsPositionExclusive ( createTextRangeFromSpan ( createTextSpanFromNode ( contextToken ) ) , position ) ||
1519
- position === contextToken . end && ( ! ! contextToken . isUnterminated || isRegularExpressionLiteral ( contextToken ) ) ) ;
1529
+ position === contextToken . end && ( ! ! contextToken . isUnterminated || isRegularExpressionLiteral ( contextToken ) ) ) ;
1520
1530
}
1521
1531
1522
1532
/**
@@ -2026,8 +2036,8 @@ namespace ts.Completions {
2026
2036
2027
2037
return baseSymbols . filter ( propertySymbol =>
2028
2038
! existingMemberNames . has ( propertySymbol . escapedName ) &&
2029
- ! ! propertySymbol . declarations &&
2030
- ! ( getDeclarationModifierFlagsFromSymbol ( propertySymbol ) & ModifierFlags . Private ) ) ;
2039
+ ! ! propertySymbol . declarations &&
2040
+ ! ( getDeclarationModifierFlagsFromSymbol ( propertySymbol ) & ModifierFlags . Private ) ) ;
2031
2041
}
2032
2042
2033
2043
/**
@@ -2139,6 +2149,8 @@ namespace ts.Completions {
2139
2149
return isParameterPropertyModifier ( kind ) ;
2140
2150
case KeywordCompletionFilters . FunctionLikeBodyKeywords :
2141
2151
return isFunctionLikeBodyKeyword ( kind ) ;
2152
+ case KeywordCompletionFilters . TypeAssertionKeywords :
2153
+ return isTypeKeyword ( kind ) || kind === SyntaxKind . ConstKeyword ;
2142
2154
case KeywordCompletionFilters . TypeKeywords :
2143
2155
return isTypeKeyword ( kind ) ;
2144
2156
default :
0 commit comments