Skip to content

Commit

Permalink
Merge pull request #220 from cyjake/docs-collection-dts
Browse files Browse the repository at this point in the history
docs: export { Collection }
  • Loading branch information
chenhui5416 authored Nov 1, 2021
2 parents bd5bf9a + 4033fb7 commit 64656ea
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
31 changes: 31 additions & 0 deletions test/types/collection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { strict as assert } from 'assert';
import { Bone, Collection, connect } from '../..';

describe('=> Collection (TypeScript)', function() {
class User extends Bone {
id: number;
createdAt: Date;
deletedAt: Date;
email: string;
nickname: string;
status: number;
}

before(async function() {
Bone.driver = null;
await connect({
dialect: 'sqlite',
database: '/tmp/leoric.sqlite3',
models: [ User ]
});
});

it('collection.save()', async function() {
const users = new Collection(
new User({ nickname: 'siri', email: '[email protected]', status: 0 }),
new User({ nickname: 'xiaoai', email: '[email protected]', status: 1 })
);
await users.save();
assert.equal(await User.count(), 2);
});
});
4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type WithOptions = {
[qualifier: string]: { select: string | string[], throughRelation?: string }
}

declare class Spell<T extends typeof Bone, U = InstanceType<T> | Collection<InstanceType<T>> | ResultSet | number | null> extends Promise<U> {
export class Spell<T extends typeof Bone, U = InstanceType<T> | Collection<InstanceType<T>> | ResultSet | number | null> extends Promise<U> {
constructor(Model: T, opts: SpellOptions);

select(...names: Array<string | RawSql>): Spell<T, U>;
Expand Down Expand Up @@ -207,7 +207,7 @@ type ResultSet = {
[key: string]: Literal
};

declare class Collection<T extends Bone> extends Array<T> {
export class Collection<T extends Bone> extends Array<T> {
save(): Promise<void>;
toJSON(): Object[];
toObject(): Object[];
Expand Down

0 comments on commit 64656ea

Please sign in to comment.