Extending an interface from a third party definition file

1.8k Views Asked by At

I'm using this definition file in my Typescript code. The problem is that, according to Sequelize documentation to set the length of a string column, I should define its type as:

 Sequelize.STRING(20)

and the current definition file doesn't allow this. It allows only Sequelize.STRING (which makes a default column length of 255).

I want to create my own definition file, patching (extending) this interface so that it supports both situations, or at least setting Sequelize.STRING as any so that I don't get compiler errors.

Any idea how should I do it?

1

There are 1 best solutions below

5
On BEST ANSWER

Fix at :

    interface DataTypeString extends DataTypeStringBase {
        (length?:number): any; // ADD this 
    }

A PR + TEST would be appreciated :)

Update

Would it be possible somehow to implement this in my own .d.ts file, extending the provided one?

FAILED ATTEMPT Untested but probably correct:

declare module "sequelize"
{
  module sequelize {
     interface DataTypeString {
            (length?:number): any;
     }
  }
} 

Update 2

Based on how the definition is currently written you can't extend it externally https://github.com/Microsoft/TypeScript/issues/2784