next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

transform SessionContextValue to tagged union type

Open casheeeewnuts opened this issue 2 years ago • 2 comments

☕️ Reasoning

Currently SessionContextValue type has a problem that is TSC cannot infer type correctly.

In detail, TSC cannot narrowing to { data: Session; status: "authenticated" } by comparing "status" field.

sample code@TS Playground

In code, func1 has a problem that session.data cannot assignable to string even through eliminated possibility data.status is "unauthenticated" or "loading"

🧢 Checklist

  • [ ] Documentation
  • [x] Tests
  • [x] Ready to be merged

🎫 Affected issues

Please scout and link issues that might be solved by this PR.

Fixes: INSERT_ISSUE_LINK_HERE

📌 Resources

casheeeewnuts avatar Sep 16 '22 11:09 casheeeewnuts

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
next-auth ⬜️ Ignored (Inspect) Sep 16, 2022 at 11:39AM (UTC)

vercel[bot] avatar Sep 16 '22 11:09 vercel[bot]

Thanks for the PR! 🙌 But I think the current union type is good enough. Any reasons why you are not checking for "authenticated" status directly? That'll give you the correct session type.

ThangHuuVu avatar Sep 17 '22 11:09 ThangHuuVu