use of com.google.javascript.rhino.jstype.TemplateType in project closure-compiler by google.
the class TypeCheck method isObjectTypeWithNonStringifiableKey.
/**
* Checks whether current type is Object type with non-stringifable key.
*/
private boolean isObjectTypeWithNonStringifiableKey(JSType type) {
if (!type.isTemplatizedType()) {
// TODO(nickreid): Why don't we care about types like `Foo extends Object<Bar, Qux>`?
return false;
}
TemplateTypeMap templateTypeMap = type.getTemplateTypeMap();
TemplateType objectIndexKey = typeRegistry.getObjectIndexKey();
if (templateTypeMap.hasTemplateKey(objectIndexKey)) {
return !isReasonableObjectPropertyKey(templateTypeMap.getResolvedTemplateType(objectIndexKey));
} else {
return false;
}
}
use of com.google.javascript.rhino.jstype.TemplateType in project closure-compiler by google.
the class TypeInferenceTest method testInferringTypeInObjectPattern_fromTemplatizedProperty.
@Test
public void testInferringTypeInObjectPattern_fromTemplatizedProperty() {
// create type Foo with one property templatized with type T
TemplateType templateKey = registry.createTemplateType("T");
FunctionType fooCtor = registry.createConstructorType("Foo", null, registry.createParameters(), null, ImmutableList.of(templateKey), false);
ObjectType fooInstanceType = fooCtor.getInstanceType();
fooInstanceType.defineDeclaredProperty("data", templateKey, null);
// create a variable obj with type Foo<number>
JSType fooOfNumber = templatize(fooInstanceType, ImmutableList.of(getNativeType(NUMBER_TYPE)));
assuming("obj", fooOfNumber);
inFunction(lines(//
"const {data} = obj;", "OBJ: obj;", "DATA: data"));
assertTypeOfExpression("OBJ").toStringIsEqualTo("Foo<number>");
assertTypeOfExpression("DATA").toStringIsEqualTo("number");
}
Aggregations