From 03fbd30d1ca463729cb956a9557e3cf4134a6338 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 25 Jul 2023 17:09:41 +0100 Subject: [PATCH] fix(nuxt): allow `validate` return typing to be either error or boolean (#22323) --- packages/nuxt/src/pages/runtime/composables.ts | 2 +- test/fixtures/basic-types/types.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/pages/runtime/composables.ts b/packages/nuxt/src/pages/runtime/composables.ts index 78ff8e1454..3fde4c6ccb 100644 --- a/packages/nuxt/src/pages/runtime/composables.ts +++ b/packages/nuxt/src/pages/runtime/composables.ts @@ -14,7 +14,7 @@ export interface PageMeta { * statusCode/statusMessage to respond immediately with an error (other matches * will not be checked). */ - validate?: (route: RouteLocationNormalized) => boolean | Promise | Partial | Promise> + validate?: (route: RouteLocationNormalized) => boolean | Partial | Promise> /** * Where to redirect if the route is directly matched. The redirection happens * before any navigation guard and triggers a new navigation with the new diff --git a/test/fixtures/basic-types/types.ts b/test/fixtures/basic-types/types.ts index 74d9868a90..c0b3f28d55 100644 --- a/test/fixtures/basic-types/types.ts +++ b/test/fixtures/basic-types/types.ts @@ -116,6 +116,21 @@ describe('middleware', () => { abortNavigation(true) }, { global: true }) }) + it('handles return types of validate', () => { + definePageMeta({ + validate: async () => { + await new Promise(resolve => setTimeout(resolve, 1000)) + // eslint-disable-next-line + if (0) { + return createError({ + statusCode: 404, + statusMessage: 'resource-type-not-found' + }) + } + return true + } + }) + }) }) describe('typed router integration', () => {