Czołem
Mam klasę, o taką, z jedną przykładową metodą — getterem
export default class Place {
type: placeVariants;
place: GeolocationORCityNameType;
fromFavorites: boolean;
forecastURL: string;
weatherURL: string;
constructor(type: placeVariants, place: GeolocationORCityNameType, fromFavorites = false) {
this.type = type;
this.place = place;
this.fromFavorites = fromFavorites;
this.forecastURL = createURL.forecast(place as Location, type);
this.weatherURL = createURL.weather(place as Location, type);
get label() {
switch (this.type) {
case placeVariants.CITY:
return this.place as string;
case placeVariants.LOCATION:
return `Lat.: ${(this.place as Location).latitude.toFixed(4)} Lon.: ${(
this.place as Location
).longitude.toFixed(4)}`;
default:
return 'non-specified value (type) passed to createLabelforHeader method';
}
}
}
Problem polega na tym, że:
Najbardziej bym się ucieszyła, gdyby można było z takiej klasy 'wyciągnąć' typ instancji bezpośrednio. Ale o ile dobrze rozumiem kilka wątków, nie można.
Chyba że jest jakiś hack? Ale jeżeli ni i jeżeli wszystko trzeba przepisać ręcznie: czy getter należy typować jako wartość zwracaną, czy jako funkcję? Pytam, bo sam w sobie getter jest swojego rodzaju hackiem i właściwie nie wiem, co ma pod pokrywką.
Tak więc jeżeli ktoś zna hacka albo odpowiedź to bym prosiła :)
type
.