Skip to content

Commit

Permalink
chore: TypeScript support (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
BaffinLee authored and atian25 committed Jul 2, 2018
1 parent 7643e78 commit a8b4ece
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
43 changes: 43 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as mongoose from 'mongoose';

declare module 'egg' {

type MongooseModels = {
[key: string]: mongoose.Model<any>
};

type MongooseSingleton = {
clients: Map<string, mongoose.Connection>,
get (id: string) : mongoose.Connection
};

type MongooseConfig = {
url: string,
options?: mongoose.ConnectionOptions
};

// extend app
interface Application {
mongooseDB: mongoose.Connection | MongooseSingleton;
mongoose: typeof mongoose;
model: MongooseModels;
}

// extend context
interface Context {
model: MongooseModels;
}

// extend your config
interface EggAppConfig {
mongoose: {
url?: string,
options?: mongoose.ConnectionOptions,
client?: MongooseConfig,
clients?: {
[key: string]: MongooseConfig
}
};
}

}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"mongoose": "^5.0.17"
},
"devDependencies": {
"@types/mongoose": "^5.0.18",
"autod": "^2.7.1",
"bluebird": "^3.5.1",
"dotenv": "^5.0.1",
Expand All @@ -41,6 +42,7 @@
},
"files": [
"index.js",
"index.d.ts",
"app.js",
"agent.js",
"config",
Expand Down

0 comments on commit a8b4ece

Please sign in to comment.