Can I specify how to handle an error in a NodeCallback<any,any>?

195 Views Asked by At

I am learning React and Typescript and working on a React, Typescript, AWS Amplify Cognito project and trying to implement this method:

public confirmRegistration(
 code: string,
 forceAliasCreation: boolean,
 callback: NodeCallback<any, any>,
 clientMetadata?: ClientMetadata
): void;

The types for the callback are both any. What are the two parts of the callback for? Can I specify that one part of the callback is for if there is an error, and one part is for if there is success?

I'm familiar with this sort of callback where in the code, when I call .updateAttributes, I specify what to do in the case of Error or in the case of result (string):

public updateAttributes(
 attributes: (CognitoUserAttribute | ICognitoUserAttributeData)[],
 callback: NodeCallback<Error, string>,
 clientMetadata?: ClientMetadata
): void;
1

There are 1 best solutions below

0
On BEST ANSWER

The callback function's two parameters are (err, result). From https://www.npmjs.com/package/amazon-cognito-identity-js use case 2:

cognitoUser.confirmRegistration('123456', true, function(err, result) {
    if (err) {
        alert(err.message || JSON.stringify(err));
        return;
    }
    console.log('call result: ' + result);
});

I confirmed by console logging in a working app, and result is type string, and has value 'SUCCESS' when the confirmation worked.