Skip to content

Instantly share code, notes, and snippets.

@leonardfactory
Created July 13, 2016 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonardfactory/aca9eb256e46b1e0c00ab8b3d9485022 to your computer and use it in GitHub Desktop.
Save leonardfactory/aca9eb256e46b1e0c00ab8b3d9485022 to your computer and use it in GitHub Desktop.
Flow - Knex typing
// Flow definition
declare module 'knex' {
declare class SchemaBuilder {
...
createTable(name:string, fn:() => void): this;
}
declare class TableBuilder {
...
}
}
// Now calling the code like this:
knex.schema.createTable('users', function() {
/**
* Here flow should identify `this` as `TableBuilder`
*/
this.column('id').primary();
this.column('username');
});
/*
Here I can do `(this:TableBuilder)`, but I would like to know if there is a more elegant way :)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment