|
| 1 | +import { expectTypeOf } from 'expect-type' |
| 2 | +import { User } from './models/User'; |
| 3 | + |
| 4 | +async () => { |
| 5 | + const user = await User.create({ |
| 6 | + id: 123, |
| 7 | + firstName: '<first-name>', |
| 8 | + }, { |
| 9 | + ignoreDuplicates: false, |
| 10 | + returning: true, |
| 11 | + }); |
| 12 | + expectTypeOf(user).toEqualTypeOf<User>() |
| 13 | + |
| 14 | + const voidUsers = await Promise.all([ |
| 15 | + User.create({ |
| 16 | + id: 123, |
| 17 | + firstName: '<first-name>', |
| 18 | + }, { |
| 19 | + ignoreDuplicates: true, |
| 20 | + returning: false, |
| 21 | + }), |
| 22 | + User.create({ |
| 23 | + id: 123, |
| 24 | + firstName: '<first-name>', |
| 25 | + }, { |
| 26 | + ignoreDuplicates: true, |
| 27 | + returning: true, |
| 28 | + }), |
| 29 | + User.create({ |
| 30 | + id: 123, |
| 31 | + firstName: '<first-name>', |
| 32 | + }, { |
| 33 | + ignoreDuplicates: false, |
| 34 | + returning: false, |
| 35 | + }), |
| 36 | + User.create({ |
| 37 | + id: 123, |
| 38 | + firstName: '<first-name>', |
| 39 | + }, { returning: false }), |
| 40 | + User.create({ |
| 41 | + id: 123, |
| 42 | + firstName: '<first-name>', |
| 43 | + }, { ignoreDuplicates: true }), |
| 44 | + ]); |
| 45 | + expectTypeOf(voidUsers).toEqualTypeOf<[void, void, void, void, void]>() |
| 46 | + |
| 47 | + const emptyUsers = await Promise.all([ |
| 48 | + User.create(), |
| 49 | + User.create(undefined), |
| 50 | + User.create(undefined, undefined), |
| 51 | + ]); |
| 52 | + expectTypeOf(emptyUsers).toEqualTypeOf<[User, User, User]>() |
| 53 | + |
| 54 | + const partialUser = await User.create({ |
| 55 | + id: 123, |
| 56 | + firstName: '<first-name>', |
| 57 | + lastName: '<last-name>', |
| 58 | + }, { |
| 59 | + fields: ['firstName'], |
| 60 | + returning: ['id'], |
| 61 | + }); |
| 62 | + expectTypeOf(partialUser).toEqualTypeOf<User>() |
| 63 | + |
| 64 | + // @ts-expect-error missing attribute |
| 65 | + await User.create({ |
| 66 | + id: 123, |
| 67 | + }); |
| 68 | + await User.create({ |
| 69 | + id: 123, |
| 70 | + firstName: '<first-name>', |
| 71 | + // @ts-expect-error unknown attribute |
| 72 | + unknown: '<unknown>', |
| 73 | + }); |
| 74 | +}; |
0 commit comments