diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 9bdb6ea430c..c5e1dafd3ed 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -10,6 +10,7 @@ namespace ts.codefix { Diagnostics.Cannot_find_namespace_0.code, Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here.code, + Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer.code ]; registerCodeFix({ diff --git a/tests/cases/fourslash/importNameCodeFix_shorthandPropertyAssignment1.ts b/tests/cases/fourslash/importNameCodeFix_shorthandPropertyAssignment1.ts new file mode 100644 index 00000000000..47de85b8ce0 --- /dev/null +++ b/tests/cases/fourslash/importNameCodeFix_shorthandPropertyAssignment1.ts @@ -0,0 +1,14 @@ +/// + +// @Filename: /a.ts +////export const a = 1; + +// @Filename: /b.ts +////const b = { /**/a }; + +goTo.file("/b.ts"); +verify.importFixAtPosition([ +`import { a } from "./a"; + +const b = { a };` +]); diff --git a/tests/cases/fourslash/importNameCodeFix_shorthandPropertyAssignment2.ts b/tests/cases/fourslash/importNameCodeFix_shorthandPropertyAssignment2.ts new file mode 100644 index 00000000000..1d938b23265 --- /dev/null +++ b/tests/cases/fourslash/importNameCodeFix_shorthandPropertyAssignment2.ts @@ -0,0 +1,15 @@ +/// + +// @Filename: /a.ts +////const a = 1; +////export default a; + +// @Filename: /b.ts +////const b = { /**/a }; + +goTo.file("/b.ts"); +verify.importFixAtPosition([ +`import a from "./a"; + +const b = { a };` +]);