Use type param constraints for computed prop types

This commit is contained in:
Nathan Shively-Sanders
2017-07-25 09:38:55 -07:00
parent d74cb24640
commit 43981eaa48

View File

@@ -13330,10 +13330,13 @@ namespace ts {
const links = getNodeLinks(node.expression);
if (!links.resolvedType) {
links.resolvedType = checkExpression(node.expression);
const t = links.resolvedType.flags & TypeFlags.TypeVariable ?
getBaseConstraintOfType(links.resolvedType) || emptyObjectType :
links.resolvedType;
// This will allow types number, string, symbol or any. It will also allow enums, the unknown
// type, and any union of these types (like string | number).
if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol)) {
if (!isTypeAnyOrAllConstituentTypesHaveKind(t, TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol)) {
error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any);
}
else {