-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
index.test-d.ts
51 lines (43 loc) · 2.08 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {expectType, expectAssignable, expectError} from 'tsd';
import packageJson, {
type FullMetadata,
type FullVersion,
type AbbreviatedMetadata,
type AbbreviatedVersion,
PackageNotFoundError,
VersionNotFoundError,
} from './index.js';
expectAssignable<Promise<AbbreviatedVersion>>(packageJson('package-json'));
expectAssignable<Promise<AbbreviatedVersion>>(
packageJson('package-json', {version: '1.2.3'}),
);
expectAssignable<Promise<AbbreviatedMetadata>>(
packageJson('package-json', {allVersions: true}),
);
expectAssignable<Promise<FullVersion>>(
packageJson('package-json', {fullMetadata: true}),
);
expectAssignable<Promise<FullMetadata>>(
packageJson('package-json', {fullMetadata: true, allVersions: true}),
);
const abbreviatedMetadata = await packageJson('package-json');
expectType<string>(abbreviatedMetadata.version);
expectError(abbreviatedMetadata.versions);
const fullMetadata = await packageJson('package-json', {fullMetadata: true});
expectType<string>(fullMetadata.version);
expectType<unknown>(fullMetadata.versions);
expectError(fullMetadata.versions['1.2.3']);
const abbreviatedVersions = await packageJson('package-json', {allVersions: true});
expectAssignable<AbbreviatedVersion | undefined>(abbreviatedVersions.versions['1.2.3']);
expectError(abbreviatedVersions.version);
const fullVersions = await packageJson('package-json', {fullMetadata: true, allVersions: true});
expectAssignable<FullVersion | undefined>(fullVersions.versions['1.2.3']);
expectError(fullVersions.version);
expectType<typeof PackageNotFoundError>(PackageNotFoundError);
expectType<typeof VersionNotFoundError>(VersionNotFoundError);
const packageNotFoundError = new PackageNotFoundError('foo');
packageNotFoundError instanceof PackageNotFoundError; // eslint-disable-line @typescript-eslint/no-unused-expressions
expectType<PackageNotFoundError>(packageNotFoundError);
const versionNotFoundError = new VersionNotFoundError('foo', 'bar');
versionNotFoundError instanceof VersionNotFoundError; // eslint-disable-line @typescript-eslint/no-unused-expressions
expectType<VersionNotFoundError>(versionNotFoundError);