Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add typescript definitions #31

Merged
merged 9 commits into from
Apr 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}