我想切换到对我的 typescript 2.0 项目使用严格的空检查,但是我在输入我的一个依赖项的依赖项时遇到了一些困难(如果你愿意,可以依赖祖父母)。
更详细地说,我有依赖关系B
,C
它们都依赖于A
. 所有这些都是转译的 TS 项目,代码和类型都在一个lib
文件夹中,它们还没有切换到严格的空检查。
相关输入A
如下:
interface IInterface {
[key: string]: string;
}
两者都使用,B
如下C
所示:
import { IInterface } from 'A/lib/iinterface';
interface IExtended extends IInterface {
myOptionalProperty?: string
}
使用严格的空检查,这会产生以下编译错误:
node_modules/B/lib/extended.d.ts(4,3): error TS2411: Property 'myOptionalProperty' of type 'string | undefined' is not assignable to string index type 'string'
node_modules/C/lib/extended.d.ts(4,3): error TS2411: Property 'myOptionalProperty' of type 'string | undefined' is not assignable to string index type 'string'
那么问题是双重的:
为了遵守严格的检查,A 中的输入需要更改为:
interface IInterface { [key: string]: string | undefined; }
I am not sure if it is possible to override such a type, as this is not simply an extension of existing types. If possible, how is it done?
If possible, how should it be included such that the typings in
B
andC
are checked against my overridden typing, and not what is in their localnode_modules
directory?