microsoft / microsoft/TypeScript
Separate type application from function application
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
As discussed in #28931, currently the type application for the function with generic parameters is tied to that function application.
Specialize the value of the function with generics is only possible during the call. So the following compiles fine:
function id<V> (v : V) { return v }
const some : Date = id<Date>(new Date())
But this does not:
function id<V> (v : V) { return v }
type IdDate = typeof id<Date> // TS1005: ';' expected
const dateId = id<Date> // TS1109: Expression expected.
It would be very beneficial to separate type application from function application. For example (the original reason of this request), it will allow mixins with generic parameters:
export type Constructable<T extends any> = new (...args : any[]) => T
export type AnyFunction = (...input: any[]) => any
export type Mixin<T extends AnyFunction> = InstanceType<ReturnType<T>>
export const Atom = <V, T extends Constructable<Object>>(base : T) =>
class Atom extends base {
value : V
hasValue () : boolean {
return this.hasOwnProperty('value')
}
}
export type Atom = Mixin<typeof Atom> // this currently works, but does not have generic argument
export type Atom<V> = Mixin<typeof Atom<V>> // this is the goal
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
Lies zuerst die Diskussion in Issue #28931 und verwende dann die Beispiele hier, um die beabsichtigte Syntax und ihre Wechselwirkung mit generischen Funktionen, Typabfragen und Mixins zu ermitteln. Als abgeschlossen gilt die Aufgabe, wenn die vorgeschlagene Typanwendung unabhängig von einem Funktionsaufruf verwendet werden kann und die gezeigten Beispiele wie vorgesehen kompiliert werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100