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

Generated .d.ts files from JS project are invalid #41258

Closed
Gozala opened this issue Oct 26, 2020 · 0 comments · Fixed by #41783
Closed

Generated .d.ts files from JS project are invalid #41258

Gozala opened this issue Oct 26, 2020 · 0 comments · Fixed by #41783
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@Gozala
Copy link

Gozala commented Oct 26, 2020

TypeScript Version: 3.7.x-dev.201xxxxx

Search Terms:

Code

lib.js

/**
 * @template T
 * @implements {IEncoder<T>}
 */
export class Encoder {
  /**
   * @param {T} value 
   */
  encode(value) {
    return new Uint8Array(0)
  }
}


/**
 * @template T
 * @typedef {import('./interface').Encoder<T>} IEncoder
 */

interface.ts

export interface Encoder<T> {
  encode(value:T): Uint8Array
}

Expected behavior:

Generating typedefs should generate TS file that type checks, e.g. for lib.js it should produce something like:

/**
 * @template T
 * @implements {IEncoder<T>}
 */
export class EncoderImpl<T> implements IEncoder<T> {
    /**
     * @param {T} value
     */
    encode(value: T): Uint8Array;
}

import { Encoder as IEncoder } from "./interface"

Actual behavior:

Instead tsc generates lib.d.ts file which does not type check, because type parameters are omitted

/**
 * @template T
 * @implements {IEncoder<T>}
 */
export class EncoderImpl<T> implements Encoder {
    /**
     * @param {T} value
     */
    encode(value: T): Uint8Array;
}
export type IEncoder<T> = import("./interface").Encoder<T>;

Playground Link:

Can't make a playground link because it requires multiple files, but here is the repo with the above example
https://github.com/Gozala/tsc-implements-bug

Related Issues:

Unfortunately it's not just that type parameters are omitted, but also the fact that importing interface turns it into a type which then can't be used as implements target.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants