Evgeniy Miroshnichenko
Evgeniy Miroshnichenko

Reputation: 1865

Error: Flow: WeakMap. Application of polymorphic type needs <list of 2 arguments>. (Can use `*` for inferrable ones)

I get error using this js code with Flow:

const _language: WeakMap = new WeakMap();

Error:(117, 18) Flow: WeakMap. Application of polymorphic type needs . (Can use * for inferrable ones)

I don't understand the cause of the error and how to fix it?

Upvotes: 0

Views: 279

Answers (1)

cbothner
cbothner

Reputation: 56

Since WeakMap can have any type of key and any type of value, Flow defines it using generics: https://github.com/facebook/flow/blob/v0.48.0/lib/core.js#L611

You can specify what types the key and value should be like this

const _language: WeakMap<string, number> = new WeakMap()

or let Flow infer the type from later usage

const _language: WeakMap<*, *> = new WeakMap()
_language.set('apple', 2)  // Flow can now figure out that _language is WeakMap<string, number>

Upvotes: 2

Related Questions