Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generated types declaration for minimal typescript support #447

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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"
Expand Down
30 changes: 30 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 5 additions & 0 deletions types/tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as WPAPI from "wpapi";

const instance = new WPAPI(''); // $ExpectType WPAPI

instance.auth(); // $ExpectError
26 changes: 26 additions & 0 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
3 changes: 3 additions & 0 deletions types/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dtslint.json"
}