从第三方定义文件扩展接口
Extending an interface from a third party definition file
我在 Typescript 代码中使用 this 定义文件。问题是,根据 Sequelize 文档设置字符串列的长度,我应该将其类型定义为:
Sequelize.STRING(20)
并且当前的定义文件不允许这样做。它只允许 Sequelize.STRING
(默认列长度为 255)。
我想创建我自己的定义文件,修补(扩展)这个接口以便它支持这两种情况,或者至少将 Sequelize.STRING 设置为 any
这样我就不会得到编译器错误。
知道我应该怎么做吗?
修复于:
interface DataTypeString extends DataTypeStringBase {
(length?:number): any; // ADD this
}
PR + 测试将不胜感激:)
更新
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 代码中使用 this 定义文件。问题是,根据 Sequelize 文档设置字符串列的长度,我应该将其类型定义为:
Sequelize.STRING(20)
并且当前的定义文件不允许这样做。它只允许 Sequelize.STRING
(默认列长度为 255)。
我想创建我自己的定义文件,修补(扩展)这个接口以便它支持这两种情况,或者至少将 Sequelize.STRING 设置为 any
这样我就不会得到编译器错误。
知道我应该怎么做吗?
修复于:
interface DataTypeString extends DataTypeStringBase {
(length?:number): any; // ADD this
}
PR + 测试将不胜感激:)
更新
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