Skip to content

"Duplicate identifier" errors introduced in TS 5.5, if declare module is used #58961

Closed as not planned
@AlessioGr

Description

@AlessioGr

🔎 Search Terms

declare module
duplicate identifier
5.5

🕗 Version & Regression Information

This issue was introduced in ts 5.5.2. It's still an issue in 5.6.0-dev.20240621. In 5.4.5 it works as expected.

Specifically, this issue was introduced in 5.5.0-dev.20240524. The last version where this was working as expected was 5.5.0-dev.20240523.

⏯ GitHub reproduction

https://github.com/AlessioGr/tsbug/blob/83e990cdb97d016f13aac969258aa36491dd31b1/src/index.ts#L9-L8

💻 Code

(as linked in the reproduction):

import type { PayloadRequest } from 'payload'

declare module 'payload' {
    export interface DatabaseAdapter {
        test: string
    }
}

🙁 Actual behavior

The code throws the following error in TypeScript 5.5.2 and works in 5.4.5:

src/index.ts:5:22 - error TS2300: Duplicate identifier 'DatabaseAdapter'.

5     export interface DatabaseAdapter {
                       ~~~~~~~~~~~~~~~

  node_modules/.pnpm/payload@3.0.0-beta.53_@swc+core@1.6.3_@swc+types@0.1.8_graphql@16.9.0_typescript@5.5.2/node_modules/payload/dist/index.d.ts:199:15
    199 export type { DatabaseAdapter, GeneratedTypes, Payload, RequestContext };
                      ~~~~~~~~~~~~~~~
    'DatabaseAdapter' was also declared here.

Here is how it is exported from the payload module:

type DatabaseAdapter = BaseDatabaseAdapter;
export type { DatabaseAdapter, GeneratedTypes, Payload, RequestContext };

Strangely, if I export it like this instead, the TypeScript error disappears:

export type { BaseDatabaseAdapter as DatabaseAdapter, GeneratedTypes, Payload, RequestContext };

🙂 Expected behavior

The code should not throw an error / the repo should compile when running npx tsc.

Additional information about the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions