Comments (8)
Yeah, we have some support for such things, but not entirely fleshed out. Try some like the following out and let's keep digging into what's missing.
declare class G {
x: number;
squared():number;
}
var Foo_: typeof G = Foo;
var c = new Foo_(0);
var y:string = c.squared();
This gives me a couple of type errors, which indicates that Flow is tracking the types around correctly:
funclass.js:4:37,42: number
This type is incompatible with
funclass.js:15:7,12: string
funclass.js:10:15,20: number
This type is incompatible with
funclass.js:15:7,12: string
Basically the trick is to use typeof to express the type of something for which you don't have surface syntax, but know that Flow may have an internal type representation.
from flow.
👍
It's incredibly hard to declare the type of a constructor function. I could not find any way to do it all; I tried everything from declare class
to declare function
to declare var
from flow.
Flow seems to understand @spicyj's original example now without any errors. Is there anything else remaining to be done here?
from flow.
can we have some examples of how to write a ES5 constructor and then how to write an declare block that declares it's type (preferably in one of those block comments that flow supports).
The use case here is to annotate a complex existing constructor with many methods using the unobtrusive block comment workflow.
from flow.
@Raynos It would be easier to start with what you have tried that didn't work. Can you share some code?
from flow.
@samwgoldman I can try and reproduce it; I worked on it a few weeks ago.
Let me update the thread with a breaking example tonight.
from flow.
@avikchaudhuri seems to have addressed @spicyj's original issue in 618186a. I think this can be closed.
from flow.
Yes, thanks!
from flow.
Related Issues (20)
- Include Hashbang in AST
- Bad error message with underconstrained-implicit-instantiation and function overload HOT 4
- Incorrect node location HOT 2
- Default value seems to be ignored
- Array.prototype.filter on non-refined nullable elements leads to unhelpful error message HOT 2
- Question about union/intersection types AST HOT 3
- Crash when parse hashbang with `{tokens: true}`
- Packages entry points support
- Cannot resolve module node:fs HOT 1
- Record types should refine Object.values HOT 2
- [flow-remove-types] doesn't remove some types HOT 1
- flow_parser.js file increased from 0.7M to 2.7M in v0.210 HOT 4
- `Omit` does not work well with unions HOT 3
- ☂️ Known unsoundness issues
- Partial type does not accept plain empty object literal as a default HOT 5
- Cannot return class type as T: Cannot return `root(...)` because a call signature declaring the expected parameter / return type is missing in `SomeModel` [1] but exists in function type [2].Flow(prop-missing) HOT 2
- 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
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.