44 * Module dependencies.
55 */
66
7+ import { InitOptions } from './types' ;
78var Entity = require ( './entity' ) ;
89var bindAll = require ( 'bind-all' ) ;
910var cookie = require ( './cookie' ) ;
@@ -17,6 +18,22 @@ var localStorage = require('./store');
1718 * User defaults
1819 */
1920
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+
2037User . defaults = {
2138 persist : true ,
2239 cookie : {
@@ -30,11 +47,9 @@ User.defaults = {
3047
3148/**
3249 * Initialize a new `User` with `options`.
33- *
34- * @param {Object } options
3550 */
3651
37- function User ( options ) {
52+ function User ( options ?: InitOptions ) {
3853 this . defaults = User . defaults ;
3954 this . debug = debug ;
4055 Entity . call ( this , options ) ;
@@ -51,9 +66,6 @@ inherit(User, Entity);
5166 *
5267 * When the user id changes, the method will reset his anonymousId to a new one.
5368 *
54- * // FIXME: What are the mixed types?
55- * @param {string } id
56- * @return {Mixed }
5769 * @example
5870 * // didn't change because the user didn't have previous id.
5971 * anonymousId = user.anonymousId();
@@ -74,7 +86,7 @@ inherit(User, Entity);
7486 * assert.notEqual(anonymousId, user.anonymousId());
7587 */
7688
77- User . prototype . id = function ( id ) {
89+ User . prototype . id = function ( id : string ) : string | undefined {
7890 var prev = this . _getId ( ) ;
7991 var ret = Entity . prototype . id . apply ( this , arguments ) ;
8092 if ( prev == null ) return ret ;
@@ -94,7 +106,7 @@ User.prototype.id = function(id) {
94106 * @return {String|User }
95107 */
96108
97- User . prototype . anonymousId = function ( anonymousId ) {
109+ User . prototype . anonymousId = function ( anonymousId : string ) : string | User {
98110 var store = this . storage ( ) ;
99111
100112 // set / remove
@@ -143,11 +155,9 @@ User.prototype.anonymousId = function(anonymousId) {
143155
144156/**
145157 * Set the user's `anonymousid` in local storage.
146- *
147- * @param {String } id
148158 */
149159
150- User . prototype . _setAnonymousIdInLocalStorage = function ( id ) {
160+ User . prototype . _setAnonymousIdInLocalStorage = function ( id : string ) {
151161 if ( ! this . _options . localStorageFallbackDisabled ) {
152162 localStorage . set ( 'ajs_anonymous_id' , id ) ;
153163 }
@@ -175,10 +185,9 @@ User.prototype.load = function() {
175185 * BACKWARDS COMPATIBILITY: Load the old user from the cookie.
176186 *
177187 * @api private
178- * @return {boolean }
179188 */
180189
181- User . prototype . _loadOldCookie = function ( ) {
190+ User . prototype . _loadOldCookie = function ( ) : boolean {
182191 var user = cookie . get ( this . _options . cookie . oldKey ) ;
183192 if ( ! user ) return false ;
184193
0 commit comments