Is it possible that retrieving a json from a mongodb database and casting it does not trigger the typescript constructor? What could be causing this issue?
I have a Team
class
export class Team {
transformations: { [transformationId: string]: Transformation }
typeTrees: { [ttMakerId: string]: TTMaker }
constructor() {
console.log('NewTree constructor called')
this.transformations = {}
this.typeTrees = {}
}
}
I am downloading a json data, which should match the structure of the Team type:
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<string | null>
) {
const transformationId = req.query.transformationId as string
const text = req.query.text as string
try {
const { mongoClient } = await connectToDatabase()
const db: Db = mongoClient.db('datamapper')
const collection = db.collection<Team>('team')
const team: Team | null = await collection.findOne({
name: 'responsive',
})
However, when I set a breakpoint at the constructor of Team, it doesn't get triggered. Why is that happening?