microsoft / microsoft/TypeScript
Runtime parameter info (name, optional, default)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
TypeScript Version:
1.8.9
Code
I'm trying to leverage decorators to create runtime contracts to check against incoming parameters.
Below is the ts code
class Foo {
@contract
test (a : integer, b : string) : boolean {
return true
}
@contract
testOptional (a : integer, b? : string) : boolean {
return true
}
@contract
testDefault (a : integer, b : string = 'hello') : boolean {
return true
}
}
The above generated the following Javascript.
var Foo = (function () {
function Foo() {
}
Foo.prototype.test = function (a, b) {
return true;
};
Foo.prototype.testOptional = function (a, b) {
return true;
};
Foo.prototype.testDefault = function (a, b) {
if (b === void 0) { b = 'hello'; }
return true;
};
__decorate([
contract,
__metadata('design:type', Function),
__metadata('design:paramtypes', [integer, String]),
__metadata('design:returntype', Boolean)
], Foo.prototype, "test", null);
__decorate([
contract,
__metadata('design:type', Function),
__metadata('design:paramtypes', [integer, String]), // same as above
__metadata('design:returntype', Boolean)
], Foo.prototype, "testOptional", null);
__decorate([
contract,
__metadata('design:type', Function),
__metadata('design:paramtypes', [integer, String]), // same as above
__metadata('design:returntype', Boolean)
], Foo.prototype, "testDefault", null);
return Foo;
}());
Note that the three different ts functions generated the exact sets of __metadata calls. The design:paramtypes alone cannot distinguish whether a particular parameter is optional or has default values, and thus insufficient for building a runtime contract.
It would be great for TypeScript to support a full parameter info so decorators can be made more capable.
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 der im generierten JavaScript gezeigten Emission der Decorator-Metadaten, insbesondere den Aufrufen design:paramtypes und __metadata. Vergleiche die für test, testOptional und testDefault erzeugten Metadaten. Die Arbeit ist abgeschlossen, wenn Runtime-Decoratoren Parameternamen, optionale Parameter und Standardwerte unterscheiden können und das relevante Verhalten durch Tests abgedeckt ist.
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