File tree 3 files changed +49
-2
lines changed
3 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ namespace ts.codefix {
50
50
importAdder : ImportAdder | undefined ,
51
51
addClassElement : ( node : AddNode ) => void ,
52
52
body : Block | undefined ,
53
+ preserveOptional = true ,
53
54
isAmbient = false ,
54
55
) : void {
55
56
const declarations = symbol . getDeclarations ( ) ;
@@ -63,7 +64,7 @@ namespace ts.codefix {
63
64
const visibilityModifier = createVisibilityModifier ( getEffectiveModifierFlags ( declaration ) ) ;
64
65
const modifiers = visibilityModifier ? factory . createNodeArray ( [ visibilityModifier ] ) : undefined ;
65
66
const type = checker . getWidenedType ( checker . getTypeOfSymbolAtLocation ( symbol , enclosingDeclaration ) ) ;
66
- const optional = ! ! ( symbol . flags & SymbolFlags . Optional ) ;
67
+ const optional = preserveOptional && ! ! ( symbol . flags & SymbolFlags . Optional ) ;
67
68
const ambient = ! ! ( enclosingDeclaration . flags & NodeFlags . Ambient ) || isAmbient ;
68
69
const quotePreference = getQuotePreference ( sourceFile , preferences ) ;
69
70
Original file line number Diff line number Diff line change @@ -888,7 +888,7 @@ namespace ts.Completions {
888
888
node => {
889
889
let requiredModifiers = ModifierFlags . None ;
890
890
if ( isAbstract ) {
891
- requiredModifiers |= ModifierFlags . Abstract ;
891
+ requiredModifiers |= ModifierFlags . Abstract ;
892
892
}
893
893
if ( isClassElement ( node )
894
894
&& checker . getMemberOverrideModifierStatus ( classLikeDeclaration , node ) === MemberOverrideStatus . NeedsOverride ) {
@@ -912,6 +912,7 @@ namespace ts.Completions {
912
912
completionNodes . push ( node ) ;
913
913
} ,
914
914
body ,
915
+ /*preserveOptional*/ false ,
915
916
isAbstract ) ;
916
917
917
918
if ( completionNodes . length ) {
@@ -3882,5 +3883,6 @@ namespace ts.Completions {
3882
3883
}
3883
3884
return charCode ;
3884
3885
}
3886
+
3885
3887
}
3886
3888
Original file line number Diff line number Diff line change
1
+ /// <reference path="fourslash.ts" />
2
+
3
+ // @Filename : a.ts
4
+ // @newline : LF
5
+
6
+ ////interface IFoo {
7
+ //// a?: number;
8
+ //// b?(x: number): void;
9
+ //// }
10
+ ////class Foo implements IFoo {
11
+ //// /**/
12
+ //// }
13
+
14
+ verify . completions ( {
15
+ marker : "" ,
16
+ isNewIdentifierLocation : true ,
17
+ preferences : {
18
+ includeCompletionsWithInsertText : true ,
19
+ includeCompletionsWithSnippetText : false ,
20
+ includeCompletionsWithClassMemberSnippets : true ,
21
+ } ,
22
+ includes : [
23
+ {
24
+ name : "a" ,
25
+ sortText : completion . SortText . LocationPriority ,
26
+ replacementSpan : {
27
+ fileName : "" ,
28
+ pos : 0 ,
29
+ end : 0 ,
30
+ } ,
31
+ insertText : "a: number;\n"
32
+ } ,
33
+ {
34
+ name : "b" ,
35
+ sortText : completion . SortText . LocationPriority ,
36
+ replacementSpan : {
37
+ fileName : "" ,
38
+ pos : 0 ,
39
+ end : 0 ,
40
+ } ,
41
+ insertText : "b(x: number): void {\n}\n"
42
+ } ,
43
+ ] ,
44
+ } ) ;
You can’t perform that action at this time.
0 commit comments