Skip to content

Commit 8dd4376

Browse files
authored
fix: generate types from jsdoc (#34)
Otherwise the types end up invalid.
1 parent 5e774e0 commit 8dd4376

9 files changed

+1500
-1067
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
node_modules
22
npm-debug.*
33
*.tsbuildinfo
4+
dist
5+
index.umd.js
6+
*.tgz

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
language: node_js
22
node_js:
3-
- "4"
4-
- "6"
3+
- "14"
4+
- "15"

index.d.ts

-16
This file was deleted.

index.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
'use strict';
22

3+
/**
4+
* @typedef {{ [key: string]: any }} Extensions
5+
* @typedef {Error} Err
6+
* @property {string} message
7+
*/
8+
9+
/**
10+
*
11+
* @param {Error} obj
12+
* @param {Extensions} props
13+
* @returns {Error & Extensions}
14+
*/
315
function assign(obj, props) {
416
for (const key in props) {
517
Object.defineProperty(obj, key, {
@@ -12,6 +24,13 @@ function assign(obj, props) {
1224
return obj;
1325
}
1426

27+
/**
28+
*
29+
* @param {any} err - An Error
30+
* @param {string|Extensions} code - A string code or props to set on the error
31+
* @param {Extensions} [props] - Props to set on the error
32+
* @returns {Error & Extensions}
33+
*/
1534
function createError(err, code, props) {
1635
if (!err || typeof err === 'string') {
1736
throw new TypeError('Please pass an Error to err-code');
@@ -23,10 +42,10 @@ function createError(err, code, props) {
2342

2443
if (typeof code === 'object') {
2544
props = code;
26-
code = undefined;
45+
code = '';
2746
}
2847

29-
if (code != null) {
48+
if (code) {
3049
props.code = code;
3150
}
3251

@@ -40,7 +59,10 @@ function createError(err, code, props) {
4059

4160
ErrClass.prototype = Object.create(Object.getPrototypeOf(err));
4261

43-
return assign(new ErrClass(), props);
62+
// @ts-ignore
63+
const output = assign(new ErrClass(), props);
64+
65+
return output;
4466
}
4567
}
4668

index.umd.js

-51
This file was deleted.

0 commit comments

Comments
 (0)