diff --git a/crates/oxc_ast/src/ast_impl/ts.rs b/crates/oxc_ast/src/ast_impl/ts.rs index c9d13e98e9aeb..624ccbcaa9037 100644 --- a/crates/oxc_ast/src/ast_impl/ts.rs +++ b/crates/oxc_ast/src/ast_impl/ts.rs @@ -55,7 +55,9 @@ impl<'a> TSType<'a> { /// Check if type maybe `undefined` pub fn is_maybe_undefined(&self) -> bool { match self { - TSType::TSUndefinedKeyword(_) => true, + TSType::TSAnyKeyword(_) + | TSType::TSUnknownKeyword(_) + | TSType::TSUndefinedKeyword(_) => true, TSType::TSUnionType(un) => un.types.iter().any(Self::is_maybe_undefined), _ => false, } diff --git a/crates/oxc_isolated_declarations/src/function.rs b/crates/oxc_isolated_declarations/src/function.rs index d6960f691e560..743f2fccefe41 100644 --- a/crates/oxc_isolated_declarations/src/function.rs +++ b/crates/oxc_isolated_declarations/src/function.rs @@ -95,7 +95,7 @@ impl<'a> IsolatedDeclarations<'a> { if matches!(ts_type, TSType::TSTypeReference(_)) { self.error(implicitly_adding_undefined_to_type(param.span)); } else if !ts_type.is_maybe_undefined() { - // union with undefined + // union with `undefined` return self.ast.ts_type_annotation( SPAN, self.ast.ts_type_union_type( diff --git a/crates/oxc_isolated_declarations/tests/fixtures/function-parameters.ts b/crates/oxc_isolated_declarations/tests/fixtures/function-parameters.ts index e22af6aac55b9..4e9efc68b9d19 100644 --- a/crates/oxc_isolated_declarations/tests/fixtures/function-parameters.ts +++ b/crates/oxc_isolated_declarations/tests/fixtures/function-parameters.ts @@ -26,3 +26,7 @@ export function fooBad([a, b] = [1, 2]): number { export const fooBad2 = ({a, b} = { a: 1, b: 2 }): number => { return 2; } + + +export function withAny(a: any = 1, b: string): void { } +export function withUnknown(a: unknown = 1, b: string): void { } diff --git a/crates/oxc_isolated_declarations/tests/snapshots/function-parameters.snap b/crates/oxc_isolated_declarations/tests/snapshots/function-parameters.snap index c006d77d4c613..458de230d6d28 100644 --- a/crates/oxc_isolated_declarations/tests/snapshots/function-parameters.snap +++ b/crates/oxc_isolated_declarations/tests/snapshots/function-parameters.snap @@ -14,6 +14,8 @@ export declare function fnDeclBad2(p: T, r2: T): void; export declare function fnDeclBad3(p: T, rParam?: T, r2: T): void; export declare function fooBad(): number; export declare const fooBad2: () => number; +export declare function withAny(a: any, b: string): void; +export declare function withUnknown(a: unknown, b: string): void; ==================== Errors ====================