From 6262ac8b3d5c3b50b26b4c88be545621de4a574c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 20 Aug 2018 12:41:48 -0700 Subject: [PATCH] Add tests --- tests/cases/compiler/infiniteConstraints.ts | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/cases/compiler/infiniteConstraints.ts diff --git a/tests/cases/compiler/infiniteConstraints.ts b/tests/cases/compiler/infiniteConstraints.ts new file mode 100644 index 0000000000..70d3879da6 --- /dev/null +++ b/tests/cases/compiler/infiniteConstraints.ts @@ -0,0 +1,33 @@ +// @strict: true + +// Both of the following types trigger the recursion limiter in getImmediateBaseConstraint + +type T1], { val: string }>["val"] }> = B; +type T2]["val"] }> = B; + +// Repros from #22950 + +type AProp = T + +declare function myBug< + T extends { [K in keyof T]: T[K] extends AProp ? U : never } +>(arg: T): T + +const out = myBug({obj1: {a: "test"}}) + +type Value = Record<"val", V>; +declare function value(val: V): Value; + +declare function ensureNoDuplicates< + T extends { + [K in keyof T]: Extract["val"] extends Extract], Value>["val"] + ? never + : any + } +>(vals: T): void; + +const noError = ensureNoDuplicates({main: value("test"), alternate: value("test2")}); + +const shouldBeNoError = ensureNoDuplicates({main: value("test")}); + +const shouldBeError = ensureNoDuplicates({main: value("dup"), alternate: value("dup")});