Files
oxc-project__oxc/crates/oxc_isolated_declarations/tests/fixtures/function-parameters.ts
camc314 53f9295ac5 fix(isolated-declarations): preserve undefined for defaulted any (#25292)
## Summary

- emit `any | undefined` for default-initialized `any` parameters followed by required parameters
- add a regression fixture for #25290 and update the existing parameter snapshot
- preserve the existing handling of `unknown`

Closes #25290
2026-08-17 09:43:42 +00:00

47 lines
1.8 KiB
TypeScript

// Correct
export function fnDeclGood(p: T = [], rParam = ""): void { };
export function fnDeclGood2(p: T = [], rParam?: number): void { };
export function fooGood([a, b]: any[] = [1, 2]): number {
return 2;
}
export const fooGood2 = ({a, b}: object = { a: 1, b: 2 }): number => {
return 2;
}
const x = 42;
const y = '';
export function fooGood3({a = x, b: [{c = y}]}: object): void {}
// Incorrect
export function fnDeclBad<T>(p: T = [], rParam: T = "", r2: T): void { }
export function fnDeclBad2<T>(p: T = [], r2: T): void { }
export function fnDeclBad3<T>(p: T = [], r2: T, rParam?: T): void { }
export function fooBad([a, b] = [1, 2]): number {
return 2;
}
export const fooBad2 = ({a, b} = { a: 1, b: 2 }): number => {
return 2;
}
export function withAny(a: any = 1, b: string): void { }
export function withAnyUnion(a: any | string = 1, b: string): void { }
export function withAnyArrayUnion(a: any | number[] = [], b: string): void { }
export function withAnyUndefinedUnion(a: any | undefined = 1, b: string): void { }
type Foo = {};
export function withAnyTypeReferenceUnion(a: any | Foo = {}, b: string): void { }
export function withAnyTypeReferenceUndefinedUnion(a: any | Foo | undefined = {}, b: string): void { }
export function withAnyTypeOperatorUnion(a: any | keyof {} = 1, b: string): void { }
export function withAnyIntersectionTypeReferenceUnion(a: any | (Foo & {}) = {}, b: string): void { }
export function withUnknown(a: unknown = 1, b: string): void { }
export function withUnknownUnion(a: unknown | string = 1, b: string): void { }
export function withTypeAssertion(a = /regular-repression-cannot-infer/ as any): void { }
export function restWithDefault(...[value, options = {}]: [string, object]): void { }
export function restWithNestedDefault(...[a, { b = 1, c = 2 }]: [number, { b: number, c: number }]): void { }