-
Notifications
You must be signed in to change notification settings - Fork 71
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
include
in tsconfigDefaults
is overridden by index from original tsconfig.json
#226
Comments
this makes using |
Interesting thing, that is, it is exactly the opposite |
and one more thing |
So I've hit this issue before in jaredpalmer/tsdx#666 (comment), and per that issue, that's just how
I could write up a PR to do a shallow merge on just
Yes, that is how
Yep, that is how |
@agilgur5 thanks for response!
I have a trick in my pocket to handle this thing, but it looks noisy from the clean code perspective - just read My suggestion:
|
Defaults do not normally concatenate when overridden, they get overridden. And as I mentioned above, concatenation makes it impossible to override the default with a I think all of the options are confusing, I'm not sure I agree that any of these are the "best DX". A shallow merge is the closest thing to how |
@agilgur5 fine, then I can’t use either default or override at all. The case:
As you can see, there is no way to configure this properly. I should read tsconfig.json, get its "include" property and merge this into ['src', 'some.d.ts', 'another.d.ts', 'config.d.ts']. Meanwhile, I figured out what the problem is. Others may not figure it out and spend their precious time to figure out what doesn’t work for them. I see it so that if we leave everything as it is, then I can’t use it, it’s a black box for me because I can't guarantee anything. I have no problem gathering the opinions of others who are involved in this. |
I mean, you're giving your own preference here while I've given multiple different options already. I've already said twice why that preference, concatenation, is fundamentally broken, similarly unintuitive, and not at all "transparent". To repeat, concatenation isn't just a breaking change, it literally makes overriding things impossible. I'll repeat again, impossible. Again, a "default" that can't be overridden isn't a default, that's a requirement. Changing a "default" to a requirement doesn't make sense and is wrong behavior. You can override the deep merge right now, you cannot override a concatenation. Making an existing use-case impossible doesn't make sense. I've also already given an alternative option twice already that isn't fundamentally broken, which is a shallow merge. I'll repeat again, you can use a shallow merge to solve this too. I have contributed here to fix bugs before (I know it's Not to mention, this can be resolved without breaking changes -- you can add a new option for To say that there is only one option and it must be breaking and must make existing use-case impossible is simply not true. |
I think we'll have to break things no matter what we do here. To make it behave according to the spirit of documentation and property names it should do basically this:
Will that cover all the cases we want to support (after users make appropriate changes), or am I missing something? |
@ezolenko sounds amazing and makes a lot of sense to use |
@ezolenko I'm not sure why you have to break things? I've given options that are non-breaking already. I'm not sure how what you've listed reflects "the spirit of the documentation and property names" because the docs say:
It says "merged", "replaced", and "deep merge", all of which mean replace and override the default. There is a single reference to "concatenated" that is different from the rest, but a deep merge does not in fact concatenate. 5 references say one thing and a 6th is incorrect. To me, that sounds like the 6th reference that is incorrect should be corrected, not the 5 correct ones changed to the incorrect 6th.
_.defaults({ a: ['a'] }, { a: ['b', 'c'] });
// => {a: ['a']}
_.defaultsDeep({ a: ['a'] }, { a: ['b', 'c'] });
// => {a: ['a', 'c']} If you'd like to add a concatenation option, I think that should be a separate configuration, because it does not match 5+ references in the docs either and because that is simply not what defaults means, neither in definition nor in usage in any library. It also breaks the symmetry with
I expect defaults to be overridden, that is the definition, making them concatenate instead is incredibly unintuitive. A deep merge may be unintuitive for arrays, but the docs plainly say it is a deep merge and it was quick for me to understand that was the issue because indexes were relevant. I also did not report a bug because that is what the docs say and even link to deep merge -- that's intended behavior, not a bug. As I've said, shallow merging the arrays may be more intuitive, as that is how So concatenate doesn't match 5+ references in the docs already, the definition of merge, the definition of defaults, nor And as I've said multiple times, making it a very unintuitive concatenation instead of overriding makes certain uses cases impossible. Here is TSDX's usage: The intent is that if you add your own If you were to change that to concatenate, then the user now has no way of overriding our default Not sure why I'm talking like a broken record here repeating existing definitions and existing usage in the whole ecosystem. |
This configuration can be disrupted easily, and I don’t understand why this is not obvious to you. I don't want my library to be fragile, and that's why I created this issue. the funny thing is that @ezolenko and I have already proposed a solution that will help protect, including TSDX, but you still resist.
I do agree with default behavior. It makes sense to apply config default only when tsconfig does not have corresponding properties, but this gives rise to many other, more complex problems, the solution of which will overcomplicate API.
The question is, why should the user have access to what the author of the library forbade? We must have leverage tsconfig configuration that cannot be overwritten, but at the same time, we need to give the opportunity to expand our presets. And this is the main point. The solution lies only in the design of the new API. |
You're taking words out of my mouth that I didn't remotely say. I did not say it can't and nor did I say it wasn't fragile. I just said that your solution doesn't match any existing definition nor existing usage in the whole ecosystem of defaults nor the docs themselves. Breaking the entire definition of default is clearly wrong behavior. Please don't take words out of my mouth. I've repeated myself numerous times, please read the actual things I wrote instead of making things up.
Yea you can add a A default =\= concatenation. That is not my opinion, that is the definition. |
This comment was marked as abuse.
This comment was marked as abuse.
Well I didn't take words out of people's mouths, not read their actual words, make things up, attack the character of a contributor, provide 0 links, give 0 alternatives, and only consider a single option and no others, that was you. If you'd like to attack a contributor that is just trying to be helpful and is giving real definitions, real use-cases, and real alternatives, I guess that's your perogative 🤷 |
I think I was under impression that lodash merge would in fact merge arrays (interleave them or something) when I was writing that part. Or I wasn't even paying attention to what happens to arrays. Since it apparently overwrites contents of arrays using indexes as element names (right? is this javascript thing about arrays originally not being true arrays, but instead being dictionaries that happened to have numbers for keys?), our documentation at the moment lies. Ideally, default/main/override tsconfigs options should allow for customization of all parameters, both scalar values and arrays, in the same unsurprising way. Lodash way of replacing array elements based on index has one major drawback -- you can't create literal sparse arrays (maybe padding array with bunch of Even with literal sparse arrays, replacing elements based on index is way too fragile. On the other hand, concatenating is surprising, if nothing else usually behaves this way. And alone doesn't allow removal of previous values. Switching between concatenating and replacing as I proposed originally is doubly surprising. Changing both merges to replace arrays wholesale as @agilgur5 proposed is probably a least surprising option, it will allow removing values, at the expense of having to repeat values one wants to keep. It is still a breaking change though and people will have to rewrite their configs for that (see https://xkcd.com/1172/). We can either change behavior of those options or create a new set and deprecate existing options with a warning. (sorry if I missed an important point somewhere, I only skimped the whole thread) |
@ezolenko I see the next way Let's look at the situation and motivation: What does this tell us? Let's start from semantics: As I said before
We can redesign this thing completely. My suggestions are:
I just trying to avoid the third additional rpt2 option, because it will complicate this API by at least 50% and any developer will cease to understand this. |
This comment was marked as abuse.
This comment was marked as abuse.
@maktarsis how in your approach would dev be able to remove include or exclude entries from tsconfig? The scenario is: you have a tsconfig.json that is used elsewhere, you want to use it in rollup without touching json itself, but you want to remove a line from excludes array for some reason. |
@ezolenko I understood your though. Naturally, as discussed above, this will not be possible. I still do not see situations when we need to rewrite the exclude. If you want to have this possibility in any case, then you need to provide an additional API for concatenation. |
We need both, adding something to array that is not there and removing something from it. With shallow merge both adding and removing are done by replicating whole array (with changes) at higher level. Not very convenient, but usable. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
Noting here that shallow merge has been previously mentioned in this repo a few times: #86 (which mentions TS's shallow merging behavior as I did here), #72 (comment), and #208 (comment) |
tsconfigDefaults
is overridden by index from original tsconfig.json
The incorrect reference to concatenation in the docs that I wrote of above has now been fixed by #314. As such, what remains of this issue duplicates older issues as mentioned in my previous comment, namely #86. The eventual change will be to implement #86 and use shallow merges on arrays (arrays just get replaced, effectively). |
Seems like this also duplicated #196, where both OP and ezolenko stated that the issue was due to |
tsconfigDefaults
is overridden by index from original tsconfig.jsoninclude
in tsconfigDefaults
is overridden by index from original tsconfig.json
#39 seems to be the original issue that everything duplicates. #39 (comment) mentions |
#53 is the original issue from which
It was also written to support Think that is a fairly decisive nail in the coffin here. |
What happens and why it is wrong
That bug is really weird.
At some point, I started getting a weird error caused by
include
option oftypescript2
config and projecttsconfig.json
.I even stopped understanding how it works, does it override or concatenate, or what?
then, I decided that I need to debug this array to check what finally gets there
My
rollup-plugin-typescript2
config:My
tsconfig.json
config:The result is
As I said before, I started debugging this it gives some kind of awkward result every time.
In fact, it does not concatenate these properties, but replaces the values in the index cell, which simply takes by surprise and worsens developer experience.
What I mean:
it takes 0 the index of the array of my
tsconfig
and puts it instead of the value under the 0 index oftypescript2
config.Example 1:
Example 2:
Example 3:
It is completely annoying
Environment
I'm not sure this is relevant, but
Node: 13.13.0
OS: macOS Catalina 10.15.4
Versions
The text was updated successfully, but these errors were encountered: