2017-04-18 4 views
0

에 대한 일반 개체로지도를 켜기 나는이 있습니다TS 선언

let cachedPromises: Map<string, Promise<any>> = new Map(); 

일반 객체에 해당하는 선언이 무엇입니까? 이 같은

뭔가 :

interface IMyMap { 
    [key: string]: Promise<any> 
} 

let cachedPromises: IMyMap = {}; 

는 것으로 충분하다?

+2

네를 보인다 충분한. – toskv

답변

1

이 충분하지만 점에서 양날의 칼이 당신이 약속 반환하지 않는 모든 속성이 클래스의 인터페이스를 구현할 수 없습니다로 올 않습니다

class Person implements IMyMap { 
    [key: string]: Promise<any> 
    constructor(private firstName) { // Error: Property 'firstName' of type 'string' is not assignable to string index type 'Promise<any>'. 
    } 
}