deno.land / x / mongoose@6.7.5 / test / types / maps.test.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Schema, model, Document, Model, Types } from 'mongoose';
interface ITest extends Document { map1: Map<string, number>, map2: Map<string, string>, map3: Map<string, number>}
const schema: Schema = new Schema<ITest>({ map1: { type: Map, of: Number }, map2: { type: Map, of: { type: String, enum: ['hello, world'] } }, map3: { type: Map, of: { type: Number, max: 44 } }});
const Test = model<ITest>('Test', schema);
const doc: ITest = new Test({});
doc.map1.set('answer', 42);doc.map1.get('answer');
function gh10575() { interface IBase { _id: Types.ObjectId; id: string;
prop1: string; prop2: string; }
interface IModel1 extends IBase { property1: number; property2: number; }
interface IModel2 extends IBase { property3: string; }
const BaseSchema: Schema<IBase> = new Schema({ prop1: String, prop2: String });
const Model1Schema: Schema<IModel1> = BaseSchema.clone() as any; Model1Schema.add({ property1: Number, property2: Number });
const Model2Schema: Schema<IModel2> = BaseSchema.clone() as any; Model2Schema.add({ property3: String });
const Model1 = model<IModel1, Model<IModel1>>('m1', Model1Schema); const Model2 = model<IModel2, Model<IModel2>>('m2', Model2Schema);
const someMap: Map<string, Model<IBase>> = new Map(); // Add `as any` to work around errors in strict mode someMap.set('A', Model1 as any); someMap.set('B', Model2 as any);}
function gh10872(): void { const doc: ITest = new Test({});
doc.toJSON().map1.foo;}
mongoose

Version Info

Tagged at
a year ago