[英]Import pattern for in Typescript with AngularJS?
This may be Typescript 101 but can't seem to get a clear answer for this. 这可能是Typescript 101,但似乎无法获得明确的答案。
I am new to Typescript and have come across some existing code (its AngularJS) that follows this format 我是Typescript的新手,遇到了一些遵循此格式的现有代码(其AngularJS)
module App.Login {
import IStateService = angular.ui.IStateService;
export class LoginController {
private _state: IStateService;
constructor($state: angular.ui.IStateService, ...) {
this._state = $state;
}
}
}
Through reading around and some experimentation I discovered this can be rewritten in a far leaner manner as the following: 通过阅读和一些实验,我发现可以用以下更为精简的方式重写它:
module App.Login {
export class LoginController {
constructor(private $state: angular.ui.IStateService, ...) {
}
}
}
My questions are: 我的问题是:
import
just to alias the interface import
来别名接口 $state
I have to use this.$state
. $state
,必须使用this.$state
。 Coming from Angular v1 this feels odd, I presume this is ok though? angular.ui.IStateService
is right on the edge of annoyingly long. angular.ui.IStateService
就在令人讨厌的长边上。 They author probably just wanted a more convenient version. public
/ protected
/ private
) on constructor parameters syntax is pretty unique to typescript so folks aren't used to it / don't like it. public
/ protected
/ private
)对于打字稿而言非常独特,因此人们不习惯/不喜欢它。 type
keyword instead. type
关键字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.