Reputation: 2053
Just a simple question I was thinking about, is it possible to include method or function in an interface as following:
Waiting for your comments and ideas about possibilities or issues doing this:
export interface INewsletter {
id: number;
title: string;
release_date: any;
filename: string;
original_filename: string;
notification: boolean;
file: File;
newsletterTranslations: any;
translations: any;
newsletterFiles: any;
newsletter_files: any;
myMethod() { something to do } // My method here
}
Upvotes: 0
Views: 289
Reputation: 62213
An interface is a contract. You can specify the interface has a method but you can't include an implementation. So adding myMethod() : void;
is valid but not myMethod() { something to do }
as this includes a implementation/body.
export interface INewsletter {
id: number;
title: string;
release_date: any;
filename: string;
original_filename: string;
notification: boolean;
file: File;
newsletterTranslations: any;
translations: any;
newsletterFiles: any;
newsletter_files: any;
myMethod():void; // replace void with any other return type or any
}
Upvotes: 2