-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
It would be great if there was a way to relax the current constraint of requiring get/set accessors to have the same type. this would be helpful in a situation like this:
class MyClass {
private _myDate: moment.Moment;
get myDate(): moment.Moment {
return this._myDate;
}
set myDate(value: Date | moment.Moment) {
this._myDate = moment(value);
}
}
Currently, this does not seems to be possible, and I have to resort to something like this:
class MyClass {
private _myDate: moment.Moment;
get myDate(): moment.Moment {
return this._myDate;
}
set myDate(value: moment.Moment) {
assert.fail('Setter for myDate is not available. Please use: setMyDate() instead');
}
setMyDate(value: Date | moment.Moment) {
this._myDate = moment(value);
}
}
This is far from ideal, and the code would be much cleaner if different types would be allowed.
Thanks!
thorn0, thw0rted, dhasilva, disjukr, Arrow7000 and 201 moreoxygenxaviergonz, klemenoslaj, SephReed, patricio-ezequiel-hondagneu-roig, jpidelatorre and 15 moreb3h3m0thklemenoslaj and brainkim
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript