我正在使用 this我的 Typescript 代码中的定义文件。问题是,根据 Sequelize 文档设置字符串列的长度,我应该将其类型定义为:
Sequelize.STRING(20)
并且当前的定义文件不允许这样做。它只允许
Sequelize.STRING
(这使得默认列长度为 255)。我想创建自己的定义文件,修补(扩展)这个接口(interface),使其支持这两种情况,或者至少将 Sequelize.STRING 设置为
any
这样我就不会收到编译器错误。知道我该怎么做吗?
最佳答案
修复:
interface DataTypeString extends DataTypeStringBase {
(length?:number): any; // ADD this
}
PR + TEST 将不胜感激:)
更新
Would it be possible somehow to implement this in my own .d.ts file, extending the provided one?
尝试失败
未经测试但可能正确:
declare module "sequelize"
{
module sequelize {
interface DataTypeString {
(length?:number): any;
}
}
}
更新 2
根据当前定义的编写方式,您无法在外部扩展它https://github.com/Microsoft/TypeScript/issues/2784
关于typescript - 从第三方定义文件扩展接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30899319/