Skip to content

Behavior difference: tsgo no longer infer variadic args type when arguments[...] is referenced inside plain js function body #4230

@hkleungai

Description

@hkleungai

There are (somewhat) related sections on CHANGES.md, but none of them are describing what I observe here.


Steps to reproduce

  1. Start a plain new project
    • "@typescript/native-preview": "7.0.0-dev.20260606.1",
    • "typescript": "6.0.3"
  2. Run npx tsgo --init to get the default tsconfig. Turn on these flags as well.
    • "allowJs": true,
    • "checkJs": true,
    • "stableTypeOrdering": true,
  3. Add src/main.js. Run npx tsc & npx tsgo to see the difference.
// src/main.js

/**
 * @param {number} length
 */
export function rectArea(length) {
    const width = arguments[1];

    if (typeof width === 'number') {
        return length * width;
    }

    return length * length;
}

rectArea(3);
rectArea(4, 5);

Behavior with typescript@6.0

Emit

/**
 * @param {number} length
 */
export function rectArea(length: number, ...args: any[]): number;
//# sourceMappingURL=main.d.ts.map

With no error.

Behavior with tsgo

Emit

/**
 * @param {number} length
 */
export declare function rectArea(length: number): number;
//# sourceMappingURL=main.d.ts.map

With error.

src/main.js:17:13 - error TS2554: Expected 1 arguments, but got 2.

17 rectArea(4, 5);
               ~


Found 1 error in src/main.js:17

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions