File tree 2 files changed +33
-1
lines changed 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -3789,7 +3789,11 @@ namespace ts {
3789
3789
// other than those within the declared type.
3790
3790
isNewIdentifierLocation = true ;
3791
3791
3792
+ // If the object literal is being assigned to something of type 'null | { hello: string }',
3793
+ // it clearly isn't trying to satisfy the 'null' type. So we grab the non-nullable type if possible.
3792
3794
typeForObject = typeChecker . getContextualType ( < ObjectLiteralExpression > objectLikeContainer ) ;
3795
+ typeForObject = typeForObject && typeForObject . getNonNullableType ( ) ;
3796
+
3793
3797
existingMembers = ( < ObjectLiteralExpression > objectLikeContainer ) . properties ;
3794
3798
}
3795
3799
else if ( objectLikeContainer . kind === SyntaxKind . ObjectBindingPattern ) {
@@ -3801,7 +3805,7 @@ namespace ts {
3801
3805
// We don't want to complete using the type acquired by the shape
3802
3806
// of the binding pattern; we are only interested in types acquired
3803
3807
// through type declaration or inference.
3804
- // Also proceed if rootDeclaration is parameter and if its containing function expression\ arrow function is contextually typed -
3808
+ // Also proceed if rootDeclaration is a parameter and if its containing function expression/ arrow function is contextually typed -
3805
3809
// type of parameter will flow in from the contextual type of the function
3806
3810
let canGetType = ! ! ( rootDeclaration . initializer || rootDeclaration . type ) ;
3807
3811
if ( ! canGetType && rootDeclaration . kind === SyntaxKind . Parameter ) {
Original file line number Diff line number Diff line change
1
+ /// <reference path='fourslash.ts'/>
2
+
3
+ // @strictNullChecks : true
4
+ ////interface Thing {
5
+ //// hello: number;
6
+ //// world: string;
7
+ //// }
8
+ ////
9
+ ////declare function funcA(x : Thing): void;
10
+ ////declare function funcB(x?: Thing): void;
11
+ ////declare function funcC(x : Thing | null): void;
12
+ ////declare function funcD(x : Thing | undefined): void;
13
+ ////declare function funcE(x : Thing | null | undefined): void;
14
+ ////declare function funcF(x?: Thing | null | undefined): void;
15
+ ////
16
+ ////funcA({ /*A*/ });
17
+ ////funcB({ /*B*/ });
18
+ ////funcC({ /*C*/ });
19
+ ////funcD({ /*D*/ });
20
+ ////funcE({ /*E*/ });
21
+ ////funcF({ /*F*/ });
22
+
23
+
24
+ for ( const marker of test . markers ( ) ) {
25
+ goTo . position ( marker . position ) ;
26
+ verify . completionListContains ( "hello" ) ;
27
+ verify . completionListContains ( "world" ) ;
28
+ }
You can’t perform that action at this time.
0 commit comments