diff --git a/cli/global_state.rs b/cli/global_state.rs index 129ab276a8..c9383bd881 100644 --- a/cli/global_state.rs +++ b/cli/global_state.rs @@ -138,6 +138,18 @@ impl GlobalState { .compile(state1.clone(), &out, target_lib) .await } else { + if let Some(types_url) = out.types_url.clone() { + let types_specifier = ModuleSpecifier::from(types_url); + state1 + .file_fetcher + .fetch_source_file( + &types_specifier, + Some(module_specifier.clone()), + ) + .await + .ok(); + }; + state1.js_compiler.compile(out).await } } diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 227566432e..bef4c8d566 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -1415,6 +1415,13 @@ itest!(type_directives_02 { output: "type_directives_02.ts.out", }); +itest!(type_directives_js_main { + args: "run --reload -L debug type_directives_js_main.js", + output: "type_directives_js_main.js.out", + check_stderr: true, + exit_code: 0, +}); + itest!(types { args: "types", output: "types.out", diff --git a/cli/tests/type_directives_js_main.js b/cli/tests/type_directives_js_main.js new file mode 100644 index 0000000000..f7274bf26d --- /dev/null +++ b/cli/tests/type_directives_js_main.js @@ -0,0 +1,3 @@ +import * as foo from "./subdir/type_reference.js"; + +console.log(foo.foo); diff --git a/cli/tests/type_directives_js_main.js.out b/cli/tests/type_directives_js_main.js.out new file mode 100644 index 0000000000..714dbd0b77 --- /dev/null +++ b/cli/tests/type_directives_js_main.js.out @@ -0,0 +1,3 @@ +[WILDCARD] +fetch_source_file specifier: file:[WILDCARD]cli/tests/subdir/type_reference.d.ts +[WILDCARD] \ No newline at end of file