2016-07-20 3 views
1

다음 코드로 취급 유효 타이프 라이터타이프 값 선언 <any>

interface AllMembersOptional { 
    first?: string; 
    second?: number; 
} 

let a: AllMembersOptional = 7; 
let b: AllMembersOptional =() => 7; 

과 각도의 IComponentOptions 인터페이스는 다음 다음

interface IComponentOptions { 
    controller?: string | Function | (string | Function)[] | IComponentController; 
    controllerAs?: string; 
    template?: string | Function | (string | Function)[]; 
    templateUrl?: string | Function | (string | Function)[]; 
    bindings?: {[binding: string]: string}; 
    transclude?: boolean | string | {[slot: string]: string}; 
    require?: {[controller: string]: string}; 
} 

로 정의되어 있기 때문에 유효 타이프 라이터입니다 또한 :

angular.module('test').component('custom', function() { 
    return { 
     controller: 'testCtrl', 
     template: '<div></div>, 
     //... 
    }; 
}); 

angular.module('test').component('custom', 7); 

angular.module('test').component('custom', "hello"); 

angular.module('test').component('custom', new Date()); 

이 코드는 런타임에 실제로 작동하지 않지만 TypeScript는 오류없이 컴파일되고 의도 된대로 작동합니다.

위의 예제에서 TypeScript 컴파일러가 '불량/호환되지 않는 형식'오류를 생성해야합니까? 빈 인터페이스를 허용하지 않아야합니까 (예 : 컴파일러 스위치를 통해)? 아니면 아무 것도하지 않고 그냥 받아들입니다. 어떻게 작동할까요?

답변

1

이것은 이미 issue 7485으로 기록되었습니다. 글을 쓰는 시점에서 해결되지 않았습니다.