[r-script] Added typings. (#19027)

This commit is contained in:
Adrian Leonhard
2017-08-16 19:10:53 +02:00
committed by Mohamed Hegazy
parent b7b8a3650b
commit 05c8f3c833
4 changed files with 77 additions and 0 deletions

32
types/r-script/index.d.ts vendored Normal file
View File

@@ -0,0 +1,32 @@
// Type definitions for r-script 0.0
// Project: https://github.com/joshkatz/r-script
// Definitions by: Adrian Leonhard <https://github.com/NaridaL/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
interface R {
data(...args: any[]): this;
call(callback: (err: any, d: any) => void): void;
call(options: R.Options, callback: (err: any, d: any) => void): void;
callSync(options?: R.Options): any;
}
declare namespace R {
interface Options {
dataframe?: "rows" | "colums" | "values";
matrix?: "rowmajor" | "columnmajor";
Date?: "ISO8601" | "epoch";
POSIXt?: "string" | "ISO8601" | "epoch" | "mongo";
factor?: "string" | "integer";
complex?: "string" | "list";
raw?: "base64" | "hex" | "mongo";
null?: "list" | "null";
na?: "null" | "string";
auto_unbox?: boolean;
digits?: number;
pretty?: boolean;
force?: boolean;
[key: string]: any;
}
}
declare function R(scriptPath: string): R;
export = R;

View File

@@ -0,0 +1,22 @@
import R = require('r-script');
function RPromise(r: R): Promise<any> {
return new Promise((resolve, reject) => {
r.call((err, d) => {
if (err) {
reject(err);
} else {
resolve(d);
}
});
});
}
const options: R.Options = {
dataframe: "rows",
anotherRandomOption: true
};
const result1 = R("foo.R").data("string data param", "another one").callSync();
const result2 = R("foo.R").data("string data param", "another one").callSync(options);
R("foo.R").data("string data param", "another one").call(options, (err, d) => d);
R("foo.R").data("string data param", "another one").call((err, d) => d);

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"r-script-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }