This library was originally written by DoctorLai. So, I decide to write the Typescript definition for those who wants to use this library in Typescript and avoid linter errors.
Benefits
Strongly typed have the benefit of being used in a Typescript environment. For instance, if you import the library without the types definitions, the tslinter will throw errors due that datatype is not specified in Javascript. By having types definitions, these errors can be avoided and you can also gain the benefit of autocompletion of code + documentation in the available methods (which is not possible with a plain Javascript library since Typescript parse it as "any" type).
Installation
First, you need to copy the "types" folder into the root of your project and tell Typescript your folder for custom typings:
"typeRoots" : ["./types/knife-edge-propagation"]
so, your tsconfig.json should look similar to this one:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"sourceMap": true,
"typeRoots" : ["./types/knife-edge-propagation"]
}
}
Examples
Typescript
import * as kep from 'knife_edge_propagation';
let d1 = 15;
let d2 = 25;
let h = 5;
let r = 0.002;
let v = kep.knife_edge_compute_v(d1, d2, h, r);
let p1 = kep.knife_edge_compute_pathloss(v);
let p2 = kep.knife_edge_compute_pathloss_lee(v);
console.log("v: ",v);
console.log("p1: ",p1);
console.log("p2: ",p2);
console.log("h: ",kep.knife_edge_compute_h(10, 100, 5, 60, 7));
Typescript
import * as kep from 'knife_edge_propagation';
let d1 = 15;
let d2 = 25;
let h = 5;
let r = 0.002;
let v = kep.knife_edge_compute_v(d1, d2, h, r);
let p1 = kep.knife_edge_compute_pathloss(v);
let p2 = kep.knife_edge_compute_pathloss_lee(v);
console.log("v: ",v);
console.log("p1: ",p1);
console.log("p2: ",p2);
console.log("h: ",kep.knife_edge_compute_h(10, 100, 5, 60, 7));
Javascript
var kep = require('knife_edge_propagation');
let d1 = 15;
let d2 = 25;
let h = 5;
let r = 0.002;
let v = kep.knife_edge_compute_v(d1, d2, h, r);
let p1 = kep.knife_edge_compute_pathloss(v);
let p2 = kep.knife_edge_compute_pathloss_lee(v);
console.log("v: ",v);
console.log("p1: ",p1);
console.log("p2: ",p2);
console.log("h: ",kep.knife_edge_compute_h(10, 100, 5, 60, 7));
AMD
define(function(require,exports,module){
var kep = require('knife_edge_propagation');
let d1 = 15;
let d2 = 25;
let h = 5;
let r = 0.002;
let v = kep.knife_edge_compute_v(d1, d2, h, r);
let p1 = kep.knife_edge_compute_pathloss(v);
let p2 = kep.knife_edge_compute_pathloss_lee(v);
console.log("v: ",v);
console.log("p1: ",p1);
console.log("p2: ",p2);
console.log("h: ",kep.knife_edge_compute_h(10, 100, 5, 60, 7));
});
All these examples should return the following output:
Contributions
- Fork this repo https://github.com/jayserdny/knife-edge-propagation-types
- Create a new branch with your feature name. i.e. git checkout -b feature-name
- Commit the change you've made: git commit -am 'Feature added'
- Push the changes to your new branch: git push origin feature-name
- Submit a PR (Pull Request)
Github account proof
Posted on Utopian.io - Rewarding Open Source Contributors