-
Notifications
You must be signed in to change notification settings - Fork 706
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
Allow overriding tsconfig options from within tsconfig.json #1891
Conversation
- In anticipation of TypeStrong/typedoc#1891
I'm not entirely against this, though I'd say said library is bad.. shouldn't be shipping TS. Putting compiler options in This should also be configurable within typedoc.json, which is another reason for using a separate name. |
Thank You for Your reply and insights .. and I do concur. Furthermore, I've noticed, that the I'm currently also investigating the possibility of implementing such overrides via a plugin, but this seems a little off, as configuration parsing should be (IMO) implemented within the core of an application. Do You have any thoughts on this? 🤔 |
I've looked through the sources again and I think I may have found a quite minimal, yet better way of implementing the discussed feature. Furthermore, I thought it might be desirable to let users also pass such overrides via CLI, so I went ahead and implemented JSON parsing, iff the I also thought of implementing some test case(s) for this feature, but I wasn't sure where to put such a test case, as the If You have any issues with the code style, logic or missing test cases, please let me know! |
I think I'd rather not do the JSON parsing - it makes the logic more complicated and I don't see anyone ever using it. None of the other complex objects do it either. (Also, if keeping it, the validate function isn't sufficient since it doesn't actually do checks on the parsed value) Other than that, I like it! The default-options.ts file is actually the appropriate place to add tests - it's meant to test validation for our default options (e.g. those not added by plugins) |
Hey, sorry for not getting back to You sooner. As You suggested, I threw out the JSON parsing and kept the remaining changes as simple and small as possible. Regarding the test case, it's currently just a duplication of the As always, if You have any issues with the code(style), please let me know and I'll try to address these. Thank You and kind regards! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
What this pull request contains
What this pull request does
This pull request implements a new TypeDoc option:
compilerOptions
. By employing this option, one may selectively override some fields of thetsconfig.json
used by TypeDoc.An example
Let's take the following (trimmed-down)
tsconfig.json
:With this configuration, TypeScript
strict
ness will be enforced throughout the codebase. But when runningtypedoc
, the strictness will be dropped by patching the originalcompilerOptions
with the providedtypedocOptions.compilerOptions
.Motivation
When working with abstracted TypeScript tooling (e.g. not using
tsc
directly, butrollup-plugin-typescript2
), the handling and transpilation of source code within a project may differ between those abstracted tools andtsc
(and therefore TypeDoc). Allowing the user to override parts of thetsconfig.json
for TypeDoc from within the sametsconfig.json
seems to be a quite well scoped way to tackle these differences (without throwing yet anothertsconfig.typedoc.json
into the project and polluting the scene further).Real world motivation
As an anecdotic example, I recently added a library to a project I'm currently working on and everything went well. Until I tried to build the documentation for said project. ... Because the libary distributes TypeScript source files instead of declaration files (
.ts
instead of.d.ts
) the--skipLibCheck
option of TypeScript does not catch those files andtsc
keeps insisting on type-checking those sources within thenode_modules
folder, which throw errors. And as the library was built without having the TypeScriptstrict
-mode enabled, I now cannot gettsc
to run on my project anymore, whilerollup-plugin-typescript2
happily transpiles my codebase and creates valid TypeScript definitions. To stress this, there are many, many examples of other people having the same issue and trying to get the TypeScript maintainers to implement a way around such behavior:skipLibCheck: true
is ignored when package'stypes
field points to a.ts
file (not a.d.ts
declaration file) microsoft/TypeScript#41883Meanwhile, Deno even implemented a CLI flag for exactly this.
Full disclosure
I know, I know, I could just create something like
tsconfig.typedoc.json
and manually override my desired preferences within this extending TypeScript configuration file. But, as stated above, I really don't like to clutter up my repository with "unnecessary" files. And to me it feels like a good practice to have the TypeScript configuration, thetypedocOptions
and thecompilerOptions
overrides all in one place: A singletsconfig.json
! 😄