1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix(cli): expand tsc roots when using checkJs (#15164)

A JS file can still point to a TS file, so we need to expand the roots
in the checkJs case too.

Fixes: #15163
This commit is contained in:
Rafael Ávila de Espíndola 2022-07-14 14:40:47 +00:00 committed by GitHub
parent 2423f83ca8
commit a34ed568e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 38 deletions

View file

@ -199,15 +199,13 @@ pub fn get_ts_config_for_emit(
/// Transform the graph into root specifiers that we can feed `tsc`. We have to /// Transform the graph into root specifiers that we can feed `tsc`. We have to
/// provide the media type for root modules because `tsc` does not "resolve" the /// provide the media type for root modules because `tsc` does not "resolve" the
/// media type like other modules, as well as a root specifier needs any /// media type like other modules, as well as a root specifier needs any
/// redirects resolved. If we aren't checking JavaScript, we need to include all /// redirects resolved. We need to include all the emittable files in
/// the emittable files in the roots, so they get type checked and optionally /// the roots, so they get type checked and optionally emitted,
/// emitted, otherwise they would be ignored if only imported into JavaScript. /// otherwise they would be ignored if only imported into JavaScript.
fn get_tsc_roots( fn get_tsc_roots(
roots: &[(ModuleSpecifier, ModuleKind)],
graph_data: &GraphData, graph_data: &GraphData,
check_js: bool, check_js: bool,
) -> Vec<(ModuleSpecifier, MediaType)> { ) -> Vec<(ModuleSpecifier, MediaType)> {
if !check_js {
graph_data graph_data
.entries() .entries()
.into_iter() .into_iter()
@ -232,17 +230,6 @@ fn get_tsc_roots(
_ => None, _ => None,
}) })
.collect() .collect()
} else {
roots
.iter()
.filter_map(|(specifier, _)| match graph_data.get(specifier) {
Some(ModuleEntry::Module { media_type, .. }) => {
Some((specifier.clone(), *media_type))
}
_ => None,
})
.collect()
}
} }
/// A hashing function that takes the source code, version and optionally a /// A hashing function that takes the source code, version and optionally a
@ -328,7 +315,7 @@ pub fn check(
return Ok(Default::default()); return Ok(Default::default());
} }
let root_names = get_tsc_roots(roots, &segment_graph_data, check_js); let root_names = get_tsc_roots(&segment_graph_data, check_js);
if options.log_checks { if options.log_checks {
for (root, _) in roots { for (root, _) in roots {
let root_str = root.to_string(); let root_str = root.to_string();

View file

@ -2701,6 +2701,13 @@ fn check_local_then_remote() {
assert_contains!(stderr, "Type 'string' is not assignable to type 'number'."); assert_contains!(stderr, "Type 'string' is not assignable to type 'number'.");
} }
// Regression test for https://github.com/denoland/deno/issues/15163
itest!(check_js_points_to_ts {
args: "run --quiet --check --config checkjs.tsconfig.json run/check_js_points_to_ts/test.js",
output: "run/check_js_points_to_ts/test.js.out",
exit_code: 1,
});
itest!(no_prompt_flag { itest!(no_prompt_flag {
args: "run --quiet --unstable --no-prompt no_prompt.ts", args: "run --quiet --unstable --no-prompt no_prompt.ts",
output_str: Some(""), output_str: Some(""),

View file

@ -0,0 +1,3 @@
export function bar(): string {
return 42;
}

View file

View file

@ -0,0 +1,4 @@
import { bar } from "./bar.ts";
export function foo() {
bar();
}

View file

@ -0,0 +1,3 @@
// @deno-types="./foo.d.ts"
import { foo } from "./foo.js";
foo();

View file

@ -0,0 +1,4 @@
error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
return 42;
~~~~~~~~~~
at [WILDCARD]