google / intermock

Mocking library to create mock objects with fake data for TypeScript interfaces
https://google.github.io/intermock/
Apache License 2.0
1.14k stars 71 forks source link

Support Typed Arrays #76

Open abarke opened 2 years ago

abarke commented 2 years ago
Error: Type 'Int8Array' is not specified in the provided files but is required for property: 'arr'. Please include it.

Would be awesome if intermock would support Typed Arrays and generate values within each range e.g.

Array<T>
ReadonlyArray<T>
Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array (represented as string for JSON compatibility)
BigInt64Array (represented as string for JSON compatibility)
BigUint64Array (represented as string for JSON compatibility)

e.g.

interface Data {
  str: string
  arr: Int8Array;
}

const arr = [...new Int8Array([127, 0, 0, 1])]

Output

{
  "Data": {
    "str": "voluptatum minima voluptates",
    "arr": [
      127,
      0,
      0,
      1,
    ]
  }
}

Ref: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/globals.d.ts#L94-L106