nuxt / nuxt

The Intuitive Vue Framework.
https://nuxt.com
MIT License
54.28k stars 4.96k forks source link

Type `LayoutKey` is not always defined #24222

Open Barbapapazes opened 10 months ago

Barbapapazes commented 10 months ago

Environment

/

Reproduction

Use a simple nuxt starter, without the pages directory nor layouts. start your project and in the .nuxt/types, there is not layouts.d.ts.

Describe the bug

When you use the import type { LayoutKey } from '#build/types/layouts' in order to type a something in a module, you expect to have this all the time because end-user could not have enabled thepages` directory and there is no way to know that.

I suggest to have the LayoutKey set to undefined.

Additional context

No response

Logs

No response

danielroe commented 10 months ago

Ideally this is not meant to be imported directly but accessed via PageMeta['layout'], but I'm willing to consider some other options here for DX. (I think it shouldn't be named LayoutKey if it's a public API, but there might be merit in exporting a type with all possible layout names...)