Skip to content

Types like "keyof interface" should not be expanded when compiled due to declaration merging #39683

@shigma

Description

@shigma

TypeScript Version: 3.9.6

Search Terms: keyof declaration merging ts2339

Code

// module-A
interface Data {
  foo: string
}

export const keys = new Set<keyof Data>(['foo'])

Expected behavior:

// emitted module-A/index.d.ts
export interface Data {
    foo: string;
}
export declare const keys: Set<keyof Data>;

Actual behavior:

// emitted module-A/index.d.ts
export interface Data {
    foo: string;
}
export declare const keys: Set<"foo">;
// module-B
declare module 'module-A' {
  interface Data {
    bar: number
  }
}

keys.add('bar') // error here (ts2339)

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions