#[SOLVED] Locals type-safety ain't working

5 messages · Page 1 of 1 (latest)

burnt spear
#
import type { User } from "@models/user";

/** @link <https://docs.astro.build/en/guides/typescript/#using-imports> */
declare namespace App {
    interface Locals {
        user?: User;
    }
}
---
const name = Astro.locals.user?.name;
---

User is being displayed inside VSCode as unknown?

trail oyster
#
/** @link <https://docs.astro.build/en/guides/typescript/#using-imports> */
declare namespace App {
    interface Locals {
        user?: import("@models/user").User;
    }
}

That should fix it

#

The docs section linked in there explains why you need inline imports

tough ravenBOT
#
If your issue is resolved, please help by doing the following two steps:
  1. From the ellipses (3-dot menu) in the top-right corner of the post (not the first message), edit the tags to include the Solved tag.
  2. From the same ellipses, select Close Post.
    Your post will still be available to search and can be re-opened simply by replying in it. Closing a post moves it down with older posts, so we can more easily focus on issues that still need to be resolved.
    Thank you for your help!
burnt spear
#

Sorry didn't read it carefully enough although I added the JSdoc link ref, it's fixed now.
Thanks 😄