From b5cce892d3a79c4dfb12857cc8a1872b8adb47fc Mon Sep 17 00:00:00 2001 From: David Norman Date: Sun, 21 Dec 2025 03:53:57 +0200 Subject: [PATCH] Done store task :) sorry for being late.. --- .hintrc | 8 ++++++++ store.ts | 55 ++++++++++++++++++++++++++++----------------------- tsconfig.json | 44 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 25 deletions(-) create mode 100644 .hintrc create mode 100644 tsconfig.json diff --git a/.hintrc b/.hintrc new file mode 100644 index 0000000..d5bb468 --- /dev/null +++ b/.hintrc @@ -0,0 +1,8 @@ +{ + "extends": [ + "development" + ], + "hints": { + "typescript-config/is-valid": "off" + } +} \ No newline at end of file diff --git a/store.ts b/store.ts index 1745d61..6ab6d3e 100644 --- a/store.ts +++ b/store.ts @@ -72,50 +72,55 @@ const store: Store = { // Shopping cart: array of product IDs // ------------------------------------ -const cart = [1, 3, 5]; +const cart : number[] = [1, 3, 5]; // ------------------------------------ // Functions to implement // ------------------------------------ function getAvailableProducts( - store /* : add type here */ -) /* : add return types */ { - return []; + store : Store +) : Product[] { + return store.products.filter(product => product.inStock); } function getProductsInPriceRange( - store /* : add type here */, - minPrice /* : add type here */, - maxPrice /* : add type here */ -) /* : add return types */ { - return []; + store : Store, + minPrice : number, + maxPrice : number +) : Product[] { + return store.products.filter(product => product.price > minPrice && product.price < maxPrice); } function getProductsByTag( - store /* : add type here */, - tag /* : add type here */ -) /* : add return types */ { - return []; + store : Store, + tag : string +) : Product[] { + return store.products.filter(product => product.tags.includes(tag)); } function getAvailableProductsByTag( - store /* : add type here */, - tag /* : add type here */ -) /* : add return types */ { - return []; + store : Store, + tag : string +) : Product[] { + return getProductsByTag(store, tag).filter(product => product.inStock); } function getCartProducts( - store /* : add type here */, - cart /* : add type here */ -) /* : add return types */ { - return []; + store : Store, + cart : number[] +) : Product[] { + return store.products.filter(product => cart.includes(product.id)); } function getCartTotalInStock( - store /* : add type here */, - cart /* : add type here */ -) /* : add return types */ { - return 0; + store : Store, + cart : number[] +) : number { + //function is not really defined, I understand it as return how much products from the cart are available + return store.products.filter(product => cart.includes(product.id) && product.inStock).length; } + + + +// note: I'm not familiar with compiling TS. I understand, using Gemini, that the errors I got are due to version differences etc. Please let me know if I miss something here 🙏 \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..cec4a3a --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,44 @@ +{ + // Visit https://aka.ms/tsconfig to read more about this file + "compilerOptions": { + // File Layout + // "rootDir": "./src", + // "outDir": "./dist", + + // Environment Settings + // See also https://aka.ms/tsconfig/module + "module": "nodenext", + "target": "esnext", + "types": [], + // For nodejs: + // "lib": ["esnext"], + // "types": ["node"], + // and npm install -D @types/node + + // Other Outputs + "sourceMap": true, + "declaration": true, + "declarationMap": true, + + // Stricter Typechecking Options + "noUncheckedIndexedAccess": true, + "exactOptionalPropertyTypes": true, + + // Style Options + // "noImplicitReturns": true, + // "noImplicitOverride": true, + // "noUnusedLocals": true, + // "noUnusedParameters": true, + // "noFallthroughCasesInSwitch": true, + // "noPropertyAccessFromIndexSignature": true, + + // Recommended Options + "strict": true, + "jsx": "react-jsx", + "verbatimModuleSyntax": true, + "isolatedModules": true, + "noUncheckedSideEffectImports": true, + "moduleDetection": "force", + "skipLibCheck": true, + } +}