microsoft / microsoft/TypeScript
Convert to class declaration quick fix misses superclass
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.4.3
Search Terms:
- class declaration quick fix
- 80002
Code
This code is a mix of ES2015- and function-style classes:
class A {
constructor() {
this.a = 'a';
}
doAThing() {
console.log(this.a);
}
}
/**
* @constructor
* @extends {A}
*/
function B() {
this.b = 'b';
}
B.prototype = new A();
B.prototype.doBThing = function() {
console.log('b: ', b);
};
The TS language services offer a quickfix to convert B into an ES2015 class. Great!
Expected behavior:
I'd hope that one of (or both of) the @extends and B.prototype = new A(); would result in B extends A:
class B extends A {
constructor() {
super();
this.b = 'b';
}
doBThing() {
console.log('b: ', b);
}
}
Actual behavior:
The quick fix produces this code:
/**
* @constructor
* @extends {A}
*/
class B {
constructor() {
this.b = 'b';
}
doBThing() {
console.log('b: ', b);
}
}
B.prototype = new A();
TypeScript flags an error on the last line:
(property) B.prototype: B
Type 'A' is missing the following properties from type 'B': b, doBThingts(2739)
Playground Link: no quickfixes on the playground, alas!
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 TypeScript language service quick fix that converts a function-style class into an ES2015 class, using the supplied example as the reproduction. Check how the @extends annotation and B.prototype = new A() are handled, then verify that the converted class preserves the superclass relationship and no longer produces the reported type error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100