diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index fcea96aa5d..c9729a5e5d 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/schemas/config-file.v1.json b/cli/schemas/config-file.v1.json index df8177af29..d0dc27e759 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" } } diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index f35fa7b5d3..4044c5fc16 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", 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 0000000000..a991c6eed4 --- /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 0000000000..28236849e3 --- /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 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 0000000000..abab554a43 --- /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); +}