-
Notifications
You must be signed in to change notification settings - Fork 70
Fix/mm2 1362: Typescript errors pt 4 #208
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…typescript-errors-pt-3
|
|
||
| export type DataTableOrderByKey<TData> = { | ||
| key: keyof TData | ||
| key: keyof TData | (string & Record<never, 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.
IMO those nevers should be removed
I tried something more strict but looks horrible
key: keyof TData | keyof TData[keyof TData][keyof TData[keyof TData]]
or
type NestedKeys = keyof T | keyof T[keyof T][keyof T[keyof T]]
export type DataTableOrderByKey = {
key: keyof TData | NestedKeys
label: string
}
another proposed by (AI)an
type NestedKeys = {
[K in keyof T]: T[K] extends object
? ${string & K}.${string & keyof T[K]}
: never
}[keyof T]
export type DataTableOrderByKey = {
key: keyof TData | NestedKeys
label: string
}
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.
My version kept autocomplete, will take a look at yours 👍
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 left it as it was: key: keyof TData
I flattened the data before passing it to the table, problem solved
| isLoading={isLoading} | ||
| count={customer_groups?.length ?? 0} | ||
| prefix={PREFIX} | ||
| navigateTo={(row) => `/customer-groups/${row.id}`} | ||
| navigateTo={(row) => `/customer-groups/${row.original.customer_group_id}`} | ||
| filters={filters} | ||
| search | ||
| pagination | ||
| orderBy={[ | ||
| { key: "name", label: t("fields.name") }, | ||
| { | ||
| key: "created_at", | ||
| label: t("fields.createdAt"), | ||
| }, | ||
| { | ||
| key: "updated_at", | ||
| label: t("fields.updatedAt"), | ||
| }, | ||
| { key: "customer_group.name", label: t("fields.name") }, | ||
| { key: "customer_group.created_at", label: t("fields.createdAt") }, | ||
| { key: "customer_group.updated_at", label: t("fields.updatedAt") }, |
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.
maybe those keys could be changed to avoid those nevers?
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.
resolved, look at first comment
| { key: "customer_group.name", label: t("fields.name") }, | ||
| { key: "customer_group.created_at", label: t("fields.createdAt") }, | ||
| { key: "customer_group.updated_at", label: t("fields.updatedAt") }, |
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.
maybe those keys could be changed to avoid those nevers?
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.
resolved, look at first comment
| item.variant?.inventory && | ||
| item.variant.inventory.length > 0 && | ||
| item.quantity && | ||
| item.detail && |
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.
how about
item.variant?.manage_inventory && !!item.variant.inventory?.length && item?.quantity - item.detail?.fulfilled_quantity > 0
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.
Corrected
| const onQuantityChange = ( | ||
| inventoryItem: InventoryItemDTO, | ||
| lineItem: OrderLineItemDTO, | ||
| inventoryItem: { id: string; location_levels?: { location_id: string; available_quantity: number }[] }, |
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.
how about defining custom type?
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.
Corrected
| onQuantityChange: ( | ||
| inventoryItem: InventoryItemDTO, | ||
| lineItem: OrderLineItemDTO, | ||
| inventoryItem: { id: string; location_levels?: { location_id: string; available_quantity: number }[] }, |
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.
pls define this in custom 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.
Corrected
| items: fulfillment?.items?.map((i) => ({ | ||
| id: i.line_item_id, | ||
| id: i.line_item_id ?? "", | ||
| quantity: i.quantity, | ||
| })), | ||
| })).filter((item) => item.id !== "") ?? [], |
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.
how about
items: fulfillment?.items ?.map((i) => ({ id: i?.line_item_id, quantity: i.quantity, })) .filter((item) => !!item.id) ?? [],
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.
Corrected
| {fulfillment.labels.map((tlink) => { | ||
| const hasUrl = | ||
| tlink.url && tlink.url.length > 0 && tlink.url !== "#" | ||
| tlink.tracking_url && tlink.tracking_url.length > 0 && tlink.tracking_url !== "#" |
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.
how about just
!!tlink.tracking_url?.length
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.
Corrected
| order, | ||
| }: { | ||
| order: AdminOrder & { region?: AdminRegion | null } | ||
| order: ExtendedAdminOrder & { region?: AdminRegion | 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.
can't we extend definition of ExtendedAdminOrder?
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.
Extended
src/types/order.ts
Outdated
|
|
||
| export interface ExtendedAdminOrderFulfillment | ||
| extends HttpTypes.AdminOrderFulfillment { | ||
| items?: Array<{ |
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.
how about
(AdminOrderLineItem & { line_item_id: string })[]
same to other large types which are very similar to default types from medusa
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.
Changed
…typescript-errors-pt-3
…typescript-errors-pt-4
Fix pt-4
Link to ticket: MM2-1362
Note: to review and merge after part 1, 2 and 3 is merged
Suggested review approach - by commits