From 43b3307ae7c854f02aae1e63a44a13754536de3f Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Fri, 6 Sep 2024 02:22:28 +0900 Subject: [PATCH 1/4] turn on useUnknownInCatchVariables in lsp --- cli/lsp/config.rs | 1 - cli/tsc/99_main_compiler.js | 1 - 2 files changed, 2 deletions(-) diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index fcea96aa5da86f..c9729a5e5d9b05 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -1084,7 +1084,6 @@ impl Default for LspTsConfig { "strict": true, "target": "esnext", "useDefineForClassFields": true, - "useUnknownInCatchVariables": false, "jsx": "react", "jsxFactory": "React.createElement", "jsxFragmentFactory": "React.Fragment", diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index f35fa7b5d3ee67..4044c5fc16129b 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -1152,7 +1152,6 @@ delete Object.prototype.__proto__; "strict": true, "target": "esnext", "useDefineForClassFields": true, - "useUnknownInCatchVariables": false, "jsx": "react", "jsxFactory": "React.createElement", "jsxFragmentFactory": "React.Fragment", From 9e3ebc0aefa9d974a30570604e29fef734e75cfd Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Fri, 6 Sep 2024 02:23:05 +0900 Subject: [PATCH 2/4] update schema --- cli/schemas/config-file.v1.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/schemas/config-file.v1.json b/cli/schemas/config-file.v1.json index df8177af2980bf..d0dc27e759d274 100644 --- a/cli/schemas/config-file.v1.json +++ b/cli/schemas/config-file.v1.json @@ -223,7 +223,7 @@ "useUnknownInCatchVariables": { "description": "Default catch clause variables as `unknown` instead of `any`.", "type": "boolean", - "default": false, + "default": true, "markdownDescription": "Default catch clause variables as `unknown` instead of `any`.\n\nSee more: https://www.typescriptlang.org/tsconfig#useUnknownInCatchVariables" } } From aa86026bce0b5523ee8e6562ace69c58923fd49a Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Fri, 6 Sep 2024 02:23:52 +0900 Subject: [PATCH 3/4] add `deno check` test for useUnknownInCatchVariables --- .../check/use_unknown_in_catch_variables/__test__.jsonc | 5 +++++ tests/specs/check/use_unknown_in_catch_variables/main.out | 5 +++++ tests/specs/check/use_unknown_in_catch_variables/main.ts | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 tests/specs/check/use_unknown_in_catch_variables/__test__.jsonc create mode 100644 tests/specs/check/use_unknown_in_catch_variables/main.out create mode 100644 tests/specs/check/use_unknown_in_catch_variables/main.ts diff --git a/tests/specs/check/use_unknown_in_catch_variables/__test__.jsonc b/tests/specs/check/use_unknown_in_catch_variables/__test__.jsonc new file mode 100644 index 00000000000000..a991c6eed4f620 --- /dev/null +++ b/tests/specs/check/use_unknown_in_catch_variables/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "check main.ts", + "output": "main.out", + "exitCode": 1 +} diff --git a/tests/specs/check/use_unknown_in_catch_variables/main.out b/tests/specs/check/use_unknown_in_catch_variables/main.out new file mode 100644 index 00000000000000..e368382031580f --- /dev/null +++ b/tests/specs/check/use_unknown_in_catch_variables/main.out @@ -0,0 +1,5 @@ +Check file:///[WILDCARD]/main.ts +error: TS18046 [ERROR]: 'e' is of type 'unknown'. + console.log(e.message); + ^ + at file://[WILDCARD]/use_unknown_in_catch_variables/main.ts:4:15 \ No newline at end of file diff --git a/tests/specs/check/use_unknown_in_catch_variables/main.ts b/tests/specs/check/use_unknown_in_catch_variables/main.ts new file mode 100644 index 00000000000000..abab554a43153a --- /dev/null +++ b/tests/specs/check/use_unknown_in_catch_variables/main.ts @@ -0,0 +1,5 @@ +try { + throw new Error(); +} catch (e) { + console.log(e.message); +} From 5a7c507cdcbbcda2cf56392b8996cd7a41bb8d66 Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Fri, 6 Sep 2024 02:54:38 +0900 Subject: [PATCH 4/4] fix --- tests/specs/check/use_unknown_in_catch_variables/main.out | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/specs/check/use_unknown_in_catch_variables/main.out b/tests/specs/check/use_unknown_in_catch_variables/main.out index e368382031580f..28236849e3ecfd 100644 --- a/tests/specs/check/use_unknown_in_catch_variables/main.out +++ b/tests/specs/check/use_unknown_in_catch_variables/main.out @@ -2,4 +2,4 @@ Check file:///[WILDCARD]/main.ts error: TS18046 [ERROR]: 'e' is of type 'unknown'. console.log(e.message); ^ - at file://[WILDCARD]/use_unknown_in_catch_variables/main.ts:4:15 \ No newline at end of file + at file://[WILDCARD]/use_unknown_in_catch_variables/main.ts:4:15