Files
oxc-project__oxc/crates/oxc_isolated_declarations/tests/snapshots/function-parameters.snap
Dunqing 134fb2228d fix(isolated-declarations): preserve unresolved parameter types (#25909)
#25292 made isolated declaration emit report a false TS9025 for a defaulted parameter whose annotation is an indexed access type. This breaks Vite's `UserConfig["base"]` case when Rolldown upgrades Oxc, even though the indexed property already includes `undefined`.

Oxc's isolated declaration emitter has no type checker, so it cannot safely resolve indexed accesses, type references, conditional types, or similar annotations. This change uses a syntax-only classification: widen or diagnose types whose syntax is conclusive, and preserve checker-dependent types rather than emit an unstable error. The union/intersection rules retain the distinct behavior of `any`, `never`, `unknown`, and `void`, and an explicit `undefined` union member is never duplicated.

Regression coverage includes the Rolldown/Vite case and a compact matrix of the relevant type algebra. The implementation and tests were reduced to one commit after review.

Validated with the isolated-declarations tests, strict Clippy, the all-features workspace suite, lint, docs, AST generation, and TypeScript 5.6.1-rc/6.0.3 type-algebra checks. The full local `just ready` run stopped only at a runner-dependent source-map snapshot because the repository expects Node 26.5.0 and this machine has 25.8.1; the remaining suite passed with that and the known terminal-color snapshot group skipped.

Follow-up to #25292. Related Rolldown failure: https://github.com/rolldown/rolldown/actions/runs/32158377691/job/95782148042?pr=10707

Disclosure: this change was prepared and verified with AI assistance (Codex).
2026-08-19 07:36:24 +00:00

69 lines
3.0 KiB
Plaintext

---
source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/function-parameters.ts
---
```
==================== .D.TS ====================
export declare function fnDeclGood(p?: T, rParam?: string): void;
export declare function fnDeclGood2(p?: T, rParam?: number): void;
export declare function fooGood([a, b]?: any[]): number;
export declare const fooGood2: ({ a, b }?: object) => number;
export declare function fooGood3({ a, b: [{ c }] }: object): void;
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, r2: T, rParam?: T): void;
export declare function fooBad(): number;
export declare const fooBad2: () => number;
export declare function withAny(a: any | undefined, b: string): void;
export declare function withAnyUnion(a: any | string | undefined, b: string): void;
export declare function withAnyArrayUnion(a: any | number[] | undefined, b: string): void;
export declare function withAnyUndefinedUnion(a: any | undefined, b: string): void;
type Foo = {};
export declare function withAnyTypeReferenceUnion(a: any | Foo, b: string): void;
export declare function withAnyTypeReferenceUndefinedUnion(a: any | Foo | undefined, b: string): void;
export declare function withAnyTypeOperatorUnion(a: any | keyof {}, b: string): void;
export declare function withAnyIntersectionTypeReferenceUnion(a: any | (Foo & {}), b: string): void;
export declare function withUnknown(a: unknown | undefined, b: string): void;
export declare function withUnknownUnion(a: unknown | string | undefined, b: string): void;
export declare function withTypeAssertion(a?: any): void;
export declare function restWithDefault(...[value, options]: [string, object]): void;
export declare function restWithNestedDefault(...[a, { b, c }]: [number, {
b: number;
c: number;
}]): void;
export {};
==================== Errors ====================
x TS9011: Parameter must have an explicit type annotation with
| --isolatedDeclarations.
,-[22:24]
21 |
22 | export function fooBad([a, b] = [1, 2]): number {
: ^^^^^^^^^^^^^^^
23 | return 2;
`----
x TS9011: Parameter must have an explicit type annotation with
| --isolatedDeclarations.
,-[26:25]
25 |
26 | export const fooBad2 = ({a, b} = { a: 1, b: 2 }): number => {
: ^^^^^^^^^^^^^^^^^^^^^^^
27 | return 2;
`----
x TS9025: Declaration emit for this parameter requires implicitly adding
| undefined to it's type. This is not supported with --isolatedDeclarations.
,-[38:42]
37 | export function withAnyTypeReferenceUndefinedUnion(a: any | Foo | undefined = {}, b: string): void { }
38 | export function withAnyTypeOperatorUnion(a: any | keyof {} = 1, b: string): void { }
: ^^^^^^^^^^^^^^^^^^^^^
39 | export function withAnyIntersectionTypeReferenceUnion(a: any | (Foo & {}) = {}, b: string): void { }
`----
```