Skip to content
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

Merged
merged 16 commits into from May 30, 2019
Merged

TS wallets #17733

merged 16 commits into from May 30, 2019

Conversation

cjb
Copy link
Contributor

@cjb cjb commented May 28, 2019

@keybase/react-hackers

@@ -25,7 +24,7 @@ const common = {

const enterKeyProps = {
...common,
view: 'key',
view: 'key' as 'key',
Copy link
Contributor Author

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'

Copy link
Contributor

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

Copy link
Contributor

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 &&
Copy link
Contributor Author

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?

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too (sorry!!)

onCancelPayment: ?() => void,
onCancelPaymentWaitingKey: string,
memo: string
onCancelPayment: () => void | null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

sourceAsset: string,
status: Types.StatusSimplified,
statusDetail: string,
onSelectTransaction?: () => void | null
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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

@cjb cjb merged commit 8ab97bb into master May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants