From 43981eaa48b70017666875d7c6f325fd9bf5aa6b Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 25 Jul 2017 09:38:55 -0700 Subject: [PATCH] Use type param constraints for computed prop types --- src/compiler/checker.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c2f40c169dc..6da61b974f1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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 {