type checking custom AppConfig entries
https://nuxt.com/docs/guide/directory-structure/app-config#app-config-output tells to use
declare module
to extend nuxt/schema
's AppConfigInput
on the index.d.ts
file... where is that?
I tried in src/composables/useFoo.ts
instead, src/composables/index.d.ts
and src/index.d.ts
, but neither validates my custom entry in app.config.ts
. where should this be done I? what if there are other declarations and exports on the same file?Nuxt
app.config.ts Β· Nuxt Directory Structure
Expose reactive configuration within your application with the App Config file.
28 Replies
I'm currently exporting a composable to access it, validating the type, but it feels wrong.
but the actual type of
myThing
will be inferred from the data on app.config.ts
instead of from the extended type.
the
index.d.ts
is a file you create at the root of your projectthanks. can I use types from composables there?
if it doesn't augment the types generated by nuxt, you'd rather want to export your types from the types folder
thanks
welcome
I'm exporting the config type from
src/types/index.ts
and the composable is happy.
then I created the following index.d.ts
on the same directory of nuxt.config.ts
:
but on src/app.config.ts
the field is still inferred and accepting anything π¦
any idea what am I missing to get AppConfigInput
extended?Is
app.config.ts
not supposed to be at the root level?
Same level as nuxt.config.ts
Nuxt
app.config.ts Β· Nuxt Directory Structure
Expose reactive configuration within your application with the App Config file.
thanks, still not type-checking though π«€
Care to share screenshots of your directory tree,
index.d.ts
file, and app.config.ts
file?
Before that try restarting the dev server and see if it worksa critical bit that can be a cause of confusion is
srcDir
on nuxt.config.ts
, but src/app.config.ts
data is being loaded so that place is correct.
my tree looks like:
the root level index.d.ts
contains
and src/app.config.ts
Having the export statement at the top of the file could be the problem
I had it at the bottom, just moved it when looking at the files generated on
.nuxt/
. I'll move it back to the bottom. same result btwOkay. Iβm not sure where nuxt looks to find the
index.d.ts
file, but if your srcDir
is set to src
Iβm guessing the index.d.ts
file would need to be in that folder.tried both π¦
π€
Can you create a repro on stackblitz for instance so I check it out?
GitHub
GitHub - amery/go-nuxt-template at issue-app.config.ts
Contribute to amery/go-nuxt-template development by creating an account on GitHub.
issue-app.config.ts
branch, web/client
subdirectory
https://stackblitz.com/~/github.com/amery/go-nuxt-template@mercs600, here
I was using
AppConfigInput
initially π where did you place the file? root or srcDir?
like this? @pyplacca
app.config.ts
still thinks myThing.something is boolean, ignoring the type πAnywhere works. Take note of the module name
@nuxt/schema
@Alejandro Meryπthe
@
!!!!
thank you so much @pyplaccaThe previous code would work in most cases, but this is a weird behaviour caused by the nuxt ui module
Glad I could help, @Alejandro Mery
I just noticed checking doesn't work on the LAST entry. is this the weird behaviour you mentioned?
Which last entry?
my fault, it caught a previous typo and didn't continue checking
thanks again. I'm closing this now π
Alright. It was a pleasure helping out. I learnt a couple of new stuff myself π