Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions crates/oxc_isolated_declarations/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ impl<'a> IsolatedDeclarations<'a> {
is_remaining_params_have_required: bool,
) -> Option<FormalParameter<'a>> {
let pattern = &param.pattern;
if pattern.type_annotation.is_none() && pattern.kind.is_destructuring_pattern() {
self.error(parameter_must_have_explicit_type(param.span));
return None;
if let BindingPatternKind::AssignmentPattern(pattern) = &pattern.kind {
if pattern.left.kind.is_destructuring_pattern()
&& pattern.left.type_annotation.is_none()
{
self.error(parameter_must_have_explicit_type(param.span));
return None;
}
}

let is_assignment_pattern = pattern.kind.is_assignment_pattern();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ input_file: crates/oxc_isolated_declarations/tests/fixtures/function-parameters.

export declare function fnDeclGood(p?: T, rParam?: string): void;
export declare function fnDeclGood2(p?: T, rParam?: number): void;
export declare function fooGood(): number;
export declare const fooGood2: () => number;
export declare function fooGood([a, b]?: any[]): number;
export declare const fooGood2: ({ a, b }?: object) => number;
export declare function fnDeclBad<T>(p: T, rParam: T, r2: T): void;
export declare function fnDeclBad2<T>(p: T, r2: T): void;
export declare function fnDeclBad3<T>(p: T, rParam?: T, r2: T): void;
Expand All @@ -17,24 +17,6 @@ export declare const fooBad2: () => number;

==================== Errors ====================

x TS9011: Parameter must have an explicit type annotation with
| --isolatedDeclarations.
,-[5:25]
4 |
5 | export function fooGood([a, b]: any[] = [1, 2]): number {
: ^^^^^^^^^^^^^^^^^^^^^^
6 | return 2;
`----

x TS9011: Parameter must have an explicit type annotation with
| --isolatedDeclarations.
,-[9:26]
8 |
9 | export const fooGood2 = ({a, b}: object = { a: 1, b: 2 }): number => {
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10 | return 2;
`----

x TS9025: Declaration emit for this parameter requires implicitly adding
| undefined to it's type. This is not supported with --isolatedDeclarations.
,-[14:30]
Expand Down