0

I got the following code and it gives me error Type 'string | null' is not assignable to type 'string'. Type 'null' is not assignable to type 'string'.

this.userId = authInformation.userId;

So I'm trying to check if authInformation.userId returns null and If it's null, do nothing, if it's not null this.userId should be set to authInformation.userId. And it still has an error and I don't know what's the error.

const usertypecheck = authInformation.userId;
this.userId = usertypecheck !==null ? "" : usertypecheck;

1 Answer 1

1

You are doing it wrong, reverse the logic here from ,

this.userId = usertypecheck !==null ? "" : usertypecheck;

to

this.userId = usertypecheck === null ? "" : usertypecheck;

That should solve the problem.

Sign up to request clarification or add additional context in comments.

Comments

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.