What I know
When using TypeScript with angular's ui state, I can provide "type assertion" with the UI-Router definitely typed library.
Using this, I can inject $state
and have code similar to the following
function myCtrl($state: ng.ui.IStateService){
// Some code
}
This gives me correct autocompletion/error reporting for $state
's methods.
So far, this is all fine.
The problem
When I try to access a property of params
like the following
function myCtrl($state: ng.ui.IStateService){
// Trying to access a property of $state.params
var example = $state.params.example;
}
I get an error saying:
Property 'example' does not exist on IStateParamsService
because quite rightly, TypeScript doesn't know about this property.
I considered trying:
Defining my own Interface that extends ng.ui.IStateService
interface IMyState extends ng.ui.IStateService{
params: {
example: string;
};
}
Then set the type to my interface
function myCtrl($state: IMyState){
var example = $state.params.example;
}
This gets rid of the error.
What is the correct type to use for $state
?
Should I be defining my own interface like in my example?