Create object with part of interface. Typescript -


i have problem, please help.

we have 2 interfaces:

interface iuserentity {     id: number;     firstname: string;     lastname: string; }  interface iuserentitymethods {     getfullname(): string; } 

i create object have type iuserentitymethods, within method getfullname through this in webstorm (for example) dropped autocomplete ability use properties of interface iuserentity.

what want in end:

var userentitymethods: iuserentitymethods = {     getfullname: function() {         return this.firstname + " " + this.lastname; // have no errors @ line.     } } 

is possible? or there other option?

i'm not sure why divided methods properties 2 interfaces, need have 1 extend other, so:

interface iuserentity {     id: number;     firstname: string;     lastname: string; }  interface iuserentitymethods extends iuserentity {     getfullname(): string; } 

then instances of iuserentitymethods should have methods , properties.
you'll need have them in concrete instance:

var userentitymethods: iuserentitymethods = {     id: a_number,     firstname: a_string,     lastname: a_string,     getfullname: function() {         return this.firstname + " " + this.lastname;     } } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -