Skip to content

Commit 7946906

Browse files
authored
fix: add hint to run with --no-check when type checking fails (#28091)
1 parent 4921411 commit 7946906

File tree

34 files changed

+131
-5
lines changed

34 files changed

+131
-5
lines changed

cli/tools/check.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use regex::Regex;
2828
use crate::args::deno_json::TsConfigResolver;
2929
use crate::args::CheckFlags;
3030
use crate::args::CliOptions;
31+
use crate::args::DenoSubcommand;
3132
use crate::args::Flags;
3233
use crate::args::TsConfig;
3334
use crate::args::TsTypeLib;
@@ -94,8 +95,16 @@ pub async fn check(
9495

9596
#[derive(Debug, thiserror::Error, deno_error::JsError)]
9697
#[class(type)]
97-
#[error("Type checking failed.")]
98-
pub struct FailedTypeCheckingError;
98+
#[error("Type checking failed.{}", if self.can_skip {
99+
color_print::cstr!(
100+
"\n\n <y>info:</y> The program failed type-checking, but it still might work correctly.\n <c>hint:</c> Re-run with <u>--no-check</u> to skip type-checking.",
101+
)
102+
} else {
103+
""
104+
})]
105+
pub struct FailedTypeCheckingError {
106+
can_skip: bool,
107+
}
99108

100109
#[derive(Debug, thiserror::Error, deno_error::JsError)]
101110
pub enum CheckError {
@@ -199,7 +208,15 @@ impl TypeChecker {
199208
}
200209
}
201210
if failed {
202-
Err(FailedTypeCheckingError.into())
211+
Err(
212+
FailedTypeCheckingError {
213+
can_skip: !matches!(
214+
self.cli_options.sub_command(),
215+
DenoSubcommand::Check(_)
216+
),
217+
}
218+
.into(),
219+
)
203220
} else {
204221
Ok(diagnostics.into_graph())
205222
}

tests/specs/bench/check_local_by_default2/check_local_by_default2.out

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ const b: "b" = 12;
44
at [WILDCARD]/check_local_by_default2.ts:3:7
55

66
error: Type checking failed.
7+
8+
info: The program failed type-checking, but it still might work correctly.
9+
hint: Re-run with --no-check to skip type-checking.

tests/specs/bench/no_run/no_run.out

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ const _value: string = 1;
55
at [WILDCARD]/no_run.ts:1:7
66

77
error: Type checking failed.
8+
9+
info: The program failed type-checking, but it still might work correctly.
10+
hint: Re-run with --no-check to skip type-checking.

