Skip to content

Commit

Permalink
Merge pull request #4 from krakenjs/typescript-def
Browse files Browse the repository at this point in the history
chore: add typescript definition
  • Loading branch information
westeezy authored Mar 23, 2022
2 parents c6cb6f7 + bf66f24 commit e5cbdfe
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
11 changes: 11 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import express from 'express';

export interface AppServerType {
EVENT: { SHUTDOWN: 'shutdown' };
close: () => Promise<void>;
on: (event: string, handler: () => void) => { cancel: () => void; } ;
listen: (options: {port: number}) => Promise<AppServerType>;
get: (url: string, handler: (req: express.Request, res: express.Response) => Promise<void> | void) => AppServerType;
}

export function server(): AppServerType;
6 changes: 6 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { expectType } from 'tsd';

import {AppServerType, server} from '.';


const appServer: AppServerType = server();
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
"version": "1.0.10",
"description": "Express with promises",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"flow-typed": "flow-typed install",
"flow:build": "flow gen-flow-files ./src/index.js --out-dir ./src",
"babel": "babel src/*.js src/**/*.js --exclude=node_modules --out-dir . --source-maps inline",
"test": "npm run flow-typed && npm run lint && npm run flow-typed && npm run flow",
"test": "npm run flow-typed && npm run lint && npm run flow && npm run tsd",
"tsd": "tsd",
"flow": "flow",
"lint": "eslint src/ *.js",
"prepublish": "in-publish && npm run babel || not-in-publish",
"postpublish": "git checkout ./src",
"jest": "jest test --env=node --no-cache --coverage --verbose --runInBand"
"postpublish": "git checkout ./src"
},
"repository": {
"type": "git",
Expand All @@ -30,9 +31,10 @@
},
"homepage": "https://github.com/krakenjs/subprocess-robot#readme",
"devDependencies": {
"@types/express": "^4.17.13",
"flow-bin": "^0.69.0",
"grumbler-scripts": "^2.0.7",
"jest": "^22.4.3",
"tsd": "^0.19.1",
"yargs-parser": "^10.0.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import https from 'https';

import express from 'express';
import express from 'express'; // eslint-disable-line import/no-unresolved

type ExpressRequest = express$Request; // eslint-disable-line no-undef
type ExpressResponse = express$Response; // eslint-disable-line no-undef
Expand Down

0 comments on commit e5cbdfe

Please sign in to comment.