-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
saveAsJSON() method not found #20
Comments
When I look at the I do however see some logic related to |
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 ! |
@Callidon I think adding |
@stbrody Please, can you test the following branch? https://github.com/Callidon/bloom-filters/tree/fix_saveasjson |
@folkvir @Callidon, sorry I just got to looking at this again. I tried upgrading the package to version 1.3.2 and things are actually worse now. There's no longer a compilation error on
Looks like because fromJSON doesn't specify a return type the TS compiler assumes it returns nothing. It probably needs to specify that it returns a BloomFilter. I assume a similar problem most likely exists for |
Well, do you still have the issue with this PR? #22 |
Yeah, I guess that makes it a little better, but it would be nice not to have to cast at all. If |
I agree with your point of a non-casting obligation but BaseFilter is a super class defining seeding properties of every bloom filters. It does not have any specific method. So I need to find another method dealing with decorators and templates. |
@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
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 |
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:
The text was updated successfully, but these errors were encountered: