Skip to content

Commit

Permalink
Merge pull request #2 from yszk0123/add-typescript-declaration-file
Browse files Browse the repository at this point in the history
Add typescript declaration file
  • Loading branch information
necojackarc committed Apr 2, 2019
2 parents ce7621b + 75f69d2 commit 02b3a77
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.6",
"description": "JavaScript extensible custom error that can take a message and/or an Error object",
"main": "src/index.js",
"types": "types/index.d.ts",
"scripts": {
"lint": "eslint src test",
"test": "nyc mocha test",
Expand All @@ -26,6 +27,8 @@
"coveralls": "^3.0.2",
"eslint": "^5.6.1",
"mocha": "^5.2.0",
"nyc": "^13.0.1"
"nyc": "^13.0.1",
"typescript": "^3.4.1",
"typings-tester": "^0.3.2"
}
}
13 changes: 13 additions & 0 deletions test/typescript.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const path = require('path');
const { expect } = require('chai');
const { checkDirectory } = require('typings-tester');

const ExtensibleCustomError = require('../src');

describe('TypeScript definitions', function() {
it('should compile against index.d.ts', function() {
checkDirectory(path.join(__dirname, 'typescript'));
});
});
15 changes: 15 additions & 0 deletions test/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ExtensibleCustomError from 'extensible-custom-error';

new ExtensibleCustomError();

new ExtensibleCustomError('message');

new ExtensibleCustomError(new Error());

new ExtensibleCustomError('message', new Error());

// typings:expect-error
new ExtensibleCustomError(Error);

// typings:expect-error
new ExtensibleCustomError(new Error(), 'message');
10 changes: 10 additions & 0 deletions test/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"lib": ["es2015"],
"strict": true,
"baseUrl": "../..",
"paths": {
"extensible-custom-error": ["types/index.d.ts"]
}
}
}
4 changes: 4 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default class ExtensibleCustomError extends Error {
constructor(message?: string, error?: Error);
constructor(error: Error);
}
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@ commander@2.15.1:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f"
integrity sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==

commander@^2.12.2:
version "2.19.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"
integrity sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==

commander@~2.17.1:
version "2.17.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"
Expand Down Expand Up @@ -2043,6 +2048,18 @@ type-detect@^4.0.0, type-detect@^4.0.5:
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==

typescript@^3.4.1:
version "3.4.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.1.tgz#b6691be11a881ffa9a05765a205cb7383f3b63c6"
integrity sha512-3NSMb2VzDQm8oBTLH6Nj55VVtUEpe/rgkIzMir0qVoLyjDZlnMBva0U6vDiV3IH+sl/Yu6oP5QwsAQtHPmDd2Q==

typings-tester@^0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/typings-tester/-/typings-tester-0.3.2.tgz#04cc499d15ab1d8b2d14dd48415a13d01333bc5b"
integrity sha512-HjGoAM2UoGhmSKKy23TYEKkxlphdJFdix5VvqWFLzH1BJVnnwG38tpC6SXPgqhfFGfHY77RlN1K8ts0dbWBQ7A==
dependencies:
commander "^2.12.2"

uglify-js@^3.1.4:
version "3.4.9"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.9.tgz#af02f180c1207d76432e473ed24a28f4a782bae3"
Expand Down

0 comments on commit 02b3a77

Please sign in to comment.