microsoft / microsoft/TypeScript
Inference for Object.isPrototypeOf()
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
Hi, I am wondering would be possible to infer types for isPrototypeOf() function same way as it's done with instanceof operator? So we could narrow type of argument if it's been created using Object.create(proto) function and its type would be something like typeof proto if check is fulfilled.
Search Terms
isPrototypeOf
Examples
if (object instanceof HTMLAnchorElement) {
console.log(object.href);
}
if (HTMLAnchorElement.prototype.isPrototypeOf(object)) {
console.log(object.href);
}
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.
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
In der Issue ist keine Implementierungsdatei, kein Test und kein Einstiegspunkt angegeben. Beginne damit, die bestehende Typverengung für instanceof zu finden, und prüfe dann, wie die Object.isPrototypeOf()-Beispiele Objekte verengen sollten, die mit Object.create(proto) erstellt wurden; abgeschlossen ist die Aufgabe, wenn das vorgeschlagene Verhalten spezifiziert und durch geeignete Compiler-Tests abgedeckt ist.
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