Skip to content

Commit bc57655

Browse files
committed
fix: 💪 more strict generic type restriction
1 parent eb099e4 commit bc57655

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

‎src/index.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PackageJson, PartialDeep, TsConfigJson } from "type-fest";
1+
import { PackageJson, PartialDeep, TsConfigJson, JsonValue } from "type-fest";
22
import detectIndent from "detect-indent";
33
import stripBom from "strip-bom";
44
import parseJson from "parse-json";
@@ -39,14 +39,16 @@ type ModifyFields<T extends object> = {
3939
};
4040

4141
type ModifyFunction<T> = (oldJson: T) => MaybePromise<T>;
42+
// todo why can't use JsonValue from type-fest
43+
type JsonRoot = number | string | boolean | null | object | any[];
4244

43-
export type ModifyJsonFileFunction<T> = (
45+
export type ModifyJsonFileFunction<T extends JsonRoot> = (
4446
path: string,
4547
modifyFields: T extends object ? ModifyFields<T> | ModifyFunction<T> : ModifyFunction<T>,
4648
options?: Partial<Options>
4749
) => Promise<void>;
4850

49-
type ModifyJsonFileGenericFunction = <T extends any = object>(
51+
type ModifyJsonFileGenericFunction = <T extends JsonRoot = object>(
5052
path: string,
5153
modifyFields: T extends object ? ModifyFields<T> | ModifyFunction<T> : ModifyFunction<T>,
5254
options?: Partial<Options>

0 commit comments

Comments
 (0)