Skip to content

Commit 5e8b886

Browse files
committed
feat(ts:client): add type annotations for TypeScript
Adds type annotations to most javascript files in the project. Closes #1812
1 parent d8346f9 commit 5e8b886

22 files changed

+275
-85
lines changed

Diff for: templates/app/client/app/account(auth)/account.routes.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
2-
2+
<%_ if(filters.ts) { _%>
3+
import {IAuth} from '../../components/auth/auth.service';
4+
<%_ } _%>
35
<%_ if (filters.uirouter) { _%>
46
export default function routes($stateProvider) {
57
'ngInject';
@@ -14,7 +16,7 @@ export default function routes($stateProvider) {
1416
url: '/logout?referrer',
1517
referrer: 'main',
1618
template: '',
17-
controller: function($state, Auth) {
19+
controller: function($state, Auth<%_ if(filters.ts) { _%>: IAuth<%_ } _%>) {
1820
'ngInject';
1921
var referrer = $state.params.referrer
2022
|| $state.current.referrer
@@ -50,7 +52,7 @@ export default function routes($routeProvider) {
5052
name: 'logout',
5153
referrer: '/',
5254
template: '',
53-
controller: function($location, $route, Auth) {
55+
controller: function($location<%_ if(filters.ts) { _%>: ng.ILocationService<%_ } _%>, $route, Auth<%_ if(filters.ts) { _%>: IAuth<%_ } _%>) {
5456
var referrer = $route.current.params.referrer ||
5557
$route.current.referrer ||
5658
'/';

Diff for: templates/app/client/app/account(auth)/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default angular.module('<%= scriptAppName %>.account', [
2424
])
2525
.config(routing)
2626
<%_ if (filters.ngroute) { _%>
27-
.run(function($rootScope) {
27+
.run(function($rootScope<%_ if(filters.ts) { _%>: ng.IRootScopeService<%_ } _%>) {
2828
'ngInject';
2929
$rootScope.$on('$routeChangeStart', function(event, next, current) {
3030
if (next.name === 'logout' && current && current.originalPath && !current.authenticate) {
@@ -33,7 +33,7 @@ export default angular.module('<%= scriptAppName %>.account', [
3333
});
3434
})<% } %>
3535
<%_ if (filters.uirouter) { _%>
36-
.run(function($rootScope) {
36+
.run(function($rootScope<%_ if(filters.ts) { _%>: ng.IRootScopeService<%_ } _%>) {
3737
'ngInject';
3838
$rootScope.$on('$stateChangeStart', function(event, next, nextParams, current) {
3939
if (next.name === 'logout' && current && current.name && !current.authenticate) {

Diff for: templates/app/client/app/account(auth)/login/login.controller.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
'use strict';
2+
<%_ if(filters.ts) { _%>
3+
4+
import {IAuth} from '../../../components/auth/auth.service';
5+
<%_ } _%>
26

37
export default class LoginController {
8+
<%_ if(filters.ts) { _%>
9+
user;
10+
errors;
11+
submitted;
12+
Auth: IAuth;<% if (filters.ngroute) { %>
13+
$location: ng.ILocationService;<% } %><% if (filters.uirouter) { %>
14+
$state;<% } %>
15+
<%_ } _%>
16+
417
/*@ngInject*/
5-
constructor(Auth<% if (filters.ngroute) { %>, $location<% } %><% if (filters.uirouter) { %>, $state<% } %>) {
18+
constructor(Auth<%_ if(filters.ts) { _%>: IAuth<%_ } _%><% if (filters.ngroute) { %>, $location<%_ if(filters.ts) { _%>: ng.ILocationService<%_ } _%><% } %><% if (filters.uirouter) { %>, $state<% } %>) {
619
this.user = {};
720
this.errors = {};
821
this.submitted = false;
@@ -12,7 +25,7 @@ export default class LoginController {
1225
this.$state = $state;<% } %>
1326
}
1427

15-
login(form) {
28+
login(form<%_ if(filters.ts) { _%>: ng.IFormController<%_ } _%>) {
1629
this.submitted = true;
1730

1831
if (form.$valid) {

Diff for: templates/app/client/app/account(auth)/settings/settings.controller.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
'use strict';
2+
<%_ if(filters.ts) { _%>
3+
4+
import {IAuth} from '../../../components/auth/auth.service';
5+
<%_ } _%>
26

37
export default class SettingsController {
4-
errors = {};
5-
submitted = false;
8+
errors<%_ if(filters.ts) { _%>: IErrors<%_ } _%> = {};
9+
submitted = false;<%_ if(filters.ts) { _%>
10+
Auth: IAuth;
11+
message;
12+
user;
13+
<%_ } _%>
614

715
/*@ngInject*/
816
constructor(Auth) {
917
this.Auth = Auth;
1018
}
1119

12-
changePassword(form) {
20+
changePassword(form<%_ if(filters.ts) { _%>: ISettingsForm<%_ } _%>) {
1321
this.submitted = true;
1422

1523
if (form.$valid) {
@@ -25,3 +33,13 @@ export default class SettingsController {
2533
}
2634
}
2735
}
36+
<%_ if(filters.ts) { _%>
37+
38+
interface ISettingsForm extends ng.IFormController {
39+
password: ng.INgModelController;
40+
}
41+
42+
interface IErrors {
43+
other?: string;
44+
}
45+
<%_ } _%>

Diff for: templates/app/client/app/account(auth)/signup/signup.controller.js

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
'use strict';
2+
<%_ if(filters.ts) { _%>
3+
4+
import {IAuth} from '../../../components/auth/auth.service';
5+
import {IUser} from '../../../components/auth/user.service';
6+
<%_ } _%>
27

38
export default class SignupController {
9+
<%_ if(filters.ts) { _%>
10+
Auth: IAuth;<% if (filters.ngroute) { %>
11+
$location: ng.ILocationService;<% } %><% if (filters.uirouter) { %>
12+
$state;<% } %>
13+
<%_ } _%>
414
//start-non-standard
5-
user = {};
15+
user<%_ if(filters.ts) { _%>: IUser|Object<%_ } _%> = {};
616
errors = {};
717
submitted = false;
818
//end-non-standard
@@ -14,14 +24,25 @@ export default class SignupController {
1424
this.$state = $state;<% } %>
1525
}
1626

17-
register(form) {
27+
<%_ if(filters.ts) { _%>
28+
isValidUser(user: IUser|Object, form: ng.IFormController): user is IUser {<%_ } else { _%>
29+
isValidUser(user, form) {<%_ } _%>
30+
if (form.$valid) {
31+
return true;
32+
} else {
33+
return false;
34+
}
35+
}
36+
37+
register(form<%_ if(filters.ts) { _%>: ng.IFormController<%_ } _%>) {
1838
this.submitted = true;
1939

20-
if (form.$valid) {
40+
let user = this.user;
41+
if (this.isValidUser(user, form)) {
2142
this.Auth.createUser({
22-
name: this.user.name,
23-
email: this.user.email,
24-
password: this.user.password
43+
name: user.name,
44+
email: user.email,
45+
password: user.password
2546
})
2647
.then(() => {
2748
// Account created, redirect to home

Diff for: templates/app/client/app/admin(auth)/admin.controller.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
'use strict';
2+
<%_ if(filters.ts) { _%>
3+
4+
import {IUser, IUserResource} from '../../components/auth/user.service';
5+
<%_ } _%>
26

37
export default class AdminController {
48
<%_ if(filters.ts || filters.flow) { _%>
5-
users: Object[];
9+
users: IUser[];
610

711
<%_ } _%>
812
/*@ngInject*/
9-
constructor(User) {
13+
constructor(User<%_ if(filters.ts) { _%>: IUserResource<%_ } _%>) {
1014
// Use the User $resource to fetch all users
1115
this.users = User.query();
1216
}
1317

14-
delete(user) {
18+
delete(user<%_ if(filters.ts) { _%>: IUser<%_ } _%>) {
1519
user.$remove();
1620
this.users.splice(this.users.indexOf(user), 1);
1721
}

Diff for: templates/app/client/app/app.config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3-
export function routeConfig(<% if (filters.ngroute) { %>$routeProvider<% } if (filters.uirouter) { %>$urlRouterProvider<% } %>, $locationProvider) {
3+
<%_ if(filters.ts) { _%>
4+
export function routeConfig(<% if (filters.ngroute) { %>$routeProvider<% } if (filters.uirouter) { %>$urlRouterProvider<% } %>, $locationProvider: ng.ILocationProvider) {<% } else { %>
5+
export function routeConfig(<% if (filters.ngroute) { %>$routeProvider<% } if (filters.uirouter) { %>$urlRouterProvider<% } %>, $locationProvider) {<% } %>
46
'ngInject';
57
<%_ if(filters.ngroute) { _%>
68
$routeProvider

Diff for: templates/app/client/app/app.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {routeConfig} from './app.config';
2121

2222
<%_ if(filters.auth) { _%>
2323
import _Auth from '../components/auth/auth.module';
24+
<%_ if(filters.ts) { _%>
25+
import {IAuth} from '../components/auth/auth.service';<% } %>
2426
import account from './account';
2527
import admin from './admin';<% } %>
2628
import navbar from '../components/navbar/navbar.component';
@@ -63,12 +65,14 @@ angular.module('<%= scriptAppName %>', [
6365
])
6466
.config(routeConfig)
6567
<%_ if(filters.auth) { _%>
66-
.run(function($rootScope, $location, Auth) {
68+
<%_ if(filters.ts) { _%>
69+
.run(function($rootScope: ng.IRootScopeService, $location: ng.ILocationService, Auth: IAuth) {<% } else { %>
70+
.run(function($rootScope, $location, Auth) {<% } %>
6771
'ngInject';
6872
// Redirect to login if route requires auth and you're not logged in
6973
$rootScope.$on('$stateChangeStart', function(event, next) {
7074
Auth.isLoggedIn(function(loggedIn) {
71-
if(next.authenticate && !loggedIn) {
75+
if (next.authenticate && !loggedIn) {
7276
$location.path('/login');
7377
}
7478
});

Diff for: templates/app/client/app/main/main.component.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ import uiRouter from 'angular-ui-router';<% } _%>
77
import routing from './main.routes';
88

99
export class MainController {
10+
<%_ if(filters.ts) { _%>
11+
$http: ng.IHttpService;
12+
socket;
13+
awesomeThings: IThing[];
14+
newThing: string;
15+
<%_ } _%>
16+
1017
/*@ngInject*/
11-
constructor($http<% if(filters.socketio) { %>, $scope, socket<% } %>) {
18+
constructor($http<%_ if(filters.ts) { _%>: ng.IHttpService<%_ } _%><% if(filters.socketio) { %>, $scope<%_ if(filters.ts) { _%>: ng.IScope<%_ } _%>, socket<% } %>) {
1219
this.$http = $http;<% if (filters.socketio) { %>
1320
this.socket = socket;<% } %>
1421
this.awesomeThings = [];
@@ -21,7 +28,7 @@ export class MainController {
2128

2229
$onInit() {
2330
this.$http.get('/api/things').then(response => {
24-
this.awesomeThings = response.data;<% if (filters.socketio) { %>
31+
this.awesomeThings = <% if(filters.ts) { %><IThing[]><% } %>response.data;<% if (filters.socketio) { %>
2532
this.socket.syncUpdates('thing', this.awesomeThings);<% } %>
2633
});
2734
}<% if (filters.models) { %>
@@ -33,11 +40,18 @@ export class MainController {
3340
}
3441
}
3542

36-
deleteThing(thing) {
43+
deleteThing(thing<%_ if(filters.ts) { _%>: IThing<%_ } _%>) {
3744
this.$http.delete('/api/things/' + thing._id);
3845
}<% } %>
3946
}
4047

48+
<%_ if(filters.ts) { _%>
49+
interface IThing {
50+
_id: string;
51+
name: string;
52+
info: string;
53+
}<% } _%>
54+
4155
export default angular.module('<%= scriptAppName %>.main', [
4256
<%_ if(filters.ngroute) { _%>
4357
ngRoute<% } _%>

Diff for: templates/app/client/app/main/main.component.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ describe('Component: MainComponent', function() {
1919
// Initialize the controller and a mock scope
2020
beforeEach(inject(function(
2121
_$httpBackend_,
22-
$http,
22+
$http<%_ if(filters.ts) { _%>: ng.IHttpService<%_ } _%>,
2323
$componentController,
24-
$rootScope<% if (filters.uirouter) {%>,
24+
$rootScope<%_ if(filters.ts) { _%>: ng.IRootScopeService<%_ } _%><% if (filters.uirouter) {%>,
2525
$state<% } %><% if (filters.socketio) {%>,
2626
socket<% } %>) {
2727
$httpBackend = _$httpBackend_;

Diff for: templates/app/client/components/auth(auth)/auth.module.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const ngRoute = require('angular-route');<% } %>
1212
<%_ if (filters.uirouter) { _%>
1313
import uiRouter from 'angular-ui-router';<% } %>
1414

15-
function addInterceptor($httpProvider) {
15+
function addInterceptor($httpProvider<%_ if(filters.ts) { _%>: ng.IHttpProvider<%_ } _%>) {
1616
'ngInject';
1717
$httpProvider.interceptors.push('authInterceptor');
1818
}

0 commit comments

Comments
 (0)