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 @implements tag/clause not checked #30156

Open
DanielRosenwasser opened this issue Feb 28, 2019 · 8 comments
Open

JSDoc @implements tag/clause not checked #30156

DanielRosenwasser opened this issue Feb 28, 2019 · 8 comments
Labels
Bug A bug in TypeScript Domain: JavaScript The issue relates to JavaScript specifically Domain: JSDoc Relates to JSDoc parsing and type generation
Milestone

Comments

@DanielRosenwasser
Copy link
Member

// @ts-check

/**
 * @typedef Foo
 * @property foo {() => string}
 */

/**
 * @implements {Foo}
 */
class C1 {
    foo = () => {
        return 10;
    }
}

/**
 * @implements {Foo}
 */
class C2 {
    foo() {
        return 10;
    }
}

Expected: At least an error on C1
Actual: Neither of these error

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Domain: JavaScript The issue relates to JavaScript specifically labels Feb 28, 2019
@DanielRosenwasser DanielRosenwasser changed the title JSDoc @implements clause not checked JSDoc @implements tag/clause not checked Feb 28, 2019
@brendankenny
Copy link
Contributor

also see #17498, though it doesn't have the clearest initial comment describing the problem :)

@TimvdLippe
Copy link
Contributor

FYI this does work with an @interface now, since #35629 has been implemented.

@Paril
Copy link

Paril commented Jun 17, 2021

I attempted this with a TS interface but was unable to get it working. ie:

interface Test
{
func(n: number): void
}
/** @implements {Test} */
class MyTest
{
func(n) // `n` is implicit any
{
}
}

EDIT: okay, so it technically does work (in that MyTest can be passed to things expecting a Test, and as long as you don't re-declare it you will see the inherited type), but "func" doesn't auto-inherit the documentation or type annotations. I think that's a different issue though? maybe?

@kevinfiol
Copy link

I attempted this with a TS interface but was unable to get it working. ie:

interface Test
{
func(n: number): void
}
/** @implements {Test} */
class MyTest
{
func(n) // `n` is implicit any
{
}
}

EDIT: okay, so it technically does work (in that MyTest can be passed to things expecting a Test, and as long as you don't re-declare it you will see the inherited type), but "func" doesn't auto-inherit the documentation or type annotations. I think that's a different issue though? maybe?

Piggybacking on this. I thought I would get my answer in this thread, but also having this issue. Tried @implements and @interface but no dice. The best workaround I found was this comment where you set the type of the this reference to the interface, but this is a very imperfect solution if you're looking to get good IDE integration since the class methods don't pick up their types from the interface.

@dtinth
Copy link
Contributor

dtinth commented Oct 27, 2021

Workaround, based on this comment.

class MyStoreImpl {
  constructor() {
    // Verify that the class implements the interface.
    void (/** @type {import('./types').MyStore} */ (this));
  }
}

@pupa91
Copy link

pupa91 commented Mar 1, 2023

解决方法,基于此注释

class MyStoreImpl {
  constructor() {
    // Verify that the class implements the interface.
    void (/** @type {import('./types').MyStore} */ (this));
  }
}

Hello, have you solved this problem

class BannerPlugin  {
    constructor(){
    // Verify that the class implements the interface.
    void (/** @type {import('webpack').LoaderOptionsPlugin} */ (this));
    }
}

vscode IntelliSense not working

@MSFTKonnor
Copy link

+1. Still hitting this problem in TypeScript 4.9.2 as well as TypeScript 5.0.

@david-sanford-deel
Copy link

+1.

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: JavaScript The issue relates to JavaScript specifically Domain: JSDoc Relates to JSDoc parsing and type generation
Projects
None yet
Development

No branches or pull requests

10 participants