Skip to content

Commit 164b3f9

Browse files
replaced NodeJS.EventEmitter interface with an inline version
1 parent 3686ae8 commit 164b3f9

7 files changed

Lines changed: 45 additions & 9 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
10.15.3 (Feb XX, 2020)
2+
- Updated type definitions to remove `@types/node` dependency and avoid conflicts between Node and DOM types.
23
- Bugfixing - Handle issue importing node-fetch library (issue #505).
34

45
10.15.2 (Dec 3, 2020)

package-lock.json

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splitsoftware/splitio",
3-
"version": "10.15.3-canary.0",
3+
"version": "10.15.3-canary.1",
44
"description": "Split SDK",
55
"files": [
66
"README.md",
@@ -34,7 +34,6 @@
3434
"dependencies": {
3535
"@babel/runtime": "^7.10.2",
3636
"@types/google.analytics": "0.0.40",
37-
"@types/node": "^13.9.1",
3837
"events": "3.1.0",
3938
"ioredis": "4.18.0",
4039
"ip": "1.1.5",

scripts/ts-tests.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
cd ts-tests ## Go to typescript tests folder
44
echo "Installing dependencies for TypeScript declarations testing..."
55
npm install ## Install dependencies
6+
npm install @types/node@6.0.31 ## Install type definitions for Node.js v6.x (the oldest supported version)
7+
echo "Dependencies installed, linking the package."
8+
npm link @splitsoftware/splitio ## Link to the cloned code
9+
echo "Running tsc compiler."
10+
./node_modules/.bin/tsc ## Run typescript compiler. No need for flags as we have a tsconfig.json file
11+
12+
echo "Testing again with the latest @types/node version..."
13+
npm install @types/node@14 ## Install latest type definitions for Node.js
614
echo "Dependencies installed, linking the package."
715
npm link @splitsoftware/splitio ## Link to the cloned code
816
echo "Running tsc compiler."

ts-tests/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ const a: boolean = client.emit(splitEvent);
226226
client = client.removeAllListeners(splitEvent);
227227
client = client.removeAllListeners();
228228
const b: number = client.listenerCount(splitEvent);
229+
let nodeEventEmitter: NodeJS.EventEmitter = client;
229230

230231
// Ready and destroy
231232
const readyPromise: Promise<void> = client.ready();
@@ -287,6 +288,7 @@ const a1: boolean = client.emit(splitEvent);
287288
client = client.removeAllListeners(splitEvent);
288289
client = client.removeAllListeners();
289290
const b1: number = client.listenerCount(splitEvent);
291+
nodeEventEmitter = client;
290292

291293
// Ready and destroy (same as for sync client, just for interface checking)
292294
const readyPromise1: Promise<void> = client.ready();
@@ -334,6 +336,7 @@ const aa: boolean = manager.emit(splitEvent);
334336
manager = manager.removeAllListeners(splitEvent);
335337
manager = manager.removeAllListeners();
336338
const bb: number = manager.listenerCount(splitEvent);
339+
nodeEventEmitter = manager;
337340

338341
// manager exposes Event constants too
339342
const managerEventConsts: {[key: string]: SplitIO.Event} = manager.Event;
@@ -357,6 +360,7 @@ const aaa: boolean = asyncManager.emit(splitEvent);
357360
asyncManager = asyncManager.removeAllListeners(splitEvent);
358361
asyncManager = asyncManager.removeAllListeners();
359362
const bbb: number = asyncManager.listenerCount(splitEvent);
363+
nodeEventEmitter = asyncManager;
360364

361365
// asyncManager exposes Event constants too
362366
const asyncManagerEventConsts: {[key: string]: SplitIO.Event} = asyncManager.Event;

ts-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"license": "Apache-2.0",
77
"repository": "splitio/javascript-client",
88
"dependencies": {
9+
"@types/node": "^14.14.25",
910
"typescript": "^3.7.4"
1011
}
1112
}

types/splitio.d.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,33 @@
22
// Project: http://www.split.io/
33
// Definitions by: Nico Zelaya <https://github.com/NicoZelaya/>
44

5-
/// <reference types="node" />
65
/// <reference types="google.analytics" />
76

87
export as namespace SplitIO;
98
export = SplitIO;
109

10+
/**
11+
* NodeJS.EventEmitter interface
12+
* @see {@link https://nodejs.org/api/events.html}
13+
*/
14+
interface EventEmitter {
15+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
16+
on(event: string | symbol, listener: (...args: any[]) => void): this;
17+
once(event: string | symbol, listener: (...args: any[]) => void): this;
18+
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
19+
off(event: string | symbol, listener: (...args: any[]) => void): this;
20+
removeAllListeners(event?: string | symbol): this;
21+
setMaxListeners(n: number): this;
22+
getMaxListeners(): number;
23+
listeners(event: string | symbol): Function[];
24+
rawListeners(event: string | symbol): Function[];
25+
emit(event: string | symbol, ...args: any[]): boolean;
26+
listenerCount(type: string | symbol): number;
27+
// Added in Node 6...
28+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
29+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
30+
eventNames(): Array<string | symbol>;
31+
}
1132
/**
1233
* @typedef {Object} EventConsts
1334
* @property {string} SDK_READY The ready event.
@@ -338,9 +359,9 @@ interface INodeBasicSettings extends ISharedSettings {
338359
/**
339360
* Common API for entities that expose status handlers.
340361
* @interface IStatusInterface
341-
* @extends NodeJS.EventEmitter
362+
* @extends EventEmitter
342363
*/
343-
interface IStatusInterface extends NodeJS.EventEmitter {
364+
interface IStatusInterface extends EventEmitter {
344365
/**
345366
* Constant object containing the SDK events for you to use.
346367
* @property {EventConsts} Event
@@ -744,13 +765,13 @@ declare namespace SplitIO {
744765
*/
745766
type UrlSettings = {
746767
/**
747-
* String property to override the base URL where the SDK will get feature flagging related data like a Split rollout plan or segments information.
768+
* String property to override the base URL where the SDK will get feature flagging related data like a Split rollout plan or segments information.
748769
* @property {string} sdk
749770
* @default 'https://sdk.split.io/api'
750771
*/
751772
sdk?: string,
752773
/**
753-
* String property to override the base URL where the SDK will post event-related information like impressions.
774+
* String property to override the base URL where the SDK will post event-related information like impressions.
754775
* @property {string} events
755776
* @default 'https://events.split.io/api'
756777
*/

0 commit comments

Comments
 (0)