Conversation
… use with typescript
description?: never to DocumentedModuleReplacement for easier…|
I'm not sure this is right. Documented replacements can have their own URL. They just don't right now. But it was typed this way because some may need their own one day that isn't the same as the mapping URL. Don't have an example off the top of my head though |
|
This is description, not URL |
|
Sorry it also applies to the description 😅 It is possible we want a description on any given replacement. We just happen to not have any right now on documented ones. If we remove this, we're locking ourselves out of the option in future without a breaking change |
|
In that case we can add |
|
Actually now that I've looked properly, I'm a bit lost 😅 Documented replacements already don't have descriptions. So the types are already right, no? |
|
Yes, they don't, this just allows you to do this: And not have typescript complain And avoid having to do something like this Or this |
|
this was by design though since all consumers should be narrowing the tagged union really. having |
|
|
|
And the difference between |
|
i understand what it does - but it declares that the type has a property the value is i know this seems picky but i really believe this is just a workaround to avoid having to narrow the types properly. the current types are correct imo |
|
@bluwy @ghostdevv what do you think? |
|
Yes, By adding Also I want to note that |
|
we're not comparing // this
interface X {
prop?: never;
}
// is not the same as this
interface X {
// no prop at all
}the types are correct right now and are doing their job by making you narrow the union correctly. it may feel like a pain but the documented replacements don't have a description property at all. setting them to |
|
But why would you want to narrow the type for the description that is already optional on other types? |
|
Because documented replacements don't have a description. It isn't optional, they just don't have one at all. So you correctly have to narrow the type to ones which do have a description. This is just a workaround to avoid having to do the narrowing |
|
I would say this is actually a very common way to do this when dealing with type unions, for example |
|
What would be yours proposed solution? |
|
I’m JavaScript it doesn’t matter if property is undefined or it doesn’t exist |

🔗 Linked issue
📚 Description
Add
description?: nevertoDocumentedModuleReplacementfor easier use with typescriptThis is to avoid doing things like this:
https://github.com/npmx-dev/npmx.dev/blob/d80c709c30b41ac68bb91b6524fabe59477417d2/app/components/Package/Replacement.vue#L17-L19