Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 BUG: Variables used in return in .astro files are ignored by TypeScript. '<variable>' is declared but its value is never read. ts(6133) #494

Closed
drevantonder opened this issue Mar 13, 2023 · 2 comments

Comments

@drevantonder
Copy link

Describe the Bug

Astro's Typescript appears to be ignoring variables in the return value e.g. return redirect() in .astro files.

When using astro/tsconfigs/strictest the variables used in the return value the variables are highlighted with ts(6133): '<variable>' is declared but its value is never read.


I came across this issue whilst using a helper for my auth in .astro files, like so:

import { requiresSession } from "@/server/auth";

const { session, redirect } = await requiresSession(Astro);
if (!session) return redirect();

Where redirect is a function that returns Astro.redirect()

Steps to Reproduce

See my reproduction repo or follow below instructions.

  1. npm create astro@latest
    1. Empty
    2. Typscript @ Strictest (Strict and base don't highlight, but still complain)
  2. Install dependencies npm i
  3. Open pages/index.astro and add (I'm using Math.random to get around other TS errors)
---
+const redirect = () => Astro.redirect('/')
+if (Math.random() > 0) return redirect()
---

<html lang="en">
	<head>
		<meta charset="utf-8" />
		<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
		<meta name="viewport" content="width=device-width" />
		<meta name="generator" content={Astro.generator} />
		<title>Astro</title>
	</head>
	<body>
		<h1>Astro</h1>
	</body>
</html>
  1. TypeScript will highlight redirect with 'redirect' is declared but its value is never read.
@Princesseuh
Copy link
Member

Closing as a duplicate of #476

(It's the same underlying issue)

@drevantonder
Copy link
Author

Thanks! Yes, that'd be the same. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants