Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a1e05c3
fix: customer group type mismatches
sylwia-werner Oct 17, 2025
a06405c
fix: collections and customer group type mismatches
sylwia-werner Oct 17, 2025
c5a20a1
fix: reservation type mismatches
sylwia-werner Oct 17, 2025
1e7f33b
fix: sales channel id type mismatch
sylwia-werner Oct 17, 2025
530860c
fix: stock location type mismatches
sylwia-werner Oct 19, 2025
0af8c58
fix: tax region type mismatches
sylwia-werner Oct 19, 2025
c8f84e7
fix: controller render props union type mismatch
sylwia-werner Oct 19, 2025
9e8af22
fix: price list type mismatches
sylwia-werner Oct 20, 2025
f99de95
fix: promotions type mismatches
sylwia-werner Oct 20, 2025
8657618
Merge branch 'fix/mm2-1209/fix-ts-errors' into fix/mm2-1280/typescrip…
sylwia-werner Oct 20, 2025
2c6703b
Merge branch 'fix/mm2-1209/fix-ts-errors' into fix/mm2-1280/typescrip…
sylwia-werner Oct 22, 2025
4e04c0e
fix: products type mismatches
sylwia-werner Oct 23, 2025
9c6ec4a
Merge branch 'fix/mm2-1209/fix-ts-errors' into fix/mm2-1280/typescrip…
sylwia-werner Oct 26, 2025
9719ac8
Merge branch 'fix/mm2-1280/typescript-errors-pt-2' into fix/mm2-1318/…
sylwia-werner Oct 26, 2025
35addae
fix: PR fixes
sylwia-werner Oct 28, 2025
a837146
fix: PR fixes
sylwia-werner Oct 29, 2025
cb3741e
fix: PR fixes
sylwia-werner Oct 29, 2025
a18176d
fix: PR fixes
sylwia-werner Nov 3, 2025
65db38e
fix: PR fixes
sylwia-werner Nov 3, 2025
93499c3
fix: PR fixes
sylwia-werner Nov 3, 2025
30c8dee
Merge branch 'test' into fix/mm2-1280/typescript-errors-pt-2
sylwia-werner Nov 3, 2025
a758438
Merge branch 'fix/mm2-1209/fix-ts-errors' into fix/mm2-1280/typescrip…
sylwia-werner Nov 3, 2025
540958d
Merge branch 'fix/mm2-1280/typescript-errors-pt-2' into fix/mm2-1318/…
sylwia-werner Nov 3, 2025
dea7923
fix: PR conflicts, move types from extended-product to products
sylwia-werner Nov 3, 2025
06ba9cf
Merge branch 'test' into fix/mm2-1318/typescript-errors-pt-3
sylwia-werner Nov 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
522 changes: 522 additions & 0 deletions # Fix TypeScript Errors - Strategic Plan.md
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure if we need this on main branch

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed

Large diffs are not rendered by default.

455 changes: 455 additions & 0 deletions fix-typescript-errors-v2.plan.md
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure if we need this on main branch

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"i18n:validate": "node ./scripts/i18n/validate-translation.js",
"i18n:schema": "node ./scripts/i18n/generate-schema.js",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"format": "prettier --write ."
"format": "prettier --write .",
"ts-check": "node ./scripts/ts-check.js > ts-errors.log 2>&1 && echo 'TypeScript check complete. Results saved to ts-errors.log'",
"typecheck": "tsc --noEmit"
},
"main": "dist/app.js",
"module": "dist/app.mjs",
Expand Down Expand Up @@ -84,6 +86,7 @@
"@medusajs/admin-vite-plugin": "^2.5.0",
"@medusajs/types": "^2.5.0",
"@medusajs/ui-preset": "^2.5.0",
"@types/lodash": "^4.17.20",
"@types/node": "^20.11.15",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
Expand Down
87 changes: 87 additions & 0 deletions scripts/ts-check.js
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure if we need this on main branch

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// scripts/ts-check.js
// Scans src/**/*.{ts,tsx} and uses tsconfig.json compilerOptions (so JSX settings are respected).

