0

I am stuck with an inheritance issue writing my first angular 5 application. I am getting the error: Property 'message' does not exist on type 'CouponEvent'. from the angular-cli

export class Event {
public _eventId: number;
public _type: string;
public _name: string;
public _sendDate: Date;
public _message: string;

constructor(){}

public get message(): string {
 return this._message;
}

public get type(): string {
 return this._type;
}

public get name(): string {
 return this._name;
}

public get sendDate(): Date {
 return this._sendDate;
}

public get eventId():number {
 return this._eventId;
}
}

import './Event';
export class CouponEvent extends Event {
 _expirationDate: Date;

get expirationDate(): Date {
 return this._expirationDate;
}
}

In my util class I am try to format the message and event.message is not found.

import { Injectable } from '@angular/core';
import {Event} from '../models/Event';
import {CouponEvent} from '../models/CouponEvent';

@Injectable()
export class UtilService {

formatMessage(event: CouponEvent): string {
  let msg = event.message.replace(/\${code}/gi,event.code);

  const date = event.expirationDate.toString
   msg = event.message.replace(/\${expiration}/gi,date);

  return msg;
 }
}

Any help would be greatly appreciated. This being my first time working with type script I am sort of lost why this not working.

Thank you for you're suggestions!!

2 Answers 2

3

I guess that's because Event is a Typescript-native type, there can be some naming collision. Try to rename your class and / or import { Event } from './Event';

Sign up to request clarification or add additional context in comments.

Comments

0

I finally figured out that I needed to put the classes into the same file. I had each class in its own event file. After putting the class declarations in one then it worked.

2 Comments

You didn't need to. The problem was in import statement. Have you seen my answer?
@DanielKucal yes. Thank you for your suggestion I really appreciate it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.