4
4
* Module dependencies.
5
5
*/
6
6
7
+ import { InitOptions } from './types' ;
7
8
var Entity = require ( './entity' ) ;
8
9
var bindAll = require ( 'bind-all' ) ;
9
10
var cookie = require ( './cookie' ) ;
@@ -17,6 +18,22 @@ var localStorage = require('./store');
17
18
* User defaults
18
19
*/
19
20
21
+ interface UserDefaults {
22
+ persist : boolean ;
23
+ cookie : {
24
+ key : string ;
25
+ oldKey : string ;
26
+ } ;
27
+ localStorage : {
28
+ key : string ;
29
+ } ;
30
+ }
31
+
32
+ interface User {
33
+ defaults : UserDefaults ;
34
+ debug : unknown ;
35
+ }
36
+
20
37
User . defaults = {
21
38
persist : true ,
22
39
cookie : {
@@ -30,11 +47,9 @@ User.defaults = {
30
47
31
48
/**
32
49
* Initialize a new `User` with `options`.
33
- *
34
- * @param {Object } options
35
50
*/
36
51
37
- function User ( options ) {
52
+ function User ( options ?: InitOptions ) {
38
53
this . defaults = User . defaults ;
39
54
this . debug = debug ;
40
55
Entity . call ( this , options ) ;
@@ -51,9 +66,6 @@ inherit(User, Entity);
51
66
*
52
67
* When the user id changes, the method will reset his anonymousId to a new one.
53
68
*
54
- * // FIXME: What are the mixed types?
55
- * @param {string } id
56
- * @return {Mixed }
57
69
* @example
58
70
* // didn't change because the user didn't have previous id.
59
71
* anonymousId = user.anonymousId();
@@ -74,7 +86,7 @@ inherit(User, Entity);
74
86
* assert.notEqual(anonymousId, user.anonymousId());
75
87
*/
76
88
77
- User . prototype . id = function ( id ) {
89
+ User . prototype . id = function ( id : string ) : string | undefined {
78
90
var prev = this . _getId ( ) ;
79
91
var ret = Entity . prototype . id . apply ( this , arguments ) ;
80
92
if ( prev == null ) return ret ;
@@ -94,7 +106,7 @@ User.prototype.id = function(id) {
94
106
* @return {String|User }
95
107
*/
96
108
97
- User . prototype . anonymousId = function ( anonymousId ) {
109
+ User . prototype . anonymousId = function ( anonymousId : string ) : string | User {
98
110
var store = this . storage ( ) ;
99
111
100
112
// set / remove
@@ -143,11 +155,9 @@ User.prototype.anonymousId = function(anonymousId) {
143
155
144
156
/**
145
157
* Set the user's `anonymousid` in local storage.
146
- *
147
- * @param {String } id
148
158
*/
149
159
150
- User . prototype . _setAnonymousIdInLocalStorage = function ( id ) {
160
+ User . prototype . _setAnonymousIdInLocalStorage = function ( id : string ) {
151
161
if ( ! this . _options . localStorageFallbackDisabled ) {
152
162
localStorage . set ( 'ajs_anonymous_id' , id ) ;
153
163
}
@@ -175,10 +185,9 @@ User.prototype.load = function() {
175
185
* BACKWARDS COMPATIBILITY: Load the old user from the cookie.
176
186
*
177
187
* @api private
178
- * @return {boolean }
179
188
*/
180
189
181
- User . prototype . _loadOldCookie = function ( ) {
190
+ User . prototype . _loadOldCookie = function ( ) : boolean {
182
191
var user = cookie . get ( this . _options . cookie . oldKey ) ;
183
192
if ( ! user ) return false ;
184
193
0 commit comments