Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The declaration file is missing the static tag #62

Closed
kong-lau opened this issue Dec 31, 2019 · 6 comments
Closed

The declaration file is missing the static tag #62

kong-lau opened this issue Dec 31, 2019 · 6 comments
Labels
Bug Something isn't working

Comments

@kong-lau
Copy link

Hi,
The dts file emit with plugin is missing the static tag

Pool.ts
class PoolImpl<T extends { dispose?(): void, onAlloc?(): void, onRelease?(): void }> {
constructor(cls: new() => T) {}
/* @internal */ public alloc(): T {}
/* @internal */ public release(item: T): void {}
/* @internal */ public resize(time: number): void {}
/* @internal */ public dispose(): void {}
}
export class Pool {
public static alloc<T>(cls: new () => T): T {}
public static release(item: any): null {}
public static releaseList(list: any[]): void {}
}

Pool.d.ts emit with rollup-plugin-ts@v1.2.0
declare class Pool {
alloc<T>(cls: new () => T): T;
release(item: any): null;
releaseList(list: any[]): void;
}

Pool.d.ts emit with tsc
export declare class Pool {
static alloc<T>(cls: new () => T): T;
static release(item: any): null;
static releaseList(list: any[]): void;
}

@wessberg
Copy link
Owner

wessberg commented Jan 1, 2020

Hey there. I can't reproduce this problem, but I do see a few things. First, your code is not valid TypeScript and will result in a TypeScript error: A function whose declared type is neither 'void' nor 'any' must return a value.'.

However, the other thing is that the output you got from rollup-plugin-ts looks a bit weird. An ExportDeclaration is missing.

Which TypeScript and Node versions are you running, and which OS and version are you using?

I've tried to reproduce this issue on Node 13 on Mac OS 10.15.3 with TypeScript v3.7.4. Here's what I got:

The following code:

class PoolImpl<T extends { dispose?(): void, onAlloc?(): void, onRelease?(): void }> {
    constructor(cls: new() => T) {}
    /* @internal */ public alloc(): T {}
    /* @internal */ public release(item: T): void {}
    /* @internal */ public resize(time: number): void {}
    /* @internal */ public dispose(): void {}
}
export class Pool {
    public static alloc<T>(cls: new () => T): T {}
    public static release(item: any): null {}
    public static releaseList(list: any[]): void {}
}

Will produce the following declaration file with v1.2.0 of rollup-plugin-ts:

declare class Pool {
    static alloc<T>(cls: new () => T): T;
    static release(item: any): null;
    static releaseList(list: any[]): void;
}
export {Pool};

@wessberg wessberg added the Need More Information Further information is requested label Jan 1, 2020
@kong-lau
Copy link
Author

kong-lau commented Jan 2, 2020

Hi, I post the sample at here.

@kong-lau
Copy link
Author

kong-lau commented Jan 2, 2020

Node v8.10.0
Windows 10 1909
TypeScript v3.7.4

@marijnh
Copy link

marijnh commented Jan 2, 2020

I'm seeing the same. It appears a class has to be re-exported for it to occur. I.e. an index.ts that just does export {Foo} from "./foo", and then a class Foo in foo.ts that has a static method, for example export class Foo { static m() { return 1 } }. You get a declaration file like this:

declare class Foo {
    m(): number;
}
export { Foo };

Which I assume is caused by dropping the static flag when copying the declaration around somewhere.

@wessberg
Copy link
Owner

wessberg commented Jan 2, 2020

Related to this issue I just opened at the TypeScript repo. Will implement a workaround.

@wessberg wessberg added Bug Something isn't working and removed Need More Information Further information is requested labels Jan 3, 2020
@wessberg
Copy link
Owner

wessberg commented Jan 3, 2020

This has been fixed in v1.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants