1
I’m using a library jsonwebtoken, defining the type of return of a callback as object | undefined
. I need to use this object to access a specific property, but I’m not getting it.
verify('', '', (err, data) => {
if (err) {
// Handle Error
throw new Error(err);
}
// Generate the new acessToken
doSomething(data?.property) // Property doesn't exists on type object
doSomething(data) // data is probably undefined
});
I couldn’t figure out how to deal with this type of error. Below follows an excerpt from the definition of types from the library in question:
export type VerifyCallback = (
err: VerifyErrors | null,
decoded: object | undefined,
) => void;
Thank you so much for the help. I was not yet aware of the assertions of type, I found quite useful for this case.
– Goufix