-
Notifications
You must be signed in to change notification settings - Fork 60
Fix/mm2 1318: Typescript errors pt 3 #205
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
Changes from 14 commits
a1e05c3
a06405c
c5a20a1
1e7f33b
530860c
0af8c58
c8f84e7
9e8af22
f99de95
8657618
2c6703b
4e04c0e
9c6ec4a
9719ac8
35addae
a837146
cb3741e
a18176d
65db38e
93499c3
30c8dee
a758438
540958d
dea7923
06ba9cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
|
Large diffs are not rendered by default.
|
| 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 |
|---|---|---|
|
|
@@ -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) | ||
|
|
@@ -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, | ||
| } | ||
| } | ||
|
|
@@ -379,9 +388,9 @@ export const useProducts = ( | |
| query?: HttpTypes.AdminProductListParams, | ||
| options?: Omit< | ||
| UseQueryOptions< | ||
| HttpTypes.AdminProductListResponse, | ||
| ExtendedAdminProductListResponse, | ||
| FetchError, | ||
| HttpTypes.AdminProductListResponse, | ||
| ExtendedAdminProductListResponse, | ||
| QueryKey | ||
| >, | ||
| "queryFn" | "queryKey" | ||
|
|
@@ -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, | ||
| }) | ||
|
|
@@ -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, | ||
|
||
| count: products?.length || 0, | ||
| ...rest, | ||
| } | ||
|
|
||
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.
not sure if we need this on main branch
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.
Removed