0

I have class, with nested object where I need only one field required and then all other keys are undefined and unlimited with string type, how could I write it in TypeScript?

I have tried this logic:

@Schema({ _id: false })
class Translations extends mongoose.Document {
  @Prop({ required: true })
  en: string;

  @Prop()
  [key: string]: string;
}

but mongoose complains about it

1 Answers1

0
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

@Schema()
export class Translation {
  @Prop({required: true})
  en: string;

  @Prop()
  [key: string]: string;
}

export const TranslationSchema = SchemaFactory.createForClass(Translation);