I have a function:
export const createTokenUsingOktaData = async (
requestBaseUrl: string,
oktaAuthorizationCode: string
) => {
try {
const { token } = await fetchOktaTokens(requestBaseUrl, oktaAuthorizationCode)
return [308, { token }]
} catch (err) {
return [401, { message: (err as Error).message }]
}
}
and an api that is trying to use that function:
router.get('/v1/auth/callback', validate(authCallbackSchema), async (req, _res) => {
const authorizationCode = String(req.query.code)
const protocol = req.get('x-forwarded-proto')?.includes('https') ? 'https' : 'http'
const baseUrl = `${protocol}://${req.get('host')}`
const [code, result] = await createTokenUsingOktaData(baseUrl, authorizationCode)
E if (result.token) { // E: Property 'token' does not exist on type 'number | { token: string; } | { message: string; }'. Property 'token' does not exist on type 'number'.
Why in the world does typescript think result is possibly a number???