Skip to content

Commit

Permalink
feat: add typescript definitions (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForbesLindesay authored Apr 26, 2020
1 parent 3af13e9 commit 19c6d89
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ commands:
command: npm pack
- run:
name: Setup Import Test
command: echo $PWD && cd .. && mkdir test-import && cp -a project/test-import/ test-import/test-import/ && cd test-import && npm init -y && npm i ../project/is-promise-2.2.2.tgz
command: echo $PWD && cd .. && cp -a project/test-import/ test-import/ && cd test-import && npm i && npm i ../project/is-promise-2.2.2.tgz
- run:
name: Test Import
command: cd ../test-import && node test-import/test.js
command: cd ../test-import && npm test

publish-dry-run:
steps:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"files": [
"index.js",
"index.mjs"
"index.mjs",
"index.d.ts"
],
"repository": {
"type": "git",
Expand Down
9 changes: 9 additions & 0 deletions test-import/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as ta from 'type-assertions';
import isPromise from 'is-promise';

declare const x: number | Promise<string>;
if (isPromise(x)) {
ta.assert<ta.Equal<typeof x, Promise<string>>>();
} else {
ta.assert<ta.Equal<typeof x, number>>();
}
11 changes: 11 additions & 0 deletions test-import/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "is-promise-test-import",
"private": true,
"@rollingversions/ignore": true,
"scripts": {
"test": "node test"
},
"dependencies": {
"type-assertions": "^1.1.0"
}
}
8 changes: 7 additions & 1 deletion test-import/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ console.log('CommonJS tests passed')

if(parseInt(process.version.split('.')[0].substr(1), 10) >= 14) {
const result = require('child_process').spawnSync('node', ['test.mjs'], {cwd: __dirname, stdio: 'inherit'});
process.exit(result.status);
if (result.status) process.exit(result.status);
}

if(parseInt(process.version.split('.')[0].substr(1), 10) >= 12) {
const result = require('child_process').spawnSync('npx', ['typescript', 'index.ts'], {cwd: __dirname, stdio: 'inherit'});
if (result.status) process.exit(result.status);
console.log('TypeScript tests passed');
}
7 changes: 7 additions & 0 deletions test-import/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"noImplicitAny": true,
"skipLibCheck": false,
"strict": true
}
}

0 comments on commit 19c6d89

Please sign in to comment.