#`Response` not well typed despite @types/bun installed

1 messages · Page 1 of 1 (latest)

wispy marlin
#

I keep getting Property 'json' does not exist on type 'Response'..

I've checked the whole internet about that issue, but I could only find a post here without a good answer. Response only seems to have .headers That's very annoying. Maybe I did something wrong with tsconfig?

async function fetchApi(url: string) {
    const response = await fetch(url);
    const result = await response.json();

    if (!response.ok) throw result;

    return result;
}
{
    "compilerOptions": {
        "rootDir": "./src",
        "outDir": "./dist",

        "lib": ["ESNext"],
        "target": "ESNext",
        "module": "Preserve",
        "moduleDetection": "force",

        "strict": true,
        "skipLibCheck": true,
        "noFallthroughCasesInSwitch": true,
        "noUncheckedIndexedAccess": true,

        "verbatimModuleSyntax": true,
        "isolatedModules": true
    },
    "exclude": ["./drizzle.config.ts"]
}
wet sluice
#

Try adding dom types too

#

Ie to lib

wispy marlin
# wet sluice Try adding dom types too

Yeah, I know that works, but I'm not in the web environment, why @types/bun doesn't take care of that to me, if fetch is available in the runtime? Why expose just fetch.headers?

#

thx for the reply btw

wet sluice
#

its because alot of things are defined in dom these days

#

TS is kinda funny

#

now that we are bringing apis that were browser only

wispy marlin
#

ok then! Thanks for your time and help!