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
TS wallets #17733
TS wallets #17733
Conversation
@@ -25,7 +24,7 @@ const common = { | |||
|
|||
const enterKeyProps = { | |||
...common, | |||
view: 'key', | |||
view: 'key' as 'key', |
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.
better way to do this? type View = 'key' | 'name'
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.
You can do this:
'key' as const
but our eslint isn't happy with it for some reason.
also see this:
typescript-eslint/typescript-eslint#312
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.
typescript-eslint/typescript-eslint#390
We might have to update our eslint
prevProps.senderAccountID && | ||
(!props.transactionID || !props.senderAccountID) && | ||
prev.transactionID && | ||
prev.senderAccountID && |
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.
Is this the best way 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.
You can use type guards to refine the types. For example you can do this:
diff --git a/shared/wallets/transaction-details/index.tsx b/shared/wallets/transaction-details/index.tsx
index 07dd203790..1392eabcd8 100644
--- a/shared/wallets/transaction-details/index.tsx
+++ b/shared/wallets/transaction-details/index.tsx
@@ -421,6 +421,10 @@ const TransactionDetails = (props: NotLoadingProps) => {
)
}
+function isNotLoadingProps(props: Props): props is NotLoadingProps {
+ return !props.loading
+}
+
class LoadTransactionDetails extends React.Component<Props> {
componentDidMount() {
this.props.onLoadPaymentDetail()
@@ -428,11 +432,11 @@ class LoadTransactionDetails extends React.Component<Props> {
componentDidUpdate(prevProps: Props) {
// An erased transaction ID likely means the payment was updated,
// which means details need to be retrieved again
- if (this.props.loading || prevProps.loading) {
+ if (!isNotLoadingProps(this.props) || !isNotLoadingProps(prevProps)) {
return
}
- const props = this.props as NotLoadingProps
- const prev = prevProps as NotLoadingProps
+ const props = this.props
+ const prev = prevProps
if (
(!props.transactionID || !props.senderAccountID) &&
prev.transactionID &&
as
should generally be avoided since it is telling the compiler "I know better than you, trust me on this."
class Qualified extends React.PureComponent<Props, State> { | ||
state = { | ||
rowIdxLoaded: -1, | ||
} | ||
_loadingTimerID: ?TimeoutID | ||
_loadingTimerID: NodeJS.Timeout |
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.
this doesn't have to be null | nodejs.timeout
?
onClickResult: (username: string) => void | ||
onShowSuggestions: () => void | ||
onShowTracker: (username: string) => void | ||
onScanQRCode: () => void | null |
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.
This is a bug in the converter, sorry. This should be (() => void) | null
.
onShowSuggestions: () => void | ||
onRemoveProfile: () => void | ||
onChangeRecipient: (recipient: string) => void | ||
onScanQRCode: () => void | null |
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.
same bug
recipientPublicKey: string | ||
errorMessage?: string | ||
onChangeRecipient: (recipient: string) => void | ||
onScanQRCode: () => void | null |
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.
here too (sorry!!)
shared/wallets/transaction/index.tsx
Outdated
onCancelPayment: ?() => void, | ||
onCancelPaymentWaitingKey: string, | ||
memo: string | ||
onCancelPayment: () => void | null |
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.
here too
shared/wallets/transaction/index.tsx
Outdated
sourceAsset: string, | ||
status: Types.StatusSimplified, | ||
statusDetail: string, | ||
onSelectTransaction?: () => void | null |
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.
here too
accountID: Types.AccountID | ||
isDefaultWallet: boolean | ||
keybaseUser: string | ||
onBack: () => void | null |
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.
here too
|
||
export type Props = { | ||
accountIDs: Array<Types.AccountID> | ||
getAttachmentRef: () => React.Component<any> | null |
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.
here too
onChanged={(node: React.Node) => { | ||
// $ForceType doesn't understand key will be string | ||
onChanged={(node: React.ReactNode) => { | ||
// @ts-ignore doesn't understand key will be string | ||
const selectedCode: Types.CurrencyCode = node.key |
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.
You could also do a as string
since you want to tell the compiler this will be a string
@keybase/react-hackers