GithubHelp home page GithubHelp logo

Comments (8)

avikchaudhuri avatar avikchaudhuri commented on April 19, 2024

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.

Raynos avatar Raynos commented on April 19, 2024

👍

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.

samwgoldman avatar samwgoldman commented on April 19, 2024

Flow seems to understand @spicyj's original example now without any errors. Is there anything else remaining to be done here?

from flow.

Raynos avatar Raynos commented on April 19, 2024

@samwgoldman

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.

samwgoldman avatar samwgoldman commented on April 19, 2024

@Raynos It would be easier to start with what you have tried that didn't work. Can you share some code?

from flow.

Raynos avatar Raynos commented on April 19, 2024

@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.

samwgoldman avatar samwgoldman commented on April 19, 2024

@avikchaudhuri seems to have addressed @spicyj's original issue in 618186a. I think this can be closed.

from flow.

sophiebits avatar sophiebits commented on April 19, 2024

Yes, thanks!

from flow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.