Skip to content

Thrown "error TS4022: 'extends' clause of exported interface '...' has or is using private name ..." with --declaration flag and mixing imported export name with equal export interface name #16440

Closed
@Manusan42

Description

@Manusan42

TypeScript Version: 2.3.4 and nightly (2.4.0-dev.20170610)

Trying to build up a hierarchical namespace structure with modules.
All seems fine till setting --declaration flag to true.

Code

index.ts

import * as Service from './Service';

class MySuccessMessage implements Service.Response.Message {
  public type = 'successMessage'
}

class MyResponse implements Service.Response {
  public message: MySuccessMessage = new MySuccessMessage();
}

class MyTypedResponse implements Service.TypedResponse {
  public type = 'successResponse';
  public message: MySuccessMessage = new MySuccessMessage();
}

console.log((new MyResponse()).message.type);
console.log((new MyTypedResponse()).type);

Service.ts

import * as Response from './Response';
export { Response };

export interface Response {
  message: Response.Message;
}

export interface TypedResponse extends Response {
  type: string;
  message: Response.Message;
}

Response.ts

export interface Message {
  key?: string;
  type: string;
}

Compiling with:

{
  "compilerOptions": {
    "baseUrl": "",
    "outDir": "../dist/app",
    "target": "es2015",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "declaration": true
  }
}

Expected behavior:
No errors while compiling and printing out:

successMessage
successResponse

just like it does without setting --declaration to true or by removing the extends Response from export interface TypedResponse extends Response.

Actual behavior:
Getting error:

src/Service.ts(8,40): error TS4022: 'extends' clause of exported interface 'TypedResponse' has or is using private name 'Response'.

sample project with code from above:
export-error-test.zip

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