This may be Typescript 101 but can't seem to get a clear answer for this.
I am new to Typescript and have come across some existing code (its AngularJS) that follows this format
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 $state
I have to use 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. They author probably just wanted a more convenient version. If you mean the declaration of the private var, some folks (especially coming from a C#/Java background) would prefer to declare class parameters explicitly. The visibility modifier ( public
/ protected
/ private
) on constructor parameters syntax is pretty unique to typescript so folks aren't used to it / don't like it. type
keyword instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.