Replies: 4 comments
-
Hi @monarcode Can you try this? You can extend the CartItems interface. interface CustomCartItems extends CartItems {
id: string;
user_id: number;
listing_category_id: string;
listing_sub_category_id?: any;
service_offering: string;
description: string;
listing_images: string[];
minimum_offer: string;
slug: string;
status: string;
size: string;
vehicle_id: number;
country_id: string;
listing_type: string;
created_at: string;
updated_at: string;
} Then just use CustomCartItems as your Type. Please let me know how it goes. Happy to help. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your response, i was able to get proper type hints by doing something similar
but i'm not sure if this is the best approach, i was thinking of extending the type of CartItems via a d.ts file, but not sure how i can achieve that..any recommendations? |
Beta Was this translation helpful? Give feedback.
-
Ah. You can do that. // custom.d.ts
interface CustomCartItems extends CartItems {
id: string;
user_id: number;
listing_category_id: string;
listing_sub_category_id?: any;
service_offering: string;
description: string;
listing_images: string[];
minimum_offer: string;
slug: string;
status: string;
size: string;
vehicle_id: number;
country_id: string;
listing_type: string;
created_at: string;
updated_at: string;
} Then in the main file. import { useCart, withSSR } from "cart";
import { CustomCartItems } from './custom';
const cart = withSSR(useCart, (state) => state);
const items = cart?.cartItems as CustomCartItems[]; |
Beta Was this translation helpful? Give feedback.
-
Hi, @monarcode Since this is not an issue, I'll be moving this to Discussion. Feel free to follow up if needed. Thanks for understanding 😄 |
Beta Was this translation helpful? Give feedback.
-
Bug Report Checklist
main
branch of the repository.Expected
Getting wrong type / autocomplete suggestions for CartItems
// my type def
interface ViewListing { id: string; user_id: number; listing_category_id: string; listing_sub_category_id?: any; service_offering: string; description: string; listing_images: string[]; minimum_offer: string; slug: string; status: string; size: string; vehicle_id: number; country_id: string; listing_type: string; created_at: string; updated_at: string; }
Actual
// default type def
interface CartItems {
cartQuantity?: number;
imagesrc?: string;
inStock?: boolean;
name: string;
price?: number;
productId: number | string | undefined;
quantity: number;
}
Additional Info
Running on:
Nextjs app router
Cart v1.1.1
How can i overwrite or extend the default types for CartItems? the default defaults do not match the items i am saving to cart
Beta Was this translation helpful? Give feedback.
All reactions