microsoft / microsoft/TypeScript

Intersection type of abstract classes does not throw error if same member exists in multiple abstract classes

Aperta
#26,617 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: Intersection Help Wanted
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

TypeScript Version: 3.0.1

Search Terms: "Intersection", "abstract"

Code

export type Constructor<T = {}> = new (...args: any[]) => T;

abstract class Outer1 {
  abstract same: number;
  abstract notSame: string;
}

abstract class Outer2 {
  abstract same: number;
}

function Mixin1<TBase extends Constructor>(Base: TBase) {
  abstract class Inner1 extends Base {   // Same as Outer1
    abstract same: number;
  }
  return Inner1;
}

function Mixin2<TBase extends Constructor>(Base: TBase) {
  abstract class Inner2 extends Base {   // Same as Outer2
    abstract same: number;
  }
  return Inner2;
}

function rollUp<T>(mixins): new (...args) => T {
  return mixins.reduce((acc, mixin) => mixin(acc), class Seed {});
}

class Example extends rollUp<Outer1 & Outer2>([Mixin1, Mixin2]) {
  // Compiler will throw error when "notSame" is unimplemented
  // Compiler DOES NOT throw error about non-implemented "same" member
}

Expected behavior:
Compiler should say that same is not implemented in regular class

Actual behavior:
Compiler does not throw error saying that same is not present in example class, despite throwing an error about notSame. It will throw an error, however, if the types of same are incompatible.

Playground Link: https://www.typescriptlang.org/play/#src=export%20type%20Constructor%3CT%20%3D%20%7B%7D%3E%20%3D%20new%20(...args%3A%20any%5B%5D)%20%3D%3E%20T%3B%0D%0A%0D%0Aabstract%20class%20Outer1%20%7B%0D%0A%20%20abstract%20same%3A%20number%3B%0D%0A%20%20abstract%20notSame%3A%20string%3B%0D%0A%7D%0D%0A%0D%0Aabstract%20class%20Outer2%20%7B%0D%0A%20%20abstract%20same%3A%20number%3B%0D%0A%7D%0D%0A%0D%0Afunction%20Mixin1%3CTBase%20extends%20Constructor%3E(Base%3A%20TBase)%20%7B%0D%0A%20%20abstract%20class%20Inner1%20extends%20Base%20%7B%20%20%20%2F%2F%20Same%20as%20Outer1%0D%0A%20%20%20%20abstract%20same%3A%20number%3B%0D%0A%20%20%7D%0D%0A%20%20return%20Inner1%3B%0D%0A%7D%0D%0A%0D%0Afunction%20Mixin2%3CTBase%20extends%20Constructor%3E(Base%3A%20TBase)%20%7B%0D%0A%20%20abstract%20class%20Inner2%20extends%20Base%20%7B%20%20%20%2F%2F%20Same%20as%20Outer2%0D%0A%20%20%20%20abstract%20same%3A%20number%3B%0D%0A%20%20%7D%0D%0A%20%20return%20Inner2%3B%0D%0A%7D%0D%0A%0D%0Afunction%20rollUp%3CT%3E(mixins)%3A%20new%20(...args)%20%3D%3E%20T%20%7B%0D%0A%20%20return%20mixins.reduce((acc%2C%20mixin)%20%3D%3E%20mixin(acc)%2C%20class%20Seed%20%7B%7D)%3B%0D%0A%7D%0D%0A%0D%0Aclass%20Example%20extends%20rollUp%3COuter1%20%26%20Outer2%3E(%5BMixin1%2C%20Mixin2%5D)%20%7B%0D%0A%20%20%2F%2F%20Compiler%20will%20throw%20error%20when%20%22notSame%22%20is%20unimplemented%0D%0A%20%20%2F%2F%20Compiler%20DOES%20NOT%20throw%20error%20about%20non-implemented%20%22same%22%20member%0D%0A%7D

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Inizia eseguendo la riproduzione collegata di TypeScript Playground e confronta le diagnosi per same e notSame nella classe Example. Traccia la gestione da parte del compilatore dei membri astratti prodotti dall'intersezione e dai mixin; il lavoro è completato quando viene segnalato il membro same mancante e la diagnosi esistente di notSame rimane corretta.

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

Valutazione

Stack tecnologico
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
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.