-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[WIP] Migrate Balance.jsx
-> Balance.tsx
#2329
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,10 @@ import { useSheetName } from './useSheetName'; | |
|
||
import { type Binding } from '.'; | ||
|
||
export function useSheetValue(binding: Binding, onChange?: (result) => void) { | ||
export function useSheetValue<T>( | ||
binding: Binding, | ||
onChange?: (result) => void, | ||
): T | null { | ||
Comment on lines
+10
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ question: any way we could make this smarter? For example: I see that Basically I'm afraid that manual type definitions here will lead to subtle bugs later. |
||
const { sheetName, fullSheetName } = useSheetName(binding); | ||
|
||
const bindingObj = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,8 +251,8 @@ export function useSelectedDispatch() { | |
return useContext(SelectedDispatch); | ||
} | ||
|
||
export function useSelectedItems() { | ||
return useContext(SelectedItems); | ||
export function useSelectedItems<Item>() { | ||
return useContext(SelectedItems) as Set<Item>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔨 warning: manual type coercions lead to subtle bugs that are hard to spot. Could we instead change line 248 to be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point, but I was concerned that the different usages of |
||
} | ||
|
||
type SelectedProviderProps<T extends Item> = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
category: Maintenance | ||
authors: [jfdoming] | ||
--- | ||
|
||
Migrate `Balance.jsx` -> `Balance.tsx` |
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.
💭 thought: this is what I was afraid of. We manually type this as a
string
, but the value here is clearly anumber
.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.
When
sheetValue
is used below, it's passed intoparseInt
, so I assumed it would be a string. Maybe I'm misunderstanding howuseSheetValue
works?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.
For now - ignore how
sheetValue
is used. Focus on the three highlighted lines.We provide
value: 0
in there as the default value. And then we also manually type the return type asstring
. So which type will be returned? According to the typings:string
. But in reality it could as well benumber
.Sample: https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABCAzgUwMoAs1qgNQEMAbENAHgBUA+ACgDcSyAuZMAazDgHcwBKVpUQBvAFCIJiAE54QUpI1JpEhFIkoBuUQF9RoiAhRREKHHiJLEAXmTpsuAkwpGpMMAHM6ABj5bRAen9EGDUAA1MHCzJQlUQwEABbACM0KUQ4NMITKFcPAH4gA