I have a service that returns an object with dates:
@Injectable() export class DateService { constructor() { } getNowDate(): Object { let d = new Date(); d.setHours(d.getHours() + 3); let dateHuman = d.toISOString(); let unixTimeStamp = Math.floor(d.getTime() / 1000) - (60 * 60 * 3); return { dateHuman: dateHuman, unixTimeStamp: unixTimeStamp }; }; } I use it in a component like this:
import { DateService } from '../services/date.service'; @Component({ selector: 'app-question', templateUrl: './question.component.html', styleUrls: ['./question.component.scss'] }) export class QuestionComponent implements OnInit { constructor(private dateService: DateService) { } ngOnInit() { console.log(this.dateService.getNowDate()['dateHuman']); } } Everything is OK - the date is displayed. But if I try to display the date like this:
ngOnInit() { console.log(this.dateService.getNowDate().dateHuman); } Then I get the following error:
Property 'dateHuman' does not exist on type 'Object'.
Explain, please, what is the reason for this phenomenon, why in this case the access to the property through a point and through a bracket are not equivalent?