Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why not update
ECallableOrMethods
if extends null or undefined and returnnever
(or possibly aRecord<PropertyKey, () => Promise<never>>
)? That would model more closely what is actually going on, where it's the action of using the result ofE()
that is invalid, not using E itself.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.
I'll look into it and see whether the feedback is better. I take it the change wouldn't affect what actually passes typecheck.
Do you have the same feedback for the
get()
change?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.
I guess the only difference would be that
const p = E(Promise.resolve(null))
is entirely valid, but thatp.foo()
is the operation that is type invalid (However it is runtime valid, just results in a rejected promise (hence theRecord<PropertyKey, () => Promise<never>>
suggestion).I think
E.get()
should be similar yes.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.
The
never
is perhaps more accurate, but I wonder if constraining the input is more useful. Here's the error message with the PR version:Basically it's saying, "if you're trying to use a method then the argument has to be defined".
Using
never
gives this feedback,which doesn't give the user much clue why or how to remedy it.
The
never
is more sound than the generic constraint in thatE(undefined)
would error in TS and not in runtime (is that true?). Though are their valid cases forE(undefined)
or evenE(Promise<undefined>)
? If those aren't runtime errors now I wonder if they should be. Though I guess that gets back into the nature of the proxy.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.
I think where it matters most if for
E(Promise<SomeRemotable | undefined>)
. For anything where the target is awaited first, the author should do a local check first. Maybe we could have the best of both worlds by doingextends {}
and have the second check inECallableOrMethods
?