1
- import { Client , Table } from './utils/init'
1
+ import { Client , Entity , Table } from './utils/init'
2
2
import { ArrayItemsSchema } from './schemas'
3
+ import { ColorEnum } from './schemas/arrayItemsSchema'
3
4
4
5
// jest.setTimeout(7200 * 1000)
5
6
@@ -14,6 +15,7 @@ const table = new Table({
14
15
const expected = {
15
16
id : '1111-2222' ,
16
17
arrayWithTypedItems : [ { bar : 'Bar' , when : new Date ( ) } ] ,
18
+ arrayWithEnumItems : [ ColorEnum . blue , ColorEnum . red , ColorEnum . white ] ,
17
19
arrayWithoutTypedItems : [ 'a' , '2' , 3 , new Date ( ) ] ,
18
20
}
19
21
@@ -34,6 +36,7 @@ test('Create', async () => {
34
36
expect ( item . arrayWithTypedItems ) . toBeDefined ( )
35
37
expect ( item . arrayWithTypedItems . length ) . toBe ( 1 )
36
38
expect ( item . arrayWithTypedItems [ 0 ] . bar ) . toBe ( 'Bar' )
39
+ expect ( item . arrayWithEnumItems ) . toStrictEqual ( expected . arrayWithEnumItems )
37
40
expect ( item . arrayWithoutTypedItems . length ) . toBe ( 4 )
38
41
expect ( item . arrayWithoutTypedItems [ 0 ] ) . toBe ( 'a' )
39
42
@@ -61,3 +64,11 @@ test('Destroy Table', async () => {
61
64
await table . deleteTable ( 'DeleteTableForever' )
62
65
expect ( await table . exists ( ) ) . toBe ( false )
63
66
} )
67
+
68
+ test ( 'Array with enum items typing' , ( ) => {
69
+ type ArrayWithEnumItemsType = Entity < typeof ArrayItemsSchema . models . TestModel > [ 'arrayWithEnumItems' ] ;
70
+ const validA : ColorEnum [ ] | undefined = { } as ArrayWithEnumItemsType ;
71
+ const validB : ArrayWithEnumItemsType = { } as ColorEnum [ ] | undefined ;
72
+ // @ts -expect-error
73
+ const invalid : ArrayWithEnumItemsType = { } as string [ ] | undefined ;
74
+ } ) ;
0 commit comments