打字稿和 Angular。施法范围类型?

Typescript and Angular. Casting Scope Type?

在一个指令中,我有一些用于扩展范围的自定义逻辑。为此,我在接收范围之外创建了一个子范围。

$scope = scope.new(false);

但是在打字稿中,这会导致问题。我有一个名为 ITableScope 的指令范围接口,它扩展了 ng.IScope。它抱怨 ng.IScope 不是 ITableScope.

的可分配类型
interface ITableScope extends ng.IScope {}
var $scope: ITableScope;
$scope = scope.$new(false);

所以我想也许我可以施法 scope.$new 但它似乎不知道我要做什么。

interface ITableScope extends ng.IScope {}
var $scope: ITableScope;
$scope = (ITableScope) scope.$new(false);

我做错了什么?

我喜欢自己回答问题。

我做错了。你用尖括号投射。

$scope = <ITableScope> scope.$new(false);

另外,感谢@musically_ut。我在写 post 几秒钟后发现了它,但您的回复非常快!