Operator ?. is not supported in TypeScript version 2.0.
So I use the following function:
export function o<T>(someObject: T, defaultValue: T = {} as T) : T { if (typeof someObject === 'undefined' || someObject === null) return defaultValue; else return someObject; } the usage looks like this:
o(o(o(o(test).level1).level2prop1).level3prop2 plus, you can set a default value:
o(o(o(o(o(test).level1).level2prop1).level3prop2, "none") It works really well with IntelliSense in Visual Studio.