Skip to content

Commit

Permalink
Add TypeScript definitions (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Aug 5, 2021
1 parent 56aed04 commit 5b909f8
Show file tree
Hide file tree
Showing 8 changed files with 566 additions and 7 deletions.
522 changes: 522 additions & 0 deletions index.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const cleanStack = require('clean-stack');
const dotProp = require('dot-prop');
const CacheConf = require('cache-conf');
const AlfredConfig = require('alfred-config');
const updateNotification = require('./lib/update-notification');
const updateNotification = require('./lib/update-notification.js');

const alfy = module.exports;

Expand Down
34 changes: 34 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-disable @typescript-eslint/no-confusing-void-expression */

import {expectType} from 'tsd';
import alfy, {ScriptFilterItem} from './index.js';

const mockItems: ScriptFilterItem[] = [
{
title: 'Unicorn'
},
{
title: 'Rainbow'
}
];

expectType<void>(alfy.output(mockItems));

expectType<string[]>(alfy.matches('Corn', ['foo', 'unicorn']));

expectType<ScriptFilterItem[]>(alfy.matches('Unicorn', mockItems, 'title'));

expectType<string[]>(alfy.inputMatches(['foo', 'unicorn']));

expectType<ScriptFilterItem[]>(alfy.inputMatches(mockItems, 'title'));

expectType<void>(alfy.error(new Error('some error')));

expectType<void>(alfy.log('some message'));

expectType<Promise<any>>(alfy.fetch('https://foo.bar', {
transform: body => {
body.foo = 'bar';
return body;
}
}));
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"node": ">=10"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts",
"init.js",
"cleanup.js",
"run-node.sh",
Expand Down Expand Up @@ -53,6 +54,8 @@
"delay": "^4.3.0",
"nock": "^13.1.0",
"tempfile": "^3.0.0",
"xo": "^0.24.0"
"tsd": "^0.17.0",
"typescript": "^4.3.5",
"xo": "^0.39.1"
}
}
2 changes: 1 addition & 1 deletion test/cache.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'ava';
import delay from 'delay';
import tempfile from 'tempfile';
import {alfy as createAlfy} from './_utils';
import {alfy as createAlfy} from './_utils.js';

test('no cache', t => {
const alfy = createAlfy();
Expand Down
2 changes: 1 addition & 1 deletion test/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'ava';
import nock from 'nock';
import delay from 'delay';
import tempfile from 'tempfile';
import {alfy as createAlfy} from './_utils';
import {alfy as createAlfy} from './_utils.js';

const URL = 'https://foo.bar';

Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava';
import hookStd from 'hook-std';
import {alfy} from './_utils';
import {alfy} from './_utils.js';

const alfyInstance = alfy();

Expand Down
2 changes: 1 addition & 1 deletion test/user-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import test from 'ava';
import {alfy as createAlfy} from './_utils';
import {alfy as createAlfy} from './_utils.js';

test('read user config', t => {
const alfy = createAlfy({
Expand Down

0 comments on commit 5b909f8

Please sign in to comment.