MasterScrat MasterScrat - 4 months ago 30
TypeScript Question

Check if an object implements an interface at runtime with TypeScript

I load a JSON configuration file at runtime, and use an interface to define its expected structure:

interface EngineConfig {
pathplanner?: PathPlannerConfig;
debug?: DebugConfig;

interface PathPlannerConfig {
nbMaxIter?: number;
nbIterPerChunk?: number;
heuristic?: string;

interface DebugConfig {
logLevel?: number;


This makes it convenient to access the various properties since I can use autocompletions etc.

Question: is there a way to use this declaration to check the correctness of the file I load? ie that I do not have unexpected properties?



Currently, types are used only during development and compile time. The type information is not translated in any way to the compiled JavaScript code.

From, as pointed out by @JasonEvans