Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS] Add test-ts-decls script #32

Open
wants to merge 2 commits into
base: type_definitions
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
87 changes: 87 additions & 0 deletions ts-tests/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
///<reference types="../types" />
///<reference types="../types/full" />

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);
29 changes: 29 additions & 0 deletions ts-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
3 changes: 1 addition & 2 deletions types/full/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
// Definitions by: Nico Zelaya <https://github.com/NicoZelaya/>

/// <reference path="../splitio.d.ts" />
export = JsSdk;

declare module JsSdk {
declare module '@splitsoftware/splitio-react-native/full' {
/**
* Full version of the Split.io sdk factory function.
*
Expand Down
3 changes: 1 addition & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
// Definitions by: Nico Zelaya <https://github.com/NicoZelaya/>

/// <reference path="./splitio.d.ts" />
export = JsSdk;

declare module JsSdk {
declare module '@splitsoftware/splitio-react-native' {
/**
* Slim version of the Split.io sdk factory function.
*
Expand Down
32 changes: 16 additions & 16 deletions types/splitio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.<AttributeType>} Attributes
* @see {@link https://help.split.io/hc/en-us/articles/4406066357901#attribute-syntax}
*/
Expand All @@ -393,7 +393,7 @@ declare namespace SplitIO {
type AttributeType = string | number | boolean | Array<string | number>;
/**
* Split properties should be an object with values of type string, number, boolean or null. Size limit of ~31kb.
* @typedef {Object.<number, string, boolean, null>} Attributes
* @typedef {Object.<number, string, boolean, null>} Properties
* @see {@link https://help.split.io/hc/en-us/articles/4406066357901#track
*/
type Properties = {
Expand Down Expand Up @@ -482,10 +482,10 @@ declare namespace SplitIO {
}
};
/**
* A promise that will be resolved with that SplitView.
* @typedef {Promise<SplitView>} SplitView
* A promise that will be resolved with that SplitView or null if the split is not found.
* @typedef {Promise<SplitView | null>} SplitView
*/
type SplitViewAsync = Promise<SplitView>;
type SplitViewAsync = Promise<SplitView | null>;
/**
* An array containing the SplitIO.SplitView elements.
*/
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -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;
}
}