In my Angular application using Typescript, I have the following setup:
userId?: number;
token?: string;
constructor(private route: ActivatedRoute) {
this.route.queryParamMap.subscribe(
(value: ParamMap) => {
this.userId = value.has('userId') ? +!value.get('userId') : undefined;
this.token = value.has('token') ? value.get('token') : undefined;
}
);
}
However, an error occurs when attempting to define token
:
Type 'string | null | undefined' is not assignable to type 'string | undefined'.
Type 'null' is not assignable to type 'string | undefined'.
What steps can I take to resolve this and achieve the same functionality as with setting userId
?