Skip to content

Error when trying to emit declarations for a module with a non exported base class #9865

Closed
@yahiko00

Description

@yahiko00

TypeScript Version: 2.0.0

Code

// file: animal.ts
abstract class Animal {
    name: string;

    constructor(name: string) {
      this.name = name;
    }

    abstract shout(): string;
}

export class Snail extends Animal {
    shout(): string {
        return '...';
    }
}

I'm trying to emit declarations files .d.ts with tsc --declaration in order to get such a following file:

Expected behavior:
File animal.js well generated as well as file animal.d.ts:

// file: animal.d.ts
declare abstract class Animal {
    name: string;
    constructor(name: string);
    abstract shout();
}

export declare class Snail extends Animal {
    shout();
}

Actual behavior:
File animal.js well generated but no file animal.d.ts. I got an error instead:
error TS4020: Extends clause of exported class 'Snail' has or is using private name 'Animal'.

It is maybe a misunderstanding of mine, but in my mind, when a code compiles with tsc, it should also compile with the --declaration flag.

For information, here is my tsconfig.json:

// file: tsconfig.json
{
    "compilerOptions": {
        "noImplicitAny": true,
        "strictNullChecks": true,
        "target": "es5",
        "module": "amd",
        "outDir": "./build"
    },
    "exclude" : [
        "./build",
        "./node_modules"
    ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions