-
Notifications
You must be signed in to change notification settings - Fork 2
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
TypeScript export for Nullable
is missing
#443
Comments
@SlimShadyIAm What exactly doesn't work? This works just fine for me:
|
So in the example you've shown in your latest comment, you've put in a map with an empty array for the The problem is that originally the type definition for With the example you added in your latest comment, I tried doing setParticipantData_CORE = async (
studyDeploymentId: string,
data: Data,
inputType: string | null,
config: AxiosRequestConfig
): Promise<ParticipantData> => {
try {
const participantDataRequest = new ParticipationServiceRequest.SetParticipantData(new UUID(studyDeploymentId), mapOf([data]), inputType); ...but that also doesn't work because When we originally talked about this issue I remember you saying you just needed to manually export the |
Yes. The API docs may need some polishing. It is a map, with keys defining "which data" is being set, identified by
Maybe. I was just adding a test replicating your issue, and couldn't. I'll try again with this additional context. But the reason it doesn't seem needed is because the TypeScript type system is flexible enough to accept |
I would have thought so as well, you're right that it doesn't complain about the third parameter being Also, my point about Here's an example of something we have in our tests for the |
@SlimShadyIAm Updated the test to pass actual data, as defined by the type system: 01b6fbc Works just fine:
I'm gonna guess the original wrapper was wrong before, and if it "worked" before, it didn't work properly. The above is what is expected by the backend. You probably want to thoroughly rework all the wrappers now that full type info is available. If the wrappers are needed at all, ... I never was certain why there are there. 🙂 |
@Whathecode Sorry for the late response on this. I've tried again and unfortunately I'm still struggling with this. In my test... test.skip('setParticipantData should succeed', async () => {
const inputByParticipantRole: string | null = null;
const setParticipantData = mapOf([new Pair(CarpInputDataTypes.SEX, Sex.Male)]);
const response = await carpInstance.setParticipantData_CORE(
studyDeploymentId.stringRepresentation,
setParticipantData, // Argument of type 'Map<NamespacedId, Sex & { readonly name: "Male"; readonly ordinal: 0; }>' is not assignable to parameter of type 'Map<NamespacedId, Data | null>'.
inputByParticipantRole,
config
);
expect(response instanceof Ok).toBeTruthy();
}); ...and the wrapper setParticipantData_CORE = async (
studyDeploymentId: string,
data: HashMap<NamespacedId, Data | null>,
inputType: string | null,
config: AxiosRequestConfig
): Promise<ParticipantData> => {
try {
const participantDataRequest = new ParticipationServiceRequest.SetParticipantData(new UUID(studyDeploymentId), data, inputType); // Argument of type 'Map<NamespacedId, Data | null>' is not assignable to parameter of type 'Map<NamespacedId, Nullable<Data>>'.
const json: Json = DefaultSerializer;
const serializer = ParticipationServiceRequest.Serializer;
const serializedRequest = json.encodeToString(serializer, participantDataRequest);
const response = await this._instance.post('/api/participation-service', serializedRequest, config);
return Promise.resolve(response.data as ParticipantData);
} catch (error) {
return Promise.reject(unwrapError(error, 'setting participant data failed').value);
}
}; (Note that I've added the type errors where I see them) |
If this is still relevant ... I still can't see the problem you are running into:
I do, however, see that you are using Are you using the correct carp imports as per the example?
|
Nullable
is used in the generated TypeScript API, but not exported.@SlimShadyIAm ran into this and provided the following use case:
The text was updated successfully, but these errors were encountered: