From dc3ebe812f548541e48c8dfcfccce1aeed57835c Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 23 Aug 2023 14:57:07 +0800 Subject: [PATCH] Add test to close #14635 (#15254) --- .../__snapshots__/jsfmt.spec.js.snap | 21 +++++++++++++++++++ .../typescript/mapped-type/jsfmt.spec.js | 1 + .../typescript/mapped-type/mapped-type.ts | 4 ++++ 3 files changed, 26 insertions(+) create mode 100644 tests/format/misc/errors/typescript/mapped-type/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/misc/errors/typescript/mapped-type/jsfmt.spec.js create mode 100644 tests/format/misc/errors/typescript/mapped-type/mapped-type.ts diff --git a/tests/format/misc/errors/typescript/mapped-type/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/typescript/mapped-type/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..61e26fd40 --- /dev/null +++ b/tests/format/misc/errors/typescript/mapped-type/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,21 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`mapped-type.ts [babel-ts] format 1`] = ` +"Unexpected token, expected "}" (3:3) + 1 | type Mapped = { + 2 | [key in keyof O]: number; +> 3 | extra_member: should_not_allowed + | ^ + 4 | }; + 5 |" +`; + +exports[`mapped-type.ts [typescript] format 1`] = ` +"A mapped type may not declare properties or methods. (3:3) + 1 | type Mapped = { + 2 | [key in keyof O]: number; +> 3 | extra_member: should_not_allowed + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 4 | }; + 5 |" +`; diff --git a/tests/format/misc/errors/typescript/mapped-type/jsfmt.spec.js b/tests/format/misc/errors/typescript/mapped-type/jsfmt.spec.js new file mode 100644 index 000000000..d6e90943d --- /dev/null +++ b/tests/format/misc/errors/typescript/mapped-type/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(import.meta, ["babel-ts", "typescript"]); diff --git a/tests/format/misc/errors/typescript/mapped-type/mapped-type.ts b/tests/format/misc/errors/typescript/mapped-type/mapped-type.ts new file mode 100644 index 000000000..6e560a0bc --- /dev/null +++ b/tests/format/misc/errors/typescript/mapped-type/mapped-type.ts @@ -0,0 +1,4 @@ +type Mapped = { + [key in keyof O]: number; + extra_member: should_not_allowed +};