1
1
import { Schema , Document , Model , connection } from 'mongoose' ;
2
2
3
- interface ITest extends Document {
4
- foo : string ;
3
+ function conventionalSyntax ( ) : void {
4
+ interface ITest extends Document {
5
+ foo : string ;
6
+ }
7
+
8
+ const TestSchema = new Schema ( {
9
+ foo : { type : String , required : true } ,
10
+ } ) ;
11
+
12
+ const Test = connection . model < ITest > ( 'Test' , TestSchema ) ;
13
+
14
+ const bar = ( SomeModel : Model < ITest > ) => console . log ( SomeModel ) ;
15
+
16
+ bar ( Test ) ;
5
17
}
6
18
7
- const TestSchema = new Schema ( {
8
- foo : { type : String , required : true } ,
9
- } ) ;
19
+ function tAndDocSyntax ( ) : void {
20
+ interface ITest {
21
+ id : number ;
22
+ foo : string ;
23
+ }
24
+
25
+ const TestSchema = new Schema ( {
26
+ foo : { type : String , required : true } ,
27
+ } ) ;
10
28
11
- const Test = connection . model < ITest > ( 'Test' , TestSchema ) ;
29
+ const Test = connection . model < ITest & Document > ( 'Test' , TestSchema ) ;
12
30
13
- const bar = ( SomeModel : Model < ITest > ) => // <<<< error here
14
- console . log ( SomeModel ) ;
31
+ const aggregated : Promise < Document > = Test . aggregate ( [ ] ) . then ( res => res [ 0 ] ) ;
15
32
16
- bar ( Test ) ;
33
+ const bar = ( SomeModel : Model < ITest & Document > ) => console . log ( SomeModel ) ;
34
+ }
17
35
18
36
const ExpiresSchema = new Schema ( {
19
37
ttl : {
@@ -22,8 +40,6 @@ const ExpiresSchema = new Schema({
22
40
} ,
23
41
} ) ;
24
42
25
- const aggregated : Promise < Document > = Test . aggregate ( [ ] ) . then ( res => res [ 0 ] ) ;
26
-
27
43
interface IProject extends Document {
28
44
name : String ;
29
45
}
0 commit comments