-
-
Notifications
You must be signed in to change notification settings - Fork 687
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
Create or document how to use a TypeScript type for configuration schema #1004
Comments
The idea makes sense and I see how this could be useful! Thanks for the suggestion! If I were to add to this library, I would want to generate the types from the JSON schema because that already captures everything that's needed and it isn't necessary to duplicate information. After a very brief bit of research, these two packages seem to offer that capability:
But I also found the following package which seems to offer the same capability dynamically at runtime, thereby avoiding the need to generate/commit an artifact at all: If it works, my preference would be for something like the last one because it seems universally applicable and limits complexity to just those scenarios that need it (i.e., pay for play). |
I tried out json-schema-to-typescript but in the end I used quicktype, because it created a more readable output. I also looked at json-schema-to-ts, but there are multiple issues open mentioning performance issues, which don't surprise me, because it can be a lot of work for the TypeScript language server to handle the conversion of big json schemas at runtime:
Fortunately, because I implemented the TypeScript type generation using the existing json schema which is the same approach you prefer, I can make draft pull request pretty quickly. I just have to migrate the code I've already written:D |
The performance issues you reference above do not seem like they would be problematic in this scenario with a single/small schema and file. That said, there is an opportunity to improve the fidelity of the existing |
v0.32.0 |
Hi David 👋
What is your opinion on generating a TS type for the configuration?
Right now people using a
json
config file get autocompletion thanks to themarkdownlint-config-schema.json
, but it's not possible to get the same experience forjs
files.Prettier and tailwind for example has such a type exported, which can be used in config files.
Another thing that could be done, is to have a
defineConfig()
function like vite, nuxt or astro has.I've created a package as a POC (the generated type can be found here) so you can check out the idea, and whether you think it would be worth it to add this to the library.
The text was updated successfully, but these errors were encountered: