diff --git a/package.json b/package.json index 4df37586..2acfc261 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "version": "2.0.0-alpha.1", "description": "An isomorphic JavaScript client for interacting with the WordPress REST API", "main": "wpapi.js", + "types": "types", "repository": { "type": "git", "url": "https://github.com/wp-api/node-wpapi.git" @@ -57,7 +58,8 @@ "test:integration": "jest tests/integration", "test:ci": "npm run eslint && jest tests/unit --coverage", "pretest": "npm run lint || true", - "test": "jest --coverage" + "test": "jest --coverage", + "dtslint": "dtslint types" }, "dependencies": { "li": "^1.3.0", @@ -75,6 +77,7 @@ "@babel/preset-env": "^7.5.0", "babel-loader": "^8.0.6", "combyne": "^2.0.0", + "dtslint": "^1.0.2", "eslint": "^4.19.1", "grunt": "^1.0.4", "grunt-cli": "^1.2.0", @@ -88,6 +91,7 @@ "minimist": "^1.2.0", "prompt": "^1.0.0", "rimraf": "^2.6.3", + "tslint": "^5.20.0", "webpack": "^4.35.0", "webpack-bundle-analyzer": "^3.3.2", "webpack-cli": "^3.3.5" diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 00000000..76ba39a6 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,30 @@ +// TypeScript Version: 2.2 + +/** + * UMD export + */ +export as namespace WPAPI; +export = WPAPI; + +declare class WPAPI { + constructor(options: any); + auth(credentials: any): any; + bootstrap(routes: any): any; + namespace(namespace: any): any; + registerRoute(namespace: any, restBase: any, options: any): any; + root(relativePath: any): any; + setHeaders(headers: any, value: any): any; + transport(transport: any): any; + url(url: any): any; + static discover(url: any): any; + static site(endpoint: any, routes: any): any; +} + +declare namespace WPAPI { + namespace transport { + function get(wpreq: any, callback: any): any; + function head(wpreq: any, callback: any): any; + function post(wpreq: any, data: any, callback: any): any; + function put(wpreq: any, data: any, callback: any): any; + } +} diff --git a/types/tests.ts b/types/tests.ts new file mode 100644 index 00000000..aff57624 --- /dev/null +++ b/types/tests.ts @@ -0,0 +1,5 @@ +import * as WPAPI from "wpapi"; + +const instance = new WPAPI(''); // $ExpectType WPAPI + +instance.auth(); // $ExpectError diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 00000000..9abcb77a --- /dev/null +++ b/types/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "paths": { + "wpapi": ["."] + }, + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "tests.ts" + ] +} diff --git a/types/tslint.json b/types/tslint.json new file mode 100644 index 00000000..4c3a5489 --- /dev/null +++ b/types/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dtslint.json" +}