microsoft / microsoft/TypeScript
Abstract property specified on multiple classes loses modifier after intersection
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 Search Terms
abstract property class intersection InstanceType typeof mixin trait
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
abstract class A {
abstract a(): number
}
abstract class A2 {
abstract a(): number
}
abstract class B {
abstract b(): number
}
declare const Base: abstract new () => A & B
// correctly has type error requiring the implementation of 'a' and 'b'
class Foo extends Base {}
declare const FalsePositiveBase: abstract new () => A & A2
// this sould be an error
// if an abstract property appears on multiple classes, it is not treated as abstract
class Bar extends FalsePositiveBase {}
Seems like there must be some flag that associates the abstractness of the original class instance when it is used as a class instance like that, but there is a logic error that checks if the prop exists on other intersection members and erases the modifier, even if all of them are also abstract.
I previously thought this was a workaround:
// can workaround this as follows:
declare const WorkaroundBase: abstract new () => InstanceType<typeof A & typeof A2>
// now gives the correct error that 'a' is missing
class Baz extends WorkaroundBase {}
But realized that it is just treating the constructor as an overload and only using one of the instance types.
🙁 Actual behavior
Behavior for multiple props of the same name was inconsistent with behavior for props with differing names
🙂 Expected behavior
Intersecting multiple props of the same name that all of the abstract modifier should preserve it
Additional information about the issue
No response
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
Inizia con il TypeScript Playground collegato e riproduci la differenza tra Foo e Bar usando intersezioni di classi astratte. Traccia il modo in cui il type checker gestisce il membro astratto condiviso durante l’estensione della classe, quindi verifica che l’errore previsto per Bar venga mantenuto senza affidarti alla soluzione alternativa.
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