Skip to content

Commit

Permalink
Removed all uses of JSONValue with any
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMinkov committed Nov 9, 2022
1 parent fddde96 commit 8e7b36a
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/lib/circuit_value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export {
InferCircuitValue,
Provables,
HashInput,
JSONValue,
};

type Constructor<T> = new (...args: any) => T;
Expand Down Expand Up @@ -207,7 +206,7 @@ abstract class CircuitValue {
}

static toJSON<T extends AnyConstructor>(this: T, v: InstanceType<T>) {
const res: { [key: string]: any } = {};
const res: any = {};
if ((this as any).prototype._fields !== undefined) {
const fields: [string, any][] = (this as any).prototype._fields;
fields.forEach(([key, propType]) => {
Expand Down Expand Up @@ -434,11 +433,11 @@ function circuitMain(
let primitives = new Set(['Field', 'Bool', 'Scalar', 'Group']);
let complexTypes = new Set(['object', 'function']);

type ProvableExtension<T, TJson = JSONValue> = {
type ProvableExtension<T, TJson = any> = {
toInput: (x: T) => { fields?: Field[]; packed?: [Field, number][] };
toJSON: (x: T) => TJson;
};
type ProvableExtended<T, TJson = JSONValue> = Provable<T> &
type ProvableExtended<T, TJson = any> = Provable<T> &
ProvableExtension<T, TJson>;

function provable<A>(
Expand Down Expand Up @@ -513,7 +512,7 @@ function provable<A>(
.map((k) => toInput(typeObj[k], obj[k]))
.reduce(HashInput.append, {});
}
function toJSON(typeObj: any, obj: any, isToplevel = false): JSONValue {
function toJSON(typeObj: any, obj: any, isToplevel = false): any {
if (typeObj === BigInt) return obj.toString();
if (typeObj === String || typeObj === Number || typeObj === Boolean)
return obj;
Expand Down Expand Up @@ -1072,14 +1071,6 @@ function getBlindingValue() {

type Tuple<T> = [T, ...T[]] | [];

type JSONValue =
| number
| string
| boolean
| null
| Array<JSONValue>
| { [key: string]: JSONValue };

type Primitive =
| typeof String
| typeof Number
Expand Down Expand Up @@ -1112,7 +1103,7 @@ type InferPrimitiveJson<P extends Primitive> = P extends typeof String
? null
: P extends undefined
? null
: JSONValue;
: any;

type InferCircuitValue<A> = A extends Constructor<infer U>
? A extends Provable<U>
Expand Down Expand Up @@ -1152,7 +1143,7 @@ type InferJson<A> = A extends WithJson<infer J>
? {
[K in keyof A]: InferJson<A[K]>;
}
: JSONValue;
: any;

type IsPure<A> = IsPureBase<A> extends true ? true : false;

Expand Down

0 comments on commit 8e7b36a

Please sign in to comment.