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

JSDoc: support @implements tag on class #17498

Closed
darky opened this issue Jul 28, 2017 · 4 comments
Closed

JSDoc: support @implements tag on class #17498

darky opened this issue Jul 28, 2017 · 4 comments
Assignees
Labels
Committed The team has roadmapped this issue Domain: JavaScript The issue relates to JavaScript specifically Domain: JSDoc Relates to JSDoc parsing and type generation Suggestion An idea for TypeScript

Comments

@darky
Copy link

darky commented Jul 28, 2017

TypeScript Version: nightly (2.5.0-dev.20170728)

Code

index.d.ts

class AClass {
    method(a: number): number
}

some.js

/** @type {AClass} */
class A {
    method(a) {
        return false;
    }
}

Expected behavior:

Type 'false' is not assignable to type 'number'.

Actual behavior:

Not working. Impossible to set type on class.

@ghost
Copy link

ghost commented Jul 29, 2017

The problem with @type {AClass} is that that would declare the type to be an instance of AClass.
Maybe you want something like this? (won't work today):

/** @import { I } from "foo.d.ts" */

/** @implements {I} */
class AClass { ... }

However, in TS code we don't allow you to omit the parameter types on an override, even if they should be inferrable due to already being declared in the parent; the best link I have on that is #2000 (comment).

@darky
Copy link
Author

darky commented Jul 29, 2017

Yeah, if it resolve problem, would be cool!

@mhegazy mhegazy changed the title JSDoc: support @type tag on class JSDoc: support @implements tag on class Aug 23, 2017
@mhegazy mhegazy added Suggestion An idea for TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Salsa labels Aug 23, 2017
@que-etc
Copy link

que-etc commented Jun 22, 2018

The Lighthouse team uses a neat workaround to assert implementation of an interface.

Here is the gist:

// @file: interface.d.ts
export interface MyInterface {
    foo(): string
}

// @file: implementation.js

/** @typedef {import('./interface').MyInterface} MyInterface */

export class MyClass {
    constructor() {
        /**
         * Assert that MyClass correctly implements MyInterface.
         * @type {MyInterface}
         */
        const instance = this;
    }

    /**
     * @returns {number}
     */
    foo() {
        return 42;
    }
}

@RyanCavanaugh RyanCavanaugh added the Committed The team has roadmapped this issue label Aug 15, 2018
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.2 milestone Aug 15, 2018
@weswigham weswigham added Domain: JavaScript The issue relates to JavaScript specifically and removed Domain: JavaScript The issue relates to JavaScript specifically Salsa labels Nov 29, 2018
@sandersn
Copy link
Member

Duplicate of #30156, which has a real code example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Committed The team has roadmapped this issue Domain: JavaScript The issue relates to JavaScript specifically Domain: JSDoc Relates to JSDoc parsing and type generation Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

7 participants