@@ -38,6 +38,7 @@ namespace ts.Completions {
3838 InterfaceElementKeywords , // Keywords inside interface body
3939 ConstructorParameterKeywords , // Keywords at constructor parameter
4040 FunctionLikeBodyKeywords , // Keywords at function like body
41+ TypeAssertionKeywords ,
4142 TypeKeywords ,
4243 Last = TypeKeywords
4344 }
@@ -441,7 +442,7 @@ namespace ts.Completions {
441442 ( symbol . escapedName === InternalSymbolName . ExportEquals ) )
442443 // Name of "export default foo;" is "foo". Name of "export default 0" is the filename converted to camelCase.
443444 ? 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 )
445446 : symbol . name ;
446447 }
447448
@@ -632,9 +633,9 @@ namespace ts.Completions {
632633 // At `,`, treat this as the next argument after the comma.
633634 ? checker . getContextualTypeForArgumentAtIndex ( argInfo . invocation , argInfo . argumentIndex + ( previousToken . kind === SyntaxKind . CommaToken ? 1 : 0 ) )
634635 : 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 ) ;
638639 }
639640 }
640641
@@ -1182,7 +1183,11 @@ namespace ts.Completions {
11821183 function filterGlobalCompletion ( symbols : Symbol [ ] ) : void {
11831184 const isTypeOnly = isTypeOnlyCompletion ( ) ;
11841185 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+ }
11861191
11871192 filterMutate ( symbols , symbol => {
11881193 if ( ! isSourceFile ( location ) ) {
@@ -1212,6 +1217,10 @@ namespace ts.Completions {
12121217 } ) ;
12131218 }
12141219
1220+ function isTypeAssertion ( ) : boolean {
1221+ return isAssertionExpression ( contextToken . parent ) ;
1222+ }
1223+
12151224 function isTypeOnlyCompletion ( ) : boolean {
12161225 return insideJsDocTagTypeExpression || ! isContextTokenValueLocation ( contextToken ) && ( isPartOfTypeNode ( location ) || isContextTokenTypeLocation ( contextToken ) ) ;
12171226 }
@@ -1240,7 +1249,8 @@ namespace ts.Completions {
12401249 return parentKind === SyntaxKind . AsExpression ;
12411250
12421251 case SyntaxKind . LessThanToken :
1243- return parentKind === SyntaxKind . TypeReference ;
1252+ return parentKind === SyntaxKind . TypeReference ||
1253+ parentKind === SyntaxKind . TypeAssertionExpression ;
12441254
12451255 case SyntaxKind . ExtendsKeyword :
12461256 return parentKind === SyntaxKind . TypeParameter ;
@@ -1516,7 +1526,7 @@ namespace ts.Completions {
15161526 // 3. at the end of a regular expression (due to trailing flags like '/foo/g').
15171527 return ( isRegularExpressionLiteral ( contextToken ) || isStringTextContainingNode ( contextToken ) ) && (
15181528 rangeContainsPositionExclusive ( createTextRangeFromSpan ( createTextSpanFromNode ( contextToken ) ) , position ) ||
1519- position === contextToken . end && ( ! ! contextToken . isUnterminated || isRegularExpressionLiteral ( contextToken ) ) ) ;
1529+ position === contextToken . end && ( ! ! contextToken . isUnterminated || isRegularExpressionLiteral ( contextToken ) ) ) ;
15201530 }
15211531
15221532 /**
@@ -2026,8 +2036,8 @@ namespace ts.Completions {
20262036
20272037 return baseSymbols . filter ( propertySymbol =>
20282038 ! existingMemberNames . has ( propertySymbol . escapedName ) &&
2029- ! ! propertySymbol . declarations &&
2030- ! ( getDeclarationModifierFlagsFromSymbol ( propertySymbol ) & ModifierFlags . Private ) ) ;
2039+ ! ! propertySymbol . declarations &&
2040+ ! ( getDeclarationModifierFlagsFromSymbol ( propertySymbol ) & ModifierFlags . Private ) ) ;
20312041 }
20322042
20332043 /**
@@ -2139,6 +2149,8 @@ namespace ts.Completions {
21392149 return isParameterPropertyModifier ( kind ) ;
21402150 case KeywordCompletionFilters . FunctionLikeBodyKeywords :
21412151 return isFunctionLikeBodyKeyword ( kind ) ;
2152+ case KeywordCompletionFilters . TypeAssertionKeywords :
2153+ return isTypeKeyword ( kind ) || kind === SyntaxKind . ConstKeyword ;
21422154 case KeywordCompletionFilters . TypeKeywords :
21432155 return isTypeKeyword ( kind ) ;
21442156 default :
0 commit comments