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

Wrong declaration file generated for JS + subclass #35932

Closed
Jack-Works opened this issue Dec 31, 2019 · 5 comments · Fixed by #37970
Closed

Wrong declaration file generated for JS + subclass #35932

Jack-Works opened this issue Dec 31, 2019 · 5 comments · Fixed by #37970
Assignees
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Fix Available A PR has been opened for this issue

Comments

@Jack-Works
Copy link
Contributor

TypeScript Version: 3.7.x-dev.201xxxxx

Search Terms:

Code

src/tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "declaration": true,
    "emitDeclarationOnly": true,
    "declarationDir": "../dts/"
  }
}

src/index.js (Important, this only happens in .js file)

export class A {
  /** @returns {this} */
  method() {}
}
export default class Base extends A {
  // This method is required to reproduce this bug
  verify() {}
}

Expected behavior:

Generated .d.ts:

export declare class A {
    /** @returns {this} */
    method(): void;
}
export default class Base extends A {
    verify(): void;
}

Actual behavior:

export class A {
    /** @returns {this} */
    method(): A;
}
export default class Base extends A {
    verify(): void;
    /** @returns {this} */
    method(): Base;
}

The wrong behavior:

  1. Methods from the parent class is copied to the subclass
  2. The return type of copied class is wrong (should be this, actually the class name.)

This behavior cause the error following:

(The parent class is import('events').EventEmitter)

image

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files labels Jan 14, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.9.0 milestone Jan 14, 2020
@chriswoodle
Copy link

Looks like I have same issue:
https://github.com/chriswoodle/typescript-allowjs-eventemitter-bug

@Jack-Works
Copy link
Contributor Author

Hmm do you sure it get fixed? When I doing code gen in 4.0.0-dev-20200505 it still exists

@weswigham
Copy link
Member

Is there a second issue? we have your repro, almost verbatim, in our test suite now

@Jack-Works
Copy link
Contributor Author

Oh strange I can't reproduce it by a POC

@Jack-Works
Copy link
Contributor Author

> const m = require('ts-morph')
> m.ts.version
'3.8.3'
> const ts = require('typescript')
> ts.version
'4.0.0-dev.20200505'
>

It's a dependency problem, sorry! 🤣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants