Comments (4)
FWIW, you get a better error message if you pass in the --show-all-branches
flag in the CLI.
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ file.js:35:3
Cannot call c.query because: [incompatible-call]
• Either R [1] is underconstrained by call of method query [2]. Either add explicit type arguments or cast the
expression to your expected type.
• Or string [3], a primitive, cannot be used as a subtype of Submittable [4]. You can wrap it in new String(...)) to
turn it into an object and attempt to use it as a subtype of an interface.
[1] 25│ query<R>(
26│ config: string,
27│ ): Promise<ResultSet<R>>,
[4] 28│ query<Q: Submittable>(
29│ config: Q,
30│ ): Q,
31│ }
32│
33│ declare var c: Client;
34│
[2][3] 35│ c.query('SELECT 1');
36│ c.query({submit: () => undefined});
37│
Found 1 error
This form exposes the fact that both branches failed speculation, with explanation for each.
I guess because the
c.query({submit: () => undefined});
line worked without any type argument,
Just to make sure that the value added with LTI is clear here: Before (so selecting version 0.197 in the dropdown for example), if you had
c.query<_>('SELECT 1');
and hover over the _
, you'd notice the type empty
. We consider this behavior problematic because it is rather unlikely that one would want the inferred type for R to be compatible with any type at the same time (as is the case with empty
).
I can see some potential avenues for improvement:
- always show all branches in situations like this.
- make
[underconstrained-implicit-instantiation]
not be a fatal error for selecting the overload. This way we'd select the "right" overload (1st), but still error requesting an annotation forR
.
from flow.
The overload seems to lead to a worse error message, but even without the overload, this code will not work, because R
is underconstrained.
Either add explicit type arguments or cast the expression to your expected type.
Following this advice from the better error message fixes the error also in the presence of the overload.
from flow.
Thanks @darichey. It was indeed the error message that threw me off.
I guess because the c.query({submit: () => undefined});
line worked without any type argument, I didn't expect the string one to. I'm not familiar enough with the new system to understand why the second call doesn't require one.
from flow.
Flow needs to determine the types of type parameters at the call site. c.query('SELECT 1');
selects the first overload, but R
cannot be determined from this call alone. By contrast, c.query({submit: () => undefined});
selects the second overload in which Q
is determined by the argument. Here's a couple more examples.
But the error message is still bad!
from flow.
Related Issues (20)
- Does not narrow down type after undefined/falsy check HOT 1
- Recursive/deep Partial HOT 2
- Bugs in negated `instanceof` expressions HOT 1
- [Question]: How to fix flowgen test after flow update HOT 3
- [Discussion]: Any plans to make Flow more interpopble with TS ecosystem? HOT 5
- Higher order type parameter support HOT 1
- Readme links to 404
- Strange index signature error if you use $Keys<O> instead of the equivalent literal union inside $ReadOnlyArray HOT 1
- [homebrew] automation script needs update HOT 2
- "Unxepcted identifier, expected the token ;" when using await inside of ES module HOT 3
- Can't iterate through chars in a string HOT 4
- Flow does not catch invalid switch statements HOT 1
- Conditional type only works if I inline it HOT 5
- Object with null prototype does not extend interface {} HOT 3
- Missing documentation for "render-types"? HOT 2
- Relay + graphql literals HOT 11
- [homebrew] regression test failure with 0.226.0,0.227.0 HOT 2
- FLOW BUG: This is a misplaced error HOT 3
- The `experimental.ts_syntax` doesn’t seem to do anything HOT 2
- Parameters<> does not support optional params HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flow.