Skip to content

Declaration emit produces a syntax error (export default namespace) for expando members of a JS export default class #65731

In review

Description

TypeScript Version

The tested TypeScript version is 7.1.0-dev.20261129.1 (also 7.0.2). This is a regression: 6.0.3 emits a valid declaration file.

User Goal

The user's project failed to type-check after upgrading a dependency whose published .d.ts, generated by tsc from JavaScript, contained a syntax error. The user asked me to find out whether this is a TypeScript bug.

Setup and Action

tsconfig.json:

{
  "compilerOptions": {
    "allowJs": true,
    "declaration": true,
    "emitDeclarationOnly": true,
    "rootDir": "src",
    "outDir": "types"
  },
  "include": ["src"]
}

src/holidays.js:

export default class Holidays {
  constructor(country) {
    this.country = Holidays.normalize(country)
  }
}

Holidays.normalize = function (country) {
  return country.toUpperCase()
}
  1. Run tsc -p ..
  2. Run tsc --noEmit --ignoreConfig types/holidays.d.ts.

Expected and Actual Behavior

What actually happened: Step 1 succeeds, but the types/holidays.d.ts it emits has a syntax error, export default namespace:

export default class Holidays {
    country: any;
    constructor(country: any);
}
export default namespace Holidays {
    var normalize: (country: any) => any;
}

Step 2 reports the syntax error:

types/holidays.d.ts(5,26): error TS1005: ';' expected.

Because it's a syntax error, skipLibCheck doesn't suppress it: every TypeScript project that imports the emitted file fails to type-check.

What I expected: A declaration file with no syntax errors, like the one 6.0.3 emits:

declare class Holidays {
    constructor(country: any);
    country: any;
}
declare namespace Holidays {
    function normalize(country: any): any;
}
export default Holidays;

Agent Info

Claude Code 2.1.288 + Claude Opus 5.5 + Skill Version 1.0

Metadata

Metadata

Labels

Bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions