From 6d215a6002f36c577ec62fe99d3385b194b0265b Mon Sep 17 00:00:00 2001 From: Josh Pollock Date: Wed, 30 Oct 2019 13:08:28 -0400 Subject: [PATCH 1/2] add manually generated types #149 --- types/index.d.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 types/index.d.ts diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 00000000..e69de29b From 32cbe72ecef45af91d4a81a2f76492d076404572 Mon Sep 17 00:00:00 2001 From: Andrew Luca Date: Fri, 1 Nov 2019 13:14:54 +0200 Subject: [PATCH 2/2] feat(types): add base files --- package.json | 6 +++++- types/index.d.ts | 30 ++++++++++++++++++++++++++++++ types/tests.ts | 5 +++++ types/tsconfig.json | 26 ++++++++++++++++++++++++++ types/tslint.json | 3 +++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 types/tests.ts create mode 100644 types/tsconfig.json create mode 100644 types/tslint.json 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 index e69de29b..76ba39a6 100644 --- a/types/index.d.ts +++ 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" +}