Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .hintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": [
"development"
],
"hints": {
"typescript-config/is-valid": "off"
}
}
55 changes: 30 additions & 25 deletions store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 🙏
44 changes: 44 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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,
}
}