Reputation: 2284
I just starting with TypeScript. I using TypeScript for my new AngularJS project. I run into the problem that id from type number is actually a type of string. Did I miss a case?
interface IRouteParams extends ng.route.IRouteParamsService {
id: number;
}
class FooController {
constructor(private $routerParams: IRouteParams, private fooService: IFooService) {
fooService.getById($routerParams.id);
}
}
export interface IFooService {
getById(id: number): ng.IPromise<number>;
}
class FooService implements IFooService {
getById(id: number): angular.IPromise<number> {
const defer = this.$q.defer<IRace>();
if (id === -1) {
// not working
}
return defer.promise;
}
}
Upvotes: 0
Views: 121
Reputation: 221192
Route parameters are always strings (because they come from the URL). Writing id: number
in TypeScript doesn't change that. You should write id: string
when defining a route parameter.
Upvotes: 1