0

I have a firebase cloud function in my web application which is mentioned below

 saveUserData (req: express.Request, res: express.Response) {
    const params = req.query.data;
    const typeof(params);

    return res.status(200).send('Inside user data');
}

here the typeof(params) is getting as object.

The value of params is

{ first_name: 'vij',email: '[email protected]',mobile_number: '9088888000',address: 'addad,dada'}

I want to get the value of mobile number, I have tried params.mobile_number but it's not working.

1
  • Hello, can you show how do you exactly call this Cloud Function? Commented May 5, 2020 at 10:26

2 Answers 2

1

I was able to access the json using interface

  interface userObj {
         first_name: string;
         email: string;
         mobile_number: string;
         address: string;
         city: string;
         gstin: string;
        }
    let obj: userObj = JSON.parse(JSON.stringify(req.query.data));
    console.log(obj.first_name);
Sign up to request clarification or add additional context in comments.

Comments

0

There's a comma missing between the value from "mobile_number" and the key "address". Could be that maybe?

If not maybe try params['mobile_number']

5 Comments

I missed the comma while typing here, Have edited that now. I tried params['mobile_number'] then I got the error Element implicitly has an 'any' type because expression of type '"mobile_number"' can't be used to index type 'string | Query | (string | Query)[]'. Property 'mobile_number' does not exist on type 'string | Query | (string | Query)[]'. const params: string | Query | (string | Query)[]
where are u using params['mobile_number']?
I tried console.log(params.mobile_number) and console.log(params['mobile_number']), they both are not working,
Edit your question to show where u are trying to get the value since it doesnt show in your initial question
So far I've tried to replicate this, this looks like it is returning a dictionary type, this means this should be able to be accessed as if it was a dictionary. Is this method showing you the error "Element implicitly has an 'any' type because expression of type '"mobile_number"' can't be..."?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.