予加載在運行時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) –