microsoft / microsoft/TypeScript
TS Spec doesn't match implementation re method signature definitions
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
TS Spec § 3.9.5 says:
A method signature of the form
f < T1, T2, ... > ( p1, p2, ... ) : Ris equivalent to the property declaration
f : { < T1, T2, ... > ( p1, p2, ... ) : R }
But this is not the case with --strictFunctionTypes:
interface IFoo1 {
bar(baz?: number): void
}
class Foo1 implements IFoo1 {
bar: (baz: number) => void = (n) => void 0;
}
interface IFoo2 {
bar: { (baz?: number): void }
}
class Foo2 implements IFoo2 {
bar: (baz: number) => void = (n) => void 0; // err: Property 'bar' in type 'Foo2' is not assignable to the same property in base type 'IFoo2'.
}
I understand that the method bivarience in general is intentional as per the PR:
With this PR we introduce a --strictFunctionTypes mode in which function type parameter positions are checked contravariantly instead of bivariantly. The stricter checking applies to all function types, except those originating in method or construcor declarations
But it would be nice if the spec didn't state the syntaxes were equivalent when they aren't.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Öffne doc/spec.md bei §3.9.5 und vergleiche dessen Äquivalenzbehauptung mit der in PR 18654 beschriebenen Ausnahme für strictFunctionTypes. Aktualisiere die Spezifikation so, dass der Unterschied zwischen Methodendeklarationen und Eigenschaften mit Funktionswerten korrekt dokumentiert ist, und überprüfe anschließend die Beispiele im Issue, um zu bestätigen, dass die Formulierung ihrem Verhalten entspricht.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers, documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 58/100