Skip to content

Commit 8a649a3

Browse files
mhausnercopybara-github
authored andcommitted
Add type inference test case for object literals
Checks that the inferred type does include the expected properties. PiperOrigin-RevId: 499517370
1 parent 633a626 commit 8a649a3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

test/com/google/javascript/jscomp/TypeInferenceTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3834,6 +3834,11 @@ public void testObjectLiteralNoSideEffect() {
38343834
assertWithMessage("Type inference must not alter OBJECT_TYPE.")
38353835
.that(registry.getNativeObjectType(JSTypeNative.OBJECT_TYPE).hasOwnProperty("data"))
38363836
.isFalse();
3837+
// Check that the inferred type of 'obj' has a property 'data' associated with it.
3838+
assertWithMessage("Cannot resolve type of 'obj'").that(getType("obj")).isNotNull();
3839+
assertWithMessage("Expect property 'data' to be defined on 'obj'")
3840+
.that(registry.canPropertyBeDefined(getType("obj"), "data"))
3841+
.isNotEqualTo(JSTypeRegistry.PropDefinitionKind.UNKNOWN);
38373842
}
38383843

38393844
@Test

0 commit comments

Comments
 (0)