question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSDoc @implements tag/clause not checked

See original GitHub issue
// @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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:23
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Parilcommented, 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?

0reactions
dtinthcommented, Oct 27, 2021

Workaround, based on this comment.

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

github_iconTop Results From Across the Web

Use JSDoc: @implements
The @implements tag indicates that a symbol implements an interface. Add the @implements tag to the top-level symbol that implements the interface (for...
Read more >
JSDoc Reference - TypeScript: Documentation
The list below outlines which constructs are currently supported when using JSDoc annotations to provide type information in JavaScript files.
Read more >
Error TS8022 JSDoc '@extends' is not attached to a class ...
Project: MyProject;; File: JavaScript Content Files;; Line: 1; Suppression State: Active. enter image description here · javascript ...
Read more >
Documenting Your JavaScript | JSDoc Crash Course - YouTube
In this video I will go over JSDoc for documenting your JavaScript code as well as using it for type checking In this...
Read more >
JSDoc typings: all the benefits of TypeScript, with none of the ...
Not at all. It's trying to formalize JavaScript's informal way of implementing APIs and package interfaces. And since most JavaScript ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found