From c663748e8e0aab8ab5acd383371bbeed71441f7f Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Tue, 25 Aug 2020 11:48:38 -0400 Subject: [PATCH] test ...infer type with parens --- .../rest-type/__snapshots__/jsfmt.spec.js.snap | 12 ++++++++++++ tests/typescript/rest-type/infer-type.ts | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/tests/typescript/rest-type/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/rest-type/__snapshots__/jsfmt.spec.js.snap index 9c3a39999737..202a13072a7f 100644 --- a/tests/typescript/rest-type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/rest-type/__snapshots__/jsfmt.spec.js.snap @@ -22,6 +22,12 @@ printWidth: 80 =====================================input====================================== type Tail = T extends [infer U, ...infer R] ? R : never; +// should remove parens from this, to avoid a type issue with TypeScript 4.0: +type Tail2 = T extends [infer U, ...(infer R)] ? R : never; + +// but not remove parens from this: +type Tail3 = T extends [infer U, ...(infer R)[]] ? R : never; + type ReduceNextElement< T extends readonly unknown[] > = T extends readonly [infer V, ...infer R] ? [V, R] : never @@ -29,6 +35,12 @@ type ReduceNextElement< =====================================output===================================== type Tail = T extends [infer U, ...infer R] ? R : never; +// should remove parens from this, to avoid a type issue with TypeScript 4.0: +type Tail2 = T extends [infer U, ...infer R] ? R : never; + +// but not remove parens from this: +type Tail3 = T extends [infer U, ...(infer R)[]] ? R : never; + type ReduceNextElement = T extends readonly [ infer V, ...infer R diff --git a/tests/typescript/rest-type/infer-type.ts b/tests/typescript/rest-type/infer-type.ts index 3829b96b382d..7d437ba1f57c 100644 --- a/tests/typescript/rest-type/infer-type.ts +++ b/tests/typescript/rest-type/infer-type.ts @@ -1,5 +1,11 @@ type Tail = T extends [infer U, ...infer R] ? R : never; +// should remove parens from this, to avoid a type issue with TypeScript 4.0: +type Tail2 = T extends [infer U, ...(infer R)] ? R : never; + +// but not remove parens from this: +type Tail3 = T extends [infer U, ...(infer R)[]] ? R : never; + type ReduceNextElement< T extends readonly unknown[] > = T extends readonly [infer V, ...infer R] ? [V, R] : never