microsoft / microsoft/TypeScript

Support `@extends` tag for ES5-style classes

Open
#36,369 5 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.7.5 and 3.8.0-dev.20200123

Search Terms: extends not attached to a class

I'm currently evaluating if TypeScript can be used to type-check old closure compiler projects which use JSDoc annotations for typing and to generate *.d.ts files for it so the old projects can be easily used within new typescript projects. But unfortunately the @extends annotation is not working as expected. I would understand if TypeScript simply didn't support it (Then this would be a feature request) but the error message error TS8022: JSDoc '@extends' is not attached to a class thrown by the compiler suggests that there is some support for but it doesn't work as expected.

Please note that the real class inheritance code which actually extends class Sub from Base is omitted in the code example below because it is irrelevant to the compiler.

Code

// Compile with: tsc --checkJS --allowJS --outDir out test.js

/**
 * @constructor
 * @class
 */
function Base() {}

Base.prototype.foo = function() {}

/**
 * @constructor
 * @class
 * @extends {Base}
 */
function Sub() {}

Sub.prototype.bar = function() {}

Expected behavior:

Typescript should recognize type Sub to be a class which extends class Base.

Actual behavior:

Compilation fails with this error:

$ tsc --checkJS --allowJS --outDir out test.js
test.js:14:10 - error TS8022: JSDoc '@extends' is not attached to a class.

14 function Sub() {}
            ~~~


Found 1 error.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported tsc --checkJS --allowJS command against test.js and trace the compiler's handling of JSDoc @extends on the ES5-style constructor. Done means the example compiles without TS8022 and TypeScript recognizes Sub as extending Base, with coverage for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.