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

fix(templates): type narrowing getGlobal #10635

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions templates/website/src/utilities/getGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { unstable_cache } from 'next/cache'

type Global = keyof Config['globals']

async function getGlobal(slug: Global, depth = 0) {
async function getGlobal<T extends Global>(slug: T, depth = 0) {
const payload = await getPayload({ config: configPromise })

const global = await payload.findGlobal({
Expand All @@ -20,7 +20,7 @@ async function getGlobal(slug: Global, depth = 0) {
/**
* Returns a unstable_cache function mapped with the cache tag for the slug
*/
export const getCachedGlobal = (slug: Global, depth = 0) =>
export const getCachedGlobal = <T extends Global>(slug: T, depth = 0) =>
unstable_cache(async () => getGlobal(slug, depth), [slug], {
tags: [`global_${slug}`],
})