From e02dcf37447e2c4053920c1662b3216c90067be6 Mon Sep 17 00:00:00 2001 From: Nobuhiro Nakamura Date: Tue, 21 Mar 2017 02:40:25 +0900 Subject: [PATCH] Ensure createTupleType([]) to return singleton --- src/compiler/checker.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8f6fbed492372..661c470927366 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6210,7 +6210,13 @@ namespace ts { return tupleTypes[arity] || (tupleTypes[arity] = createTupleTypeOfArity(arity)); } - function createTupleType(elementTypes: Type[]) { + function createTupleType(elementTypes: Type[]): TypeReference { + // We have to ensure that we get same instance for empty tuple type, + // because we use === in isTupleLikeType(type). + if (!elementTypes.length && emptyTupleType) { + return emptyTupleType; + } + return createTypeReference(getTupleTypeOfArity(elementTypes.length), elementTypes); }