diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 862e583..c4defdf 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -28,6 +28,9 @@ jobs:
- name: npm Check
run: npm run check
+ - name: npm TS tests
+ run: npm run test-ts-decls
+
- name: npm Test
run: npm run test
diff --git a/package.json b/package.json
index e215c95..71a3175 100644
--- a/package.json
+++ b/package.json
@@ -27,6 +27,7 @@
],
"scripts": {
"test": "jest",
+ "test-ts-decls": "tsc --build ts-tests",
"check": "npm run check:lint && npm run check:types && npm run check:version",
"check:lint": "eslint \"**/*.{js,ts,tsx}\"",
"check:types": "tsc --noEmit",
diff --git a/ts-tests/index.ts b/ts-tests/index.ts
new file mode 100644
index 0000000..76f5699
--- /dev/null
+++ b/ts-tests/index.ts
@@ -0,0 +1,87 @@
+///
+///
+
+import {
+ SplitFactory as SplitFactoryFull,
+ DebugLogger as DebugLoggerFull,
+ InfoLogger as InfoLoggerFull,
+ WarnLogger as WarnLoggerFull,
+ ErrorLogger as ErrorLoggerFull,
+} from '@splitsoftware/splitio-react-native/full';
+import { SplitFactory, DebugLogger, InfoLogger, WarnLogger, ErrorLogger, LocalhostFromObject } from '@splitsoftware/splitio-react-native';
+
+const fullReactNativeConfig: SplitIO.IReactNativeSettings = {
+ core: {
+ authorizationKey: 'api-key',
+ key: 'some-key',
+ labelsEnabled: false,
+ },
+ scheduler: {
+ featuresRefreshRate: 1,
+ impressionsRefreshRate: 1,
+ impressionsQueueSize: 1,
+ telemetryRefreshRate: 1,
+ segmentsRefreshRate: 1,
+ offlineRefreshRate: 1,
+ eventsPushRate: 1,
+ eventsQueueSize: 1,
+ pushRetryBackoffBase: 1,
+ },
+ startup: {
+ readyTimeout: 1,
+ requestTimeoutBeforeReady: 1,
+ retriesOnFailureBeforeReady: 1,
+ eventsFirstPushWindow: 1,
+ },
+ urls: {
+ sdk: 'https://asd.com/sdk',
+ events: 'https://asd.com/events',
+ auth: 'https://asd.com/auth',
+ streaming: 'https://asd.com/streaming',
+ telemetry: 'https://asd.com/telemetry',
+ },
+ features: {
+ feature1: 'treatment',
+ },
+ // @TODO should not let to define a storage
+ impressionListener: {
+ logImpression: (data: SplitIO.ImpressionData) => {
+ console.log(data);
+ },
+ },
+ debug: DebugLogger(),
+ // @TODO shold fail
+ integrations: [],
+ streamingEnabled: true,
+ sync: {
+ splitFilters: [
+ { type: 'byName', values: ['my_split_1', 'my_split_1'] },
+ { type: 'byPrefix', values: ['my_split', 'test_split_'] },
+ ],
+ impressionsMode: 'DEBUG',
+ localhostMode: LocalhostFromObject(),
+ enabled: true,
+ },
+ userConsent: 'GRANTED',
+};
+
+fullReactNativeConfig.debug = InfoLogger();
+fullReactNativeConfig.debug = WarnLogger();
+fullReactNativeConfig.debug = ErrorLogger();
+fullReactNativeConfig.debug = DebugLoggerFull();
+fullReactNativeConfig.debug = InfoLoggerFull();
+fullReactNativeConfig.debug = WarnLoggerFull();
+fullReactNativeConfig.debug = ErrorLoggerFull();
+
+const sdkSlim = SplitFactory(fullReactNativeConfig);
+const sdkFull = SplitFactoryFull(fullReactNativeConfig);
+
+let client: SplitIO.IClient = sdkSlim.client();
+client = sdkSlim.client('other key');
+client = sdkFull.client();
+client = sdkFull.client('other key');
+console.log(client);
+
+let manager: SplitIO.IManager = sdkSlim.manager();
+manager = sdkFull.manager();
+console.log(manager);
diff --git a/ts-tests/tsconfig.json b/ts-tests/tsconfig.json
new file mode 100644
index 0000000..29bc676
--- /dev/null
+++ b/ts-tests/tsconfig.json
@@ -0,0 +1,29 @@
+{
+ "compilerOptions": {
+ "baseUrl": "./",
+ "allowUnreachableCode": false,
+ "allowUnusedLabels": false,
+ "esModuleInterop": true,
+ // "importsNotUsedAsValues": "error",
+ "forceConsistentCasingInFileNames": true,
+ "jsx": "react",
+ "lib": [
+ "esnext",
+ "DOM"
+ ],
+ "module": "esnext",
+ "moduleResolution": "node",
+ "noImplicitUseStrict": false,
+ "noStrictGenericChecks": false,
+ "noUnusedLocals": true,
+ // "noUnusedParameters": true,
+ "resolveJsonModule": true,
+ "skipLibCheck": true,
+ "strict": true,
+ "target": "esnext",
+ "noEmit": true,
+ },
+ "files": [
+ "index"
+ ]
+}
diff --git a/types/full/index.d.ts b/types/full/index.d.ts
index 13bf73d..8837329 100644
--- a/types/full/index.d.ts
+++ b/types/full/index.d.ts
@@ -3,9 +3,8 @@
// Definitions by: Nico Zelaya
///
-export = JsSdk;
-declare module JsSdk {
+declare module '@splitsoftware/splitio-react-native/full' {
/**
* Full version of the Split.io sdk factory function.
*
diff --git a/types/index.d.ts b/types/index.d.ts
index 655da3e..389c0cb 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -3,9 +3,8 @@
// Definitions by: Nico Zelaya
///
-export = JsSdk;
-declare module JsSdk {
+declare module '@splitsoftware/splitio-react-native' {
/**
* Slim version of the Split.io sdk factory function.
*
diff --git a/types/splitio.d.ts b/types/splitio.d.ts
index 454c77b..3493d1c 100644
--- a/types/splitio.d.ts
+++ b/types/splitio.d.ts
@@ -212,7 +212,7 @@ interface ISharedSettings {
* Possible values are 'DEBUG' and 'OPTIMIZED'.
* - DEBUG: will send all the impressions generated (recommended only for debugging purposes).
* - OPTIMIZED: will send unique impressions to Split Servers avoiding a considerable amount of traffic that duplicated impressions could generate.
- * @property {String} impressionsMode
+ * @property {string} impressionsMode
* @default 'OPTIMIZED'
*/
impressionsMode?: SplitIO.ImpressionsMode,
@@ -379,7 +379,7 @@ declare namespace SplitIO {
*/
type Event = 'init::timeout' | 'init::ready' | 'init::cache-ready' | 'state::update';
/**
- * Split attributes should be on object with values of type string or number (dates should be sent as millis since epoch).
+ * Split attributes should be on object with values of type string, boolean, number (dates should be sent as millis since epoch) or array of strings or numbers.
* @typedef {Object.} Attributes
* @see {@link https://help.split.io/hc/en-us/articles/4406066357901#attribute-syntax}
*/
@@ -393,7 +393,7 @@ declare namespace SplitIO {
type AttributeType = string | number | boolean | Array;
/**
* Split properties should be an object with values of type string, number, boolean or null. Size limit of ~31kb.
- * @typedef {Object.} Attributes
+ * @typedef {Object.} Properties
* @see {@link https://help.split.io/hc/en-us/articles/4406066357901#track
*/
type Properties = {
@@ -482,10 +482,10 @@ declare namespace SplitIO {
}
};
/**
- * A promise that will be resolved with that SplitView.
- * @typedef {Promise} SplitView
+ * A promise that will be resolved with that SplitView or null if the split is not found.
+ * @typedef {Promise} SplitView
*/
- type SplitViewAsync = Promise;
+ type SplitViewAsync = Promise;
/**
* An array containing the SplitIO.SplitView elements.
*/
@@ -848,7 +848,7 @@ declare namespace SplitIO {
/**
* This represents the interface for the Client instance with synchronous storage for server-side SDK, where we don't have only one key.
- * @interface IClient
+ * @interface IClientSS
* @extends IBasicClient
*/
interface IClientSS extends IBasicClient {
@@ -903,7 +903,7 @@ declare namespace SplitIO {
}
/**
* This represents the interface for the Client instance with asynchronous storage for server-side SDK, where we don't have only one key.
- * @interface IAsyncClient
+ * @interface IAsyncClientSS
* @extends IBasicClient
*/
interface IAsyncClientSS extends IBasicClient {
@@ -1062,20 +1062,20 @@ declare namespace SplitIO {
* @function names
* @returns {SplitNames} The lists of Split names.
*/
- names(): SplitNames,
+ names(): SplitNames;
/**
* Get the array of splits data in SplitView format.
* @function splits
* @returns {SplitViews} The list of SplitIO.SplitView.
*/
- splits(): SplitViews,
+ splits(): SplitViews;
/**
* Get the data of a split in SplitView format.
* @function split
* @param {string} splitName The name of the split we wan't to get info of.
- * @returns {SplitView} The SplitIO.SplitView of the given split.
+ * @returns {SplitView | null} The SplitIO.SplitView of the given split or null if the split is not found.
*/
- split(splitName: string): SplitView,
+ split(splitName: string): SplitView | null;
}
/**
* Representation of a manager instance with asynchronous storage of the SDK.
@@ -1088,19 +1088,19 @@ declare namespace SplitIO {
* @function names
* @returns {SplitNamesAsync} A promise that will resolve to the array of Splitio.SplitNames.
*/
- names(): SplitNamesAsync,
+ names(): SplitNamesAsync;
/**
* Get the array of splits data in SplitView format.
* @function splits
* @returns {SplitViewsAsync} A promise that will resolve to the SplitIO.SplitView list.
*/
- splits(): SplitViewsAsync,
+ splits(): SplitViewsAsync;
/**
* Get the data of a split in SplitView format.
* @function split
* @param {string} splitName The name of the split we wan't to get info of.
- * @returns {SplitViewAsync} A promise that will resolve to the SplitIO.SplitView value.
+ * @returns {SplitViewAsync} A promise that will resolve to the SplitIO.SplitView value or null if the split is not found.
*/
- split(splitName: string): SplitViewAsync,
+ split(splitName: string): SplitViewAsync;
}
}