Abstract methods block coverage and direct calls when no subclass exists

Aperta
#3,077 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@alantriesagain ci sta già lavorando.

Dal 6/11/2026.

  • #3082 di @alantriesagain — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
typescript
Ambito
compilers

Direzione di ricerca

Start by reading the compiler paths that handle abstract method declarations, untyped property lookup, and direct calls; the issue gives reproductions but names no source files or tests. Compare the two examples with Node and inspect the existing SC1090 handling. Done means coverage treats abstract declarations as having no runtime value and direct calls match Node’s receiver, argument, and TypeError behavior. A linked pull request is already open.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Abstract methods block coverage and direct calls when no subclass exists

The compiler refuses or defers abstract methods in two shapes that JavaScript handles.

Untyped lookup

A value held as any whose instances reach o[k] gets a branch per class and member. For an abstract method, the branch asks for the method's value, which an abstract declaration does not have. Every such branch is deferred with SC1090 values of abstract method declarations. The program runs and matches Node, but coverage never reports it as fully static.

abstract class Holder {
  abstract current(): string;
}

class Impl extends Holder {
  current(): string {
    return "ok";
  }
}

const read = (o: any, k: string) => o[k];
const impl: Holder = new Impl();
console.log(read(impl, "current"), impl.current());

On 0.4.8, scriptc coverage of the larger form in our corpus (abstract-methods-untyped-lookup.ts) reports 6 deferred sites. The same failure reproduces on main (979a65246).

Direct call

A concrete method that calls an abstract method with no concrete implementation below the receiver's static class is refused at build time, even when the program never subclasses the class. tsc makes every instantiable subclass implement the method, so no instance can reach the call.

abstract class Source {
  abstract count(): number;

  liveFrom(): number {
    return this.count();
  }
}

class Shelf {
  source: Source | null = null;
}

const shelf = new Shelf();
console.log(shelf.source === null ? "none" : shelf.source.liveFrom());

Node prints none. On 0.4.8, the build fails with SC1090 calls of the abstract method 'count' with no concrete implementation below the receiver's static class.

An abstract declaration has no value at run time. An untyped lookup should select the implementation of the constructible subclass the instance belongs to, nearest first, and read undefined when no class below the receiver implements it. A direct call should evaluate its receiver and arguments, then throw Node's TypeError, <callee> is not a function.

I opened #TBD with a patch that implements both behaviors.

Lingua principale
TypeScript
Stelle
6.4k
Fork
204
Merge medio
9h 48m
PR unite (30g)
795

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vercel-labs/scriptc

Tutte le issue di vercel-labs/scriptc

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.