From b7ba9c01a126c182c1b29eec49dc34fc05c1c9c2 Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:45:22 +0000 Subject: [PATCH] fix(linter) fix bug in fixer for prefer-function-type when interface is exported (#5122) part of https://github.com/oxc-project/oxc/issues/5103 --- .../src/rules/typescript/prefer_function_type.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/oxc_linter/src/rules/typescript/prefer_function_type.rs b/crates/oxc_linter/src/rules/typescript/prefer_function_type.rs index 485b0094c..3ab61df59 100644 --- a/crates/oxc_linter/src/rules/typescript/prefer_function_type.rs +++ b/crates/oxc_linter/src/rules/typescript/prefer_function_type.rs @@ -206,8 +206,10 @@ fn check_member(member: &TSSignature, node: &AstNode<'_>, ctx: &LintContext<'_>) Fix::new( format!( - "type {} = {};", - &interface_decl.id.name, &suggestion + "{} {} = {};", + if is_parent_exported { "export type" } else { "type" }, + &interface_decl.id.name, + &suggestion ), Span::new(node_start, node_end), ) @@ -718,6 +720,11 @@ type X = {} & (() => void); ", None, ), + ( + "export interface AnyFn { (...args: any[]): any }", + "export type AnyFn = (...args: any[]) => any;", + None, + ), ]; Tester::new(PreferFunctionType::NAME, pass, fail).expect_fix(fix).test_and_snapshot();