microsoft / microsoft/TypeScript
Add typed return for Object.defineProperties
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
Search Terms
Object.defineProperties typed
Suggestion
const newObject = Object.defineProperties(o, map);
Use Cases
Creating extensions of certain properties while still being able to type-check them
Examples
/** @type {NodeList} */
const nodeListObject = Object.defineProperties(/** @type {Node[]} */ ([]), {
item: {
enumerable: false,
/** @param {number} [index] */
value: function item(index) { return this[index]; },
},
});
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
The current type I'm using is the following:
interface ObjectConstructor {
defineProperties<T1, T2 = PropertyDescriptorMap>(o: T1, properties: T2 & ThisType<T1>): T1 & {
[K in keyof T2]: (
T2[K]['get'] extends Function ? ReturnType<T2[K]['get']> :
T2[K]['set'] extends Function ? Parameters<T2[K]['set']>[0] :
T2[K]['value'] extends undefined ? any : T2[K]['value']
)
};
}
It seems alright but I would love to get some feedback. Currently, I'm targeting against .get() first, then .set(arg0) and finally .value.
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
Beginne mit dem Einstiegspunkt Object.defineProperties und der vorgeschlagenen ObjectConstructor-Signatur. Prüfe, wie die get-, set- und value-Fälle anhand der Checkliste für Kompatibilität und Designziele ein typisiertes Ergebnis liefern sollten; abgeschlossen ist die Aufgabe, wenn die angeforderte Rückgabetypisierung ohne Laufzeitänderungen unterstützt wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100