I am building a shopping cart using expressjs, typescript and redis OM as the in memory database. After creating a schema using Redis OM, an error
Property 'fetchRepository' does not exist on type 'typeof App'.ts(2339)
in this line of code
export let CartRepository = client.fetchRepository(CartSchema)
I am a bit new to typescript
the whole schema:
import { Entity, Schema,Repository } from 'redis-om'
import client from '../../../../app'
export default class Cart extends Entity {}
const CartSchema = new Schema(Cart, {
item_name: { type: 'string' },
item_Cost:{ type: 'number' },
coin_type:{type:'string'}
})
export let CartRepository = client.fetchRepository(CartSchema)
CartRepository.createIndex()
Below is where the client is being exported from .
//app.ts
const url:any = process.env.REDIS_URL
const connection:any = createClient({url}).connect().then(() =>{
console.log("database connected successfully");
})
let client:any;
module.exports.client = new Client().use(connection);
You are mixing CommonJS (module.exports) and ESM (import & export)
In app.ts change module.exports.client to export const client = and in the other file change to import { client } from.