microsoft / microsoft/TypeScript
Cryptic error message without --noImplicitAny
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 4.1.0-dev.20201015
Search Terms: noImplicitAny
In the JS mode given the class inheritance hierarchy A -> B -> C, when B code refers to class declaration (e.g. in a clone() method) and the class is assigned to an object property (NS.B = class ...), an attempt to convert an instance of C to B returns a cryptic error message: Property <property name> is missing in type 'C' but required in type 'B'.
Expected behavior: This diagnostic isn't helping, maybe omit it?
Related Issues:
Code
class A {
clone() {
return new A();
}
}
var NS = {};
NS.B = class extends A {
constructor(v) {
super();
this.val = v;
}
//** @returns {NS.B} */ // this jsdoc comment fixes the error
clone() {
return new NS.B(this.val);
}
}
class C extends NS.B {
constructor() {
super(1);
}
clone() {
return new C();
}
}
/** @returns {NS.B} */
function f() {
return new C(); // error here: Property 'val' is missing in type 'C' but required in type 'B'.
}
Compiler Options
{
"compilerOptions": {
"alwaysStrict": true,
"esModuleInterop": true,
"checkJs": true,
"allowJs": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "Latest",
"jsx": "React",
"module": "ESNext"
}
}
Playground Link: Provided
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
Reproduce the example from the issue or its TypeScript Playground link with checkJs and the shown JavaScript class hierarchy. Start by tracing the type-checking path for the return in f() and the inferred type of NS.B. Done means the diagnostic is removed or made useful without requiring the JSDoc workaround, with the behavior covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100