Skip to content

Fix isolatedDeclarations errors for arrow functions with default parameters#3521

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-isolateddeclarations-error
Draft

Fix isolatedDeclarations errors for arrow functions with default parameters#3521
Copilot wants to merge 3 commits intomainfrom
copilot/fix-isolateddeclarations-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 23, 2026

isolatedDeclarations incorrectly reported TS9025/TS9013 errors on arrow function parameters that have both type annotations and default values when followed by required parameters:

// Both erroneously reported errors with isolatedDeclarations
export const foo = (one: string = "DEFAULT", two: string): string => { ... };        // TS9025
export const bar = (one: string | undefined = "DEFAULT", two: string): string => { ... }; // TS9013

Root cause: the pseudochecker's pseudo type for these parameters didn't match the checker's type during the equivalence check in serializeTypeForDeclaration, causing spurious ReportInferenceFallback calls.

Three fixes in internal/pseudochecker/lookup.go:

  • cloneParameters: Was unconditionally setting Optional=true for parameters with initializers. Now matches the checker's isOptionalParameter semantics — a parameter with an initializer is optional only when all subsequent parameters are also optional/initialized/rest.
  • typeFromParameter: When a typed parameter has an initializer and is followed by required parameters, the pseudo type now includes | undefined to match getTypeOfParameter.
  • typeNodeCouldReferToUndefined: KindUndefinedKeyword was falling through to the default return false case (flagged by an existing TODO comment), causing string | undefined annotations to not be recognized as already containing undefined.

Also improves convergence with tsc on isolatedDeclarationsAddUndefined (2 errors → 1, matching tsc's count).

Copilot AI and others added 2 commits April 23, 2026 05:43
…meters

Fix pseudochecker to correctly handle parameter optionality and type
inference for parameters with default values in function-like expressions:

1. cloneParameters: A parameter with an initializer is now correctly
   marked as optional only when all subsequent parameters are also
   optional/initialized/rest, matching the checker's isOptionalParameter.

2. typeFromParameter: When a parameter has both a type annotation and an
   initializer, and there are required parameters after it, add
   | undefined to the pseudo type to match the checker's getTypeOfParameter.

3. typeNodeCouldReferToUndefined: Correctly recognize KindUndefinedKeyword
   as referring to undefined, fixing a known TODO.

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/53d7fd07-d1fd-491c-9d95-c05007af347d

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix isolatedDeclarations error with arrow functions Fix isolatedDeclarations errors for arrow functions with default parameters Apr 23, 2026
Copilot AI requested a review from jakebailey April 23, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isolatedDeclarations with arrow functions that have default parameters

2 participants