question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

saveAsJSON() method not found

See original GitHub issue

The README says that you can call .saveAsJSON() on any bloom filter to get a serialization of the bloom filter state that can be persisted or sent over the network. When I try to use it, however, my Typescript code fails to compile with the error: error TS2339: Property 'saveAsJSON' does not exist on type 'BloomFilter'.

My code looks like:

import { BloomFilter } from 'bloom-filters'

// [...]
const bloomFilterEntries = new Set<string>()
// [...]

const bloomFilter = BloomFilter.from(bloomFilterEntries, 0.01)
const bloomJSON = bloomFilter.saveAsJSON()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
folkvircommented, Mar 15, 2021

@Callidon @stbrody Unfortunately with our templating methods and decorators we cannot make a small change without redefining fromJSON in all Filters of the project. So in the last commit I defined the return type of fromJSON to any this way you can have type definitions only in two ways.

  • const b: BloomFilter = BloomFilter.fromJSON(bloomJSON)
  • const b = BloomFilter.fromJSON(bloomJSON) as BloomFilter

This is the only solution for us.

Working example:

import { BloomFilter } from '../../bloom-filters/dist/api'

// [...]
const bloomFilterEntries = new Set<string>(["test"])
// [...]

const bloomFilter: BloomFilter = BloomFilter.from(bloomFilterEntries, 0.01)
const bloomJSON: Object = bloomFilter.saveAsJSON()
console.log('JSON: ', bloomJSON)
const b: BloomFilter = BloomFilter.fromJSON(bloomJSON)
console.log('B: ', b)
console.log(b.has('test'))

PS: Just a reminder if you are not aware of it, don’t even try to test or add data on a Filter that are initialized with an empty set or array. It will cause RangeError: Maximum call stack size exceeded. T.from functions are used to initialize filters with predefined values. Otherwise use the classic constructor or the T.create function to initialize a filter of fixed size with desired error rate.

1reaction
Callidoncommented, Mar 2, 2021

The method exists for all classes in the package, but I think the latest rework might have removed the method from the definition files, which causes your TypeScript compiler to fail.

I can’t promise that we can provide a fix quickly, because we now have very little time to work on open source projects (sadly). But I will definitively look into it, because that 's a rather nasty bug !

Read more comments on GitHub >

github_iconTop Results From Across the Web

FabricJS object.set() gives not a function error when loading ...
After performing actions with fabric js, I convert the content of the canvas to json and save it to localstorage by calling saveAsJson()...
Read more >
Saving workbook using SaveSettings causes JSON ...
I am trying to save a workbook using my ASP.NET Core 6 backend API. The workbook is sent to a controller method on...
Read more >
How to print the json (pretty) response and also save as json
MissingMethodException: No signature of method: static groovy.json. ... prettyPrint() is applicable for argument types: ... not working.
Read more >
Class WorkBook | C# Excel API | IronXL - IronSoftware
Methods. Close(). Closes the workbook object. Once this has been called, no further operations, ... Returns null if the named worksheet would not...
Read more >
JSON Files - Spark 3.3.1 Documentation
Property Name Default Scope primitivesAsString false read prefersDecimal false read allowComments false read
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found