予加载在运行时JSON配置文件,并使用接口来定义它的预期结构的接口:检查是否一个对象实现在与打字稿运行时
interface EngineConfig {
pathplanner?: PathPlannerConfig;
debug?: DebugConfig;
...
}
interface PathPlannerConfig {
nbMaxIter?: number;
nbIterPerChunk?: number;
heuristic?: string;
}
interface DebugConfig {
logLevel?: number;
}
...
这使得方便的,因为访问的各种属性我可以使用自动完成等。
问题:有没有办法使用这个声明来检查我加载的文件的正确性?即我没有意想不到的属性?
仅供参考:[检测TypeScript动态中的对象实现接口](http://stackoverflow.com/questions/16013667/detect-whether-object-implement-interface-in-typescript-dynamicaly) –
可能的重复[使用Typescript检查接口类型](https://stackoverflow.com/questions/14425568/interface-type-check-with-typescript) –