Skip to content

Commit e2ab7a5

Browse files
authored
fix: make types allow { to: 0 } (#223)
1 parent 6cc76a5 commit e2ab7a5

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"sqlite3": "^4.1.1",
4545
"ts-jest": "^25.4.0",
4646
"type-fest": "^0.13.0",
47-
"typescript": "~3.8.3",
47+
"typescript": "~3.9.2",
4848
"uuid": "^7.0.2"
4949
},
5050
"scripts": {

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,5 @@ export type UmzugRunOptions =
145145
from?: string;
146146

147147
/** The last migration to execute (included). */
148-
to?: string;
148+
to?: string | 0;
149149
};

src/umzug.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export class Umzug extends EventEmitter {
177177
If `from` is omitted, takes from the beginning.
178178
If `to` is omitted, takes to the end.
179179
*/
180-
async up(options: { from?: string; to?: string }): Promise<Migration[]>;
180+
async up(options: { from?: string; to?: string | 0 }): Promise<Migration[]>;
181181

182182
async up(options?: UmzugRunOptions): Promise<Migration[]> {
183183
return this._run('up', options, this.pending.bind(this));
@@ -204,7 +204,7 @@ export class Umzug extends EventEmitter {
204204
If `from` is omitted, takes from the beginning.
205205
If `to` is omitted, takes to the end.
206206
*/
207-
async down(options: { from?: string; to?: string }): Promise<Migration[]>;
207+
async down(options: { from?: string; to?: string | 0 }): Promise<Migration[]>;
208208

209209
async down(options?: UmzugRunOptions): Promise<Migration[]> {
210210
const getReversedExecuted = async () => {
@@ -396,7 +396,7 @@ export class Umzug extends EventEmitter {
396396
/**
397397
Skip migrations in a given migration list after `to` migration.
398398
*/
399-
private async _findMigrationsUntilMatch(to?: string, migrations?: Migration[]): Promise<string[]> {
399+
private async _findMigrationsUntilMatch(to?: string | 0, migrations?: Migration[]): Promise<string[]> {
400400
if (!Array.isArray(migrations)) {
401401
migrations = [migrations];
402402
}

test/test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Umzug, Migration, migrationsList, memoryStorage } from '../src';
22
import pkgDir = require('pkg-dir');
3+
import { expectTypeOf } from 'expect-type';
34

45
test('Compiles & exports correctly', async () => {
56
const dir = await pkgDir(__dirname);
@@ -15,6 +16,29 @@ test('Compiles & exports correctly', async () => {
1516
expect(requiredJS.migrationsList).toBeTruthy();
1617
});
1718

19+
test('type', () => {
20+
expectTypeOf(Umzug).toBeConstructibleWith();
21+
expectTypeOf(Umzug).toBeConstructibleWith({ storage: memoryStorage() });
22+
expectTypeOf(Umzug).toBeConstructibleWith({ logging: false });
23+
expectTypeOf(Umzug).toBeConstructibleWith({ logging: console.log });
24+
expectTypeOf(Umzug).toBeConstructibleWith({ migrationSorting: (a, b) => a.localeCompare(b) });
25+
expectTypeOf(Umzug).toBeConstructibleWith({ migrations: { path: 'test/abc' } });
26+
27+
expectTypeOf(Umzug).instance.toHaveProperty('up').toBeCallableWith({ to: 'migration123' });
28+
expectTypeOf(Umzug).instance.toHaveProperty('up').toBeCallableWith({ to: 0 });
29+
30+
expectTypeOf(Umzug).instance.toHaveProperty('down').toBeCallableWith({ to: 'migration123' });
31+
expectTypeOf(Umzug).instance.toHaveProperty('down').toBeCallableWith({ to: 0 });
32+
33+
// `{ to: 0 }` is a special case. `{ to: 1 }` shouldn't be allowed:
34+
35+
// @ts-expect-error
36+
expectTypeOf(Umzug).instance.toHaveProperty('up').toBeCallableWith({ to: 1 });
37+
38+
// @ts-expect-error
39+
expectTypeOf(Umzug).instance.toHaveProperty('down').toBeCallableWith({ to: 1 });
40+
});
41+
1842
test('migrationsList() works', async () => {
1943
const executed = [];
2044

0 commit comments

Comments
 (0)