forked from sindresorhus/package-json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test-d.ts
37 lines (32 loc) · 1.27 KB
/
index.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import {expectType} from 'tsd';
import packageJson = require('.');
import {
FullMetadata,
FullVersion,
AbbreviatedMetadata,
AbbreviatedVersion,
PackageNotFoundError,
VersionNotFoundError
} from '.';
expectType<Promise<AbbreviatedMetadata>>(packageJson('package-json'));
expectType<Promise<AbbreviatedMetadata>>(
packageJson('package-json', {version: '1.2.3'})
);
expectType<Promise<AbbreviatedMetadata>>(
packageJson('package-json', {allVersions: true})
);
expectType<Promise<FullMetadata>>(
packageJson('package-json', {fullMetadata: true})
);
const abbreviatedMetadata = await packageJson('package-json');
expectType<AbbreviatedVersion>(abbreviatedMetadata.versions['1.2.3']);
const fullMetadata = await packageJson('package-json', {fullMetadata: true});
expectType<FullVersion>(fullMetadata.versions['1.2.3']);
expectType<typeof PackageNotFoundError>(PackageNotFoundError);
expectType<typeof VersionNotFoundError>(VersionNotFoundError);
const packageNotFoundError = new PackageNotFoundError('foo');
packageNotFoundError instanceof PackageNotFoundError;
expectType<PackageNotFoundError>(packageNotFoundError);
const versionNotFoundError = new VersionNotFoundError('foo', 'bar');
versionNotFoundError instanceof VersionNotFoundError;
expectType<VersionNotFoundError>(versionNotFoundError);