Created
July 13, 2016 14:04
-
-
Save leonardfactory/aca9eb256e46b1e0c00ab8b3d9485022 to your computer and use it in GitHub Desktop.
Flow - Knex typing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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