microsoft / microsoft/TypeScript
Checking JS types does not accept @implements or @augments on constructor functions
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.9.5 (also tested on 3.9.3 initially)
Search Terms: @implements, jsdoc
Code
/**
* @param {string} name
* @implements {EventTarget}
* @constructor
*/
function Foo (name) {
this.name = name
}
/**
* @param {string} type
* @param {EventListenerOrEventListenerObject} listener
* @param {boolean | AddEventListenerOptions} [options]
*/
Foo.prototype.addEventListener = function (type, listener, options) {}
Then run tsc --noEmit --checkJS --allowJS reproducer.js
Expected behavior:
According to https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#constructor-functions-are-equivalent-to-classes, constructor functions are treated like classes. So using @implements or @augments on them should be possible. It used to work in the past.
Actual behavior:
reproducer.js:6:10 - error TS8022: JSDoc '@implements' is not attached to a class.
6 function Foo (name) {
~~~
Found 1 error.
Playground Link: I was not able to reproduce this in the playground (but it does not have the latest 3.9 versions available)
Related Issues:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer.js example and run tsc --noEmit --checkJS --allowJS reproducer.js using the affected TypeScript version. Trace the handling of JSDoc @implements and @augments on constructor functions; done means the annotations are accepted without TS8022 and the existing JavaScript checks remain valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100