opral / inlang-paraglide-js

Tree-shakable i18n library build on the inlang ecosystem.
https://inlang.com/m/gerre34r/library-inlang-paraglideJs
42 stars 0 forks source link

`paraglide-next` redirect() does not have return-type `never` #29

Open herkulano opened 7 months ago

herkulano commented 7 months ago

Problem

Internally nextjs throws an error on redirect() so Typescript infers that there's no return after redirect().

Using paraglide-js-adapter-next redirect() this is no longer the case.

If the server action/route/rsc ends with a redirect Typescript should understand that redirect throws an error and ignore the code below it:

  ...
  redirect(`somewhere`)
  return {error: "this should not run" }
}

Expected behavior

No response

Reproduction

Use paraglide-js-adapter-next redirect() in a route/server action/rsc

  ...
  redirect(`somewhere`)
  return {error: "this should not run" }
}

Other information

No response

LorisSigrist commented 7 months ago

TIL Typescript treats

const fn1 = () : never => {}
// and
function fn2(): never {}

differently :)

Update: It seems like this is unfixable at the moment because it is blocked by microsoft/TypeScript#56049. I'll look if we can adjust the API in order to sidestep this

linear[bot] commented 6 months ago

PARJS-32 [bug] in paraglide-js-adapter-next redirect() type the throw is not inferred