tests/specs/check/css_import/__test__.jsonc

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"exitCode": 1
1313
}, {
1414
"args": "run --check not_exists.ts",
15-
"output": "not_exists.out",
15+
"output": "not_exists_run.out",
1616
"exitCode": 1
1717
}, {
1818
"args": "check exists_and_try_uses.ts",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Check [WILDLINE]exists.ts
2+
TS2307 [ERROR]: Cannot find module 'file:///[WILDLINE]/not_exists.css'.
3+
at file:///[WILDLINE]/not_exists.ts:1:8
4+
5+
error: Type checking failed.
6+
7+
info: The program failed type-checking, but it still might work correctly.
8+
hint: Re-run with --no-check to skip type-checking.

tests/specs/check/module_not_found/__test__.jsonc

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"run": {
99
"args": "run --check --allow-import main.ts",
10-
"output": "main.out",
10+
"output": "main_run.out",
1111
"exitCode": 1
1212
},
1313
"missing_local_root": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Download http://localhost:4545/remote.ts
2+
Check file:///[WILDLINE]/module_not_found/main.ts
3+
TS2307 [ERROR]: Cannot find module 'file:///[WILDLINE]/other.js'.
4+
at file:///[WILDLINE]/main.ts:1:22
5+
6+
TS2307 [ERROR]: Cannot find module 'http://localhost:4545/remote.ts'.
7+
at file:///[WILDLINE]/main.ts:2:24
8+
9+
Found 2 errors.
10+
11+
error: Type checking failed.
12+
13+
info: The program failed type-checking, but it still might work correctly.
14+
hint: Re-run with --no-check to skip type-checking.

tests/specs/publish/sloppy_imports/sloppy_imports_not_enabled.out

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ TS2307 [ERROR]: Cannot find module 'file:///[WILDLINE]/b'. Maybe specify path to
33
at file:///[WILDLINE]/mod.ts:1:20
44

55
error: Type checking failed.
6+
7+
info: The program failed type-checking, but it still might work correctly.
8+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/_038_checkjs/038_checkjs.js.out

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ const foo = new Foo();
2222
Found 2 errors.
2323

2424
error: Type checking failed.
25+
26+
info: The program failed type-checking, but it still might work correctly.
27+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/check_js_points_to_ts/check_js_points_to_ts/test.js.out

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
44
at [WILDCARD]
55

66
error: Type checking failed.
7+
8+
info: The program failed type-checking, but it still might work correctly.
9+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/check_remote/no_check_remote.ts.disabled.out

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ export const a: "a" = 12;
44
at [WILDCARD]/type_error.ts:1:14
55

66
error: Type checking failed.
7+
8+
info: The program failed type-checking, but it still might work correctly.
9+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/error_003_typescript/error_003_typescript.ts.out

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ x = y;
77
at [WILDCARD]/error_003_typescript.ts:20:1
88

99
error: Type checking failed.
10+
11+
info: The program failed type-checking, but it still might work correctly.
12+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/error_003_typescript2/error_003_typescript.ts.out

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ x = y;
77
at [WILDCARD]/error_003_typescript.ts:20:1
88

99
error: Type checking failed.
10+
11+
info: The program failed type-checking, but it still might work correctly.
12+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/error_017_hide_long_source_ts/error_017_hide_long_source_ts.ts.out

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ TS2532 [ERROR]: Object is possibly 'undefined'.
33
at [WILDCARD]/error_017_hide_long_source_ts.ts:3:1
44

55
error: Type checking failed.
6+
7+
info: The program failed type-checking, but it still might work correctly.
8+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/error_for_await/error_for_await.ts.out

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ TS1356 [ERROR]: Did you mean to mark this function as 'async'?
1010
at [WILDCARD]error_for_await.ts:7:10
1111

1212
error: Type checking failed.
13+
14+
info: The program failed type-checking, but it still might work correctly.
15+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/import_attributes_type_check/type_check.out

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ console.log(data2.foo);
1212
Found 2 errors.
1313

1414
error: Type checking failed.
15+
16+
info: The program failed type-checking, but it still might work correctly.
17+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/js_root_with_ts_check/js_root_with_ts_check.js.out

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ const a = "";
44
at [WILDCARD]
55

66
error: Type checking failed.
7+
8+
info: The program failed type-checking, but it still might work correctly.
9+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/jsx_import_source/jsx_import_source_error.out

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ TS2307 [ERROR]: Cannot find module 'file:///[WILDCARD]/nonexistent/jsx-runtime'.
33
at file:///[WILDLINE]/jsx_import_source_no_pragma.tsx:1:1
44

55
error: Type checking failed.
6+
7+
info: The program failed type-checking, but it still might work correctly.
8+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/no_config_auto_discovery_for_local_script/no_auto_discovery.out

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ TS2584 [ERROR]: Cannot find name 'document'. Do you need to change your target l
44
at [WILDCARD]frontend_work.ts:2:15
55

66
error: Type checking failed.
7+
8+
info: The program failed type-checking, but it still might work correctly.
9+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/reference_types_error/reference_types_error.js.out

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ TS2307 [ERROR]: Cannot find module 'file:///[WILDLINE]/nonexistent.d.ts'.
33
at file:///[WILDLINE]/reference_types_error.js:1:22
44

55
error: Type checking failed.
6+
7+
info: The program failed type-checking, but it still might work correctly.
8+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/reference_types_error_vendor_dir/reference_types_error.js.out

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ TS2307 [ERROR]: Cannot find module 'file:///[WILDLINE]/nonexistent.d.ts'.
33
at file:///[WILDLINE]/reference_types_error.js:1:22
44

55
error: Type checking failed.
6+
7+
info: The program failed type-checking, but it still might work correctly.
8+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/sloppy_imports/no_sloppy.out

+3
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ TS2307 [ERROR]: Cannot find module 'file:///[WILDLINE]/dir'. Maybe specify path
2626
Found 8 errors.
2727

2828
error: Type checking failed.
29+
30+
info: The program failed type-checking, but it still might work correctly.
31+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/ts_type_imports/ts_type_imports.ts.out

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ const foo: Foo = new Map<string, string>();
66
at [WILDCARD]ts_type_imports.ts:5:7
77

88
error: Type checking failed.
9+
10+
info: The program failed type-checking, but it still might work correctly.
11+
hint: Re-run with --no-check to skip type-checking.

tests/specs/run/type_definitions_for_export/type_definitions_for_export.ts.out

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ bar(foo);
55
at [WILDCARD]type_definitions_for_export.ts:7:5
66

77
error: Type checking failed.
8+
9+
info: The program failed type-checking, but it still might work correctly.
10+
hint: Re-run with --no-check to skip type-checking.

tests/specs/serve/type_check/main.out

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ TS2353 [ERROR]: Object literal may only specify known properties, and 'bad' does
55
at [WILDCARD]main.ts:2:3
66

77
error: Type checking failed.
8+
9+
info: The program failed type-checking, but it still might work correctly.
10+
hint: Re-run with --no-check to skip type-checking.

tests/specs/serve/type_check2/main.out

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ TS2339 [ERROR]: Property 'doesnt_exist' does not exist on type 'Request'.
55
at [WILDCARD]main.ts:3:25
66

77
error: Type checking failed.
8+
9+
info: The program failed type-checking, but it still might work correctly.
10+
hint: Re-run with --no-check to skip type-checking.

tests/specs/test/check_local_by_default2/main.out

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ const b: "b" = 12;
44
at [WILDCARD]/main.ts:3:7
55

66
error: Type checking failed.
7+
8+
info: The program failed type-checking, but it still might work correctly.
9+
hint: Re-run with --no-check to skip type-checking.

tests/specs/test/doc/main.out

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ TS2367 [ERROR]: This comparison appears to be unintentional because the types 's
99
at [WILDCARD]/main.ts$30-35.ts:3:20
1010

1111
error: Type checking failed.
12+
13+
info: The program failed type-checking, but it still might work correctly.
14+
hint: Re-run with --no-check to skip type-checking.

tests/specs/test/markdown/main.out

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
77
at [WILDCARD]/main.md$29-32.ts:2:11
88

99
error: Type checking failed.
10+
11+
info: The program failed type-checking, but it still might work correctly.
12+
hint: Re-run with --no-check to skip type-checking.

tests/specs/test/markdown_full_block_names/main.out

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
66
at [WILDCARD]/main.md$17-20.ts:2:11
77

88
error: Type checking failed.
9+
10+
info: The program failed type-checking, but it still might work correctly.
11+
hint: Re-run with --no-check to skip type-checking.

tests/specs/test/markdown_ignore_html_comment/main.out

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
55
at [WILDCARD]/main.md$34-37.ts:2:11
66

77
error: Type checking failed.
8+
9+
info: The program failed type-checking, but it still might work correctly.
10+
hint: Re-run with --no-check to skip type-checking.

tests/specs/test/markdown_windows/main.out

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
77
at [WILDCARD]/main.md$29-32.ts:2:11
88

99
error: Type checking failed.
10+
11+
info: The program failed type-checking, but it still might work correctly.
12+
hint: Re-run with --no-check to skip type-checking.

tests/specs/test/no_run/main.out

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ const _value: string = 1;
55
at [WILDCARD]/main.ts:1:7
66

77
error: Type checking failed.
8+
9+
info: The program failed type-checking, but it still might work correctly.
10+
hint: Re-run with --no-check to skip type-checking.

tests/specs/test/type_check_with_doc/main.out

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ TS2322 [ERROR]: Type 'string' is not assignable to type 'number'.
1313
Found 2 errors.
1414

1515
error: Type checking failed.
16+
17+
info: The program failed type-checking, but it still might work correctly.
18+
hint: Re-run with --no-check to skip type-checking.

0 commit comments

Comments
 (0)