const ts = require("typescript")
const glob = require("glob")
const path = require("path")

// 1) Collect files under /src
const files = glob.sync("src/**/*.{ts,tsx}", { absolute: true })

if (files.length === 0) {
console.log("No TypeScript files found under /src.")
process.exit(0)
}

// 2) Try to find and parse tsconfig.json to reuse compilerOptions (important for JSX)
let compilerOptions = {}
const configPath = ts.findConfigFile(
process.cwd(),
ts.sys.fileExists,
"tsconfig.json"
)

if (configPath) {
const parsed = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys)
if (parsed && parsed.options) {
compilerOptions = parsed.options
} else {
console.warn(
"Warning: Couldn't fully parse tsconfig.json — falling back to defaults."
)
}
} else {
console.warn("Warning: No tsconfig.json found. Using sensible defaults.")
}

// 3) Ensure we don't emit and skip noisy lib checks
compilerOptions = Object.assign({}, compilerOptions, {
noEmit: true,
skipLibCheck: true,
})

// 4) Create program with the explicit file list (so we ignore tsconfig includes/excludes)
const program = ts.createProgram(files, compilerOptions)

// 5) Collect diagnostics
const diagnostics = ts.getPreEmitDiagnostics(program)

if (diagnostics.length === 0) {
console.log(`✅ No TypeScript errors found in ${files.length} files.`)
process.exit(0)
}

// 6) Print diagnostics in "file:line:col - error TS..." form and collect stats
let errorCount = 0
const filesWithErrors = new Set()

diagnostics.forEach((diag) => {
if (diag.file) {
const { line, character } = diag.file.getLineAndCharacterOfPosition(
diag.start
)
const message = ts.flattenDiagnosticMessageText(diag.messageText, "\n")
const relativeFile = path.relative(process.cwd(), diag.file.fileName)

console.log(
`${relativeFile}:${line + 1}:${character + 1} - error TS${diag.code}: ${message}`
)

errorCount++
filesWithErrors.add(relativeFile)
} else {
// global/unbound diagnostic
console.log(
`error TS${diag.code}: ${ts.flattenDiagnosticMessageText(diag.messageText, "\n")}`
)
errorCount++
}
})

// 7) Summary
console.log("\n--- TypeScript Check Summary ---")
console.log(`Scanned files: ${files.length}`)
console.log(`Files with errors: ${filesWithErrors.size}`)
console.log(`Total errors: ${errorCount}`)

process.exit(0)
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useTranslation } from "react-i18next"

import { PlaceholderCell } from "../../common/placeholder-cell"
import { HttpTypes } from "@medusajs/types"
import { ExtendedAdminProductVariant } from "../../../../../types/extended-product"

type VariantCellProps = {
variants?: HttpTypes.AdminProductVariant[] | null
variants?: ExtendedAdminProductVariant[] | null
}

