Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

329
Views
Typescript: promise.then() still returning a promise

I have a function that returns a promise. I then want to get the value of said function, but when I call promise.then( result => result ) I'm still getting a promise.

The below code returns the following error:

error: Type 'Promise<void | SunriseSunsetResultsType>' is not assignable to type 'string'.

import {
    HebCalResponseType, 
    OpenweatherResponseType,
    SunriseSunsetResultsType,
    SunriseSunsetResponseType
} from "../src/app";

const lat: number = 40.8915;
const lng: number = -74.0119;
const date: string = "2012-11-09";
const url: string = `https://api.sunrise-sunset.org/json?lat=${lat}&lng=${lng}&date=${date}&formatted=0`;

async function request(url: string): Promise<HebCalResponseType | OpenweatherResponseType | SunriseSunsetResponseType> {
    // Make a request of one of our three external apis
    const jsonResult: (HebCalResponseType | OpenweatherResponseType | SunriseSunsetResponseType) = (await fetch(url)).json();
    return jsonResult;
};

const promise: Promise<HebCalResponseType | OpenweatherResponseType | SunriseSunsetResponseType> = request(url); 
const msg: Promise<SunriseSunsetResultsType | void> =  promise
    .then(response => { (response as SunriseSunsetResponseType).results; }, 
        error => { throw `failed to load ${url} with error ${error}`; })
const test: HTMLElement = document.getElementById("source");
test.innerText = msg;
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!