From 4e239e3189bd05bf6523fdd95b33bed3e152d0ba Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Tue, 4 Feb 2025 16:19:01 -0800 Subject: [PATCH] [flow][test] Add additional test for `declare global {...}` without explicit react import Summary: The added test helps to ensure that the globals can still be correctly used even when react is not imported. It helps to test the interaction between the declare global feature and the implicit inclusion of react import in file_sig. Changelog: [internal] Reviewed By: panagosg7 Differential Revision: D69133647 fbshipit-source-id: c13a169e64e14ce1bc35e8411413d372a231e88a --- .../declare_global_in_react_module.exp | 17 ++++++++++++++++- .../test_no_explicit_react_import.js | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/declare_global_in_react_module/test_no_explicit_react_import.js diff --git a/tests/declare_global_in_react_module/declare_global_in_react_module.exp b/tests/declare_global_in_react_module/declare_global_in_react_module.exp index 128aac2a9b3..00d8aa02fb6 100644 --- a/tests/declare_global_in_react_module/declare_global_in_react_module.exp +++ b/tests/declare_global_in_react_module/declare_global_in_react_module.exp @@ -85,5 +85,20 @@ References: ^^ [2] +Error ----------------------------------------------------------------------------- test_no_explicit_react_import.js:1:1 -Found 7 errors +Cannot cast empty string to `MyReact` because string [1] is incompatible with string literal `react` [2]. +[incompatible-cast] + + test_no_explicit_react_import.js:1:1 + 1| '' as ReactTypes.MyReact; // error: '' ~> 'react' + ^^ [1] + +References: + test_no_explicit_react_import.js:1:7 + 1| '' as ReactTypes.MyReact; // error: '' ~> 'react' + ^^^^^^^^^^^^^^^^^^ [2] + + + +Found 8 errors diff --git a/tests/declare_global_in_react_module/test_no_explicit_react_import.js b/tests/declare_global_in_react_module/test_no_explicit_react_import.js new file mode 100644 index 00000000000..b41d475fbb6 --- /dev/null +++ b/tests/declare_global_in_react_module/test_no_explicit_react_import.js @@ -0,0 +1 @@ +'' as ReactTypes.MyReact; // error: '' ~> 'react'