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

SplitIO does not seem to be properly imported into the files #130

Open
profaurore opened this issue Nov 15, 2024 · 2 comments
Open

SplitIO does not seem to be properly imported into the files #130

profaurore opened this issue Nov 15, 2024 · 2 comments

Comments

@profaurore
Copy link

profaurore commented Nov 15, 2024

I am working on a Typescript application that makes use of this package, and have been unable to the get Typescript types that use SplitIO.* to correctly resolve; they all resolve to any. Are there some imports that are missing?

For example,

// This should be `SplitIO.TreatmentWithConfig`, but produces `any`.
type LocalTreatmentWithConfig = ISplitState['treatments'][string][string];
@EmilianoSanchez
Copy link
Contributor

Hi @profaurore ,

The problem you have is that the ISplitState interface is not part of the SplitIO namespace, and so, you need to explicitly import it from the @splitsoftware/splitio-redux package (Redux SDK). For example:

import { ISplitState } from '@splitsoftware/splitio-redux';

type LocalTreatmentWithConfig = ISplitState['treatments'][string][string];

const someTreatmentWithConfig: LocalTreatmentWithConfig = {
  treatment: 'on',
  config: null
};

// SplitIO.TreatmentWithConfig and LocalTreatmentWithConfig are the same types
const sameTreatmentWithConfig: SplitIO.TreatmentWithConfig = someTreatmentWithConfig;

Note that the SplitIO namespace, unlike ISplitState, is available automatically when importing any Split SDK. But if you prefer, you can import it explicitly as follows: import SplitIO from '@splitsoftware/splitio/types/splitio';

The SplitIO namespace is defined in the @splitsoftware/splitio package, which is the base JavaScript SDK that the Redux SDK (@splitsoftware/splitio-redux package) extends from. And Redux SDK exports a few more types and interfaces, like ISplitState, that we weren't able to merge into the namespace (due to some conflicts with CommonJS module system) and so they are not part of it.

You can check this line, for the complete list of TypeScript definitions that the Redux SDK exports but are not part of the namespace:

// Types
import type { IStatus, ISplitState, IGetSplitState, IInitSplitSdkParams, IGetTreatmentsParams, IDestroySplitSdkParams, ITrackParams } from '@splitsoftware/splitio-redux';

@profaurore
Copy link
Author

profaurore commented Nov 16, 2024

Hi @EmilianoSanchez, thank you for the prompt response!

I must have a Typescript configuration that is interfering with the namespace import.

If I do the following, the resulting type is any.

import type { ISplitState } from '@splitsoftware/splitio-redux';

type TestType = ISplitState['treatments'][string][string];

Whereas if I do the following, the resulting type is the expected SplitIO.TreatmentWithConfig | undefined.

import type { ISplitState } from '@splitsoftware/splitio-redux';
import type SplitIO from '@splitsoftware/splitio/types/splitio';

type TestType = ISplitState['treatments'][string][string];

I'll take a closer look on Monday and report back any findings in case others run into the same problem. Feel free to close this issue beforehand, if appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants