Skip to content

Duplicate function declarations in generated .d.ts for non-module JS files with allowJs + declaration #63546

@LangLangBart

Description

@LangLangBart

🔎 Search Terms

allowJs declaration duplicate, allowJs declaration emit multiple files global function, declaration emit global scope merged symbol resolveAnonymousTypeMembers, script file declaration emit duplicates

🕗 Version & Regression Information

This is the behavior in every version I tried, including 6.0.3 (also tested typescript@next)

Playground Link: requires multi-file setup with tsconfig.json.

I used stackblitz instead.

⏯ Playground Link

https://stackblitz.com/edit/node-emxsybj1?file=tsconfig.json

💻 Code

tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "declaration": true,
    "emitDeclarationOnly": true
  },
  "include": ["*.js"]
}

a.js

/** @filename: a.js */
function func(x) {
  return x + 1;
}

b.js

/** @filename: b.js */
function func(x) {
  return x + 2;
}

🙁 Actual behavior

a.d.ts and b.d.ts each contain the function declaration twice (once from each file).

a.d.ts

/** @filename: a.js */
declare function func(x: any): any;
declare function func(x: any): any;

b.d.ts

declare function func(x: any): any;
/** @filename: b.js */
declare function func(x: any): any;

🙂 Expected behavior

Each .d.ts should only contain the declaration from its own source file or error (not sure).

Additional information about the issue

related issues:

EDIT1: updated Expected behavior

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