2016-12-20 4 views
0

클래스의 오브젝트는 set 일 수 있습니까? 해결 I get 내가 가진 지금오브젝트가있는 ECMAScript 2015/TypeScript 2 설정자

interface IAddress { 
    streetAddress: string; 
    postCode: string; 
    city: string; 
} 

class C { 
    private _data = <any> {}; 

    public get postAddress(): IAddress { 
     return this._data.postAddress; 
    } 

    /* 
    public set postAddress() { 

    } 
    */ 
} 

let a = new C(); 

:

let address = a.postAddress; 

/* 
{ 
    streetAddress: ""; 
    postCode: ""; 
    city: ""; 
} 
*/ 

가 그럼 난 세터를 통해 몇 가지 속성을 설정하려면 (내가 수 없습니다 모르겠어요 방법) :

a.postAddress.city = 'NEW YORK'; 

a.postAddress이 먼저 객체를 가져오고 C 클래스 'setter가 호출되지 않습니다. 이것을 달성하는 방법?

답변

0

당신은 postAddress 게터가 IAddress 인터페이스를 구현하고 streetAddress, postCodecity에 대한 setter를 가진 개체를 반환 할 필요가있다.