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(schema): add type hints for runtime config #18652

Merged
merged 4 commits into from
Feb 6, 2023
Merged

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Jan 31, 2023

πŸ”— Linked issue

#18594 (comment)

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 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)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR adds type hints (within nuxt.config only, not within useRuntimeConfig) to advise on the way to override runtime config:

CleanShot 2023-01-31 at 22 58 22@2x

I would value some testing on this and improving the algorithm to make sure we are matching scule. (We might also move into scule itself if you like @pi0, and that way we could add more type tests there.)

BTW, I initially considered using https://github.com/sindresorhus/type-fest/blob/main/source/snake-case.d.ts but there were issues with it (e.g. baseURL and PascalCase both gave incorrect results) and I thought better to take a completely different approach.

▢️ TypeScript playground.

πŸ“ Checklist

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

@codesandbox
Copy link

codesandbox bot commented Jan 31, 2023

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@danielroe danielroe marked this pull request as ready for review January 31, 2023 23:19
@manniL
Copy link
Member

manniL commented Feb 1, 2023

Really nice DX πŸ”₯

@pi0
Copy link
Member

pi0 commented Feb 1, 2023

Since env handling logic is happening in Nitro, i think we could generate types also from nitro types. BTW really nice addition πŸ”₯

@pi0
Copy link
Member

pi0 commented Feb 1, 2023

For runtime consistency, we might also directly use scule (in build time) to generate precise types.

Copy link
Member Author

Indeed, it might be nice to add a facility to generate TSDoc comments via a callback for generateTypes from untyped, meaning we could annotate directly in the declarations we generate. That would be guaranteed to be accurate and would be a more natural way of providing the help.

@danielroe danielroe added the 3.x label Feb 1, 2023
@Baroshem
Copy link
Contributor

Baroshem commented Feb 2, 2023

This is a really great feature! Cant wait to see it in the new version of nuxt πŸ™‚

@danielroe
Copy link
Member Author

merging as a first step - moving to tsdoc is definitely better performance-wise but will need to be implemented in https://github.com/unjs/untyped.

@danielroe danielroe merged commit 01076d1 into main Feb 6, 2023
@danielroe danielroe deleted the feat/config-type-hints branch February 6, 2023 23:27
@danielroe danielroe mentioned this pull request Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants