Skip to content

Commit 5b909f8

Browse files
authored
Add TypeScript definitions (#138)
1 parent 56aed04 commit 5b909f8

File tree

8 files changed

+566
-7
lines changed

8 files changed

+566
-7
lines changed

index.d.ts

Lines changed: 522 additions & 0 deletions
Large diffs are not rendered by default.

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const cleanStack = require('clean-stack');
88
const dotProp = require('dot-prop');
99
const CacheConf = require('cache-conf');
1010
const AlfredConfig = require('alfred-config');
11-
const updateNotification = require('./lib/update-notification');
11+
const updateNotification = require('./lib/update-notification.js');
1212

1313
const alfy = module.exports;
1414

index.test-d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* eslint-disable @typescript-eslint/no-confusing-void-expression */
2+
3+
import {expectType} from 'tsd';
4+
import alfy, {ScriptFilterItem} from './index.js';
5+
6+
const mockItems: ScriptFilterItem[] = [
7+
{
8+
title: 'Unicorn'
9+
},
10+
{
11+
title: 'Rainbow'
12+
}
13+
];
14+
15+
expectType<void>(alfy.output(mockItems));
16+
17+
expectType<string[]>(alfy.matches('Corn', ['foo', 'unicorn']));
18+
19+
expectType<ScriptFilterItem[]>(alfy.matches('Unicorn', mockItems, 'title'));
20+
21+
expectType<string[]>(alfy.inputMatches(['foo', 'unicorn']));
22+
23+
expectType<ScriptFilterItem[]>(alfy.inputMatches(mockItems, 'title'));
24+
25+
expectType<void>(alfy.error(new Error('some error')));
26+
27+
expectType<void>(alfy.log('some message'));
28+
29+
expectType<Promise<any>>(alfy.fetch('https://foo.bar', {
30+
transform: body => {
31+
body.foo = 'bar';
32+
return body;
33+
}
34+
}));

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"node": ">=10"
1414
},
1515
"scripts": {
16-
"test": "xo && ava"
16+
"test": "xo && ava && tsd"
1717
},
1818
"files": [
1919
"index.js",
20+
"index.d.ts",
2021
"init.js",
2122
"cleanup.js",
2223
"run-node.sh",
@@ -53,6 +54,8 @@
5354
"delay": "^4.3.0",
5455
"nock": "^13.1.0",
5556
"tempfile": "^3.0.0",
56-
"xo": "^0.24.0"
57+
"tsd": "^0.17.0",
58+
"typescript": "^4.3.5",
59+
"xo": "^0.39.1"
5760
}
5861
}

test/cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava';
22
import delay from 'delay';
33
import tempfile from 'tempfile';
4-
import {alfy as createAlfy} from './_utils';
4+
import {alfy as createAlfy} from './_utils.js';
55

66
test('no cache', t => {
77
const alfy = createAlfy();

test/fetch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import test from 'ava';
22
import nock from 'nock';
33
import delay from 'delay';
44
import tempfile from 'tempfile';
5-
import {alfy as createAlfy} from './_utils';
5+
import {alfy as createAlfy} from './_utils.js';
66

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

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava';
22
import hookStd from 'hook-std';
3-
import {alfy} from './_utils';
3+
import {alfy} from './_utils.js';
44

55
const alfyInstance = alfy();
66

test/user-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path';
22
import test from 'ava';
3-
import {alfy as createAlfy} from './_utils';
3+
import {alfy as createAlfy} from './_utils.js';
44

55
test('read user config', t => {
66
const alfy = createAlfy({

0 commit comments

Comments
 (0)