Skip to main content
deleted 24 characters in body
Source Link
VeganHunter
  • 6.1k
  • 2
  • 28
  • 26

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.

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).level2).level3 

plus, you can set a default value:

o(o(o(o(o(test).level1).level2).level3, "none") 

It works really well with IntelliSense in Visual Studio.

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(test).prop1).prop2 

plus, you can set a default value:

o(o(o(o(test).prop1).prop2, "none") 

It works really well with IntelliSense in Visual Studio.

added 6 characters in body
Source Link
VeganHunter
  • 6.1k
  • 2
  • 28
  • 26

As soon as I couldOperator ?. is not find anything like thatsupported in TypeScript, I 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).level2).level3 

plus, you can set a default value:

o(o(o(o(o(test).level1).level2).level3, "none") 

It works really well with IntelliSense in Visual Studio.

As soon as I could not find anything like that in TypeScript, 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).level2).level3 

plus, you can set a default value:

o(o(o(o(o(test).level1).level2).level3, "none") 

It works really well with IntelliSense in Visual Studio.

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).level2).level3 

plus, you can set a default value:

o(o(o(o(o(test).level1).level2).level3, "none") 

It works really well with IntelliSense in Visual Studio.

Source Link
VeganHunter
  • 6.1k
  • 2
  • 28
  • 26

As soon as I could not find anything like that in TypeScript, 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).level2).level3 

plus, you can set a default value:

o(o(o(o(o(test).level1).level2).level3, "none") 

It works really well with IntelliSense in Visual Studio.