@@ -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
@@ -1181,7 +1182,11 @@ namespace ts.Completions {
1181
1182
function filterGlobalCompletion ( symbols : Symbol [ ] ) : void {
1182
1183
const isTypeOnly = isTypeOnlyCompletion ( ) ;
1183
1184
const allowTypes = isTypeOnly || ! isContextTokenValueLocation ( contextToken ) && isPossiblyTypeArgumentPosition ( contextToken , sourceFile , typeChecker ) ;
1184
- if ( isTypeOnly ) keywordFilters = KeywordCompletionFilters . TypeKeywords ;
1185
+ if ( isTypeOnly ) {
1186
+ keywordFilters = isInsideTypeAssertion ( )
1187
+ ? KeywordCompletionFilters . TypeAssertionKeywords
1188
+ : KeywordCompletionFilters . TypeKeywords ;
1189
+ }
1185
1190
1186
1191
filterMutate ( symbols , symbol => {
1187
1192
if ( ! isSourceFile ( location ) ) {
@@ -1211,6 +1216,10 @@ namespace ts.Completions {
1211
1216
} ) ;
1212
1217
}
1213
1218
1219
+ function isInsideTypeAssertion ( ) : boolean {
1220
+ return isAsExpression ( contextToken . parent ) ;
1221
+ }
1222
+
1214
1223
function isTypeOnlyCompletion ( ) : boolean {
1215
1224
return insideJsDocTagTypeExpression || ! isContextTokenValueLocation ( contextToken ) && ( isPartOfTypeNode ( location ) || isContextTokenTypeLocation ( contextToken ) ) ;
1216
1225
}
@@ -1434,7 +1443,7 @@ namespace ts.Completions {
1434
1443
// 3. at the end of a regular expression (due to trailing flags like '/foo/g').
1435
1444
return ( isRegularExpressionLiteral ( contextToken ) || isStringTextContainingNode ( contextToken ) ) && (
1436
1445
rangeContainsPositionExclusive ( createTextRangeFromSpan ( createTextSpanFromNode ( contextToken ) ) , position ) ||
1437
- position === contextToken . end && ( ! ! contextToken . isUnterminated || isRegularExpressionLiteral ( contextToken ) ) ) ;
1446
+ position === contextToken . end && ( ! ! contextToken . isUnterminated || isRegularExpressionLiteral ( contextToken ) ) ) ;
1438
1447
}
1439
1448
1440
1449
/**
@@ -1944,8 +1953,8 @@ namespace ts.Completions {
1944
1953
1945
1954
return baseSymbols . filter ( propertySymbol =>
1946
1955
! existingMemberNames . has ( propertySymbol . escapedName ) &&
1947
- ! ! propertySymbol . declarations &&
1948
- ! ( getDeclarationModifierFlagsFromSymbol ( propertySymbol ) & ModifierFlags . Private ) ) ;
1956
+ ! ! propertySymbol . declarations &&
1957
+ ! ( getDeclarationModifierFlagsFromSymbol ( propertySymbol ) & ModifierFlags . Private ) ) ;
1949
1958
}
1950
1959
1951
1960
/**
@@ -2057,6 +2066,8 @@ namespace ts.Completions {
2057
2066
return isParameterPropertyModifier ( kind ) ;
2058
2067
case KeywordCompletionFilters . FunctionLikeBodyKeywords :
2059
2068
return isFunctionLikeBodyKeyword ( kind ) ;
2069
+ case KeywordCompletionFilters . TypeAssertionKeywords :
2070
+ return isTypeKeyword ( kind ) || kind === SyntaxKind . ConstKeyword ;
2060
2071
case KeywordCompletionFilters . TypeKeywords :
2061
2072
return isTypeKeyword ( kind ) ;
2062
2073
default :
0 commit comments