forked from sindresorhus/write-json-file
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test-d.ts
43 lines (39 loc) · 2.94 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
import {expectType, expectAssignable} from 'tsd';
import {writeJsonFile, writeJsonFileSync, Replacer, SortKeys} from './index.js';
expectAssignable<SortKeys>(() => 1);
expectAssignable<SortKeys>((a: string) => a.length);
expectAssignable<SortKeys>((a: string, b: string) => a.length - b.length);
expectAssignable<Replacer>(() => 1);
expectAssignable<Replacer>(() => 'unicorn');
expectAssignable<Replacer>(() => true);
expectAssignable<Replacer>(() => null);
expectAssignable<Replacer>(() => undefined);
expectAssignable<Replacer>(() => ({unicorn: '🦄'}));
expectAssignable<Replacer>(() => ['unicorn', 1]);
expectAssignable<Replacer>(() => () => 'foo');
expectAssignable<Replacer>((key: string) => key.toUpperCase());
expectAssignable<Replacer>((key: string, value: unknown) => (key + (value as string)).toUpperCase());
expectType<Promise<void>>(writeJsonFile('unicorn.json', {unicorn: '🦄'}));
expectType<Promise<void>>(writeJsonFile('unicorn.json', '🦄'));
expectType<Promise<void>>(writeJsonFile('date.json', new Date()));
expectType<Promise<void>>(writeJsonFile('unicorn.json', {unicorn: '🦄'}, {detectIndent: true}));
expectType<Promise<void>>(writeJsonFile('unicorn.json', {unicorn: '🦄'}, {indent: ' '}));
expectType<Promise<void>>(writeJsonFile('unicorn.json', {unicorn: '🦄'}, {indent: 4}));
expectType<Promise<void>>(writeJsonFile('unicorn.json', {unicorn: '🦄'}, {mode: 0o666}));
expectType<Promise<void>>(writeJsonFile('unicorn.json', {unicorn: '🦄'}, {replacer: ['unicorn', 1]}));
expectType<Promise<void>>(writeJsonFile('unicorn.json', {unicorn: '🦄'}, {replacer: () => 'unicorn'}));
expectType<Promise<void>>(writeJsonFile('unicorn.json', {unicorn: '🦄'}, {sortKeys: () => -1}));
expectType<Promise<void>>(writeJsonFile('unicorn.json', {unicorn: '🦄'}, {sortKeys: (a: string, b: string) => a.length - b.length}));
expectType<Promise<void>>(writeJsonFile('unicorn.json', {unicorn: '🦄'}, {sortKeys: true}));
expectType<void>(writeJsonFileSync('unicorn.json', {unicorn: '🦄'}));
expectType<void>(writeJsonFileSync('unicorn.json', '🦄'));
expectType<void>(writeJsonFileSync('date.json', new Date()));
expectType<void>(writeJsonFileSync('unicorn.json', {unicorn: '🦄'}, {detectIndent: true}));
expectType<void>(writeJsonFileSync('unicorn.json', {unicorn: '🦄'}, {indent: ' '}));
expectType<void>(writeJsonFileSync('unicorn.json', {unicorn: '🦄'}, {indent: 4}));
expectType<void>(writeJsonFileSync('unicorn.json', {unicorn: '🦄'}, {mode: 0o666}));
expectType<void>(writeJsonFileSync('unicorn.json', {unicorn: '🦄'}, {replacer: ['unicorn', 1]}));
expectType<void>(writeJsonFileSync('unicorn.json', {unicorn: '🦄'}, {replacer: () => 'unicorn'}));
expectType<void>(writeJsonFileSync('unicorn.json', {unicorn: '🦄'}, {sortKeys: () => -1}));
expectType<void>(writeJsonFileSync('unicorn.json', {unicorn: '🦄'}, {sortKeys: (a: string, b: string) => a.length - b.length}));
expectType<void>(writeJsonFileSync('unicorn.json', {unicorn: '🦄'}, {sortKeys: true}));