microsoft / microsoft/TypeScript
Cryptic error message without --noImplicitAny
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci l’esempio dell’issue o il relativo link a TypeScript Playground con checkJs e la gerarchia di classi JavaScript mostrata. Inizia tracciando il percorso del controllo dei tipi per il valore restituito in f() e il tipo inferito di NS.B. Il lavoro è completo quando la diagnostica viene rimossa o resa utile senza richiedere il workaround JSDoc e il comportamento è coperto da un test di regressione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100