我在运行时加载JSON配置文件,并使用接口定义其预期结构:
interface EngineConfig {
pathplanner?: PathPlannerConfig;
debug?: DebugConfig;
...
}
interface PathPlannerConfig {
nbMaxIter?: number;
nbIterPerChunk?: number;
heuristic?: string;
}
interface DebugConfig {
logLevel?: number;
}
...
由于可以使用自动填充等功能,因此可以方便地访问各种属性。
问题:有没有一种方法可以使用此声明来检查我加载的文件的正确性?即我没有意外的属性?