2016-07-20 7 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として記録されています。執筆時点では、解決されていません。