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

feat: generate types for runtime config #2306

Merged
merged 4 commits into from
Apr 3, 2024

Conversation

BlankParticle
Copy link
Contributor

πŸ”— Linked issue

#1706

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

I have add untyped as a dependency and now nitro can generate types for useRuntimeConfig() just like Nuxt does.
It would be helpful for users to have types for useRuntimeConfig() which helps a lot while using nitro standalone.

For now I have utilized nitro-config.d.ts to keep the types in, please let me know If you would want to change the file.

Fixes #1706

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Copy link
Collaborator

It would maybe be nice to allow this to be disabled, in case there's an issue with types conflicting between auto-generated nuxt + nitro types.

@BlankParticle
Copy link
Contributor Author

It would maybe be nice to allow this to be disabled, in case there's an issue with types conflicting between auto-generated nuxt + nitro types.

I was thinking about that, but what condition do I check against to disable it?

Copy link
Collaborator

You would add a nitro option:

nitro/src/options.ts

Lines 121 to 128 in d12aae1

// Advanced
typescript: {
strict: false,
generateTsConfig: true,
tsconfigPath: "types/tsconfig.json",
internalPaths: false,
tsConfig: {},
},

@pi0
Copy link
Member

pi0 commented Mar 25, 2024

in case there's an issue with types conflicting between auto-generated nuxt + nitro types.

We can disable when framework usage is detected. What inconsistency can happen?

Copy link
Collaborator

Ideally we wouldn't disable - just wanted a way to bail out if there was an issue. Sometimes if you have multiple augmentations of the same underlying property there can be failure, and I haven't yet tested this implementation. (Which might be a better first step! πŸ˜†)

@pi0 pi0 changed the title feat: generate types for useRuntimeConfig like nuxt feat: generate types for runtime config Mar 26, 2024
@danielroe
Copy link
Collaborator

Might be nice to add a type test to the fixture to verify that these types do in fact type the runtimeConfig. πŸ™

@BlankParticle
Copy link
Contributor Author

BlankParticle commented Mar 26, 2024

Might be nice to add a type test to the fixture to verify that these types do in fact type the runtimeConfig. πŸ™

Ok, I will add tests too
Edit: I just checked out the tests and it looks like all tests call a given nitro api endpoint to test against.
How do you want me to test this?

@BlankParticle
Copy link
Contributor Author

I was looking into test the types but I don't see a good way to do so, any suggestions?

@pi0 pi0 merged commit ebd27cc into nitrojs:main Apr 3, 2024
4 checks passed
@BlankParticle BlankParticle deleted the feat/generate-runtime-types branch April 3, 2024 11:23
@pi0 pi0 mentioned this pull request Jun 13, 2024
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

Successfully merging this pull request may close these issues.

Automatically generate runtime config types from nitro.config the same as Nuxt
3 participants