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