From 1ee8279dd903d8a260b8614076931be2d48e7356 Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Sat, 11 Jan 2025 13:25:54 +0800 Subject: [PATCH] chore: remove useless as --- package.json | 1 + test/scripts/database.ts | 2 +- test/scripts/document.ts | 2 +- test/scripts/model.ts | 21 ++++++++++----------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 053adfd..0464c55 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "devDependencies": { "@types/bluebird": "^3.5.37", "@types/chai": "^4.3.3", + "@types/chai-as-promised": "^8.0.1", "@types/graceful-fs": "^4.1.5", "@types/jsonstream": "^0.8.30", "@types/mocha": "^10.0.0", diff --git a/test/scripts/database.ts b/test/scripts/database.ts index 7edafe9..702852d 100644 --- a/test/scripts/database.ts +++ b/test/scripts/database.ts @@ -114,7 +114,7 @@ describe('Database', () => { const model = db.model('Test'); const json = db.toJSON(); json.meta.version.should.eql(0); - (json.models as any).Test.should.eql(model); + json.models.Test.should.eql(model); console.log(db.toJSON()); }); }); diff --git a/test/scripts/document.ts b/test/scripts/document.ts index ac9fd00..cf523f4 100644 --- a/test/scripts/document.ts +++ b/test/scripts/document.ts @@ -51,7 +51,7 @@ describe('Document', () => { const doc = User.new({}); return doc.save().then(item => { - User.findById(doc._id as string | number).should.exist; + User.findById(doc._id).should.exist; return User.removeById(item._id); }); }); diff --git a/test/scripts/model.ts b/test/scripts/model.ts index 6b3748c..6508229 100644 --- a/test/scripts/model.ts +++ b/test/scripts/model.ts @@ -9,8 +9,6 @@ import Promise from 'bluebird'; import sinon from 'sinon'; import { nanoid } from 'nanoid'; import Database from '../../src/database'; -import type Query from '../../src/query'; -import type Document from '../../src/document'; import type Model from '../../src/model'; interface UserType { @@ -124,18 +122,19 @@ describe('Model', () => { it('insert() - no id', () => { const doc = User.new(); + // @ts-ignore delete doc._id; - return (User.insert(doc) as any).should.eventually.be.rejected; + return User.insert(doc).should.eventually.be.rejected; }); it('insert() - already existed', () => { let user; - return (User.insert({}).then(data => { + return User.insert({}).then(data => { user = data; return User.insert(data); - }).finally(() => User.removeById(user._id)) as any).should.eventually.be.rejected; + }).finally(() => User.removeById(user._id)).should.eventually.be.rejected; }); it('insert() - hook', () => { @@ -329,7 +328,7 @@ describe('Model', () => { return data; }).then(data => User.removeById(data._id))); - it('updateById() - id not exist', () => (User.updateById('foo', {}) as any).should.eventually.be.rejected); + it('updateById() - id not exist', () => User.updateById('foo', {}).should.eventually.be.rejected); it('updateById() - hook', () => { const db = new Database(); @@ -399,7 +398,7 @@ describe('Model', () => { }).then(data => User.removeById(data._id)); }); - it('replaceById() - id not exist', () => (User.replaceById('foo', {}) as any).should.eventually.be.rejected); + it('replaceById() - id not exist', () => User.replaceById('foo', {}).should.eventually.be.rejected); it('replaceById() - pre-hook', () => { const db = new Database(); @@ -458,7 +457,7 @@ describe('Model', () => { }); }); - it('removeById() - id not exist', () => (User.removeById('foo', () => {}) as any).should.eventually.be.rejected); + it('removeById() - id not exist', () => User.removeById('foo', () => {}).should.eventually.be.rejected); it('removeById() - hook', () => { const db = new Database(); @@ -555,7 +554,7 @@ describe('Model', () => { {age: 30}, {age: 40} ]).then(data => { - const query = User.find({age: {$gt: 20}}) as Query; + const query = User.find({age: {$gt: 20}}); query.data.should.eql(data.slice(2)); return data; }).map(item => User.removeById(item._id))); @@ -695,7 +694,7 @@ describe('Model', () => { {age: 30}, {age: 40} ]).then(data => { - (User.findOne({age: {$gt: 20}}, {lean: true}) as Document)._id!.should.eql(data[2]._id); + (User.findOne({age: {$gt: 20}}, {lean: true}) as UserType & { _id: string })._id.should.eql(data[2]._id); return data; }).map(item => User.removeById(item._id))); @@ -1259,7 +1258,7 @@ describe('Model', () => { const Test = db.model('Test', schema); - (Test as any).add({name: 'foo'}).then(data => { + Test.add({name: 'foo'}).then(data => { data.name.should.eql('foo'); });