Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/global-modules.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export {};

declare global {
interface Window {
jQuery: any;
Zepto: any;
}
}
6 changes: 0 additions & 6 deletions lib/index.d.ts → lib/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
declare interface Window {
// TODO Remove use of any and import types for JQuery/Zepto
jQuery: any;
Zepto: any;
}

declare namespace SegmentAnalytics {
interface AnalyticsJS {}
}
Expand Down
6 changes: 0 additions & 6 deletions lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
export interface SegmentAnalytics {
Integrations: { [name: string]: unknown };
options: InitOptions;
_sourceMiddlewares;
_integrationMiddlewares;
_destinationMiddlewares;
_integrations;
_readied: boolean;
_timeout: number;
}

export interface IntegrationsSettings {
Expand Down
35 changes: 22 additions & 13 deletions lib/user.js → lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Module dependencies.
*/

import { InitOptions } from './types';
var Entity = require('./entity');
var bindAll = require('bind-all');
var cookie = require('./cookie');
Expand All @@ -17,6 +18,22 @@ var localStorage = require('./store');
* User defaults
*/

interface UserDefaults {
persist: boolean;
cookie: {
key: string;
oldKey: string;
};
localStorage: {
key: string;
};
}

interface User {
defaults: UserDefaults;
debug: unknown;
}

User.defaults = {
persist: true,
cookie: {
Expand All @@ -30,11 +47,9 @@ User.defaults = {

/**
* Initialize a new `User` with `options`.
*
* @param {Object} options
*/

function User(options) {
function User(options?: InitOptions) {
this.defaults = User.defaults;
this.debug = debug;
Entity.call(this, options);
Expand All @@ -51,9 +66,6 @@ inherit(User, Entity);
*
* When the user id changes, the method will reset his anonymousId to a new one.
*
* // FIXME: What are the mixed types?
* @param {string} id
* @return {Mixed}
* @example
* // didn't change because the user didn't have previous id.
* anonymousId = user.anonymousId();
Expand All @@ -74,7 +86,7 @@ inherit(User, Entity);
* assert.notEqual(anonymousId, user.anonymousId());
*/

User.prototype.id = function(id) {
User.prototype.id = function(id: string): string | undefined {
var prev = this._getId();
var ret = Entity.prototype.id.apply(this, arguments);
if (prev == null) return ret;
Expand All @@ -94,7 +106,7 @@ User.prototype.id = function(id) {
* @return {String|User}
*/

User.prototype.anonymousId = function(anonymousId) {
User.prototype.anonymousId = function(anonymousId: string): string | User {
var store = this.storage();

// set / remove
Expand Down Expand Up @@ -143,11 +155,9 @@ User.prototype.anonymousId = function(anonymousId) {

/**
* Set the user's `anonymousid` in local storage.
*
* @param {String} id
*/

User.prototype._setAnonymousIdInLocalStorage = function(id) {
User.prototype._setAnonymousIdInLocalStorage = function(id: string) {
if (!this._options.localStorageFallbackDisabled) {
localStorage.set('ajs_anonymous_id', id);
}
Expand Down Expand Up @@ -175,10 +185,9 @@ User.prototype.load = function() {
* BACKWARDS COMPATIBILITY: Load the old user from the cookie.
*
* @api private
* @return {boolean}
*/

User.prototype._loadOldCookie = function() {
User.prototype._loadOldCookie = function(): boolean {
var user = cookie.get(this._options.cookie.oldKey);
if (!user) return false;

Expand Down