Skip to content

[3.7.0] Generic class with private property generates d.ts file missing type on generic property #33877

@fearthecowboy

Description

@fearthecowboy

TypeScript Version: 3.7.0-beta (and just tested with typescript@next)

Search Terms: private field declaration

Given a class:

class foo<T> {
    private get value() : T {
        return this.v;
    }   
    constructor (private v:T) {
    }
}

Actual behavior:

running:
.\node_modules\.bin\tsc .\foo.ts --target es2016 --declaration

you will get a foo.d.ts file that looks like this:

declare class foo<T> {
    private v;
    private get value();
    constructor(v: T);
}

Dependent projects consuming that d.ts file will break, because the generic type isn't propagated to the private field declaration.

node_modules/foo/index.d.ts:3:17 - error TS7033: Property 'value' implicitly has type 'any', because its get accessor lacks a return type annotation.           
     private get value();                                                                                                                                                        ~~~~~           

Expected behavior:

declare class foo<T> {
    private v: T;
    private get value() : T;
    constructor(v: T);
}

Playground Link: playground doesn't generate d.ts file... (grrr!)

Related Issues: no.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions