-
Notifications
You must be signed in to change notification settings - Fork 514
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
feat: add feature
RPC
#2719
feat: add feature
RPC
#2719
Conversation
export interface FeatureAllRequest extends BaseRequest { | ||
command: 'feature' | ||
|
||
feature?: never |
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.
feature?: never |
Can we remove this line?
I've seen never
used in the context of infeasible control flows. Why do we need to state the absence of a field in an interface?
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.
It's necessary to distinguish the types. One weirdness about TS types is that you can add on extra fields and it'll still be that type. So this is still a valid FeatureAllRequest
object according to TS without this field:
{
command: 'feature'
feature: 'something'
}
Adding the never
is needed to ensure that this isn't actually a valid FeatureAllRequest
type.
The ?
is needed because for some reason you get errors for 'feature' field not included
in the FeatureAllRequest
type if you don't have it.
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.
cc @justinr1234, our local expert on TS types
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.
Will look
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.
An example in our codebase:
xrpl.js/packages/xrpl/src/models/ledger/BaseLedgerEntry.ts
Lines 18 to 27 in 7e733c4
export interface MissingPreviousTxnID { | |
/** | |
* This field is missing on this object but is present on most other returned objects. | |
*/ | |
PreviousTxnID: never | |
/** | |
* This field is missing on this object but is present on most other returned objects. | |
*/ | |
PreviousTxnLgrSeq: never | |
} |
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.
yes, I did come across other examples in the codebase
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 only saw control-flow related examples in the Typescript docs website: https://www.typescriptlang.org/docs/handbook/2/functions.html#never
It just feels strange that we are listing non-existent variables in the interface. But I get the rationale as a work-around to typescript's type inference.
This is not a strong objection, but it's nice to not have to do this
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 agree that it's kind of ugly, but I think it's necessary in TypeScript's typing system.
High Level Overview of Change
This PR adds the
feature
RPC to the models.Context of Change
There is now a non-admin user version of this RPC: XRPLF/rippled#4781
Type of Change
Did you update HISTORY.md?
Test Plan
Added integration tests.