export const VariantCell = ({ variants }: VariantCellProps) => {
Expand Down
10 changes: 0 additions & 10 deletions src/hooks/api/collections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export const useCollections = (
>,
"queryFn" | "queryKey"
>,
id?: string
) => {
const { data, ...rest } = useQuery({
queryKey: collectionsQueryKeys.list(query),
Expand All @@ -67,15 +66,6 @@ export const useCollections = (
...options,
})

if (id) {
return {
...rest,
...data,
product_collections: data?.product_collections.find(
(item) => item.id === id
),
}
}
return { ...data, ...rest }
}

Expand Down
12 changes: 6 additions & 6 deletions src/hooks/api/customer-groups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { queryClient } from "../../lib/query-client"
import { queryKeysFactory } from "../../lib/query-key-factory"
import { customersQueryKeys } from "./customers"
import { filterCustomerGroups } from "../../routes/orders/common/customerGroupFiltering"
import { CustomerGroupListResponse } from "../../types/customer-group"

const CUSTOMER_GROUPS_QUERY_KEY = "customer_groups" as const
export const customerGroupsQueryKeys = queryKeysFactory(
Expand Down Expand Up @@ -50,9 +51,7 @@ export const useCustomerGroups = (
UseQueryOptions<
HttpTypes.AdminGetCustomerGroupsParams,
FetchError,
HttpTypes.AdminCustomerGroupListResponse & {
customer_group?: any
},
CustomerGroupListResponse,
QueryKey
>,
"queryFn" | "queryKey"
Expand All @@ -67,7 +66,7 @@ export const useCustomerGroups = (
queryKey: customerGroupsQueryKeys.list(query),
...options,
})

const filteredData = filterCustomerGroups(
data?.customer_groups,
filters,
Expand All @@ -79,10 +78,11 @@ export const useCustomerGroups = (
const count = customer_groups?.length || 0

return {
...data,
...rest,
count,
customer_groups,
...rest,
offset: data?.offset,
limit: data?.limit,
}
}

Expand Down
14 changes: 11 additions & 3 deletions src/hooks/api/price-lists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { fetchQuery, sdk } from "../../lib/client"
import { queryClient } from "../../lib/query-client"
import { queryKeysFactory } from "../../lib/query-key-factory"
import { ExtendedPriceList, PriceListListResponse } from "../../types/price-list"
import { customerGroupsQueryKeys } from "./customer-groups"
import { productsQueryKeys } from "./products"

Expand Down Expand Up @@ -72,9 +73,9 @@ export const usePriceLists = (
query?: HttpTypes.AdminPriceListListParams,
options?: Omit<
UseQueryOptions<
HttpTypes.AdminPriceListListResponse,
PriceListListResponse,
FetchError,
any,
PriceListListResponse,
QueryKey
>,
"queryKey" | "queryFn"
Expand All @@ -90,8 +91,15 @@ export const usePriceLists = (
...options,
})

const price_lists = data?.price_lists?.filter((item: any) => item.price_list)
const price_lists: ExtendedPriceList[] | undefined = data?.price_lists
?.filter((item) => item.price_list)
.map((item) => ({
...item.price_list,
id: item.price_list.id,
}))

const count = price_lists?.length || 0

return { ...data, price_lists, count, ...rest }
}

Expand Down
45 changes: 32 additions & 13 deletions src/hooks/api/products.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import {
checkStatusMatch,
} from "./helpers/productFilters"
import productsImagesFormatter from "../../utils/products-images-formatter"
import {
ExtendedAdminProductResponse,
ExtendedAdminProductListResponse,
} from "../../types/extended-product"

const PRODUCTS_QUERY_KEY = "products" as const
export const productsQueryKeys = queryKeysFactory(PRODUCTS_QUERY_KEY)
Expand Down Expand Up @@ -350,27 +354,32 @@ export const useProduct = (
query?: Record<string, any>,
options?: Omit<
UseQueryOptions<
HttpTypes.AdminProductResponse,
ExtendedAdminProductResponse,
FetchError,
HttpTypes.AdminProductResponse,
ExtendedAdminProductResponse,
QueryKey
>,
"queryFn" | "queryKey"
>
) => {
const { data, ...rest } = useQuery({
queryFn: () =>
fetchQuery(`/vendor/products/${id}`, {
queryFn: async () => {
const response = await fetchQuery(`/vendor/products/${id}`, {
method: "GET",
query: query as { [key: string]: string | number },
}),
queryKey: productsQueryKeys.detail(id),
})

return {
...response,
product: productsImagesFormatter(response.product),
}
},
queryKey: productsQueryKeys.detail(id, query),
...options,
})

return {
...data,
product: productsImagesFormatter(data?.product),
...rest,
}
}
Expand All @@ -379,9 +388,9 @@ export const useProducts = (
query?: HttpTypes.AdminProductListParams,
options?: Omit<
UseQueryOptions<
HttpTypes.AdminProductListResponse,
ExtendedAdminProductListResponse,
FetchError,
HttpTypes.AdminProductListResponse,
ExtendedAdminProductListResponse,
QueryKey
>,
"queryFn" | "queryKey"
Expand All @@ -397,11 +406,17 @@ export const useProducts = (
}
) => {
const { data, ...rest } = useQuery({
queryFn: () =>
fetchQuery("/vendor/products", {
queryFn: async () => {
const response = await fetchQuery("/vendor/products", {
method: "GET",
query: query as Record<string, string | number>,
}),
})

return {
...response,
products: productsImagesFormatter(response.products) || [],
}
},
queryKey: productsQueryKeys.list(query),
...options,
})
Expand Down Expand Up @@ -460,9 +475,13 @@ export const useProducts = (
}
}

const limitedProducts = filter?.limit
? products.slice(0, filter.limit)
: products

return {
...data,
products: productsImagesFormatter(products?.slice(0, filter?.limit)) || [],
products: limitedProducts,
Copy link
Collaborator

Choose a reason for hiding this comment

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

we're going to remove FE filtering, soon this will be unused

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed

count: products?.length || 0,
...rest,
}
Expand Down
1 change: 0 additions & 1 deletion src/hooks/api/promotions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ export const usePromotionUpdateRules = (
)

const rulesIds = rules.map((rule: any) => rule.id)
console.log("rules", rulesIds)
await fetchQuery(`/vendor/promotions/${id}/${ruleType}/batch`, {
method: "POST",
body: { delete: rulesIds },
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/api/stock-locations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { fetchQuery } from "../../lib/client"
import { queryClient } from "../../lib/query-client"
import { queryKeysFactory } from "../../lib/query-key-factory"
import { fulfillmentProvidersQueryKeys } from "./fulfillment-providers"
import { VendorExtendedAdminStockLocationResponse } from "../../types/stock-location"

const STOCK_LOCATIONS_QUERY_KEY = "stock_locations" as const
export const stockLocationsQueryKeys = queryKeysFactory(
Expand All @@ -25,7 +26,7 @@ export const useStockLocation = (
UseQueryOptions<
HttpTypes.AdminStockLocationResponse,
FetchError,
HttpTypes.AdminStockLocationResponse,
VendorExtendedAdminStockLocationResponse,
QueryKey
>,
"queryKey" | "queryFn"
Expand All @@ -40,7 +41,7 @@ export const useStockLocation = (
queryKey: stockLocationsQueryKeys.detail(id, query),
...options,
})

return { ...data, ...rest }
}

Expand Down
6 changes: 2 additions & 4 deletions src/hooks/table/columns/use-customer-group-table-columns.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HttpTypes } from "@medusajs/types"
import { createColumnHelper } from "@tanstack/react-table"
import { useMemo } from "react"

Expand All @@ -6,7 +7,6 @@ import {
TextCell,
TextHeader,
} from "../../../components/table/table-cells/common/text-cell"
import { HttpTypes } from "@medusajs/types"

const columnHelper = createColumnHelper<HttpTypes.AdminCustomerGroup>()

Expand All @@ -20,9 +20,7 @@ export const useCustomerGroupTableColumns = () => {
cell: ({ row }) => {
return (
<TextCell
text={
row.original?.customer_group?.name || row.original?.name || "-"
}
text={row.original?.name || "-"}
/>
)
},
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/table/columns/use-product-table-columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import {
VariantCell,
VariantHeader,
} from "../../../components/table/table-cells/product/variant-cell"
import { HttpTypes } from "@medusajs/types"
import { ExtendedAdminProduct } from "../../../types/extended-product"

const columnHelper = createColumnHelper<HttpTypes.AdminProduct>()
const columnHelper = createColumnHelper<ExtendedAdminProduct>()

export const useProductTableColumns = () => {
return useMemo(
Expand Down
Loading