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

include flow type definitions #2732

Open
bahmutov opened this Issue Nov 7, 2018 · 5 comments

Comments

4 participants
@bahmutov
Copy link
Collaborator

bahmutov commented Nov 7, 2018

It would be nice to ship at least basic Flow definitions in addition to TypeScript definitions. From my experiments, we can just add index.js.flow file for example to the NPM package, something like this

// to point flow at these type declarations in .flowconfig set
//
// [libs]
// node_modules/cypress/index.js.flow

// Mocha functions
declare function describe(name:string, callback:Function):void;
declare function before(callback:Function):void;
declare function beforeEach(callback:Function):void;
declare function it(name:string, callback:Function):void;
declare function after(callback:Function):void;
declare function afterEach(callback:Function):void;

// Cypress own types
declare interface subject {
  should(x: string, y: any): void;
  should('have.length', n: number): void
  // a lot more
}

declare interface cypress {
  visit(url: string): cypress;
  wrap(x: any): subject
  // a lot more
}

declare var cy: cypress

Then user projects has to include in .flowconfig

[ignore]

[include]

[libs]
node_modules/cypress/index.js.flow

[lints]

[options]

[strict]

and it gets IntelliSense and type checks

screen shot 2018-11-06 at 9 48 46 pm

Of course it is a lot of work to properly describe all available API functions and assertions, but if we get the ball rolling, users can contribute.

@k7n4n5t3w4rt

This comment has been minimized.

Copy link

k7n4n5t3w4rt commented Dec 9, 2018

This is a good idea.

@lukeapage

This comment has been minimized.

Copy link

lukeapage commented Dec 14, 2018

We have flow definitions we found on a gist and have been improving as we need to. I was going to contribute to flow-typed - as I believe is more normal for flow.

@bahmutov

This comment has been minimized.

Copy link
Collaborator

bahmutov commented Dec 14, 2018

I am thinking for now it would be a separate package we could quickly iterate on and accept user pull requests. User would be able to install it separately from Cypress to get Flow type definitions. Once it is mature (I am thinking passing cypress-example-kitchensink through the type linter is a good metric), we could start including the flow definitions with Cypress test runner itself

@lukeapage

This comment has been minimized.

Copy link

lukeapage commented Dec 14, 2018

I don’t think that is possible? Flow-typed copies the types locally. In our setup we even ignore all flow coming from node_modules and rely only on flow-typed since it’s faster

@lukeapage

This comment has been minimized.

Copy link

lukeapage commented Dec 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment